根据官方的代码做IOS内购支付,支付环境与支付商品信息都能获取到,但是最后点击支付的时候没有任何回调信息。
<u-button v-if="!is_an" type="warning" @click="requestPayment('234')" ripple shape="circle">确认支付</u-button>
<script>
let iapChannel = null,
productId = '234',
productIds = ['234', '1234'];
export default {
data() {
return {
// 支付环境
zfhj: false,
//
info: {},
is_an: '',
payType: 0,
price: "",
//ios内购测试数据
loading: false,
disabled: true,
priceList: [{
value: '234',
text: '购买视频',
checked: true
}, {
value: '1234',
text: '购买会员VIP ',
checked: false
}]
};
},
computed: {
userInfo() {
return this.$store.state.userInfo
}
},
onLoad: function(options) {
this.info = options || {}
this.price = options.price || {}
this.id = options.id
this.chapter_id = options.chapter_id
if (!this.$store.state.hasLogin) {
uni.redirectTo({
url: '../login/login'
})
}
//检测环境
switch (uni.getSystemInfoSync().platform) {
case 'android':
console.log('运行Android上')
this.is_an = true
break;
case 'ios':
console.log('运行iOS上')
this.is_an = false
//拉取支付环境
plus.payment.getChannels((channels) => {
console.log("获取到channel" + JSON.stringify(channels))
this.zfhj = JSON.stringify(channels)
for (var i in channels) {
var channel = channels[i];
if (channel.id === 'appleiap') {
iapChannel = channel;
this.requestOrder();
this.zfhj = iapChannel
}
}
if (!iapChannel) {
this.errorMsg()
}
}, (error) => {
this.errorMsg()
});
break;
default:
console.log('运行在开发者工具上')
break;
}
},
methods: {
/*********************************************************************************************************/
//ios内购支付
requestOrder() {
uni.showLoading({
title: '检测支付环境...'
})
iapChannel.requestOrder(productIds, (orderList) => { //必须调用此方法才能进行 iap 支付
this.disabled = false;
console.log('requestOrder success666: ' + JSON.stringify(orderList));
uni.hideLoading();
this.zfhj = 'requestOrder success666: ' + JSON.stringify(orderList)
}, (e) => {
this.zfhj = 'requestOrder failed: ' + JSON.stringify(orderList)
console.log('requestOrder failed: ' + JSON.stringify(e));
uni.hideLoading();
this.errorMsg()
});
},
requestPayment(e) {
this.loading = true;
uni.requestPayment({
provider: 'appleiap',
orderInfo: {
productid: this.productId,
username: "购买视频"
},
success: (e) => {
uni.showModal({
content: "感谢您的赞助",
showCancel: false
})
this.zfhj = "感谢您的赞助?" + e
},
fail: (e) => {
this.zfhj = "支付失败?" + e
uni.showModal({
content: "支付失败,原因为: " + e.errMsg,
showCancel: false
})
},
complete: () => {
console.log("payment结束")
this.loading = false;
}
})
},
applePriceChange(e) {
productId = e.detail.value;
},
errorMsg() {
uni.showModal({
content: "暂不支持苹果 iap 支付",
showCancel: false
})
},
/*********************************************************************************************************/
}
</script>
c***@163.com
正常参数后回调正常嘛?我这里支付成功回调很慢
2022-09-01 11:48
y***@163.com
回复 c***@163.com: 过程确实是很慢,这个可能走苹果国外服务器了,非常慢。
2022-09-01 17:52
1***@qq.com
APP卸载了重新编译安装一遍就能拿到了,坑我了起码半小时。。。
2022-09-03 23:11
Gyys148
遇到了一样的问题,感谢
2022-10-17 15:16
d***@qq.com
果然是这个问题,从文档里拷贝的代码,改成productid就可以了,感谢感谢。
2022-11-15 23:47