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

132 lines
9.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 WxPromotionApi
{
/// <summary>在编辑商品时设置联盟及团长推广开关和佣金。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="itemSwitch">普通联盟推广开关的接口原始值。</param>
/// <param name="itemRatio">普通联盟推广佣金比例的接口原始整数值,不在本方法内换算。</param>
/// <param name="headSupplierItemSwitch">团长推广开关的接口原始值。</param>
/// <param name="HeadSupplierItemRatio">团长推广佣金比例的接口原始整数值,不在本方法内换算。</param>
/// <param name="prodId">微信商品 ID。</param>
/// <param name="updType">推广更新类型的接口原始值。 默认值:2。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXDBProdUploadForm.cs,WXUpload.addLeagueItemForUpdatingProduct。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string AddLeagueItemForUpdatingProduct(ShopLoginInfo shop, int itemSwitch, int itemRatio, int headSupplierItemSwitch, int HeadSupplierItemRatio, long prodId, int updType = 2)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/addLeagueItemForUpdatingProduct?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/home";
string body = @"{""itemSwitch"":" + itemSwitch + @",""itemRatio"":" + itemRatio + @",""headSupplierPublicItemSwitch"":" + headSupplierItemSwitch + @",""headSupplierPublicItemServiceRatio"":" + HeadSupplierItemRatio + @",""productId"":" + prodId + @",""scene"":2,""updType"":" + updType + @"}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>查询商品是否满足推广条件。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodIdLst">微信商品 ID 列表。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxGetCanPromotion。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxGetCanPromotion(ShopLoginInfo shop, List<string> prodIdLst)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/plan/getItemList?token=&lang=zh_CN";
foreach (var prodId in prodIdLst)
{
url += "&spuIdList[]=" + prodId;
}
url += "&offset=0&list_type=1";
string referer = "https://store.weixin.qq.com/shop/shopleague/home/normal-add";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>批量为商品添加推广计划并设置佣金比例。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodIdLst">微信商品 ID 列表。</param>
/// <param name="ratio">推广佣金比例的接口原始整数值,不在本方法内换算。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxAddPromotion。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxAddPromotion(ShopLoginInfo shop, List<string> prodIdLst, int ratio)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/plan/batchAddItem?token=&lang=zh_CN";
string body = @"{""list"":[";
foreach (var prodId in prodIdLst)
body += @"{""spuId"":""" + prodId + @""",""ratio"":" + ratio + @",""finderCoupon"":0},";
body = body.TrimEnd(',');
body += @"]}";
string referer = "https://store.weixin.qq.com/shop/shopleague/home/normal-add";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>按商品 ID 查询推广计划。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodId">微信商品 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxSearchPromotion。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxSearchPromotion(ShopLoginInfo shop, string prodId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/plan/getItemListBySearch?" + "token=&lang=zh_CN&offset=0&size=10&product_title=" + prodId + "&status=1&list_type=2&needWarning=true&needStockNum=true";
string referer = "https://store.weixin.qq.com/shop/shopleague/home";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
/// <summary>结束指定商品的推广计划。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodId">微信商品 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxEndPromotion。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxEndPromotion(ShopLoginInfo shop, string prodId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/plan/updateItem?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/shopleague/home";
string body = @"{""spu_id"":""" + prodId + @""",""operate_type"":2}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>删除指定商品的推广计划。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="prodId">微信商品 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxDelPromotion。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxDelPromotion(ShopLoginInfo shop, string prodId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/plan/updateItem?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/shopleague/home";
string body = @"{""spu_id"":""" + prodId + @""",""operate_type"":3}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
}
}