May 20, 2021 WeChat Mini Program Development Document
This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0
Call the service provided by the service platform
How to call:
POST https://api.weixin.qq.com/wxa/servicemarket?access_token=ACCESS_TOKEN
Property | Type | The default | Required | Description |
---|---|---|---|---|
access_token | string | Is | The interface calls the credentials | |
service | string | Is | The service ID | |
Api | string | Is | The name of the interface | |
data | string | Is | Data in JSON format defined by the service provider interface | |
client_msg_id | string | Is | Random string ID, the unique identity requested by the caller |
The returned JSON packet
Property | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | The error message |
template_id | string | Add to the template id under your account, as needed to send a small program template message |
{
"service" : "wx79ac3de8be320b71",
"api" : "OcrAllInOne",
"data" : {
"img_url": "http://mmbiz.qpic.cn/mmbiz_jpg/7UFjuNbYxibu66xSqsQqKcuoGBZM77HIyibdiczeWibdMeA2XMt5oibWVQMgDibriazJSOibLqZxcO6DVVcZMxDKgeAtbQ/0",
"data_type": 3,
"ocr_type": 1
},
"client_msg_id" : "id123"
}
{
"errcode": 0,
"errmsg": "ok",
"data": "{\"idcard_res\":{\"type\":0,\"name\":{\"text\":\"abc\",\"pos\"…0312500}}},\"image_width\":480,\"image_height\":304}}"
}
Cloud calling is the ability provided by the small program Cloud Development to invoke WeChat's open interface in cloud functions and needs to be used in cloud functions via wx-server-sdk.
openapi.serviceMarket.invokeService
Permissions for the serviceMarket.invokeService API need to be configured in config.json, details
Property | Type | The default | Required | Description |
---|---|---|---|---|
service | string | Is | The service ID | |
Api | string | Is | The name of the interface | |
data | string | Is | Data in JSON format defined by the service provider interface | |
clientMsgId | string | Is | Random string ID, the unique identity requested by the caller |
The returned JSON packet
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
templateId | string | Add to the template id under your account, as needed to send a small program template message |
The exception thrown
Property | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.serviceMarket.invokeService({
service: 'wx79ac3de8be320b71',
api: 'OcrAllInOne',
data: {
imgUrl: 'http://mmbiz.qpic.cn/mmbiz_jpg/7UFjuNbYxibu66xSqsQqKcuoGBZM77HIyibdiczeWibdMeA2XMt5oibWVQMgDibriazJSOibLqZxcO6DVVcZMxDKgeAtbQ/0',
dataType: 3,
ocrType: 1
},
clientMsgId: 'id123'
})
return result
} catch (err) {
return err
}
}
{
"errCode": 0,
"errMsg": "openapi.serviceMarket.invokeService:ok",
"data": "{\"idcardRes\":{\"type\":0,\"name\":{\"text\":\"abc\",\"pos\"…0312500}}},\"imageWidth\":480,\"imageHeight\":304}}"
}