77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using AllBase;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.Result;
|
|
using NaiBa.Util.Extension;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Work;
|
|
|
|
namespace TemuKJD.BLL.PddApi
|
|
{
|
|
public class PddApiHelper
|
|
{
|
|
public static void RefreshApi(ShopLoginInfo shop, bool isForceRefresh = false)
|
|
{
|
|
if (isForceRefresh || shop.AuthAddTime <= DateTime.Now.AddDays(-1))
|
|
{
|
|
shop.ApiAuthInfoList.Clear();
|
|
|
|
var authInfo = PddApiHelper.GetShopPddToken(shop);
|
|
shop.ApiAuthInfoList.Add(authInfo);
|
|
}
|
|
}
|
|
|
|
public static void RefreshApi(List<ShopLoginInfo> shops, bool isForceRefresh = false)
|
|
{
|
|
foreach (var shop in shops)
|
|
{
|
|
RefreshApi(shop, isForceRefresh);
|
|
}
|
|
}
|
|
|
|
public static AuthInfo GetShopPddToken(ShopLoginInfo shop)
|
|
{
|
|
var url = BaseClass.BuildObjString("shop/e57_get_pdd_shop_token");
|
|
var data = UserLogin.GetSignaturex();
|
|
data += "&mall_id=" + shop.MallId;
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":0"))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
var token = new AuthInfo()
|
|
{
|
|
ShopId = shop.ShopId,
|
|
AddTime = DateTime.Now,
|
|
AppKey = BaseRegex.GetStringJson(ref html, "appKey").ParseToString(),
|
|
AccessToken = BaseRegex.GetStringJson(ref html, "accessToken"),
|
|
ExpiresTime = BaseClass.StampToDateTime(BaseRegex.GetIntJson(ref html, "tokenExpiresTime")),
|
|
ApiAuthStatus = "授权成功",
|
|
};
|
|
return token;
|
|
}
|
|
return new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = DateTime.Now };
|
|
}
|
|
|
|
public static void PddGetLocalTokens()
|
|
{
|
|
if (BaseClass.MainPath == "binxixi")
|
|
{
|
|
List<List<AuthInfo>> lsts = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<List<AuthInfo>>>("pdd_shop_api_auth_info_lists");
|
|
if (lsts == null)
|
|
lsts = new List<List<AuthInfo>>();
|
|
foreach (var shop in GlobalConfig.ShopLoginList)
|
|
{
|
|
shop.ApiAuthInfoList = lsts.FirstOrDefault(l => l.FirstOrDefault()?.ShopId == shop.ShopId);
|
|
if (shop.ApiAuthInfoList == null)
|
|
shop.ApiAuthInfoList = new List<AuthInfo>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|