美文网首页uniapp
uniapp requestOrder 调用失败

uniapp requestOrder 调用失败

作者: 卢融霜 | 来源:发表于2021-08-20 09:12 被阅读0次

    获取到channel[{"id":"appleiap","description":"In-App Purchase","serviceReady":true}]

    requestOrder failed: {"code":-100,"message":"Payment_appleiap:返回订单信息失败

    <template>  
        <view>  
            <view class="uni-list">  
                <radio-group @change="applePriceChange">  
                    <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in priceList" :key="index">  
                        {{item.text}}  
                        <radio :value="item.value" :checked="item.checked" />  
                    </label>  
                </radio-group>  
            </view>  
            <view class="uni-padding-wrap">  
                <button class="ipaPayBtn" @click="requestPayment" :loading="loading" :disabled="disabled">确认支付</button>  
            </view>  
        </view>  
        </view>  
    </template>  
    
    <script>  
        let iapChannel = null,  
            productId = 'opiclibraryApp01',  
            productIds = ['opiclibraryApp01'];  
        export default {  
            data() {  
                return {  
                    title: 'request-payment',  
                    loading: false,  
                    disabled: true,  
                    priceList: [{  
                        value: 'opiclibraryApp01',  
                        text: '支付1元',  
                        checked: true  
                    }, {  
                        value: 'opiclibraryApp01',  
                        text: '支付6元',  
                        checked: false  
                    }]  
                }  
            },  
            onLoad: function() {  
                plus.payment.getChannels((channels) => {  
                    console.log("获取到channel" + JSON.stringify(channels))  
                    for (var i in channels) {  
                        var channel = channels[i];  
                        if (channel.id === 'appleiap') {  
                            iapChannel = channel;  
                            this.requestOrder();  
                        }  
                    }  
                    if(!iapChannel){  
                        this.errorMsg()  
                    }  
                }, (error) => {  
                    this.errorMsg()  
                });  
            },  
            methods: {  
                requestOrder() {  
                    uni.showLoading({  
                        title:'检测支付环境...'  
                    })  
                    iapChannel.requestOrder(productIds, (orderList) => { //必须调用此方法才能进行 iap 支付  
                        this.disabled = false;  
                        console.log('requestOrder success666: ' + JSON.stringify(orderList));  
                        uni.hideLoading();  
                    }, (e) => {  
                        console.log('requestOrder failed: ' + JSON.stringify(e));  
                        uni.hideLoading();  
                        this.errorMsg()  
                    });  
                },  
                requestPayment(e) {  
                    this.loading = true;  
                    uni.requestPayment({  
                        provider: 'appleiap',  
                        orderInfo: {  
                            productid: productId  
                        },  
                        success: (e) => {  
                            uni.showModal({  
                                content: "感谢您的赞助",  
                                showCancel: false  
                            })  
                        },  
                        fail: (e) => {  
                            uni.showModal({  
                                content: "支付失败,原因为: " + e.errMsg,  
                                showCancel: false  
                            })  
                        },  
                        complete: () => {  
                            console.log("payment结束")  
                            this.loading = false;  
                        }  
                    })  
                },  
                applePriceChange(e) {  
                    productId = e.detail.value;  
                },  
                errorMsg(){  
                    uni.showModal({  
                        content: "暂不支持苹果 iap 支付",  
                        showCancel: false  
                    })  
                }  
            }  
        }  
    </script>  
    <style>  
    
    </style>  
    
    image.png

    问题解答:

    1. 内购项目要和APP关联上

    2. 如果是第一次在这个开发者账号上集成内购功能,先将iTune Connect上的税务协议都填写好。

    我遇到的是这两个问题,现在可以访问通了

    requestOrder success666: [{"description":"题库购买","price":4.99,"pricelocal":"en_US@currency=USD","productid":"opiclibraryApp0001","title":"题库购买"}]

    原文地址:https://ask.dcloud.net.cn/question/120078
    

    相关文章

      网友评论

        本文标题:uniapp requestOrder 调用失败

        本文链接:https://www.haomeiwen.com/subject/awnzbltx.html