zoukankan      html  css  js  c++  java
  • 【支付签名失败问题】

    /**
    * 每次返回【支付签名失败问题】
     * 
     * 解决:
     *   1,签名方式使用微信sdk提供的加密方式
     *   2, result.put("nonceStr",unifiedorder.get("nonce_str"));  随机字符串需要使用微信下单后反给我们的字符串 自己生成的无效
     *   3,微信单号          result.put("package","prepay_id="+unifiedorder.get("prepay_id"));  需要按照文档拼接
     *   4,加密方式需要四个参数就可以 
     *   【
     *         result.put("appId",unifiedorder.get("appid"));
     *         result.put("timeStamp",WXPayUtil.getCurrentTimestamp()+"");
     *         result.put("signType",WXPayConstants.SignType.HMACSHA256.toString());
     *         result.put("package","prepay_id="+unifiedorder.get("prepay_id"));
     *         result.put("nonceStr",unifiedorder.get("nonce_str"));
     *     】
     *    5,加密方式  final WXPay wxPay = new WXPay(wxPayConfig); 默认加密方式是 HMACSHA256
     *    6,下单的加密方式和支付的加密方式需要保持一直
     */

    支付需要这几个参数就可以

            result.put("appId",unifiedorder.get("appid"));
            result.put("timeStamp",WXPayUtil.getCurrentTimestamp()+"");
            result.put("signType",WXPayConstants.SignType.HMACSHA256.toString());
            result.put("package","prepay_id="+unifiedorder.get("prepay_id"));
            result.put("nonceStr",unifiedorder.get("nonce_str"));
            final String sign = WXPayUtil.generateSignature(result, "vG8xK6oH4fP3yN0sY1oH9HH2PK4tJ8xK", WXPayConstants.SignType.HMACSHA256);
            result.put("paySign", sign);

    前段代码,需要使用微信的内置浏览器打开,如果需支付完成流程,那么需要在微信中配置所需要的参数。

    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>支付</title>
    </head>
    <body>
    dsffsadfsdf
    <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=20_1">微信支付签名方式</a>
    <input th:text="${map}"/>
    <script>
       // let newVar = "[[${map}]]";
    
        function onBridgeReady(){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId":"[[${appId}]]",     //公众号名称,由商户传入
                    "timeStamp":"[[${timeStamp}]]",         //时间戳,自1970年以来的秒数
                    "nonceStr":"[[${nonceStr}]]", //微信下单返回随机串
                    "package":"[[${package}]]",
                    "signType":"[[${signType}]]",         //微信签名方式:
                    "paySign":"[[${paySign}]]" //微信签名
                },
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ){
                        // 使用以上方式判断前端返回,微信团队郑重提示:
                        //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
                    }
                });
        }
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    </script>
    </body>
    </html>

    使用自己测试的地址,会提示  没有配置这个支付地址

  • 相关阅读:
    java poi 从服务器下载模板写入数据再导出
    一个华为面试题
    ForEach 循环
    fmt标签格式化数字和时间
    Ichars制作数据统计图
    jQuery中的事件
    oracle学习第四天
    GET请求和POST请求
    Jsp的九个隐含对象
    Oracle学习【语句查询】
  • 原文地址:https://www.cnblogs.com/renjianjun/p/14306629.html
Copyright © 2011-2022 走看看