直接使用示例代码都报错,能不能给个详细的使用教程
官方文档示例代码
const {
verifyHttpInfo
} = require('uni-cloud-s2s')
exports.main = async (event) => {
verifyHttpInfo({
httpMethod: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'Unicloud-S2s-Timestamp': '1677090154735',
"Unicloud-S2s-Signature": "hmac-sha256 74416c6ffaa74bc3b70a1dca7c66406dd113e2f0aaf9713d7c3bd19a21d77b47"
},
body: 'a=1&b=2&c=3'
})
};
错误信息
Invalid uni-cloud-s2s config, expected policy is "code" or "sign", got undefined
Error: Invalid uni-cloud-s2s config, expected policy is "code" or "sign", got undefined
at b (/tmp/function/@common_modules/uni-cloud-s2s/index.js:1:4877)
at exports.verifyHttpInfo (/tmp/function/@common_modules/uni-cloud-s2s/index.js:1:5366)
at exports.main (/tmp/function/__index.js:11:2)
at Q (/tmp/function/index.js:1:24007)
at z (/tmp/function/index.js:1:25070)
at ae (/tmp/function/index.js:1:26040)
at runUserFunction (/code/index.js:98:271594)
at (<anonymous>)
at _tickCallback (internal/process/next_tick.js:189:7)
补充
1、按官方示例const { verifyHttpInfo} = require('uni-cloud-s2s') 引入s2s模块是不行的,还需要在引入该模块的云函数管理公共依赖中引入s2s。
2、于应用市场引入s2s后,仅有index.js、package.json文件,不含官方文档描述中config.json文件,自己创建后复制官方文档中代码 并删掉注释,上传公共模块及云函数后运行报上述错误信息
{
"type": "sign",
"signKey": "s83jkd7g24ds7v1f5vf6s3s6c8ekh7d9",
"hashMethod": "hmac-sha256",
"timeDiffTolerance": 60
}
h***@carbon-tech.cn
这文档里写的配置文件在是 uni-cloud-s2s 下吧。 如果在uni-config-center 里配置,配置文件不应该是 uniCloud\cloudfunctions\common\uni-config-center\uni-cloud-s2s\config.json 么?
2023-06-27 11:20
DCloud_uniCloud_CRL
回复 h***@carbon-tech.cn: 是的,文档有误,感谢指出,我现在修改一下。
2023-06-27 11:23