报错如下:
[uni-sms/ac1cc3201735431011879105441/387ms/DEBUG] jql报错
at _callCloudFunction (/tmp/function/@common_modules/uni-cloud-jql/index.js:1:6144)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errMsg: '权限校验未通过,未能获取当前用户信息,当前用户为匿名身份,请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error',
errCode: 'TOKEN_INVALID_ANONYMOUS_USER',
code: 'TOKEN_INVALID_ANONYMOUS_USER',
subject: undefined,
errSubject: undefined,
cause: undefined,
requestId: undefined
}
我的普通云函数的入参event对象能获取到uniIdToken,为什么会报这个错误呢,我去查看opendb-verify-codes表的dbscheme也没有permission属性的设置,我也没去修改它。
我的云函数代码如下:
// 发送单条短信示例
'use strict';
const crypto = require('crypto');
function generateCode() {
return crypto.randomInt(100000, 999999).toString();
}
const smscode = generateCode()
const db = uniCloud.databaseForJQL();
exports.main = async (event, context) => {
console.log(event,context)
try {
const res = await uniCloud.sendSms({
appid: 'UNIXXXXXXX',
phone: event.mobile,
templateId: '33333', // 请替换为自己申请的模板id
data: {
code: smscode
}
})
console.log('test sms')
// 调用成功,请注意这时不代表发送成功
db.collection('opendb-verify-codes').where({
mobile: event.mobile,
status: 0,
scene: 'claim-shop'
}).orderBy('created_date desc').get({getOne: true}).then((res)=>{
console.log('查询成功')
console.log(res)
db.collection('opendb-verify-codes').add({
mobile: event.mobile,
scene: 'claim-shop',
code: smscode,
state: 0,
ip: $cloudEnv_clientIP,
created_date: $cloudEnv_now,
expired_date: $cloudEnv_now + 300000
}).then((res)=>{console.log('新郑成功')}).catch((err)=>{
console.log('新增失败')
})
}).catch((err)=>{
console.log('jql报错')
console.log(err)
})
return res
} catch(err) {
// 调用失败
console.log(err.errCode)
console.log(err.errMsg)
return {
code: err.errCode,
msg: err.errMsg
}
}
};
0 个回复