APIcloud微信支付和支付宝支付(方案2,主要在后台进行)
支付宝代码
var aliPay = api.require('aliPay');
api.ajax({
url: yuming+'index.php/api/Alipay/getOrder',
method: 'post',
data:{values: {
'user_id':$api.getStorage('id'),'totalfee':totalfee,house_id:$api.getStorage('fid'),user_payment_type:user_payment_type,user_payment_type_id:user_payment_type_id,count:$api.dom('#num').value
}}
}, function(rets) {
// alert(JSON.stringify(rets));
aliPay.payOrder({
orderInfo: rets.str
}, function(ret, err) {
if(ret.status)
{
$api.dom('#chongzhi2').style.display='none';
//
$api.setStorage('tiaoshu',0)
api.alert({
title: '',
msg: '支付成功',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
/////////
api.ajax({
url: yuming+ 'index.php/api/History/addHistory/',
method: 'post',
data:{values: {
'house_id':$api.getStorage('fid'),'user_id':$api.getStorage('id')
}}
}, function(ret) {
var jsfun = 'shuaxin();';
api.execScript({
name: 'root',
frameName: 'frame3',
script: jsfun
});
})
}
else
{
api.alert({
title: '',
msg: '付款失败',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
jfk=0;
$api.dom('#qrfk').innerText='确认付款'
}
});
});
微信支付代码
var wx = api.require('wx');
var wxPay = api.require('wxPay');
wx.auth({
apiKey: ''
}, function(ret, err) {
if (ret.status) {
var code = ret.code;
wx.getToken({
apiKey: '',
apiSecret: '',
code: code
}, function(ret, err) {
if (ret.status) {
api.ajax({
url: yuming+'index.php/api/weixin/getOrder',
method: 'post',
data:{values: {
'openid':ret.openId,'user_id':$api.getStorage('id'),'totalfee':totalfee,house_id:$api.getStorage('fid'),user_payment_type:user_payment_type,user_payment_type_id:user_payment_type_id,count:$api.dom('#num').value
}}
}, function(rets) {
wxPay.payOrder({
apiKey: rets.return.apiKey,
orderId: rets.return.orderId,
mchId: rets.return.mchId,
nonceStr: rets.return.nonceStr,
timeStamp: rets.return.timeStamp,
package: rets.return.package,
sign: rets.return.sign,
}, function(ret, err) {
if (ret.status) {
$api.dom('#chongzhi2').style.display='none';
//
$api.setStorage('tiaoshu',0)
api.alert({
title: '',
msg: '支付成功',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
///////////
api.ajax({
url: yuming+ 'index.php/api/History/addHistory/',
method: 'post',
data:{values: {
'house_id':$api.getStorage('fid'),'user_id':$api.getStorage('id')
}}
}, function(ret) {
var jsfun = 'shuaxin();';
api.execScript({
name: 'root',
frameName: 'frame3',
script: jsfun
});
})
} else {
api.alert({
title: '',
msg: '付款失败',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
jfk=0;
$api.dom('#qrfk').innerText='确认付款'
}
});
});
} else {
api.alert({
title: '',
msg: '付款失败',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
$api.dom('#qrfk').innerText='确认付款'
}
});
} else {
api.alert({
title: '',
msg: '付款失败',
buttons:[ '确定']
},function(ret,err){
if(ret.buttonIndex == 1){
return;
}
});
$api.dom('#qrfk').innerText='确认付款'
}
});
}
}
}
}
})
})
}
})