苹果支付引入
This commit is contained in:
@@ -258,8 +258,7 @@ export default {
|
||||
// console.log(this.radioValue)
|
||||
},
|
||||
iphonepay() {
|
||||
const that = this;
|
||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
||||
const that = this;
|
||||
console.log("检测支付环境...");
|
||||
plus.payment.getChannels((channels) => {
|
||||
console.log(channels, "channels");
|
||||
@@ -281,9 +280,13 @@ export default {
|
||||
console.log(that.stepsCj.priceTypeId, 88888888);
|
||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||
let IAPOrders = [];
|
||||
IAPOrders.push(that.stepsCj.priceTypeId + "");
|
||||
console.log(IAPOrders, "IAPOrders");
|
||||
IAPOrders.push('Z'+that.stepsCj.priceTypeId);
|
||||
// console.log(IAPOrders, "IAPOrders");
|
||||
// 新建订单
|
||||
uni.showLoading({
|
||||
title: "正在创建订单",
|
||||
mask: true,
|
||||
});
|
||||
that.iapChannel.requestOrder(
|
||||
IAPOrders,
|
||||
function (event) {
|
||||
@@ -306,16 +309,15 @@ export default {
|
||||
},
|
||||
topay(id) {
|
||||
const that = this;
|
||||
uni.hideLoading();
|
||||
uni.showLoading({
|
||||
title: "正在支付",
|
||||
mask: true,
|
||||
});
|
||||
// if(this.chargeOrderSn != '' || this.chargeOrderSn != undefined){ // 判断是不是二次支付的订单
|
||||
// that.orderSn = this.chargeOrderSn
|
||||
// console.log(that.orderSn,'二次支付的订单号')
|
||||
// }
|
||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
||||
this.setUserInfo({
|
||||
restoreFlag: true,
|
||||
});
|
||||
console.log(this.userInfo, "更新后的用户信息");
|
||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
||||
plus.payment.request(
|
||||
that.iapChannel,
|
||||
{
|
||||
@@ -330,17 +332,21 @@ export default {
|
||||
that.iapCheck(result);
|
||||
},
|
||||
function (e) {
|
||||
console.log("错误回调", e);
|
||||
if (e.errCode == 2) {
|
||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
||||
plus.runtime.openURL("https://apps.apple.com/account/billing");
|
||||
} else {
|
||||
// restoreFlag = false; // 支付失败清楚标记
|
||||
that.finishTransaction(result);
|
||||
//console.log('订单关闭后的用户信息', that.userInfo);
|
||||
console.log(e);
|
||||
//console.log(e.message)
|
||||
}
|
||||
// that.checking = false
|
||||
console.log("错误回调", e);
|
||||
if (e.code == 2) {
|
||||
uni.showToast({
|
||||
title:'取消支付,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title:'支付失败,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
console.log('其他支付错误',e);
|
||||
}
|
||||
that.restoreComplateRequest()
|
||||
}
|
||||
);
|
||||
},
|
||||
@@ -350,12 +356,12 @@ export default {
|
||||
let data = {
|
||||
transactionId: result.transactionIdentifier, // 支付交易id
|
||||
customerOid: that.userInfo.id,
|
||||
productId: result.payment.productid, // 产品id
|
||||
productId: result.payment.productid.slice(1), // 产品id
|
||||
orderId: result.payment.username, // 系统订单号
|
||||
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
};
|
||||
console.log(data, "data");
|
||||
console.log("提交给后台的数据",data);
|
||||
$http
|
||||
.request({
|
||||
url: "/Ipa/veri",
|
||||
@@ -369,32 +375,31 @@ export default {
|
||||
.then((res) => {
|
||||
console.log(JSON.stringify(res));
|
||||
if (res.code == 0) {
|
||||
//uni.hideLoading()
|
||||
that.userInfo.restoreFlag == true
|
||||
? that.setUserInfo({
|
||||
restoreFlag: false,
|
||||
})
|
||||
: "";
|
||||
console.log(that.userInfo.restoreFlag);
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:'充值成功!',
|
||||
icon:'success'
|
||||
})
|
||||
console.log("充值订单已处理,请留意账户金额变动....");
|
||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
content:
|
||||
"支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服",
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击确定");
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
uni.hideLoading()
|
||||
console.log('后台验证失败=>',e);
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
content: "支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服",
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击确定");
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
)},
|
||||
getDevName() {
|
||||
// 获取使用环境
|
||||
if (uni.getSystemInfoSync().platform === "android") {
|
||||
|
||||
Reference in New Issue
Block a user