微信小程序 小程序使用·getPrinter
作者: --时间: 2022-09-29
阅读量:
标题:使用微信小程序getPrinter接口实现打印员获取
若想要使用微信打单 PC 软件,需要调用微信小程序的logistics.getPrinter接口来获取打印员。接口可以通过HTTPS调用或云调用实现。
1. HTTPS调用
发起GET请求到如下地址获取所有已经绑定的打印员列表:
GET https://api.weixin.qq.com/cgi-bin/express/business/printer/getall?access_token=ACCESS_TOKEN
其中,access_token为接口调用凭证,并且在请求参数中是必填项。成功返回数据示例如下:
{
"count": 2,
"openid": [
"oABC",
"oXYZ"
],
"tagid_list": [
"123",
"456"
]
}
2. 云调用
小程序·云开发提供了在云函数中调用微信开放接口的能力。
使用API时需要先在config.json中配置logistics.getPrinter API 的权限。接口方法为:
openapi.logistics.getPrinter
请求示例:
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.logistics.getPrinter({})
return result
} catch (err) {
return err
}
}
返回数据示例如下:
{
"count": 2,
"openid": [
"oABC",
"oXYZ"
],
"tagidList": [
"123",
"456"
],
"errMsg": "openapi.logistics.getPrinter:ok"
}
通过以上两种调用方式可以实现获取打印员的功能。如果您是企业用户,并且需要开发微信小程序来实现相关需求,欢迎咨询我们的小程序开发服务。

