UniAPP IAP支付流程

1,plus.payment.getChannels(function(channels) {}) //获取所有支付方式

2,let iap = channels.find(x => x.id == 'appleiap');  //筛选ios内购 iap

3,iap.requestOrder([内购商品ID], function(event) {} //请求内购商品的订单,好像返回结果没啥实际作用,但必须要这一步操作(未检验)。

4,发起支付

                            uni.requestPayment({
                                provider: 'appleiap',
                                orderInfo: {
                                    productid: 内购商品ID
                                },
                                success: (e) => {
                      //支付成功的回调参数(iaptransaction) console.log(JSON.stringify(e));
uni.showModal({ content: "感谢您的赞助", showCancel: false }) }, fail: (e) => { uni.showModal({ content: "支付失败,原因为: " + e.errMsg, showCancel: false }) }, complete: () => { console.log("payment结束") } })
IAPTransaction {
    attribute IAPProductInfo payment;
    attribute String transactionDate;
    attribute String transactionIdentifier;
    attribute String transactionReceipt;
    attribute String transactionState;
}
	

  此时APP端步骤已完成

5,服务端校验

https://sandbox.itunes.apple.com/verifyReceipt

https://buy.itunes.apple.com/verifyReceipt

post {"receipt-data":支付成功返回中的transactionReceipt}

返回结果中包含状态0表示成功

 

另外 第5步还有服务器通知模式。

参考:

https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store

https://gsl201600.github.io/2019/06/19/iOSIAP%E6%94%AF%E4%BB%98%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E6%B1%87%E6%80%BB%E4%B8%8E%E8%A7%A3%E5%86%B3/

https://www.jianshu.com/p/a8747442c38d

http://www.html5plus.org/doc/zh_cn/payment.html

https://ask.dcloud.net.cn/article/497

https://uniapp.dcloud.io/api/plugins/payment

 

posted @ 2021-03-12 00:57  yesicoo  阅读(657)  评论(0编辑  收藏  举报