Files
KJD/Work/Api/Wx/WxOrderApi.cs
2026-10-30 11:30:02 +08:00

246 lines
22 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using AllBase.Model.Result;
using AllBase.Model.Param.WXParam;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Work.Api.Wx
{
/// <summary>微信小店订单查询、备注、解密及发货接口;独立于原窗体,使用 HttpHelper 发送请求。</summary>
/// <remarks>传入原 ShopLoginInfo 登录信息;方法同步执行,界面调用请置于后台任务。返回原始正文,不自动登录、重试或解释业务状态。</remarks>
public static class WxOrderApi
{
/// <summary>按订单状态分页查询订单,可指定创建时间范围。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderStatus">微信订单状态筛选值,原列表查询默认使用 20;以当前接口枚举为准。 默认值:20。</param>
/// <param name="pageNum">页码,从 1 开始。 默认值:1。</param>
/// <param name="pageSize">每页条数,默认值沿用原调用。 默认值:30。</param>
/// <param name="timeStart">订单创建开始时间的 Unix 毫秒时间戳;与 timeEnd 同时提供才生效。 默认值:null。</param>
/// <param name="timeEnd">订单创建结束时间的 Unix 毫秒时间戳;与 timeStart 同时提供才生效。 默认值:null。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.orderListSearch。
/// 保留旧行为:同时指定开始与结束时间时,实际 pageSize 固定为 30。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string OrderListSearch(ShopLoginInfo shop, int orderStatus = 20, int pageNum = 1, int pageSize = 30, long? timeStart = null, long? timeEnd = null)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string body = @"{""isSearch"":false,""pageSize"":" + pageSize + @",""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":1" + @",""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus + @"}";
if (pageNum > 1)
body = @"{""isSearch"":false,""pageSize"":" + pageSize + @",""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":1" + @",""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus + @",""page"":" + pageNum + @"}";
if (timeStart != null && timeEnd != null)
body = @"{""isSearch"":true,""pageSize"":30,""orderId"":"""",""orderTime"":{""type"":0,""time"":[" + timeStart + @"," + timeEnd + @"]},
""telNumber"":"""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",""merchantNotes"":"""",""merchantNotesTagColor"":0,
""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,
""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":" + pageNum + @",""overTime"":0,""pengingShipOneDay"":0,
""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":1,""onAftersaleOrderExist"":0,
""orderStatus"":" + orderStatus + @",""startCreateTime"":" + timeStart + @",""endCreateTime"":" + timeEnd + @"}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>查询订单;单参数重载按订单号查询,双参数重载按商品标题和收件人查询。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.orderSearch。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string OrderSearch(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string body = @"{""isSearch"":true,""pageSize"":30,""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,
""waybillStatus"":0,""pageNum"":1,""onAftersaleOrderExist"":0,""orderStatus"":0,""orderId"":""" + orderId + @""",
""orderTime"":{""type"":0,""time"":[null,null]},""telNumber"":"""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",
""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,
""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",
""page"":1,""startCreateTime"":null,""endCreateTime"":null}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>给订单添加商家备注及颜色标签。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <param name="notes">商家订单备注文本。</param>
/// <param name="tagColor">商家备注颜色的接口值,0 沿用原代码默认值。 默认值:0。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.addNotes。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string AddNotes(ShopLoginInfo shop, string orderId, string notes, int tagColor = 0)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/common/cgi/batchMerchantNotes?token=&lang=zh_CN";
string body = @"{""items"":[{""orderId"":""" + orderId + @""",""merchantNotes"":""" + notes + @""",""merchantNotesTagColor"":" + tagColor + @"}]}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>申请解密订单信息,返回平台允许显示的收件信息。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.decryptOrder。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string DecryptOrder(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/common/cgi/decryptOrder?token=&lang=zh_CN";
string body = @"{""id"":""" + orderId + @"""}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>提交订单发货,原实现使用 OTHER 物流公司编码。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <param name="waybillId">物流运单号。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.orderSendOut。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string OrderSendOut(ShopLoginInfo shop, string orderId, string waybillId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/orderSendOut?token=&lang=zh_CN";
string body = @"{""orderId"":""" + orderId + @""",""deliveryProduct"":{""deliveryId"":""OTHER"",""waybillId"":""" + waybillId + @""",""isAllProduct"":true,""deliverType"":1}}";
string refere = "https://store.weixin.qq.com/shop/order/list?type=3";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>修改订单已登记的物流公司、运单号和包裹商品信息。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="param">物流变更参数,包含订单号及各包裹变更明细。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.updateDeliveryInfo。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string UpdateDeliveryInfo(ShopLoginInfo shop, UpdateDeliverInfoParam param)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/updateDeliveryInfo?token=&lang=zh_CN";
string body = JsonHelper.SerializeObject(param);
string refere = "https://store.weixin.qq.com/shop/order/list?type=3";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>查询订单发货初始化数据,用于取得包裹和物流相关信息。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\OrderForms\WXOrderListForm.cs,WXOrderList.initDeliveryInfo。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string InitDeliveryInfo(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/initShipData?token=&lang=zh_CN";
string body = @"{""id"":""" + orderId + @"""}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WxHttpClient.Post(shop, url, body, refere);
return result;
}
/// <summary>查询订单;单参数重载按订单号查询,双参数重载按商品标题和收件人查询。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodTitle">订单中的商品标题筛选条件。</param>
/// <param name="receiverName">收件人姓名筛选条件。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ShopForms\WXShopOptimizeForm.cs,ShopOptimize.orderSearch。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string OrderSearch(ShopLoginInfo shop, string prodTitle, string receiverName)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/order/list";
string body = @"{""isSearch"":true,""pageSize"":30,""orderId"":"""",""orderTime"":{""type"":0,""time"":[null,null]},
""telNumber"":"""",""title"":""复古刺绣盘扣麻棉衬衫女2022夏新款中式禅意茶服宽松短款v领上衣"",""receiverName"":""浅菊夏離、"",""finderNickName"":"""",
""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,
""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,
""endCreateTime"":null}";
body = @"{""isSearch"":true,""pageSize"":30,""orderId"":"""",""orderTime"":{""type"":0,""time"":[null,null]},
""telNumber"":"""",""title"":""" + prodTitle + @""",""receiverName"":""" + receiverName + @""",""finderNickName"":"""",""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,""endCreateTime"":null}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>按订单号字符串查询订单列表。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderIds">订单号查询字符串,格式沿用原订单查询接口。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ShopForms\WXShopOptimizeForm.cs,ShopOptimize.orderSearchByOrderId。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string SearchOrdersByIds(ShopLoginInfo shop, string orderIds)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/order/list";
string body = @"{""isSearch"":true,""pageSize"":30,""orderId"":""" + orderIds + @""",""orderTime"":{""type"":0,""time"":[null,null]},""telNumber"":"""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,""endCreateTime"":null}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>提交订单补发,包含物流和补发商品明细。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <param name="deliveryId">微信物流公司编码。</param>
/// <param name="waybillId">物流运单号。</param>
/// <param name="productId">微信商品 ID。</param>
/// <param name="skuId">商品规格 SKU ID。</param>
/// <param name="productCnt">本次补发的商品件数。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ShopForms\WXShopOptimizeForm.cs,ShopOptimize.orderCompensationDelivery。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string OrderCompensationDelivery(ShopLoginInfo shop, string orderId, string deliveryId, string waybillId, string productId, string skuId, int productCnt)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/compensationDelivery?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/order/list";
string body = @"{""orderId"":""" + orderId + @""",""reason"":1,""deliveryProductInfo"":[{""deliveryId"":""" + deliveryId + @""",""waybillId"":""" + waybillId + @""",""productInfos"":[{""productId"":""" + productId + @""",""skuId"":""" + skuId + @""",""productCnt"":" + productCnt + @"}]}]}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>按订单号或手机号查询订单,支持指定订单时间范围。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="orderId">微信订单 ID。</param>
/// <param name="telNumber">收件联系电话或原查询接口支持的手机号条件。</param>
/// <param name="orderStatus">微信订单状态筛选值,原列表查询默认使用 20;以当前接口枚举为准。 默认值:20。</param>
/// <param name="page">页码,从 1 开始。 默认值:1。</param>
/// <param name="startTime">Unix 毫秒时间戳字符串;空值使用本机一个月前当天零点。 默认值:&quot;&quot;。</param>
/// <param name="endTime">Unix 毫秒时间戳字符串;空值使用本机今天零点。 默认值:&quot;&quot;。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\TalkForms\PDDBuyerOrderListForm.cs,WxOrder.OrderSeach。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string SearchOrdersByContact(ShopLoginInfo shop, string orderId, string telNumber, int orderStatus = 20, int page = 1, string startTime = "", string endTime = "")
{
if (string.IsNullOrWhiteSpace(startTime))
startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddMonths(-1)).ToString();
if (string.IsNullOrWhiteSpace(endTime))
endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date).ToString();
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/order/list";
string body = @"{""isSearch"":true,""pageSize"":100,""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0," + @"""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":1,""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus + @",""page"":" + page + @",""orderId"":""" + orderId + @""",""orderTime"":{""type"":0,""time"":[" + startTime + @"," + endTime + @"]}," + @"""telNumber"":""" + telNumber + @""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",""merchantNotes"":""""," + @"""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0," + @"""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":""""," + @"""startCreateTime"":" + startTime + @",""endCreateTime"":" + endTime + @"}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
}
}