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

90 lines
6.6 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 WxAddressApi
{
/// <summary>查询商品发布时可选的运费模板。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getFreightTemplate。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetFreightTemplate(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/express/cgi/goods/getFreightTemplate?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>查询商品发布时可选的售后地址,支持搜索条件。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="searchText">地址搜索关键词,空字符串表示不指定关键词。 默认值:&quot;&quot;。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getAddress。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetAddress(ShopLoginInfo shop, string searchText = "")
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?token=&lang=zh_CN";
if (!string.IsNullOrEmpty(searchText))
url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?searchStr=" + GetHtml.UrlEncodeUtf8(searchText) + "&token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>按地址 ID 查询售后地址详情。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="AddressId">售后地址 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getAddressById。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetAddressById(ShopLoginInfo shop, string AddressId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?offset=0&limit=20&includeBlock=1&addressId=" + AddressId + "&token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/address/expressAddressMgmt";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>新增售后寄回地址。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="provinceName">收件地址的省份名称。</param>
/// <param name="cityName">收件地址的城市名称。</param>
/// <param name="countyName">收件地址的区县名称。</param>
/// <param name="detailInfo">详细街道及门牌地址。</param>
/// <param name="userName">地址联系人姓名。</param>
/// <param name="telNumber">收件联系电话或原查询接口支持的手机号条件。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.addAddress。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string AddAddress(ShopLoginInfo shop, string provinceName, string cityName, string countyName, string detailInfo, string userName, string telNumber)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/address/addAddress?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/address/expressAddressMgmt";
string address = "{\"addressInfo\":{\"provinceName\":\"" + provinceName + "\",\"cityName\":\"" + cityName + "\",\"countyName\":\"" + countyName + "\",\"detailInfo\":\"" + detailInfo + "\",\"userName\":\"" + userName + "\",\"telNumber\":\"" + telNumber + "\",\"location\":{}},\"defaultSend\":0,\"defaultRecv\":0}";
JObject obj = new JObject();
obj["data"] = address;
string body = JsonHelper.SerializeObject(obj);
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
}
}