'use strict';  
const db = uniCloud.database()  
exports.main = async (event, context) => {  
    //event为客户端上传的参数  
    const collection = db.collection('user')  
       //根据官网示例调用云函数  
    let callFunctionResult = await uniCloud.callFunction({  
        name: "queryUser",  
        data: {  
            mobilePhone:event.mobilePhone  
        }  
    })  
    console.log('callFunctionResult',callFunctionResult)  
    return event  
};

————–报错如下:
[uniappCloud] 17:28:40.513 [腾讯云:solo-cloud]运行状态:失败
[uniappCloud] 17:28:40.514 [腾讯云:solo-cloud]返回结果:{“errorCode”:-1,”errorMessage”:”user code exception caught”,”stackTrace”:”errCode: FUNCTIONS_EXECUTE_FAIL | errMsg: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature\nError: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature\n at t.then.t (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1182)\n at \u003canonymous\u003e\n at process._tickCallback (internal/process/next_tick.js:188:7)\nError: errCode: FUNCTIONS_EXECUTE_FAIL | errMsg: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature\nError: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature\n at t.then.t (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1182)\n at \u003canonymous\u003e\n at process._tickCallback (internal/process/next_tick.js:188:7)\n at t.then.t (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1182)\n at \u003canonymous\u003e\n at process._tickCallback (internal/process/next_tick.js:188:7)”}
[uniappCloud] 17:28:40.514 [腾讯云:solo-cloud]运行日志:
Error: errCode: FUNCTIONS_EXECUTE_FAIL | errMsg: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature
Error: errCode: SIGN_PARAM_INVALID | errMsg: signature calculated is different from client signature
at t.then.t (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1182)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
at t.then.t (/var/user/@dcloudio/serverless/lib/tcb/uni-cloud.js:1:1182)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
[uniappCloud] 17:28:40.514 [腾讯云:solo-cloud]运行报告:计费时间:200ms 计费时间:125ms 运行内存:34.5MB


·回复

没有用过腾讯云,看代码似乎是要访问数据库取数

个人的愚见

云函数:

'use strict';    
const db = uniCloud.database()    
exports.main = async (event, context) => {    
    //event为客户端上传的参数    
    const collection = db.collection('user')    
       //这里直接去数据库取数,没有再调用云函数的必要(仅看目前的代码)  
    let res= await collection.where({  
          mobilePhone:event.mobilePhone   
         }) .get()  
    console.log(res)    
    return res  
};

前端调用:

let callFunctionResult = await uniCloud.callFunction({    
        name: "queryUser",  //这里是云函数的名称  
        data: {    
            mobilePhone:this.mobilePhone  //这个是前端要传到后端的数据,具体从哪里来不知道  
        }    
    })    
console.log(callFunctionResult )

·回复

既然如此,queryUser这个函数是不需要的,因为云函数是可以直接访问数据库的,直接在addUser 中调用数据查询方法即可获取结果,再根据结果判断是插入还是返回。


·回复

如果要调用公用云函数,请参考官方的文档。阿里云
在公用模块内exports,在云函数内require即可。示例代码如下:

//公用函数  
// common/hello-common/index.js  
function getVersion() {  
  return '0.0.1'  
}  
module.exports = {  
  getVersion,  
  secret: 'your secret'  
}
// useCommon/index.js  
'use strict';  
//在这里引入  
const {secret,getVersion} = require('hello-common')  
exports.main = async (event, context) => {  
  let version = getVersion()  
  return {  
    secret,  
    version  
  }  
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Scroll Up