Skip to content

Commit 219a8f4

Browse files
authored
🎨 #3620 【小程序】修复同城配送API签名错误问题(添加RSA私钥序列号到签名payload和请求头)
1 parent cd4317a commit 219a8f4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ public String postWithSignature(String url, JsonObject jsonObject) throws WxErro
912912
String rndStr = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
913913
String aesKey = this.getWxMaConfig().getApiSignatureAesKey();
914914
String aesKeySn = this.getWxMaConfig().getApiSignatureAesKeySn();
915+
String rsaKeySn = this.getWxMaConfig().getApiSignatureRsaPrivateKeySn();
916+
if (rsaKeySn == null || rsaKeySn.isEmpty()) {
917+
throw new SecurityException("ApiSignatureRsaPrivateKeySn不能为空,请检查配置");
918+
}
915919

916920
jsonObject.addProperty("_n", rndStr);
917921
jsonObject.addProperty("_appid", appId);
@@ -956,7 +960,7 @@ public String postWithSignature(String url, JsonObject jsonObject) throws WxErro
956960
String requestJson = reqData.toString();
957961

958962
// 计算签名 RSA
959-
String payload = urlPath + "\n" + appId + "\n" + timestamp + "\n" + requestJson;
963+
String payload = urlPath + "\n" + appId + "\n" + timestamp + "\n" + rsaKeySn + "\n" + requestJson;
960964
byte[] dataBuffer = payload.getBytes(StandardCharsets.UTF_8);
961965
RSAPrivateKey priKey;
962966
try {
@@ -985,6 +989,7 @@ public String postWithSignature(String url, JsonObject jsonObject) throws WxErro
985989
header.put("Wechatmp-Signature", signatureString);
986990
header.put("Wechatmp-Appid", appId);
987991
header.put("Wechatmp-TimeStamp", String.valueOf(timestamp));
992+
header.put("Wechatmp-Serial", rsaKeySn);
988993
log.debug("发送请求uri:{}, headers:{}, postData:{}", url, header, requestJson);
989994
WxMaApiResponse response =
990995
this.execute(ApiSignaturePostRequestExecutor.create(this), url, header, requestJson);

0 commit comments

Comments
 (0)