From 05382ad5b2e0e4c48b36c7081dd5a74adfcfbdde Mon Sep 17 00:00:00 2001 From: lxy Date: Tue, 11 Mar 2025 14:39:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=89=A9=E6=B5=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/service/wechat/WechatMp.d.ts | 27 ++++++++++++- es/service/wechat/WechatMp.js | 46 +++++++++++++++++++++ es/types/Wechat.d.ts | 21 ++++++++++ lib/service/wechat/WechatMp.d.ts | 27 ++++++++++++- lib/service/wechat/WechatMp.js | 46 +++++++++++++++++++++ lib/types/Wechat.d.ts | 21 ++++++++++ src/service/wechat/WechatMp.ts | 69 +++++++++++++++++++++++++++++++- src/types/Wechat.ts | 57 +++++++++++++++++++------- 8 files changed, 296 insertions(+), 18 deletions(-) diff --git a/es/service/wechat/WechatMp.d.ts b/es/service/wechat/WechatMp.d.ts index 1af3be3..b441c6c 100644 --- a/es/service/wechat/WechatMp.d.ts +++ b/es/service/wechat/WechatMp.d.ts @@ -52,7 +52,7 @@ type UploadShippingInfo = { }; }>; }; -import { AddExpressOrderData, CancelExpressOrderData } from '../../types/Wechat'; +import { AddExpressOrderData, CancelExpressOrderData, getExpressPathData, getWaybillTokenData } from '../../types/Wechat'; export declare class WechatMpInstance { appId: string; appSecret?: string; @@ -195,5 +195,30 @@ export declare class WechatMpInstance { * @param data */ cancelExpressOrder(data: CancelExpressOrderData): Promise; + /** + * 查询运单轨迹 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html + * @param data + */ + getExpressPath(data: getExpressPathData): Promise<{ + path_item_num: number; + path_item_list: Array<{ + action_time: number; + action_type: number; + action_msg: string; + }>; + }>; + /** + * 获取运单token + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + getWaybillToken(data: getWaybillTokenData): Promise; + /** + * 获取运单状态 + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + getExpressState(waybillToken: string): Promise; } export {}; diff --git a/es/service/wechat/WechatMp.js b/es/service/wechat/WechatMp.js index a67c27c..29e51b3 100644 --- a/es/service/wechat/WechatMp.js +++ b/es/service/wechat/WechatMp.js @@ -420,4 +420,50 @@ export class WechatMpInstance { body: JSON.stringify(data), }); } + /** + * 查询运单轨迹 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html + * @param data + */ + async getExpressPath(data) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=${token}`, { + method: 'POST', + body: JSON.stringify(data), + }); + const { path_item_num, path_item_list } = result; + return { + path_item_num, + path_item_list, + }; + } + /** + * 获取运单token + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getWaybillToken(data) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/trace_waybill?access_token=${token}`, { + method: 'POST', + body: JSON.stringify(data), + }); + const { waybill_token } = result; + return waybill_token; + } + /** + * 获取运单状态 + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getExpressState(waybillToken) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/query_trace?access_token=${token}`, { + method: 'POST', + body: JSON.stringify({ + waybill_token: waybillToken, + }), + }); + return result; + } } diff --git a/es/types/Wechat.d.ts b/es/types/Wechat.d.ts index 4fd52af..e6b35e3 100644 --- a/es/types/Wechat.d.ts +++ b/es/types/Wechat.d.ts @@ -110,4 +110,25 @@ export type CancelExpressOrderData = { waybill_id: string; order_id: string; }; +export type getExpressPathData = { + openId?: string; + delivery_id: string; + waybill_id: string; +}; +export type getWaybillTokenData = { + openId?: string; + sender_phone?: string; + receiver_phone: string; + delivery_id?: string; + waybill_id: string; + goods_info: { + detail_list: { + goods_name: string; + goods_img_url: string; + goods_desc?: string; + }[]; + }; + trans_id?: string; + order_detail_path?: string; +}; export {}; diff --git a/lib/service/wechat/WechatMp.d.ts b/lib/service/wechat/WechatMp.d.ts index 1af3be3..b441c6c 100644 --- a/lib/service/wechat/WechatMp.d.ts +++ b/lib/service/wechat/WechatMp.d.ts @@ -52,7 +52,7 @@ type UploadShippingInfo = { }; }>; }; -import { AddExpressOrderData, CancelExpressOrderData } from '../../types/Wechat'; +import { AddExpressOrderData, CancelExpressOrderData, getExpressPathData, getWaybillTokenData } from '../../types/Wechat'; export declare class WechatMpInstance { appId: string; appSecret?: string; @@ -195,5 +195,30 @@ export declare class WechatMpInstance { * @param data */ cancelExpressOrder(data: CancelExpressOrderData): Promise; + /** + * 查询运单轨迹 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html + * @param data + */ + getExpressPath(data: getExpressPathData): Promise<{ + path_item_num: number; + path_item_list: Array<{ + action_time: number; + action_type: number; + action_msg: string; + }>; + }>; + /** + * 获取运单token + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + getWaybillToken(data: getWaybillTokenData): Promise; + /** + * 获取运单状态 + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + getExpressState(waybillToken: string): Promise; } export {}; diff --git a/lib/service/wechat/WechatMp.js b/lib/service/wechat/WechatMp.js index bfe3c50..38dc568 100644 --- a/lib/service/wechat/WechatMp.js +++ b/lib/service/wechat/WechatMp.js @@ -424,5 +424,51 @@ class WechatMpInstance { body: JSON.stringify(data), }); } + /** + * 查询运单轨迹 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html + * @param data + */ + async getExpressPath(data) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=${token}`, { + method: 'POST', + body: JSON.stringify(data), + }); + const { path_item_num, path_item_list } = result; + return { + path_item_num, + path_item_list, + }; + } + /** + * 获取运单token + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getWaybillToken(data) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/trace_waybill?access_token=${token}`, { + method: 'POST', + body: JSON.stringify(data), + }); + const { waybill_token } = result; + return waybill_token; + } + /** + * 获取运单状态 + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getExpressState(waybillToken) { + const token = await this.getAccessToken(); + const result = await this.access(`https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/query_trace?access_token=${token}`, { + method: 'POST', + body: JSON.stringify({ + waybill_token: waybillToken, + }), + }); + return result; + } } exports.WechatMpInstance = WechatMpInstance; diff --git a/lib/types/Wechat.d.ts b/lib/types/Wechat.d.ts index 4fd52af..e6b35e3 100644 --- a/lib/types/Wechat.d.ts +++ b/lib/types/Wechat.d.ts @@ -110,4 +110,25 @@ export type CancelExpressOrderData = { waybill_id: string; order_id: string; }; +export type getExpressPathData = { + openId?: string; + delivery_id: string; + waybill_id: string; +}; +export type getWaybillTokenData = { + openId?: string; + sender_phone?: string; + receiver_phone: string; + delivery_id?: string; + waybill_id: string; + goods_info: { + detail_list: { + goods_name: string; + goods_img_url: string; + goods_desc?: string; + }[]; + }; + trans_id?: string; + order_detail_path?: string; +}; export {}; diff --git a/src/service/wechat/WechatMp.ts b/src/service/wechat/WechatMp.ts index 8f3e600..1078eb4 100644 --- a/src/service/wechat/WechatMp.ts +++ b/src/service/wechat/WechatMp.ts @@ -70,7 +70,7 @@ type UploadShippingInfo = { }>; } -import { AddExpressOrderData, CancelExpressOrderData } from '../../types/Wechat'; +import { AddExpressOrderData, CancelExpressOrderData, getExpressPathData, getWaybillTokenData } from '../../types/Wechat'; export class WechatMpInstance { appId: string; @@ -695,4 +695,71 @@ export class WechatMpInstance { } ); } + + /** + * 查询运单轨迹 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html + * @param data + */ + async getExpressPath(data: getExpressPathData) { + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/express/business/path/get?access_token=${token}`, + { + method: 'POST', + body: JSON.stringify(data), + } + ); + + const { path_item_num, path_item_list } = result; + return { + path_item_num, + path_item_list, + } as { + path_item_num: number; + path_item_list: Array<{ + action_time: number, + action_type: number, + action_msg: string, + }> + } + } + + /** + * 获取运单token + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getWaybillToken(data: getWaybillTokenData) { + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/trace_waybill?access_token=${token}`, + { + method: 'POST', + body: JSON.stringify(data), + } + ); + const { waybill_token } = result; + return waybill_token as string; + } + + /** + * 获取运单状态 + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html + * @param data + */ + async getExpressState(waybillToken: string) { + const token = await this.getAccessToken(); + const result = await this.access( + `https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/query_trace?access_token=${token}`, + { + method: 'POST', + body: JSON.stringify({ + waybill_token: waybillToken, + }), + } + ); + return result; + } + } diff --git a/src/types/Wechat.ts b/src/types/Wechat.ts index 655f6ca..897ff3a 100644 --- a/src/types/Wechat.ts +++ b/src/types/Wechat.ts @@ -12,22 +12,22 @@ export type WechatPublicEventData = { CreateTime: number; MsgID: string; MsgType: - | 'text' - | 'image' - | 'voice' - | 'video' - | 'location' - | 'link' - | 'event'; // 消息类型; event接收事件推送 + | 'text' + | 'image' + | 'voice' + | 'video' + | 'location' + | 'link' + | 'event'; // 消息类型; event接收事件推送 // 接收事件 Event?: - | 'subscribe' - | 'unsubscribe' - | 'SCAN' - | 'LOCATION' - | 'CLICK' - | 'VIEW' - | 'TEMPLATESENDJOBFINISH'; // MsgType是event + | 'subscribe' + | 'unsubscribe' + | 'SCAN' + | 'LOCATION' + | 'CLICK' + | 'VIEW' + | 'TEMPLATESENDJOBFINISH'; // MsgType是event EventKey?: string; // 事件KEY值,subscribe: qrscene_为前缀,后面为二维码的参数值; SCAN: 一个32位无符号整数,即创建二维码时的二维码scene_id; CLICK: 自定义菜单接口中KEY值对应; VIEW: 设置的跳转URL; Ticket?: string; // subscribe 二维码的ticket,可用来换取二维码图片 Latitude?: string; // LOCATION 地理位置纬度 @@ -141,4 +141,31 @@ export type CancelExpressOrderData = { delivery_id: string; waybill_id: string; order_id: string; -}; \ No newline at end of file +}; + +// 查询运单轨迹 +// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/express/express-by-business/getPath.html +export type getExpressPathData = { + openId?: string; + delivery_id: string, + waybill_id: string, +} + +//传运单 +// https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html +export type getWaybillTokenData = { + openId?: string; + sender_phone?: string; + receiver_phone: string; + delivery_id?: string, + waybill_id: string, + goods_info: { + detail_list: { + goods_name: string, + goods_img_url: string, + goods_desc?: string, + }[] + }, + trans_id?: string, //当前非必填 https://developers.weixin.qq.com/community/develop/doc/000e2e2c284a089a965d8f2765bc00?highLine=trans_id + order_detail_path?: string, +} \ No newline at end of file