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

160 lines
12 KiB
C#
Raw 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 WxCategoryApi
{
/// <summary>根据商品标题及本地图片识别推荐类目。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="goodsName">商品标题;方法内部执行 UTF-8 URL 编码。</param>
/// <param name="goodImgUrlsLst">用于识别类目的本地图片文件完整路径列表;原参数名含 Url,但实际读取本地文件。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getProductClassify。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetProductClassify(ShopLoginInfo shop, string goodsName, List<string> goodImgUrlsLst)
{
string boundaryLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
string boundaryStr = "----WebKitFormBoundary";
for (int i = 0; i < 16; i++)
{
boundaryStr += boundaryLetters[Randomx.GetId(boundaryLetters.Length)];
}
string url = "https://store.weixin.qq.com/shop-faas/cgi/common/productClassify?from=B&title=" + GetHtml.UrlEncodeUtf8(goodsName) + "&token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"--" + boundaryStr + @"
";
foreach (var imgFullPath in goodImgUrlsLst)
{
string fileName = imgFullPath.Split('\\').LastOrDefault();
body += @"Content-Disposition: form-data; name=""file""; filename=""" + fileName + @"""
Content-Type: image/jpeg
<!>" + imgFullPath + @"<!>
--" + boundaryStr;
}
body += @"--
";
var result = WxHttpClient.UploadMultipart(shop, url, body, boundaryStr, referer);
return result;
}
/// <summary>查询所选类目及品牌的上架要求。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catIdLst">从上级到末级的类目 ID 列表,用于查询或申请类目资质。</param>
/// <param name="brandId">微信品牌 ID,直接按原协议写入请求。 默认值:&quot;2100000000&quot;。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getCategoryOnShelf。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetCategoryOnShelf(ShopLoginInfo shop, List<long> catIdLst, string brandId = "2100000000")
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/getCategoryOnShelfV2?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"{""catIdList"":[" + string.Join(",", catIdLst) + @"],""brandId"":" + brandId + "}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>查询类目可用品牌及品牌资质信息。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catId">微信商品类目 ID。 默认值:&quot;547591&quot;。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getMixBrand。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetMixBrand(ShopLoginInfo shop, string catId = "547591")
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/getMixBrand?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"{""categoryId"":""" + catId + @"""}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>检查店铺与指定商品类目的关联及经营资格。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catId">微信商品类目 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.batchCheckCategoryRelation。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string BatchCheckCategoryRelation(ShopLoginInfo shop, long catId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/batchCheckCategoryRelation?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"{""categoryIdList"":[" + catId + "]}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>按原快捷申请流程提交类目经营资格申请。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catId">微信商品类目 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.addFinderCategoryV2。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string AddFinderCategoryV2(ShopLoginInfo shop, long catId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"{""categoryInfo"":{""categories"":[{""id"":""" + catId + @"""}]},""brandIdList"":[],""leafCategoryId"":""" + catId + @""",""reuse"":0,""applyType"":1}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>申请类目资质前查询该类目的详细要求。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catId">微信商品类目 ID。</param>
/// <param name="catIdLst">从上级到末级的类目 ID 列表,用于查询或申请类目资质。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.getSingleCategoryData。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string GetSingleCategoryData(ShopLoginInfo shop, long catId, List<long> catIdLst)
{
var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]";
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/getSingleCategoryData?token=&lang=zh_CN&categoryId=" + catId;
string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>提交类目资质申请资料。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="catIdLst">从上级到末级的类目 ID 列表,用于查询或申请类目资质。</param>
/// <param name="wxCateAuthParam">类目资质申请模型,包含资质图片等平台要求字段。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.wxCateAuth。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxCateAuth(ShopLoginInfo shop, List<long> catIdLst, WXCateAuthParam wxCateAuthParam)
{
var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]";
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply";
string data = JsonHelper.SerializeObject(wxCateAuthParam);
var result = WxHttpClient.Post(shop, url, data, referer);
return result;
}
}
}