# uniformMessage.send

Call this API at the server side. For more information, see Server API.

This API supports Cloud Calls. The WeChat DevTools version must be 1.02.1904090 or later (download the latest stable version here), and the wx-server-sdk version must be 0.4.0 or later.

Delivers a uniform service message for Mini Programs and Official Accounts.

Calling methods:

# HTTPS Call

# Request Address

POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
touser string Yes The openid of the user. It can be the openid of a Mini Program or the openid of the Official Account corresponding to `mp_template_msg.appid.
weapp_template_msg Object No Information related to a Mini Program's template message. For details, see the template message API for Mini Programs. If this field is available, template messages of Mini Programs are preferentially sent.
mp_template_msg Object Yes Information related to an Official Account's template message. For details, see the template message API for Official Accounts. If this field is available and weapp_template_msg field is not available, template messages of Official Accounts are sent.

weapp_template_msg is composed as follows

Property Type Default Required Description
template_id string Yes The ID of the Mini Program template
page string Yes The path of a Mini Program page
form_id string Yes The formid of a template message of the Mini Program
data string Yes The data of a Mini Program template
emphasis_keyword string Yes The enlarged keyword on a Mini Program template

mp_template_msg is composed as follows

Property Type Default Required Description
appid string Yes The AppID of the Official Account. It must be bound with a Mini Program and owned by the same entity with the Mini Program.
template_id string Yes The ID of an Official Account template.
url string Yes The URL to be redirected to from a template message of the Official Account.
miniprogram string Yes The Mini Program to be redirected to from a template message of the Official Account. It must be bound with the Official Account.
data string Yes The data of a template message of the Official Account.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
errcode number Error code
errmsg string Error message

# Errors

Error Code Error Message Description
40037 weapp_template_msg.template_id or mp_template_msg.template_id is incorrect.
41028 weapp_template_msg.form_id expired or is incorrect.
41029 weapp_template_msg.form_id is already in use.
41030 Weapp_template_msg.page is incorrect.
45009 API calls exceeded the upper limit.
40003 The openid of touser is incorrect.
40013 The appid is incorrect or failed to meet binding requirements.

# Request Data Example

{
    "touser":"OPENID",
    "weapp_template_msg":{
        "template_id":"TEMPLATE_ID",
        "page":"page/page/index",
        "form_id":"FORMID",
        "data":{
            "keyword1":{
                "value":"339208499"
            },
            "keyword2":{
                "value":"2015-01-05,  12:30"
            },
            "keyword3":{
                "value":"Tencent WeChat Headquarters"
            },
            "keyword4":{
                "value":"No. 397, Xingang Zhonglu, Haizhu District, Guangzhou"
            }
        },
        "emphasis_keyword":"keyword1.DATA"
    },
    "mp_template_msg":{
        "appid":"APPID ",
        "template_id":"TEMPLATE_ID",
        "url":"http://weixin.qq.com/download",
        "miniprogram":{
            "appid":"xiaochengxuappid12345",
            "pagepath":"index?foo=bar"
        },
        "data":{
            "first":{
                "value":"Purchase succeeded!",
                "color":"#173177"
            },
            "keyword1":{
                "value":"Chocolates",
                "color":"#173177"
            },
            "keyword2":{
                "value":"39.8CNY",
                "color":"#173177"
            },
            "keyword3":{
                "value":"2014-9-22, ",
                "color":"#173177"
            },
            "remark":{
                "value":"Welcome to purchase more!",
                "color":"#173177"
            }
        }
    }
}

# Return Data Example

{
 "errcode": 0,
 "errmsg": "ok"
}

# Cloud Call

Cloud call is a capability provided by Mini Program·Cloud Base that allows you to call WeChat APIs in a cloud function. It must be used via wx-server-sdk in the cloud function.

# API Calling Method

openapi.uniformMessage.send

You need to configure the permissions for the uniformMessage.send API via config.json. Details

# Request Parameters

Attribute Type Default Required Description
touser string Yes The openid of the user. It can be the openid of a Mini Program or the openid of the Official Account corresponding to `mp_template_msg.appid.
weappTemplateMsg Object No Information related to a Mini Program's template message. For details, see the template message API for Mini Programs. If this field is available, template messages of Mini Programs are preferentially sent.
mpTemplateMsg Object Yes Information related to an Official Account's template message. For details, see the template message API for Official Accounts. If this field is available and weapp_template_msg field is not available, template messages of Official Accounts are sent.

weappTemplateMsg is composed as follows

Property Type Default Required Description
templateId string Yes The ID of the Mini Program template
page string Yes The path of a Mini Program page
formId string Yes The formid of a template message of the Mini Program
data string Yes The data of a Mini Program template
emphasisKeyword string Yes The enlarged keyword on a Mini Program template

mpTemplateMsg is composed as follows

Property Type Default Required Description
appid string Yes The AppID of the Official Account. It must be bound with a Mini Program and owned by the same entity with the Mini Program.
templateId string Yes The ID of an Official Account template.
url string Yes The URL to be redirected to from a template message of the Official Account.
miniprogram string Yes The Mini Program to be redirected to from a template message of the Official Account. It must be bound with the Official Account.
data string Yes The data of a template message of the Official Account.

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
errCode number Error code
errMsg string Error message

# Exceptions

# Object

Thrown Exceptions

Property Type Description
errCode number Error code
errMsg string Error message

Valid values of errCode

Value Description Minimum Version

# Errors

Error Code Error Message Description
40037 weapp_template_msg.template_id or mp_template_msg.template_id is incorrect.
41028 weapp_template_msg.form_id expired or is incorrect.
41029 weapp_template_msg.form_id is already in use.
41030 Weapp_template_msg.page is incorrect.
45009 API calls exceeded the upper limit.
40003 The openid of touser is incorrect.
40013 The appid is incorrect or failed to meet binding requirements.

# Request Data Example

const cloud = require('wx-server-sdk')
  cloud.init()
  exports.main = async (event, context) => {
    try {
      const result = await cloud.openapi.uniformMessage.send({
        touser: 'OPENID',
        weappTemplateMsg: {
          page: 'page/page/index',
          data: {
            keyword1: {
              value: '339208499'
            },
            keyword2: {
              value: '2015-01-05,  12:30'
            },
            keyword3: {
              value: 'Tencent WeChat Headquarters'
            },
            keyword4: {
              value: 'No. 397, Xingang Zhonglu, Haizhu District, Guangzhou'
            }
          },
          templateId: 'TEMPLATE_ID',
          formId: 'FORMID',
          emphasisKeyword: 'keyword1.DATA'
        },
        mpTemplateMsg: {
          appid: 'APPID ',
          url: 'http://weixin.qq.com/download',
          miniprogram: {
            appid: 'xiaochengxuappid12345',
            pagepath: 'index?foo=bar'
          },
          data: {
            first: {
              value: 'Purchase successful!',
              color: '#173177'
            },
            keyword1: {
              value: 'Chocolates',
              color: '#173177'
            },
            keyword2: {
              value: '39.8CNY',
              color: '#173177'
            },
            keyword3: {
              value: '2014-9-22, ',
              color: '#173177'
            },
            remark: {
              value: 'Come back to shop again soon!',
              color: '#173177'
            }
          },
          templateId: 'TEMPLATE_ID'
        }
      })
      console.log(result)
      return result
    } catch (err) {
      console.log(err)
      return err
    }
  }

# Return Data Example

{
  "errCode": 0,
  "errMsg": "openapi.uniformMessage.send:ok"
}