收藏
回答

微信商户开户意愿 -提交申请单API

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的????!!!




回答关注问题邀请回答
收藏

2 个回答

  • h.b
    h.b
    2020-06-28

    请问一下大佬,我也遇到这个问题,应该怎么解决

    2020-06-28
    有用
    回复
  • 微信支付技术助手8
    微信支付技术助手8
    2020-03-19

    添加一下wepayTS8(备注:微信社区XXX问题)

    2020-03-19
    有用
    回复 3
    • 木鱼
      木鱼
      2020-03-19
      申请了
      2020-03-19
      回复
    • 木鱼
      木鱼
      2020-03-19
      加了也没人同意,能解决问题么
      2020-03-19
      回复
    • 壹苆隨緣
      壹苆隨緣
      2020-09-17
      有demo或者sdk吗?
      2020-09-17
      回复
登录 后发表内容
问题标签