coa-wx-isv
Version:
一个轻量的微信SDK服务商版 for Node.js
77 lines (76 loc) • 5.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WxIsvExpressService = void 0;
const coa_error_1 = require("coa-error");
const coa_helper_1 = require("coa-helper");
const WxIsvServiceBase_1 = require("../libs/WxIsvServiceBase");
class WxIsvExpressService extends WxIsvServiceBase_1.WxIsvServiceBase {
// 批量获取运单数据 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.batchGetOrder.html
async batchGetOrder(accessToken, orderList) {
const order_list = coa_helper_1.$.snakeCaseKeys(orderList);
return (await this.request('POST', '/cgi-bin/express/business/order/batchget', { order_list }, { access_token: accessToken }));
}
// 生成运单 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.addOrder.html
async addOrder(accessToken, order) {
const orderData = coa_helper_1.$.snakeCaseKeys(order);
return (await this.request('POST', '/cgi-bin/express/business/order/add', orderData, { access_token: accessToken }));
}
// 绑定、解绑物流账号 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.bindAccount.html
async bindAccount(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/account/bind', param, { access_token: accessToken }));
}
// 取消运单 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.cancelOrder.html
async cancelOrder(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/order/cancel', param, { access_token: accessToken }));
}
// 获取所有绑定的物流账号 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getAllAccount.html
async getAllAccount(accessToken) {
return (await this.request('GET', '/cgi-bin/express/business/account/getall', {}, { access_token: accessToken }));
}
// 获取支持的快递公司列表 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getAllDelivery.html
async getAllDelivery(accessToken) {
return (await this.request('GET', '/cgi-bin/express/business/delivery/getall', {}, { access_token: accessToken }));
}
// 获取运单数据 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getOrder.html
async getOrder(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/order/get', param, { access_token: accessToken }));
}
// 查询运单轨迹 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getPath.html
async getPath(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/path/get', param, { access_token: accessToken }));
}
// 获取打印员。若需要使用微信打单 PC 软件,才需要调用。 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getPrinter.html
async getPrinter(accessToken) {
return (await this.request('GET', '/cgi-bin/express/business/printer/getall', {}, { access_token: accessToken }));
}
// 获取电子面单余额。仅在使用加盟类快递公司时,才可以调用。 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.getQuota.html
async getQuota(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/quota/get', param, { access_token: accessToken }));
}
// 模拟快递公司更新订单状态, 该接口只能用户测试 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.testUpdateOrder.html
async testUpdateOrder(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/test_update_order', param, { access_token: accessToken }));
}
// 配置面单打印员,可以设置多个,若需要使用微信打单 PC 软件,才需要调用。 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/express/by-business/logistics.updatePrinter.html
async updatePrinter(accessToken, data) {
const param = coa_helper_1.$.snakeCaseKeys(data);
return (await this.request('POST', '/cgi-bin/express/business/printer/update', param, { access_token: accessToken }));
}
customErrorHandler(res) {
const data = res.data || {};
const errorCode = coa_helper_1._.toNumber(data.errcode) || 0;
// 快递公司系统错误,其他错误则执行默认操作
if (errorCode === 9300501) {
const code = data.delivery_resultcode || '';
const message = data.delivery_resultmsg || '快递公司未知错误';
coa_error_1.CoaError.throw('WxIsvExpress.ExpressReturnError.' + code, message);
}
}
}
exports.WxIsvExpressService = WxIsvExpressService;