微信支付调用API
$.ajax({
contentType: "application/x-www-form-urlencoded", ?
url: URL + "", ? //請求的url地址
dataType: "json", ? //返回格式為json
headers:{"userId":userId},
data:{"url":url1}, ??
async: true, //請求是否異步,默認(rèn)為異步,這也是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, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會(huì)在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會(huì)通過log打出,僅在pc端時(shí)才會(huì)打印。
? ? appId: appId, // 必填,公眾號(hào)的唯一標(biāo)識(shí)
? ? timestamp: timeStamp, // 必填,生成簽名的時(shí)間戳
? ? nonceStr: nonceStr, // 必填,生成簽名的隨機(jī)串
? ? signature: signature,// 必填,簽名,見附錄1
? ? jsApiList: ["chooseWXPay"] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
});
wx.ready(function(){
wx.chooseWXPay({
appId: appId,
? ? timestamp: timeStamp, // 支付簽名時(shí)間戳,注意微信jssdk中的所有使用timestamp字段均為小寫。但最新版的支付后臺(tái)生成簽名使用的timeStamp字段名需大寫其中的S字符
? ? nonceStr: nonceStr, // 支付簽名隨機(jī)串,不長于 32 位
? ? package: packages, // 統(tǒng)一支付接口返回的prepay_id參數(shù)值,提交格式如:prepay_id=***)
? ? signType: signType, // 簽名方式,默認(rèn)為'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, //請求是否異步,默認(rèn)為異步,這也是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;
});
contentType: "application/x-www-form-urlencoded", ?
url: URL + "", ? //請求的url地址
dataType: "json", ? //返回格式為json
headers:{"userId":userId},
data:{"url":url1}, ??
async: true, //請求是否異步,默認(rèn)為異步,這也是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, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會(huì)在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會(huì)通過log打出,僅在pc端時(shí)才會(huì)打印。
? ? appId: appId, // 必填,公眾號(hào)的唯一標(biāo)識(shí)
? ? timestamp: timeStamp, // 必填,生成簽名的時(shí)間戳
? ? nonceStr: nonceStr, // 必填,生成簽名的隨機(jī)串
? ? signature: signature,// 必填,簽名,見附錄1
? ? jsApiList: ["chooseWXPay"] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
});
wx.ready(function(){
wx.chooseWXPay({
appId: appId,
? ? timestamp: timeStamp, // 支付簽名時(shí)間戳,注意微信jssdk中的所有使用timestamp字段均為小寫。但最新版的支付后臺(tái)生成簽名使用的timeStamp字段名需大寫其中的S字符
? ? nonceStr: nonceStr, // 支付簽名隨機(jī)串,不長于 32 位
? ? package: packages, // 統(tǒng)一支付接口返回的prepay_id參數(shù)值,提交格式如:prepay_id=***)
? ? signType: signType, // 簽名方式,默認(rèn)為'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, //請求是否異步,默認(rèn)為異步,這也是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;
});
總結(jié)
- 上一篇: 前端知识二
- 下一篇: 2022年最新垃圾分类小程序,含图片识别