gx
This commit is contained in:
1 parent
0a3e5af6a9
commit
c2dcedd238
59 files changed
+2053
-1274
No files matched your search
@@ -0,0 +1,62 @@
|
||||
using AllBase;
|
||||
using AllBase.Extension;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Config;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.WXResult;
|
||||
using NaiBa.Util;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Work;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
|
||||
/// <summary>
|
||||
/// 微信 API Token 的无控件迁移实现。
|
||||
/// </summary>
|
||||
internal sealed class WxApiBLL
|
||||
{
|
||||
public WXShopTokenInfo GetRandomWxToken(bool isShowErrorDlg = true)
|
||||
{
|
||||
if (GlobalConfig.WxGlobalTokenList == null)
|
||||
GlobalConfig.WxGlobalTokenList = new ConcurrentList<WXShopTokenInfo>();
|
||||
|
||||
if (GlobalConfig.WxGlobalTokenList.Count == 0 || GlobalConfig.WxGlobalTokenList.All(t => t.isExpire))
|
||||
{
|
||||
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"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
throw new Exception("获取授权失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||||
|
||||
var tokenStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["tokens"].FirstOrDefault());
|
||||
GlobalConfig.WxGlobalTokenList = new ConcurrentList<WXShopTokenInfo>();
|
||||
GlobalConfig.WxGlobalTokenList.AddRange(JsonHelper.DeserializeJsonToList<WXShopTokenInfo>(tokenStr));
|
||||
foreach (var token in GlobalConfig.WxGlobalTokenList)
|
||||
token.mdyTime = Convert.ToDateTime(BaseRegex.GetStringJson(ref html, "mdy_time"));
|
||||
}
|
||||
|
||||
return GlobalConfig.WxGlobalTokenList.Where(t => !t.isExpire).OrderBy(x => Guid.NewGuid()).FirstOrDefault()
|
||||
?? new WXShopTokenInfo();
|
||||
}
|
||||
|
||||
public WXShopTokenInfo GetShopWxToken(ShopLoginInfo shop)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("shop/e57_get_wx_shop_token");
|
||||
var data = UserLogin.GetSignaturex() + "&shop_id=" + shop.ShopId;
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":0"))
|
||||
{
|
||||
return new WXShopTokenInfo
|
||||
{
|
||||
shopId = shop.ShopId,
|
||||
accessToken = BaseRegex.GetStringJson(ref html, "accessToken"),
|
||||
mdyTime = DateTime.Now
|
||||
};
|
||||
}
|
||||
|
||||
return new WXShopTokenInfo { shopId = shop.ShopId, accessToken = "", mdyTime = DateTime.Now };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user