8***@qq.com
8***@qq.com
  • 发布:2024-03-14 18:43
  • 更新:2024-03-15 16:37
  • 阅读:198

【报Bug】cloud云路由发送短信bug

分类:uniCloud

产品分类: uniCloud/App

示例代码:

// 发送短信
async sendingSms() {
const data = this.ctx.data
try {
// 短信额度
const balance = await this.db.collection("natural-resources")
.where({
type: "SMS"
})
.get(); // 统计符合条件的记录数量

        const res = await uniCloud.sendSms({  
            appid: '__UNI__FA6***',  
            phone: data.phone,  
            templateId: '320***', // 请替换为自己申请的模板id  
            data: {  
                orderNo: data.orderNo,  
            }  
        })  
        console.log("res", res);  
        // if (balance.data[0].balance >= 10) {  
        //  console.log("111111111");  

        //  // if (res.errCode == 0) {  
        //  //  console.log("发送成功");  
        //  //  this.db.collection('natural-resources').where({  
        //  //      type: "SMS"  
        //  //  }).update({  
        //  //      'balance': this.db.command.inc(-10) // 减少余额  
        //  //  })  
        //  // }  
        // }  
    } catch (e) {  
        //TODO handle the exception  
        console.log("短信发送错误", e);  
    }  
}  

报错18:34:18.799 [本地调试]短信发送错误 uniCloud-aliyun/cloudfunctions/cloud-router/service/expressDelivery.js:354:11
18:34:18.799 [本地调试]TypeError: Cannot read properties of undefined (reading 'provider')

操作步骤:

不能同时存在,否则报错TypeError: Cannot read properties of undefined (reading 'provider')

去掉其中一个,另一个可以运行

预期结果:

先查询额度,再执行发送短信

实际结果:

发送短信成功

bug描述:

cloud云路由有bug,

我事先查询短信额度,额度满足再执行发送短信。
但是
const balance = await this.db.collection("natural-resources")
.where({
type: "SMS"
})
.get(); // 统计符合条件的记录数量

const res = await uniCloud.sendSms({
appid: 'UNIFA6',
phone: data.phone,
templateId: '320
', // 请替换为自己申请的模板id
data: {
orderNo: data.orderNo,
}
})

不能同时存在,否则报错TypeError: Cannot read properties of undefined (reading 'provider')

去掉其中一个,另一个可以运行

发送短信的代码我是放到 // if (balance.data[0].balance >= 10) {中的,但是出错了,然后我排除错误,就放到了与const balance = await this.db.collection("natural-resources")评级

2024-03-14 18:43 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

意思是单独调用uniCloud.sendSms不报错?

  • 8***@qq.com (作者)

    是的

    2024-03-14 21:58

  • DCloud_uniCloud_WYQ

    回复 8***@qq.com: “TypeError: Cannot read properties of undefined (reading 'provider')” 这个错误带着错误堆栈截图发出来看看

    2024-03-15 13:09

  • 8***@qq.com (作者)

    回复 DCloud_uniCloud_WYQ: 你看看是不是这个

    2024-03-15 16:04

8***@qq.com

8***@qq.com (作者) - 小学一下代码

就这样

  • DCloud_uniCloud_WYQ

    调用sendingSms的地方怎么写的?

    2024-03-15 16:16

  • DCloud_uniCloud_WYQ

    看下是不是哪里漏写了await

    2024-03-15 16:17

  • 8***@qq.com (作者)

    回复 DCloud_uniCloud_WYQ: if (result.id) {

    if (data.message) {

    this.sendingSms()

    }

    return new resultModel(200, "添加成功")

    }

    2024-03-15 16:35

  • 8***@qq.com (作者)

    回复 DCloud_uniCloud_WYQ: https://mp-05f26e8b-6519-4bf9-b0d4-3f6561d5094a.cdn.bspapp.com/4ff98044a9467fec6f9f10e66540ea42.mp4 演示视频

    2024-03-15 16:37

  • 8***@qq.com (作者)

    回复 DCloud_uniCloud_WYQ: 视频有看了吗哥,我好解决问题

    2024-03-15 16:47

  • DCloud_uniCloud_WYQ

    回复 8***@qq.com: 需要看代码,注意看你的日志是在云函数结果打印出来之后再打印的发送短信失败,检查下是不是哪里漏写了await导致云函数return之后再执行的发送短信

    2024-03-18 11:15

8***@qq.com

8***@qq.com (作者) - 小学一下代码

!我把视频放到了云存储中

要回复问题请先登录注册