• 记一次小程序支付开发的坑,超级坑


    经过一周的加班加点开发,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);
        }

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

  • 相关阅读:
    java(样品集成框架spring、spring mvc、spring data jpa、hibernate)
    设定十分钟android在状态栏上集成的开源project推荐
    分析javascript关闭
    排列-条件求和(Code)
    Leetcode: Remove Duplicates from Sorted Array
    怎样将baidu地图中的baidu logo 去掉
    Android自适应不同屏幕几种方法
    浏览器兼容性问题解决方式
    XMPP入门
    “聊天剽窃手”--ptrace进程注入型病毒
  • 原文地址:https://www.cnblogs.com/syscn/p/7644458.html
Copyright © 2020-2023  润新知