Skip to content

统一下单签名值与返回值不一致 #284

Closed

Description

@ivancxj

https://github.com/Wechat-Group/weixin-java-tools/blob/master/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImpl.java#L203
WxPayServiceImpl的200行-213行

      configMap.put("prepayid", prepayId);
      configMap.put("partnerid", partnerid);
      configMap.put("package", "Sign=WXPay");
      configMap.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
      configMap.put("noncestr", String.valueOf(System.currentTimeMillis()));
      configMap.put("appid", appId);
      // 此map用于客户端与微信服务器交互
      payInfo.put("sign", SignUtils.createSign(configMap, this.getConfig().getMchKey()));
      payInfo.put("prepayId", prepayId);
      payInfo.put("partnerId", partnerid);
      payInfo.put("appId", appId);
      payInfo.put("packageValue", "Sign=WXPay");
      payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
      payInfo.put("nonceStr", String.valueOf(System.currentTimeMillis()));

在configMap生成签名需要字段timestamp和noncestr是实时生成,但是返回的时候payInfo又重新生成一个新的,实际签名用两个字段与返回的不一致,导致客户端签名失败
可以改成

      String timestamp =  String.valueOf(System.currentTimeMillis() / 1000);
      String nonceStr =  String.valueOf(System.currentTimeMillis());
      configMap.put("prepayid", prepayId);
      configMap.put("partnerid", partnerid);
      configMap.put("package", "Sign=WXPay");
      configMap.put("timestamp", timestamp); // 同一个timestamp
      configMap.put("noncestr", nonceStr); // 同一个nonceStr
      configMap.put("appid", appId);
      // 此map用于客户端与微信服务器交互
      payInfo.put("sign", SignUtils.createSign(configMap, this.getConfig().getMchKey()));
      payInfo.put("prepayId", prepayId);
      payInfo.put("partnerId", partnerid);
      payInfo.put("appId", appId);
      payInfo.put("packageValue", "Sign=WXPay");
      payInfo.put("timeStamp", timestamp); // 同一个timestamp
      payInfo.put("nonceStr", nonceStr); // 同一个nonceStr

Activity

  1. binarywang commented on Jul 20, 2017

    @binarywang
    Owner

    这可能是个问题, @DDLeEHi 能帮忙确认下吗?

  2. added a commit that references this issue on Jul 20, 2017
  3. DDLeEHi commented on Jul 21, 2017

    @DDLeEHi

    原来代码是可以调起支付的(已测),这个点可以说是代码优化,原来写的时候没注意去暂存时间戳跟随机字符串

  4. binarywang commented on Aug 1, 2017

    @binarywang
    Owner

    2.7.7.BETA已修复

  5. added a commit that references this issue on Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions