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

WeChat small program capacity side using previewTemplate


May 19, 2021 WeChat Mini Program Development Document


Table of contents


logistics.previewTemplate

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

Preview the facet template. Used for debugging face-to-face templates.

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

POST https://api.weixin.qq.com/cgi-bin/express/delivery/template/preview?access_token=ACCESS_TOKEN

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials
waybill_id string Is The ticket ID
waybill_template string Is Facet HTML template content (base64 encoded)
waybill_data string Is Facet data. For more information, refer to WaybillData in the return value of the order event
custom Object Is Merchant order data in the format of the request body in the Merchant Side Order API

Returns a value

Object

Property Type Description
waybill_id string The ticket ID
rendered_waybill_template string Rendered single-sided HTML file (base64 encoded)
errcode number Error code
errmsg string The error message

The legal value of errcode

Value Description The lowest version
0 Success
-1 Other errors
40199 The ticket ID was incorrect and the ticket was not found
9300507 Token is incorrect
9300502 This error occurs in the preview template, typically because waybill_data data error
9300512 The template is in the wrong format and the rendering failed

An example of requesting data

{
  "waybill_id": "1234567890123",
  "waybill_data": "##ZTO_mark##11-22-33##ZTO_bagAddr##广州##",
  "waybill_template": "PGh0bWw+dGVzdDwvaHRtbD4=",
  "custom": {
    "order_id": "012345678901234567890123456789",
    "openid": "oABC123456",
    "delivery_id": "ZTO",
    "biz_id": "xyz",
    "custom_remark": "易碎物品",
    "sender": {
      "name": "张三",
      "tel": "18666666666",
      "mobile": "020-88888888",
      "company": "公司名",
      "post_code": "123456",
      "country": "中国",
      "province": "广东省",
      "city": "广州市",
      "area": "海珠区",
      "address": "XX路XX号XX大厦XX栋XX"
    },
    "receiver": {
      "name": "王小蒙",
      "tel": "18610000000",
      "mobile": "020-77777777",
      "company": "公司名",
      "post_code": "654321",
      "country": "中国",
      "province": "广东省",
      "city": "广州市",
      "area": "天河区",
      "address": "XX路XX号XX大厦XX栋XX"
    },
    "shop": {
      "wxa_path": "/index/index?from=waybill",
      "img_url": "https://mmbiz.qpic.cn/mmbiz_png/KfrZwACMrmwbPGicysN6kibW0ibXwzmA3mtTwgSsdw4Uicabduu2pfbfwdKicQ8n0v91kRAUX6SDESQypl5tlRwHUPA/640",
      "goods_name": "一千零一夜钻石包&爱马仕柏金钻石包",
      "goods_count": 2
    },
    "cargo": {
      "count": 2,
      "weight": 5.5,
      "space_x": 30.5,
      "space_y": 20,
      "space_z": 20,
      "detail_list": [
        {
          "name": "一千零一夜钻石包",
          "count": 1
        },
        {
          "name": "爱马仕柏金钻石包",
          "count": 1
        }
      ]
    },
    "insured": {
      "use_insured": 1,
      "insured_value": 10000
    },
    "service": {
      "service_type": 0,
      "service_name": "标准快递"
    }
  }
}

Return an example of the data

{
  "waybill_id": "1234567890123",
  "rendered_waybill_template": "PGh0bWw+dGVzdDwvaHRtbD4="
}

The template renders the syntax

  1. All rendering syntaxes are # Starting for Reference To Examples.
  2. The #VAR (key) is populated with a value corresponding to the parameter key. The supported parameters are shown in the table below
