您好!请问问题有解决方案了吗
var crypto = require('crypto'); 无效?做腾讯云的OCR识别,把腾讯云demo里的这段代码丢进js里,第一句就不跑,为啥? [代码]auth () { [代码] [代码] var[代码] [代码]crypto = require([代码][代码]'crypto'[代码][代码]);[代码] [代码] var[代码] [代码]secretId = [代码][代码]'YOUR SECRET_ID'[代码][代码],[代码][代码] [代码][代码]secretKey = [代码][代码]'YOUR SECRET_KEY'[代码][代码],[代码][代码] [代码][代码]appid = [代码][代码]'APPID'[代码][代码],[代码][代码] [代码][代码]pexpired = 86400,[代码][代码] [代码][代码]userid = 0;[代码] [代码] var[代码] [代码]now = parseInt(Date.now() / 1000),[代码][代码] [代码][代码]rdm = parseInt(Math.random() * Math.pow(2, 32)),[代码][代码] [代码][代码]plainText = [代码][代码]'a='[代码] [代码]+ appid + [代码][代码]'&k='[代码] [代码]+ secretId + [代码][代码]'&e='[代码] [代码]+ (now+pexpired) + [代码][代码]'&t='[代码] [代码]+ now + [代码][代码]'&r='[代码] [代码]+ rdm + userid + [代码][代码]'&f='[代码][代码],[代码][代码] [代码][代码]data = [代码][代码]new[代码] [代码]Buffer(plainText,[代码][代码]'utf8'[代码][代码]),[代码][代码] [代码][代码]res = crypto.createHmac([代码][代码]'sha1'[代码][代码],secretKey).update(data).digest(),[代码][代码] [代码][代码]bin = Buffer.concat([res,data]);[代码] [代码] var[代码] [代码]sign = bin.toString([代码][代码]'base64'[代码][代码]);[代码] [代码] [代码] return sign; } js有点菜,请赐教!
2022-04-24