Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Small Programs Service Market invokeService


May 20, 2021 WeChat Mini Program Development Document


Table of contents


serviceMarket.invokeService

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:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

POST https://api.weixin.qq.com/wxa/servicemarket?access_token=ACCESS_TOKEN

Request parameters

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

Returns a value

Object

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

An example of requesting data

{
  "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"
}

Return an example of the data

{
 "errcode": 0,
 "errmsg": "ok",
 "data": "{\"idcard_res\":{\"type\":0,\"name\":{\"text\":\"abc\",\"pos\"…0312500}}},\"image_width\":480,\"image_height\":304}}"
}

Cloud calls

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.

The interface method

openapi.serviceMarket.invokeService
Permissions for the serviceMarket.invokeService API need to be configured in config.json, details

Request parameters

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

Returns a value

Object

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

Abnormal

Object

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

An example of requesting data

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
  }
}

Return an example of the data

{
  "errCode": 0,
  "errMsg": "openapi.serviceMarket.invokeService:ok",
  "data": "{\"idcardRes\":{\"type\":0,\"name\":{\"text\":\"abc\",\"pos\"…0312500}}},\"imageWidth\":480,\"imageHeight\":304}}"
}