• uni-app 苹果内购支付及获取苹果支付成功信息


    先在头部定义商品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
                            })
                        }
                    })
                },
  • 相关阅读:
    android 代码上传到jcenter
    android library打包成aar形式供别的项目引用
    使用AndroidStudio导入github项目
    使用Postman在Chrome下进行rest请求测试
    Android 编码规范
    GsonFormat根据返回值json快速构建Model
    码云git使用四(分支的创建,使用和合并)
    码云git使用三(本地代码合并)
    码云git使用二(从码云git服务器上下载到本地)
    计算最长英语单词链
  • 原文地址:https://www.cnblogs.com/qdjj/p/15001147.html
Copyright © 2020-2023  润新知