https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/ocr/ocr.businessLicense.html
尝试了两种方式,
第一种img_url:
async readBizLicense(imgUrl){
let at = await this.getAccessToken()
let readUrl = 'https://api.weixin.qq.com/cv/ocr/bizlicense?access_token=’ + at
let data = {img_url: imgUrl}
console.log(“data”, data)
let content = await http({url: readUrl,method: ‘POST’,data: data}).then(res => {
console.log(res.data)
return res.data
})
return content
}
img_url的格式是https://…/xx.jpg,尝试过直接给出,encodeUrl和encodeUrlComponent三种方式,均报41005错误, media data missing hint.
第二种img:buffer:
const stream = await this.ctx.getFileStream();
let result = null;
let fullpath = uploadPath + “/license/”
if (!fs.existsSync(fullpath)) fs.mkdirSync(fullpath)
let filename = encodeURIComponent(stream.filename)
let extname = path.extname(filename)
filename = this.ctx.helper.getUUID() + extname
const target = path.join(this.config.baseDir, fullpath, filename);
const writeStream = fs.createWriteStream(target);
await pump(stream, writeStream);
let data = fs.readFileSync(target);
let bufferData = new Buffer(data,‘base64’);
let buffer = ‘data:’ + stream.mimeType + ‘;base64,’ + bufferData;
let img = {
contentType: stream.mimeType,
value: buffer
}
result = await this.ctx.service.content.readBizLicense(img)
上传小于2M大于1M的图片时报错:content out of size limit,上传小于1M 的图片时报错:media data missing hint
试了一天了,不知道该怎么解决?求大神帮助!谢谢!