参考文章
与
uniapp文档
流程
step1|✨manifest.json文件中勾选Apple应用内支付

step2|✨调用getAppleChannel(productId)函数即可调起苹果支付
getAppleChannel(productId) {
let that = this
uni.showLoading({
title: '检测支付环境...',
mask: true
})
plus.payment.getChannels((channels) => {
for (let i in channels) {
if (channels[i].id === 'appleiap') {
that.iapChannel = channels[i];
that.compareAppleProduce(productId)
}
}
}, (err) => {
uni.hideLoading()
uni.showToast({
title: "获取支付通道失败:" + err.message,
icon: 'none'
})
})
},
compareAppleProduce(productId) {
let that = this
that.iapChannel.requestOrder([productId], (event) => {
uni.hideLoading()
for (let index in event) {
that.applePay(productId)
}
}, (err) => {
uni.hideLoading()
uni.showToast({
title: "该商品未录入:" + err.message,
icon: 'none'
})
})
},
applePay(productId) {
let that = this
uni.showLoading({
title: '支付中...',
mask: true
})
uni.requestPayment({
provider: 'appleiap',
orderInfo: {
productid: productId
},
async success(res) {
BaseCenterApi.voucher({voucher: res.transactionReceipt}).then(res => {
if(res.code != 1) {
uni.$u.toast('支付失败');
}else {
uni.$u.toast('支付成功');
setTimeout(() => {
uni.navigateTo({
url: '/pages/mine/tool/transactionDetail'
})
}, 500);
}
})
},
fail(e) {
uni.$u.toast('支付已取消');
},
complete() {
uni.hideLoading()
}
})
}