uniapp ios内购支付问题(返回订单信息失败)

uniapp ios内购支付问题(返回订单信息失败),第1张

先上代码

export default {
	components: {
		pHeader
	},
	data() {
		return {
			iap: null, // 支付通道
			ids: ['qiming100', 'meimingbao','ceming811'], // 应用内购项目产品 ID 数组
			product_list: [] ,// 应用内购项目列表
			mealId:0,

		};
	},
	methods: {
		// 获取支付通道
		getChannels() {
			// #ifdef APP-PLUS
			plus.payment.getChannels(res => {
				let channel = res.find(i => i.id === 'appleiap')
				this.iap = channel ? channel : null
				this.requestOrder()
			}, function(e) {
				plus.nativeUI.alert("获取支付通道失败,请稍后重试。", function() {}, "提示");
			})
			// #endif
		},
		// 获取内购项目列表
		requestOrder() {
			uni.showLoading({  
				title: '检测支付环境...'  
			})  
			// #ifdef APP-PLUS
			this.iap.requestOrder(
				this.ids,
				res => {
					uni.hideLoading()
					this.product_list = res;
					console.log(res);
					this.pay();
				},
				(errormsg)=> {
					uni.hideLoading()
					plus.nativeUI.alert("获取应用内购项目失败,请稍后重试。", function(e) {
					}, "提示");
					console.log(JSON.stringify(errormsg))
					
				}
			)
			// #endif
		},
		// 调起支付
		pay() {
			console.log('开始支付')
			uni.requestPayment({
				provider: 'appleiap',
				orderInfo: {
					productid: this.ids[this.mealId]
				},
				success: (e) => {
					console.log('支付成功')
					console.log(e)
				
				},
				fail: (e) => {
					uni.showModal({
						content: "支付失败,原因为: " + e.errMsg,
						showCancel: false
					})
					this.restoreComplateRequest();
				},
				complete: () => {
					console.log("payment结束")
					this.loading = false;
				}
			})
		},
		// 获取已购的非消耗性商品和订阅商品
		restoreComplateRequest() {
			this.iap.restoreComplateRequest({}, results => {
				// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证  
				console.log('restoreComplateRequest-results---', JSON.stringify(results))
			}, e => {
				// 错误回调
				console.log('restoreComplateRequest-results ---fail---', JSON.stringify(e))
			});
		},
		handlePay() {
			this.iospay();
		},
		
	}
};

如果出现返回订单信息失败,很大原因是你打包的测试包appId 和你后台申请内购的appId不相同导致的

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996875.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存