87,984
社区成员
发帖
与我相关
我的任务
分享function pay(openId) {
debug:true;
alert("进来了1");
wx.ready(function() {
debug:true;
alert("进来了2");
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
$("input[name='weixinpay']").on('click', function(t) {
alert("进来了3");
var n = parseInt($(this).attr("money"));
$.ajax({
type : 'POST',
url : "http://www.yiquanmian.com/Unifiedorder?openId="+openId+"&money="+n,
success : function(response) {
var params = eval("(" + response + ")");
if (params.result_code == "SUCCESS"
&& params.return_code == "SUCCESS"
) {
wx.chooseWXPay({
timestamp :parseInt(params.timeStamp), // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr : params.nonceStr, // 支付签名随机串,不长于 32 位
package : params["package"], // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
signType : params.signType,
paySign : params.paySign,
success : function(res) {
//alert('success');
paysuccess(params.order_id,params.totalmoney,params.product_id);
},
cancel: function (res) {
//alert('cancel');
paycancel(params.order_id,params.totalmoney,params.product_id);
},
fail:function(res){
payfailure(params.order_id,params.totalmoney,params.product_id);
}
});
} else {
alert("支付请求失败,PREPAY_ID为空!");
}
},
error : function() {
alert("服务器异常,统一下单接口出错!");
}
})
});
});
}