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

90 lines
6.1 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 Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Work.Api.Wx
{
/// <summary>微信小店店铺优惠券接口;独立于原窗体,使用 HttpHelper 发送请求。</summary>
/// <remarks>传入原 ShopLoginInfo 登录信息;方法同步执行,界面调用请置于后台任务。返回原始正文,不自动登录、重试或解释业务状态。</remarks>
public static class WxCouponApi
{
/// <summary>创建优惠券,保留原优惠券模型及忽略 null 字段的序列化方式。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="couponParam">优惠券创建参数,沿用 AllBase 中的微信优惠券模型。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxSetCoupon。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxSetCoupon(ShopLoginInfo shop, WXCouponParamBase couponParam)
{
string url = "https://store.weixin.qq.com/shop-faas/market/coupon/cgi/makeQp?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/marketing/coupon/make?type=990";
JsonSerializerSettings jsonSetting = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
var prodStr = JsonConvert.SerializeObject(couponParam, jsonSetting);
string body = prodStr;
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>按优惠券名称查询优惠券。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="couponName">查询用的优惠券名称。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxSearchCoupon。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxSearchCoupon(ShopLoginInfo shop, string couponName)
{
string url = "https://store.weixin.qq.com/shop-faas/market/coupon/cgi/searchCoupon?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/marketing/coupon";
string body = "{\"pageSize\":20,\"page\":0,\"couponName\":\"" + couponName + "\",\"couponCustomizeChannel\":\"\",\"couponTypeList\":[],\"promoteTypeList\":[],\"couponStatusList\":[\"2\"]}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>结束指定优惠券的发放或活动。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="couponId">微信优惠券 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxEndCoupon。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxEndCoupon(ShopLoginInfo shop, string couponId)
{
string url = "https://store.weixin.qq.com/shop-faas/market/coupon/cgi/upCouponStatus?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/marketing/coupon";
string body = @"{""couponId"":""" + couponId + @""",""status"":4}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
/// <summary>删除指定优惠券。</summary>
/// <param name="shop">店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。</param>
/// <param name="couponId">微信优惠券 ID。</param>
/// <returns>微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。</returns>
/// <remarks>
/// 来源:TEMUKJD\WXForms\ProductForms\WXProdCouponOrderBoomForm.cs,WxCoupon.WxDelCoupon。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
/// </remarks>
public static string WxDelCoupon(ShopLoginInfo shop, string couponId)
{
string url = "https://store.weixin.qq.com/shop-faas/market/coupon/cgi/upCouponStatus?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/marketing/coupon";
string body = @"{""couponId"":""" + couponId + @""",""status"":5}";
var result = WxHttpClient.Post(shop, url, body, referer);
return result;
}
}
}