调用OCR识别出错
发布于 5 年前 作者 chaohu 14473 次浏览 来自 问答

调用腾讯云的OCR识别时,报错了。

var CryptoJS = require('crypto-js');
      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 = CryptoJS.HmacSHA1(data, secretKey);
 
      var bin = Buffer.concat([res, data]);   //这一句运行时报错了
 
      var sign = bin.toString('base64');
 
      return sign;

694 Uncaught (in promise) TypeError: "list" argument must be an Array of Buffers

不知道是什么原因?求解答!

2 回复
var hmac = CryptoJS.HmacSHA1(CryptoJS.enc.Utf8.parse(plainText), CryptoJS.enc.Utf8.parse(secretKey))
var sign = CryptoJS.enc.Base64.stringify(hmac.concat(CryptoJS.enc.Utf8.parse(plainText)))

两个值类型不一样

回到顶部