微信支付调用API

xiaoxiao2021-02-28  45

$.ajax({ contentType: "application/x-www-form-urlencoded",   url: URL + "",   //请求的url地址 dataType: "json",   //返回格式为json headers:{"userId":userId}, data:{"url":url1},    async: true, //请求是否异步,默认为异步,这也是ajax重要特性 type: "POST",  success: function(result) { var m = result.data; signature = m.signature; appId = m.appId; timeStamp = m.timeStamp; nonceStr = m.nonceStr; packages = n.packages; signType = n.signType; paySign = n.paySign; } })*/ wx.config({     //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。     appId: appId, // 必填,公众号的唯一标识     timestamp: timeStamp, // 必填,生成签名的时间戳     nonceStr: nonceStr, // 必填,生成签名的随机串     signature: signature,// 必填,签名,见附录1     jsApiList: ["chooseWXPay"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ wx.chooseWXPay({ appId: appId,     timestamp: timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符     nonceStr: nonceStr, // 支付签名随机串,不长于 32 位     package: packages, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)     signType: signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'     paySign: paySign, // 支付签名         success: function (res) { $.ajax({     contentType: "application/x-www-form-urlencoded",       url: URL + "wxpay/notify",  //请求的url地址     dataType: "json",   //返回格式为json headers:{"userId":userId}, data:{"orderId":orderid},        async: true, //请求是否异步,默认为异步,这也是ajax重要特性     type: "POST",  success: function(result) { /*var m = result.data; if(m=="PAID") { new TipBox({type:'success',str:'支付成功',setTime:2000,hasBtn:true});} else if(m=="NOPAY") {new TipBox({type:'error',str:'支付失败!',clickDomCancel:true,setTime:1000,hasBtn:true});}*/ document.location.href ="order_detail.html?=" + orderid; } })     }, error:function(res){ if(res.errMsg == "chooseWXPay:fail" )  document.location.href ="order_detail.html?=" + orderid; } }); }); wx.error(function(res){ document.location.href ="order_detail.html?=" + orderid; });
转载请注明原文地址: https://www.6miu.com/read-77926.html

最新回复(0)