星星不怕黑
星星不怕黑
  • 发布:2025-01-11 17:13
  • 更新:2025-01-11 17:20
  • 阅读:16

【报Bug】ios 内购商品在获取商品时报错,但不是每次都报错

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 4.45

手机系统: iOS

手机系统版本号: iOS 18

手机厂商: 苹果

手机机型: 14pro max

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
    getProduct(productIds) {  
        return new Promise((resolve, reject) => {  
            console.log("获取苹果内购产品" , productIds)  
            this._channel.requestProduct(productIds, (res) => {  
                console.log(res)  
                resolve(res);  
            }, (err) => {  
                console.log("获取苹果内购产品-error",err)  
                reject(err);  
            })  
        });  
    },
获取苹果内购产品-error,  
{  
    "code": 0,  
    "message": "Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"发生未知错误\" UserInfo={NSLocalizedDescription=发生未知错误, NSUnderlyingError=0x281600f00 {Error Domain=ASDErrorDomain Code=507 \"Error decoding response\" UserInfo={NSLocalizedDescription=Error decoding response, NSLocalizedFailureReason=Could not decode media products response}}},https://ask.dcloud.net.cn/article/282",  
    "errCode": 0,  
    "errMsg": "Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"发生未知错误\" UserInfo={NSLocalizedDescription=发生未知错误, NSUnderlyingError=0x281600f00 {Error Domain=ASDErrorDomain Code=507 \"Error decoding response\" UserInfo={NSLocalizedDescription=Error decoding response, NSLocalizedFailureReason=Could not decode media products response}}},https://ask.dcloud.net.cn/article/282"  
}

操作步骤:
import Iap, {IapTransactionState} from "@/pages-train/activeOrder/js/iap";  
    // 初始化,获取iap支付通道  
        await Iap.init();  
        let res = await Iap.getProduct(['q3']);  
// Iap.js  

    init() {  
        return new Promise((resolve, reject) => {  
            this.getChannels((channel) => {  
                console.log(channel)  
                resolve(channel);  
            }, (err) => {  
                console.log(err)  
                reject(err);  
            })  
        })  
    },  
    getProduct(productIds) {  
        return new Promise((resolve, reject) => {  
            console.log("获取苹果内购产品" , productIds)  
            this._channel.requestProduct(productIds, (res) => {  
                console.log(res)  
                resolve(res);  
            }, (err) => {  
                console.log("获取苹果内购产品-error",err)  
                reject(err);  
            })  
        });  
    },  
getChannels(success, fail) {  
        if (this._channel !== null) {  
            success(this._channel)  
            return  
        }  

        if (this._channelError !== null) {  
            fail(this._channelError)  
            return  
        }  

        uni.getProvider({  
            service: 'payment',  
            success: (res) => {  
                // console.log(res)  
                this._channel = res.providers.find((channel) => {  
                    return (channel.id === 'appleiap')  
                })  

                if (this._channel) {  
                    success(this._channel)  
                } else {  
                    this._channelError = {  
                        errMsg: 'paymentContext:fail iap service not found'  
                    }  
                    fail(this._channelError)  
                }  
            },  
            fail(err) {  
                console.log(err)  
            }  
        });  
    },  

    get channel() {  
        return this._channel;  
    }, 

预期结果:

可以获取到商品列表

实际结果:

有时能获取到有时报错

bug描述:

this._channel.requestProduct 获取内购商品时报错,但是过一会又好了,再过一段时又会报错,检查过证书协议和内购商品都没得问题
代码也是复制的官方demo
{
"code": 0,
"message": "Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"发生未知错误\" UserInfo={NSLocalizedDescription=发生未知错误, NSUnderlyingError=0x2828f9cb0 {Error Domain=ASDErrorDomain Code=507 \"Error decoding response\" UserInfo={NSLocalizedDescription=Error decoding response, NSLocalizedFailureReason=Could not decode media products response}}},https://ask.dcloud.net.cn/article/282",
"errCode": 0,
"errMsg": "Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"发生未知错误\" UserInfo={NSLocalizedDescription=发生未知错误, NSUnderlyingError=0x2828f9cb0 {Error Domain=ASDErrorDomain Code=507 \"Error decoding response\" UserInfo={NSLocalizedDescription=Error decoding response, NSLocalizedFailureReason=Could not decode media products response}}},https://ask.dcloud.net.cn/article/282"
}

2025-01-11 17:13 负责人:无 分享
已邀请:
星星不怕黑

星星不怕黑 (作者)

1.证书协议没得问题

  1. 内购商品正常
  2. 代码复制的demo id和格式均正确
  3. 这个问题一会出现一会又正常,并不是每次都出现

要回复问题请先登录注册