zoukankan      html  css  js  c++  java
  • 记一次小程序支付开发的坑,超级坑

    经过一周的加班加点开发,xxx有机商城小程序终于接近尾声,来到支付这一块了。由于用户的域名备案问题(小程程上线必须要域名)还没申请下来,只好暂且使用公司域名调试

    万事俱备,只欠东风。微信小程序支付。省略申请时间。。。。。。。。

    着手开发支付。。。。。

    1 获取用户openid正常

    2 微信支付统一下单正常(签名正常)

    3 小程序再次加密返回正常(签名正常)

      各项参数都正常

    可就是付款不成功,报签名错误。

    后来打电话询问腾讯微信支付客服,说也不知道怎么解决,后来他们给我发了个短信,里面有个网址 http://developers.weixin.qq.com 微信开发者社区,。

    我就抱着试试看的心态去打开这个网址,经过不懈的寻找奋斗,终于发现有个人和我的问题一样。

    他也是使用微信支付com.github.wxpay.sdk来开发的。

    在WXpay.java有这么一个构造方法

    public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport, final boolean useSandbox) throws Exception {
            this.config = config;
            this.notifyUrl = notifyUrl;
            this.autoReport = autoReport;
            this.useSandbox = useSandbox;
            if (useSandbox) {
                this.signType = SignType.MD5; // 沙箱环境
            }
            else {
               this.signType = SignType.HMACSHA256;
            }
            this.wxPayRequest = new WXPayRequest(config);
        }

    微信支付sdk默认不是在沙箱环境里执行的,所以统一下单支付签名不是md5,而目前小程序的签名必须是md5,由于两者签名不统一导致小程序支付失败,报签名错误。

    既然找到原因了,那就好解决了,只需签名换成md5即可。

     public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport, final boolean useSandbox) throws Exception {
            this.config = config;
            this.notifyUrl = notifyUrl;
            this.autoReport = autoReport;
            this.useSandbox = useSandbox;
            if (useSandbox) {
                this.signType = SignType.MD5; // 沙箱环境
            }
            else {
               // this.signType = SignType.HMACSHA256;
                this.signType = SignType.MD5; 
            }
            this.wxPayRequest = new WXPayRequest(config);
        }

    到此大功告成。支付测试顺利通过。

  • 相关阅读:
    2019 SDN上机第5次作业
    iOS 多线程
    安装pygame
    五分钟学会ios反编译
    反编译ipa包
    Flutter 混合开发(一)
    iOS开发-block异步实现return
    Mac下Anaconda的安装和使用
    挣值分析
    【PMP】挣值分析
  • 原文地址:https://www.cnblogs.com/syscn/p/7644458.html
Copyright © 2011-2022 走看看