标签:内购 res hideLoading 苹果 支付 var uni data id
先在头部定义商品id 全部商品id (在苹果商店申请的真实商品id)
let iapChannel = null; var productId = 'lvbi_a'; var productIds = ['lvbi_a'];
进入页面就判断
//1.获取支付渠道 plus.payment.getChannels((channels) => { for (var i in channels) { var channel = channels[i]; //苹果支付 if (channel.id === 'appleiap') { iapChannel = channel; this.requestOrder(); //关键 } } if (!iapChannel) { that.errorMsg() } }, (error) => { that.errorMsg() });
requestOrder() { iapChannel.requestOrder(productIds, (orderList) => { //必须调用此方法才能进行 iap 支付 uni.hideLoading(); }, (e) => { uni.hideLoading(); this.errorMsg() }); },
调接口获取真实的商品id
// 获取页面内容 getAppleProducts() { AppleProducts({ openid:this.openid, token:this.tpken }).then(res =>{ if(res.code == 1){ this.data = res.data; this.price = this.data.products[0]; productId = this.data.products[0].product_id; productIds = this.data.products_ids; } }) },
确定支付
topupprice() { let that = this; uni.showLoading({}); uni.requestPayment({ provider: 'appleiap', orderInfo: { productid: productId }, success: (e) => { uni.hideLoading(); var statement = { productid: productId } // 支付成功查询订单 plus.payment.request(iapChannel, statement, function(res){ paysuccers({ data:{ openid:that.openid, token:that.token, receipt_data:JSON.stringify(res) } }).then(tow =>{ uni.hideLoading(); if(tow.code == 1){ uni.showToast({ title:tow.msg, icon:'none' }) }else{ uni.showToast({ title:tow.msg, icon:'none' }) } }) }, function(){ }); }, fail: (e) => { uni.hideLoading(); uni.showModal({ content: "支付失败,原因为: " + e.errMsg, showCancel: false }) } }) },
标签:内购,res,hideLoading,苹果,支付,var,uni,data,id 来源: https://www.cnblogs.com/shaozhu520/p/15260989.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。