店铺单店token获取并使用逻辑实现

This commit is contained in:
wule committed 2026-02-06 15:13:43 +08:00
1 parent 4fd8d9cc17
commit b42155ae6c
12 files changed
+289 -203

No files matched your search

+20 -17
View File
@@ -19,7 +19,7 @@ namespace TemuKJD.BLL
{
if (GlobalConfig.WxTokenList.Count == 0 || GlobalConfig.WxTokenList.All(t => t.isExpire == true))
{
var url = BaseClass.BuildPDDObjString("product/get_wx_tokens");
var url = BaseClass.BuildObjString("shop/e57_get_wx_tokens");
var data = UserLogin.GetSignaturex();
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
@@ -41,25 +41,28 @@ namespace TemuKJD.BLL
return GlobalConfig.WxTokenList.Where(t => t.isExpire != true).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
}
public string GetShopWxToken(ShopLoginInfo shop)
public WXShopTokenInfo GetShopWxToken(ShopLoginInfo shop)
{
if (string.IsNullOrEmpty(shop.WxToken) || DateTime.Now.AddMinutes(115) > shop.WxTokenExpire)
var url = BaseClass.BuildObjString("shop/e57_get_wx_shop_token");
var data = UserLogin.GetSignaturex();
data += "&shop_id=" + shop.ShopId;
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":0"))
{
var url = BaseClass.BuildPDDObjString("product/get_shop_wx_token");
var data = UserLogin.GetSignaturex();
data += "&shop_id=" + shop.ShopId;
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
BaseMsgForm.ShowError("获取授权失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
return "";
}
var tokenStr = BaseRegex.GetStringJson(ref html, "token");
var ExpireStr = BaseRegex.GetStringJson(ref html, "expire");
shop.WxToken = tokenStr;
shop.WxTokenExpire = Convert.ToDateTime(ExpireStr);
}
return shop.WxToken;
else
{
var token = new WXShopTokenInfo()
{
shopId = shop.ShopId,
accessToken = BaseRegex.GetStringJson(ref html, "accessToken"),
mdyTime = DateTime.Now,
};
//shop.WxToken = BaseRegex.GetStringJson(ref html, "accessToken");
//shop.WxTokenExpire = DateTime.Now.AddMinutes(60);
return token;
}
return new WXShopTokenInfo() { shopId = shop.ShopId, accessToken = "", mdyTime = DateTime.Now };
}
}
}
@@ -985,7 +985,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms
{
new WxApiBLL().GetRandomWxToken();
var url1 = BaseClass.BuildPDDObjString("product/get_wx_all_cate");
var url1 = BaseClass.BuildPDDObjString("product/wx_api_get_all_cate");
var data1 = UserLogin.GetSignaturex();
data1 += "&token=" + GlobalConfig.WxTokenList.OrderBy(x => Guid.NewGuid()).FirstOrDefault()?.accessToken;
var html1 = GetHtml.PostUtf8(url1, data1);
@@ -39,9 +39,8 @@ namespace TemuKJD.WXForms.ProductForms
bool isInit = false;
CheckBox chkSelectAll = null;
//Dictionary<ShopLoginInfo, int> dicShopGetCount = new Dictionary<ShopLoginInfo, int>();
//Dictionary<ShopLoginInfo, List<string>> dicNotSupportCate = new Dictionary<ShopLoginInfo, List<string>>();
ConcurrentList<AuthInfo> lstShopAuthInfo = new ConcurrentList<AuthInfo>();
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
public NaiBa.Util.ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
NaiBa.Util.ConcurrentList<AddPriceRule> lstAddPriceRule = new NaiBa.Util.ConcurrentList<AddPriceRule>();
AddPriceRule defaultAddPriceRule = null;
@@ -72,6 +71,10 @@ namespace TemuKJD.WXForms.ProductForms
if (lstShopAuthInfo == null)
lstShopAuthInfo = new ConcurrentList<AuthInfo>();
lstWXShopTokenInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WXShopTokenInfo>>("wx_shop_token_list");
if (lstWXShopTokenInfo == null)
lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
lstTemuDBProductSelect = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<TemuDBProductSelect>>("wx_db_prod_upload_list");
if (lstTemuDBProductSelect == null)
lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
@@ -1520,8 +1523,29 @@ namespace TemuKJD.WXForms.ProductForms
var upProdInitParam = new WXUploadProductInitParam();
// 生成上传商品对象
var upProdParam = new WXUploadProductParam();
// 随机获取一个上传图片的accessToken
var token = new WxApiBLL().GetRandomWxToken();
// 获取店铺的accessToken
WXShopTokenInfo token = lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId);
if (token == null)
token = new WXShopTokenInfo();
if (token.isExpire || string.IsNullOrEmpty(token.accessToken))
{
AuthInfo auth = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
if (auth != null && auth.ExpiresTime > DateTime.Now.AddMinutes(5))
{
token = new WxApiBLL().GetShopWxToken(shop);
if (!string.IsNullOrEmpty(token.accessToken))
{
lstWXShopTokenInfo.RemoveAll(t => t.shopId == shop.ShopId);
lstWXShopTokenInfo.Add(token);
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_token_list", lstWXShopTokenInfo);
}
}
}
// 如果店铺token不可用,随机获取一个上传图片的accessToken
if (token == null || token.isExpire || string.IsNullOrEmpty(token.accessToken))
token = new WxApiBLL().GetRandomWxToken();
#region 设置标题
upProdInitParam.product.info.title = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
@@ -1979,12 +2003,14 @@ namespace TemuKJD.WXForms.ProductForms
}
}
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
if (string.IsNullOrEmpty(afterSaleAddress))
{
// 获取推单售后地址
//https://po.e57.cn/prod-api/api/sys-api/system/open/api/afterSale/info?warehouseNum=10361546&shopId=46568955
var urlAfter = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/afterSale/info?warehouseNum=" + dbProd.skc_id; //+ "&userName=阿杰账户";
var afterRst = WXHttpResponseBLL.e57GetResponse(urlAfter, "");
var urlAfter = BaseClass.BuildObjString("product/e57_after_sale");
var dataAfter = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
var afterRst = GetHtml.PostUtf8(urlAfter, dataAfter);
try
{
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(afterRst)["data"]);
@@ -2093,11 +2119,12 @@ namespace TemuKJD.WXForms.ProductForms
if (string.IsNullOrEmpty(shippingTemplateJson))
{
// 获取运费模板
//"https://po.e57.cn/prod-api/api/sys-api/system/open/api/freightTemplate/list?warehouseNum=10361546";
var urlShip = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/freightTemplate/list?warehouseNum=" + dbProd.skc_id;
var shipRst = WXHttpResponseBLL.e57GetResponse(urlShip, "");
var urlShip = BaseClass.BuildObjString("product/e57_get_freight_template");
var dataShip = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
var shipRst = GetHtml.PostUtf8(urlShip, dataShip);
if (string.IsNullOrEmpty(shipRst) || !shipRst.Contains("\"code\":0"))
shipRst = GetHtml.PostUtf8(urlShipping, dataShipping);
try
{
//[{"id":"204","warehouseNum":"15016108","freightType":0,"provinces":"香港特别行政区,台湾省,澳门特别行政区","freightPrice":9999900,"createBy":"vmslin","createTime":"2026-01-30T16:45:03+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:03+08:00"},{"id":"205","warehouseNum":"15016108","freightType":3,"provinces":"海南省,新疆维吾尔自治区,西藏自治区,内蒙古自治区","freightPrice":1530,"createBy":"vmslin","createTime":"2026-01-30T16:45:51+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:51+08:00"},{"id":"206","warehouseNum":"15016108","freightType":1,"provinces":"北京市,上海市","freightPrice":410,"createBy":"vmslin","createTime":"2026-01-30T16:46:04+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:04+08:00"},{"id":"207","warehouseNum":"15016108","freightType":1,"provinces":"安徽省,重庆市,福建省,广东省,甘肃省,广西壮族自治区,贵州省,河北省,湖北省,黑龙江省,河南省,湖南省,吉林省,江苏省,江西省,辽宁省,宁夏回族自治区,青海省,四川省,山东省,山西省,陕西省,天津市,云南省,浙江省","freightPrice":310,"createBy":"vmslin","createTime":"2026-01-30T16:46:17+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:17+08:00"}]