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
{
/// 微信小店客服统计及消息回调接口;独立于原窗体,使用 HttpHelper 发送请求。
/// 传入原 ShopLoginInfo 登录信息;方法同步执行,界面调用请置于后台任务。返回原始正文,不自动登录、重试或解释业务状态。
public static class WxCustomerServiceApi
{
/// 提交 AI 客服消息推送回调验证,对应 WxAiTalkForm.Lf_SaveComplete 中的微信请求。
/// 店铺登录信息,Cookies 为原程序保存的 Cookie 列表 JSON。
/// 客服服务提供方返回的消息推送回调 URL。
/// 回调验证 token,原流程传入客服应用 appId。
/// 客服服务提供方返回的 Base64 消息加解密密钥。
/// 微信原始 JSON 或传输错误文字;调用方检查 code,不自动重试。
public static string VerifyCallback(ShopLoginInfo shop, string callbackUrl, string token, string base64Key)
{
var body = new JObject { ["url"] = callbackUrl, ["token"] = token, ["base64Key"] = base64Key };
return WxHttpClient.Post(shop, WxHttpClient.ShopHost + "/shop-faas/mmecnodeservicemarket/channel/ChannelsEcVerifyCallbackInfo?token=&lang=zh_CN",
body.ToString(), WxHttpClient.ShopHost + "/shop/servicemarket/home");
}
/// 查询客服实时接待统计;原人工客服与 AI 客服共用此接口。
/// 店铺登录信息;Cookies 为原程序保存的 CefSharp.Cookie 列表 JSON,图片上传还需 openid。
/// 开始时间的 Unix 毫秒时间戳;请求发送时转换为秒。
/// 结束时间的 Unix 毫秒时间戳;请求发送时转换为含三位小数的秒。
/// 微信接口原始 JSON 正文;传输或登录参数配置失败可能返回错误文字。调用方须验证响应格式和业务状态,不能仅以非空判断成功。
///
/// 来源:TEMUKJD\WXForms\AiTalkForms\WxAiTalkForm.cs,WxAiTalkForm.GetKfMsgStatistics。
/// 来源:TEMUKJD\WXForms\TalkForms\WxTalkForm.cs,WxTalkForm.GetKfMsgStatistics。
/// 原方法中直接拼接的 ID、JSON 数值片段应按上述格式传入;不会自动转义或转换单位。参数模型构造或序列化失败会向调用方抛出异常。
///
public static string GetKfMsgStatistics(ShopLoginInfo shop, long beginDateTick, long endDateTick)
{
string url = "https://store.weixin.qq.com/shop/kf/cgi/data/getRealTimeShopV2?" + "beginDate=" + (beginDateTick / 1000) + "&endDate=" + (endDateTick / 1000m).ToString("0.000");
string referer = "https://store.weixin.qq.com/shop/kf/data/store";
var result = WxHttpClient.Get(shop, url, referer);
return result;
}
}
}