key value
sys.waybillid The ticket ID
sys.wxaappid Merchant applet APPID
waybilldata.* Order events return custom data in WaybillData, express side
custom.* is an incoming field in the Merchant Side Order API
custom.order_id The ID that uniquely identifies the order and is passed in by the merchant
custom.custom_remark Express notes, printed to custom areas of the face list, such as "fragile items"
custom.sender.name The sender's name
custom.sender.tel Sender landline number
custom.sender.mobile The sender's mobile phone number
custom.sender.company The name of the sender's company
custom.sender.post_code Sender zip code
custom.sender.country The country in which the sender is located
custom.sender.province Sender's province
custom.sender.city Sender region/city
custom.sender.area Sender area/county
custom.sender.address The sender's detailed address
custom.receiver.name The recipient's first name
custom.receiver.tel The recipient landline number
custom.receiver.mobile The recipient's mobile phone number
custom.receiver.company The recipient's company name
custom.receiver.post_code Recipient zip code
custom.receiver.country The recipient's country
custom.receiver.province The province of the recipient
custom.receiver.city Recipient region/city
custom.receiver.area Recipient area/county
custom.receiver.address The recipient's detailed address
custom.cargo.count The number of packages
custom.cargo.weight Total package weight in kg (kg)
custom.cargo.space_x Package length in centimeters (cm)
custom.cargo.space_y Package width in centimeters (cm)
custom.cargo.space_z Package height in centimeters (cm)
custom.shop.goods_name The name of the product
custom.shop.goods_count The quantity of goods
custom.insured.use_insured Whether to use a guaranteed price
custom.insured.insured_value Quote amount, in points
custom.service.service_type Service type ID
custom.service.service_name The name of the service
  1. The #TIME (DATE) fills the current position with a date in the format %Y/%m/%d, e.g. 2018/11/22.
  2. The #TIME (TIME) fills the current position with time in the format %H:%M:%S, e.g. 17:54:06.
  3. The #TIME (FULL) fills the current position with date time in the format %Y/%m/%d %H:%M:%M:%S, e.g. 2018/11/22 17:54:06.
  4. The #STRBLOAT (VAR (sys.waybillid)) gets the ticket ID and fills in spaces between each character.
  5. The #CODE128 (sys.waybillid)) gets the waybly ID and converts it to CODE128, pictured is base64 code.
  6. The #QRCODE (sys.waybillid) gets the waybly ID and converts it to a QR code, pictured is base64.
  7. The #WXASUNCODE (VAR (sys.wxaappid)) gets the merchant's small program code, pictured is base64 code.
For example, if you want to print a barcode with packaged information on a face list, you can add:
<img src="data:image/jpeg;base64, ##CODE128(VAR(waybilldata.ZTO_bagAddr))" class="block_5__barCode">

Cloud calls

Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.

The interface method

openapi.logistics.previewTemplate
Permissions for the logistics.previewTemplate API need to be configured in config.json, details

Request parameters

Property Type The default Required Description
waybillId string Is The ticket ID
waybillTemplate string Is Facet HTML template content (base64 encoded)
waybillData string Is Facet data. For more information, refer to WaybillData in the return value of the order event
custom Object Is Merchant order data in the format of the request body in the Merchant Side Order API

Returns a value

Object

Property Type Description
waybillId string The ticket ID
renderedWaybillTemplate string Rendered single-sided HTML file (base64 encoded)
errCode number Error code
errMsg string The error message

The legal value of errCode

Value Description The lowest version
0 Success

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
-1 Other errors
40199 The ticket ID was incorrect and the ticket was not found
9300507 Token is incorrect
9300502 This error occurs in the preview template, typically because waybill_data data error
9300512 The template is in the wrong format and the rendering failed

An example of requesting data

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.logistics.previewTemplate({
        custom: {
          openid: 'oABC123456',
          sender: {
            name: '张三',
            tel: '18666666666',
            mobile: '020-88888888',
            company: '公司名',
            country: '中国',
            province: '广东省',
            city: '广州市',
            area: '海珠区',
            address: 'XX路XX号XX大厦XX栋XX',
            postCode: '123456'
          },
          receiver: {
            name: '王小蒙',
            tel: '18610000000',
            mobile: '020-77777777',
            company: '公司名',
            country: '中国',
            province: '广东省',
            city: '广州市',
            area: '天河区',
            address: 'XX路XX号XX大厦XX栋XX',
            postCode: '654321'
          },
          shop: {
            wxaPath: '/index/index?from=waybill',
            imgUrl: 'https://mmbiz.qpic.cn/mmbiz_png/KfrZwACMrmwbPGicysN6kibW0ibXwzmA3mtTwgSsdw4Uicabduu2pfbfwdKicQ8n0v91kRAUX6SDESQypl5tlRwHUPA/640',
            goodsName: '一千零一夜钻石包&爱马仕柏金钻石包',
            goodsCount: 2
          },
          cargo: {
            count: 2,
            weight: 5.5,
            spaceX: 30.5,
            spaceY: 20,
            spaceZ: 20,
            detailList: [
              {
                name: '一千零一夜钻石包',
                count: 1
              },
              {
                name: '爱马仕柏金钻石包',
                count: 1
              }
            ]
          },
          insured: {
            useInsured: 1,
            insuredValue: 10000
          },
          service: {
            serviceType: 0,
            serviceName: '标准快递'
          },
          orderId: '012345678901234567890123456789',
          deliveryId: 'ZTO',
          bizId: 'xyz',
          customRemark: '易碎物品'
        },
        waybillId: '1234567890123',
        waybillData: '##ZTO_mark##11-22-33##ZTO_bagAddr##广州##',
        waybillTemplate: 'PGh0bWw+dGVzdDwvaHRtbD4='
      })
    return result
  } catch (err) {
    return err
  }
}

Return an example of the data

{
  "waybillId": "1234567890123",
  "renderedWaybillTemplate": "PGh0bWw+dGVzdDwvaHRtbD4=",
  "errMsg": "openapi.logistics.previewTemplate:ok"
}