枣庄联通网站备案,wordpress post id清理,推荐优秀网站,东莞建设网站推广公司地址用uniapp开发iOS应用内支付 准备前端代码服务器端处理如果iOS支付遇到问题实在解决不了#xff0c;可以联系我帮忙解决#xff0c;前端后端都可以解决#xff08;添加的时候一定要备注咨询iOS支付问题#xff09; 准备前端代码
获取支付通道 (uni.getProvider)
uni.getPr… 用uniapp开发iOS应用内支付 准备前端代码服务器端处理如果iOS支付遇到问题实在解决不了可以联系我帮忙解决前端后端都可以解决添加的时候一定要备注咨询iOS支付问题 准备前端代码
获取支付通道 (uni.getProvider)
uni.getProvider({service: payment,success: (res) {const iapChannel res.providers.find((channel) {return (channel.id appleiap)})}
});通过支付通道获取产品列表 (iapChannel.requestProduct) getProduct(productIds) {return new Promise((resolve, reject) {this._channel.requestProduct(productIds || this._productIds,(res) {resolve(res);},(err) {reject(err);});});}检查是否存在未关闭的订单 (iapChannel.restoreCompletedTransactions, 可选在合适的时机检查) async restore() {// 检查上次用户已支付且未关闭的订单可能出现原因首次绑卡网络中断等异常let _this thistry {// 从苹果服务器检查未关闭的订单可选根据 username 过滤和调用支付时透传的值一致const transactions await this.restoreCompletedTransactions({});if (!transactions.length) {return;}for (const transaction of transactions) {switch (transaction.transactionState) {case IapTransactionState.purchased://这里写上传数据到服务器的代码console.log(成功);_this.finishTransaction(transaction);}break;case IapTransactionState.failed:// 关闭未支付的订单_this.finishTransaction(transaction);break;default:break;}};} catch (e) {uni.showModal({content: e.message,showCancel: false});} finally {}}请求支付传递产品信息 (uni.requestPayment) requestPayment(orderInfo) {return new Promise((resolve, reject) {uni.requestPayment({provider: appleiap,orderInfo: orderInfo,success: (res) {resolve(res);},fail: (err) {reject(err);}});});}客户端接收苹果返回的支付票据发送到服务器在服务器请求苹果服务器验证支付是否有效服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
服务器端处理
前端传过来transactionReceipt以及透传参数一般是自己的订单号 我们拿着transactionReceipt请求苹果的服务器即可请求苹果服务器会返回该支付的一切信息包括支付订单号支付时间支付数量等
如果iOS支付遇到问题实在解决不了可以联系我帮忙解决前端后端都可以解决添加的时候一定要备注咨询iOS支付问题