苹果内购+订单结算页面条件编译
This commit is contained in:
@@ -103,6 +103,7 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
checking : false,
|
||||
playData: {},
|
||||
options: {},
|
||||
xieyi: {
|
||||
@@ -180,29 +181,52 @@
|
||||
//方法
|
||||
methods: {
|
||||
...mapMutations(["setUserInfo"]),
|
||||
// 查询未关闭iap订单
|
||||
async restoreComplateRequest() {
|
||||
let that = this
|
||||
console.log('检测未完成订单')
|
||||
// if (!that.checking) {
|
||||
// that.checking = true
|
||||
// console.log(this.iapChannel, 'this.iapChannel')
|
||||
await this.iapChannel.restoreComplateRequest({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
// console.log(that.checking)
|
||||
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证
|
||||
that.ComplateRequestArr = results
|
||||
console.log('未完成订单数组共有:=》',that.ComplateRequestArr.length )
|
||||
if (results && results.length > 0) {
|
||||
results.map((item, index) => {
|
||||
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
|
||||
if (item.transactionState == '1') {
|
||||
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
|
||||
that.iapCheck('未完成订单的验证',item, index)
|
||||
// that.finishTransaction(item)
|
||||
} else if(item.transactionState != '1' || item.transactionState != '0') {
|
||||
// 不是正在支付订单,也不是已经支付订单就关闭掉
|
||||
// 其他状态的内购订单
|
||||
that.finishTransaction(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
// }
|
||||
|
||||
},
|
||||
// 关闭交易订单
|
||||
finishTransaction(trans) {
|
||||
this.iapChannel.finishTransaction(
|
||||
trans,
|
||||
(success) => {
|
||||
console.log("关闭订单成功");
|
||||
this.setUserInfo({
|
||||
restoreFlag: false
|
||||
});
|
||||
console.log("关闭订单成功");
|
||||
},
|
||||
(fail) => {
|
||||
console.log("关闭订单失败");
|
||||
}
|
||||
);
|
||||
},
|
||||
async showXieyi() {
|
||||
|
||||
// this.$http.get(`sys/agreement/list?key=pay`).then((res) => {
|
||||
// this.xieyi = res.page.list[0];
|
||||
// this.xieyiShow = true;
|
||||
// });
|
||||
|
||||
|
||||
async showXieyi() {
|
||||
var data = await this.$commonJS.getAgreement(106);
|
||||
if (data.content) {
|
||||
data.content = data.content.replace(
|
||||
@@ -231,17 +255,41 @@
|
||||
}
|
||||
// console.log(this.radioValue)
|
||||
},
|
||||
iphonepay() {
|
||||
async iphonepay() {
|
||||
const that = this;
|
||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
||||
console.log("检测支付环境...");
|
||||
plus.payment.getChannels((channels) => {
|
||||
uni.showLoading({
|
||||
title:'检测支付环境'
|
||||
})
|
||||
// console.log("检测支付环境...");
|
||||
plus.payment.getChannels(async (channels) => {
|
||||
console.log(channels, "channels");
|
||||
for (var i in channels) {
|
||||
// 判断是否苹果支付1
|
||||
for (var i in channels) {
|
||||
if (channels[i].id === "appleiap") {
|
||||
that.iapChannel = channels[i];
|
||||
that.requestOrder();
|
||||
// 先检测有没有未完成的订单
|
||||
uni.showLoading({
|
||||
title:'检测历史订单'
|
||||
})
|
||||
await that.restoreComplateRequest()
|
||||
var timer = setInterval(()=>{
|
||||
console.log('检测历史订单数量');
|
||||
that.iapChannel.restoreComplateRequest({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
if(results.length > 0){
|
||||
console.log('未处理订单还存在,继续轮询...');
|
||||
}else{
|
||||
console.log('没有历史订单,开始请求新订单..');
|
||||
that.requestOrder();
|
||||
clearInterval(timer)
|
||||
console.log('timer清除了吗',timer);
|
||||
}
|
||||
})
|
||||
},1000)
|
||||
// console.log('that.checking',that.checking)
|
||||
/// 限制调用
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -251,13 +299,17 @@
|
||||
title: "获取商品信息",
|
||||
mask: true,
|
||||
});
|
||||
const that = this;
|
||||
const that = this;
|
||||
console.log(that.stepsCj.priceTypeId, 88888888);
|
||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||
let IAPOrders = [];
|
||||
IAPOrders.push(that.stepsCj.priceTypeId + "");
|
||||
IAPOrders.push("p"+that.stepsCj.priceTypeId);
|
||||
console.log(IAPOrders, "IAPOrders");
|
||||
// 新建订单
|
||||
uni.showLoading({
|
||||
title: "正在创建订单",
|
||||
mask: true,
|
||||
});
|
||||
that.iapChannel.requestOrder(
|
||||
IAPOrders,
|
||||
function(event) {
|
||||
@@ -279,17 +331,11 @@
|
||||
);
|
||||
},
|
||||
topay(id) {
|
||||
const that = this;
|
||||
uni.hideLoading();
|
||||
// if(this.chargeOrderSn != '' || this.chargeOrderSn != undefined){ // 判断是不是二次支付的订单
|
||||
// that.orderSn = this.chargeOrderSn
|
||||
// console.log(that.orderSn,'二次支付的订单号')
|
||||
// }
|
||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
||||
this.setUserInfo({
|
||||
restoreFlag: true
|
||||
const that = this;
|
||||
uni.showLoading({
|
||||
title: "正在支付",
|
||||
mask: true,
|
||||
});
|
||||
console.log(this.userInfo, "更新后的用户信息");
|
||||
plus.payment.request(
|
||||
that.iapChannel, {
|
||||
productid: id,
|
||||
@@ -297,38 +343,51 @@
|
||||
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
||||
},
|
||||
function(result) {
|
||||
// restoreFlag = false; // 支付成功清除标记 restoreFlag = false
|
||||
// that.checking = false
|
||||
that.transaction = result;
|
||||
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
|
||||
that.iapCheck(result);
|
||||
},
|
||||
function(e) {
|
||||
// that.checking = false
|
||||
console.log("错误回调", e);
|
||||
if (e.errCode == 2) {
|
||||
if (e.code == 2) {
|
||||
uni.showToast({
|
||||
title:'取消支付,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
|
||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
||||
plus.runtime.openURL("https://apps.apple.com/account/billing");
|
||||
// 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)
|
||||
uni.showToast({
|
||||
title:'支付失败,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
console.log('其他支付错误',e);
|
||||
}
|
||||
|
||||
// that.finishTransaction(result);
|
||||
that.restoreComplateRequest()
|
||||
}
|
||||
);
|
||||
},
|
||||
iapCheck(result) {
|
||||
let that = this;
|
||||
console.log("进入后台验证");
|
||||
uni.showLoading({
|
||||
title:'正在验证订单结果'
|
||||
})
|
||||
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, // 苹果返回收据
|
||||
// isSandBox:true
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
};
|
||||
console.log(data, "data");
|
||||
console.log("提交给后台的数据",data);
|
||||
$http
|
||||
.request({
|
||||
url: "/Ipa/veri",
|
||||
@@ -342,19 +401,24 @@
|
||||
.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()
|
||||
// that.userInfo.restoreFlag == true ?
|
||||
// that.setUserInfo({
|
||||
// restoreFlag: false
|
||||
// }) :
|
||||
// "";
|
||||
uni.showToast({
|
||||
title:'充值成功!',
|
||||
icon:'success'
|
||||
})
|
||||
console.log("充值订单已处理,请留意账户金额变动....");
|
||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
uni.hideLoading()
|
||||
console.log('后台验证失败=>',e);
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
@@ -448,7 +512,11 @@
|
||||
that.payType = e;
|
||||
},
|
||||
//ios充值
|
||||
iosPay() {
|
||||
iosPay() {
|
||||
// 苹果内购实现思路:
|
||||
// 1.先确认支付通道是否包含苹果内购
|
||||
// 2.检查一下是否存在上次未处理完的订单(主要是支付成功没有走回调的订单),异常订单直接关闭掉,成功没有走回调的提交给后台进行验证
|
||||
// 3.请求并创建新的订单
|
||||
this.iphonepay();
|
||||
},
|
||||
// 充值
|
||||
|
||||
Reference in New Issue
Block a user