云函数中调用ocr.idcard总是返回参数错误
按照如下指导,使用云调用方式使用
// 云函数入口文件 const cloud = require( 'wx-server-sdk' ) cloud.init() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() let imgUrl = 'https://...' console.log(encodeURIComponent(imgUrl)) try { const result = await cloud.openapi.ocr.idcard({ type: 'photo' , imgUrl: encodeURIComponent(imgUrl) }) console.log(result) return result } catch (err) { console.log(err) return err } } |
云端测试时总是报如下错误:
{ Error: errCode: -501007 invalid parameters | errMsg: ocr.idcard:fail Invalid request param at new CloudSDKError ( /var/user/node_modules/wx-server-sdk/index .js:6360:28) at Object.<anonymous> ( /var/user/node_modules/wx-server-sdk/index .js:434:35) at step ( /var/user/node_modules/tslib/tslib .js:136:27) at Object.next ( /var/user/node_modules/tslib/tslib .js:117:57) at fulfilled ( /var/user/node_modules/tslib/tslib .js:107:62) at <anonymous> at process._tickCallback (internal /process/next_tick .js:188:7) errCode: -501007, errMsg: 'ocr.idcard:fail Invalid request param' } END RequestId: 0161d73f-ba95-11e9-abb2-5254002fa145 Report RequestId: 0161d73f-ba95-11e9-abb2-5254002fa145 Duration:94ms Memory:256MB MaxMemoryUsed:3.371094MB |
NOTE: 此代码中的imgUrl是身份证照片,此处省略,测试时是有效的url。
使用https方式调用时是可以成功的,代码很简单,怀疑是个云端bug