1 图片上传post ok, 签名Ok,返回正常
2 提交申请单api,同样的方法拼装json,返回:
{"code":"SIGN_ERROR","detail":{"detail":{"issue":"sign not match"},"field":"signature","location":"authorization","sign_information":{"method":"POST","sign_message_length":78,"truncated_sign_message":"POST\n/v3/apply4subject/applyment\n1584584235\nWQeqUDrJOmM073PJLJhk2T0B0jDmpNze\n\n","url":"/v3/apply4subject/applyment"}},"message":"错误的签名,验签失败"}
方法:
public static String getAuthorization(String method, HttpUrl url, String body, PrivateKey yourPrivateKey, String yourMerchantId, String yourCertificateSerialNo) throws Exception {
String nonceStr = generateNonceStr();
long timestamp = System.currentTimeMillis() / 1000;
String message = buildMessage(method, url, timestamp, nonceStr, body);
System.out.println("message===="+message);
String signature = sign(message.getBytes("utf-8"),yourPrivateKey);
System.out.println("SHA256withRSA签名是:"+signature);
return schema+" "+"mchid=\"" + yourMerchantId + "\","
+ "nonce_str=\"" + nonceStr + "\","
+ "timestamp=\"" + timestamp + "\","
+ "serial_no=\"" + yourCertificateSerialNo + "\","
+ "signature=\"" + signature + "\"";
}
private static String buildMessage(String method, HttpUrl url, long timestamp, String nonceStr, String body) {
String canonicalUrl = url.encodedPath();
if (url.encodedQuery() != null) {
canonicalUrl += "?" + url.encodedQuery();
}
return method + "\n"
+ canonicalUrl + "\n"
+ timestamp + "\n"
+ nonceStr + "\n"
+ body + "\n";
}
private static String sign(byte[] message, PrivateKey yourPrivateKey) throws Exception {
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initSign(yourPrivateKey);
sign.update(message);
return Base64.getEncoder().encodeToString(sign.sign());
}
message====打印信息为:
message====POST
/v3/apply4subject/applyment
1584584235
WQeqUDrJOmM073PJLJhk2T0B0jDmpNze
{"business_code":"1111111111"}
s所以 为什么官方返回的truncated_sign_message 标签 里在,签名是没有body的????!!!
请问一下大佬,我也遇到这个问题,应该怎么解决
添加一下wepayTS8(备注:微信社区XXX问题)