广告显示

This commit is contained in:
2024-11-25 13:13:42 +08:00
parent 0b975c2418
commit 0ad2bb2b93
515 changed files with 256872 additions and 2253 deletions

87
utils/IosApplePay.js Normal file
View File

@@ -0,0 +1,87 @@
var iapChannel = null
//获取是否支持iap支付
export function Init() {
return new Promise((resolve, reject) => {
//使用uni.getProvider来获取通道
uni.getProvider({
service: 'payment',
success: (res) => {
console.log(res, 'init')
iapChannel = res.providers.find((channel) => {
return (channel.id === 'appleiap')
})
//成功之后会返回通道
resolve(iapChannel)
},
})
})
}
//获取订单
export function restore(iapChannel) {
console.log("获取苹果服务器已支付且未关闭的交易列表")
return new Promise((resolve, reject) => {
iapChannel.restoreCompletedTransactions({
manualFinishTransaction: true,
username: ''
}, (res) => {
resolve(res)
}, (err) => {
reject(err);
})
});
}
//关闭订单
export function finishTransaction(transaction, iapChannel) {
console.log("关闭订单")
return new Promise((resolve, reject) => {
iapChannel.finishTransaction(transaction, (res) => {
console.log("关闭订单成功", res)
resolve(res);
}, (err) => {
reject(err);
});
});
}
export function getReview(iapChannel, token, dev) {
//请求是否有已完成未关闭的订单
restore(iapChannel).then(res => {
//如果有并且状态为已支付则请求关闭并回调给后端
console.log(res)
if (res.length > 0) {
//轮询关闭订单
res.map(item => {
finishTransaction(item, iapChannel)
//如果状态为已完成的状态
if (item.transactionState == '1') {
}
})
}
})
}
export function requestOrder(iapChannel, productIds) {
uni.showLoading({
title: '初始化中~',
mask: true
})
return new Promise((resolve, reject) => {
iapChannel.requestOrder(productIds, (orderList) => { //必须调用此方法才能进行 iap 支付
console.log('requestOrder success: ' + JSON.stringify(orderList));
resolve(orderList)
uni.hideLoading()
}, (e) => {
console.log('requestOrder failed: ' + JSON.stringify(e));
uni.hideLoading()
uni.showToast({
icon: 'none',
title: '当前环境不支持内购支付'
})
reject(e)
});
})
}

View File

@@ -11,7 +11,7 @@ const ComplateRequestArr = []
var iap = {
getProvider() {
getProvider() {
return new Promise((resolve, reject) => {
uni.getProvider({
service: 'payment',
@@ -26,54 +26,54 @@ var iap = {
})
},
// 检测支付通道
async getChannels(){
async getChannels() {
const that = this;
console.log('检测支付通道')
this.iapChannel = await this.getProvider()
if(this.iapChannel){
if (this.iapChannel) {
// this.requestOrder();
this.restoreComplateRequest()
}else{
console.log("不支持iap支付");
}
} else {
console.log("不支持iap支付");
}
},
// 检测是否有未关闭订单
restoreComplateRequest() {
let that = this
console.log('检测未完成订单')
this.iapChannel.restoreCompletedTransactions({
manualFinishTransaction: true
}, function(results) {
if (!that.checking) {
that.checking = true
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction通用需将返回的支付凭证传给后端进行二次认证
that.ComplateRequestArr = results
console.log('未完成订单数组共有:=》',that.ComplateRequestArr.length ,that.ComplateRequestArr)
if (that.ComplateRequestArr.length > 0) {
that.ComplateRequestArr.map((item, index) => {
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
if (item.transactionState == '1') {
console.log('待验证订单,即将进入后台验证:=>', item)
// return false
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
that.iapCheck(item, index)
// that.finishTransaction(item)
} else {
// 其他状态的内购订单
that.finishTransaction(item)
}
})
}
restoreComplateRequest() {
let that = this
console.log('检测未完成订单')
this.iapChannel.restoreCompletedTransactions({
manualFinishTransaction: true
}, function(results) {
if (!that.checking) {
that.checking = true
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction通用需将返回的支付凭证传给后端进行二次认证
that.ComplateRequestArr = results
console.log('未完成订单数组共有:=》', that.ComplateRequestArr.length, that.ComplateRequestArr)
if (that.ComplateRequestArr.length > 0) {
that.ComplateRequestArr.map((item, index) => {
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
if (item.transactionState == '1') {
console.log('待验证订单,即将进入后台验证:=>', item)
// return false
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
that.iapCheck(item, index)
// that.finishTransaction(item)
} else {
// 其他状态的内购订单
that.finishTransaction(item)
}
})
}
});
}
});
},
// 关闭订单
finishTransaction(trans) {
this.iapChannel.finishTransaction(
trans,
(success) => {
console.log("关闭订单成功");
console.log("关闭订单成功");
that.checking = false
},
(fail) => {
@@ -84,14 +84,14 @@ var iap = {
},
iapCheck(result) {
let that = this;
console.log("进入后台验证");
console.log("进入后台验证", result);
let data = {
transactionId: result.transactionIdentifier, // 支付交易id
customerOid: store.state.userInfo.id,
productId: result.payment.productid.slice(1), // 产品id
orderId: result.payment.username, // 系统订单号
receiptData: result.transactionReceipt, // 苹果返回收据
// isSandBox:true
// isSandBox: true,//测试数据
// body: that.stepsCj.priceTypeId // 充值类型id
};
console.log("提交给后台的数据=>", data);
@@ -117,25 +117,26 @@ var iap = {
}
})
.catch((e) => {
console.log('后台验证失败=>',e);
console.log('后台验证失败=>', e);
uni.showModal({
title: "提示",
cancelColor:'#0081ff',
title: "提示",
cancelColor: '#0081ff',
content: `您的账户下存在验证异常的订单(订单编号为:${e.data.orderId})可尝试稍后重启app如不能解决您的问题可联系官方客服`,
cancelText:'已验证关闭订单',
confirmText:'知道了',
cancelText: '已验证关闭订单',
confirmText: '知道了',
success: function(res) {
if (res.confirm) {
console.log("用户点击确定");
}else{
} else {
console.log('点了取消')
that.finishTransaction(result);
}
},
});
// that.finishTransaction(result);
// that.finishTransaction(result);
});
},
}
module.exports = {iap}
module.exports = {
iap
}