优化了微店商品上传 优化pdd买手读单

This commit is contained in:
wule committed 2026-04-15 21:04:37 +08:00
1 parent 6c4f16b897
commit f360688c43
62 files changed
+5620 -1432

No files matched your search

+32 -20
View File
@@ -1,4 +1,5 @@
using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using NaiBa.Util.Extension;
using Newtonsoft.Json;
@@ -25,8 +26,18 @@ namespace TemuKJD.BLL.PddApi
}
Data["access_token"] = shop.AccessToken;
Data["client_id"] = shop.AppKey;
}
/// <summary>
/// 貔貅管家
/// </summary>
public static string clientId_pi_xiu_guan_jia { get; set; } = "ad502ec19e0c49ab9df14f83494e153c";
///// <summary>
///// 小红椒商品管理
///// </summary>
//public static string clientId_xiao_hong_jiao_ { get; set; } = "48e76c60853d47d8a4e2e631b6db26b5";
public string PddGoodsAdd()
{
string type = "pdd.goods.add";
@@ -91,11 +102,11 @@ namespace TemuKJD.BLL.PddApi
return html;
}
public string PddPopAuthTokenCreate()
public string PddPopAuthTokenCreate(string code)
{
string type = "pdd.pop.auth.token.create";
if (!Data.Keys.Contains("code"))
Data["code"] = "83be994d5ed04e6cb9643a423094a3296bf8827a";
Data["code"] = code; //"83be994d5ed04e6cb9643a423094a3296bf8827a";
string html = PddApiRequest(type, Data);
return html;
}
@@ -103,7 +114,7 @@ namespace TemuKJD.BLL.PddApi
/// <summary>
/// 关联
/// </summary>
/// <param name="pid"></param>
/// <param name="goodsId"></param>
/// <param name="outGoodsId"></param>
/// <param name="minPrice">最低价 分</param>
/// <param name="maxPrice">最高价 分</param>
@@ -114,12 +125,11 @@ namespace TemuKJD.BLL.PddApi
/// 15-折800,16-当当,17-青创网,18-开山网,19-新款网
/// </param>
/// <returns></returns>
public string Relation2603(long pid, long outGoodsId, int minPrice, int maxPrice, int postAge, int sourceType)
public string Relation2603(long goodsId, string outGoodsId, int minPrice, int maxPrice, int postAge, int sourceType)
{
string type = "pdd.goods.relation.set";
Data = new Dictionary<string, object>();
Data.Add("goods_id", pid.ToString());
Data.Add("out_goods_id", outGoodsId.ToString());
Data["goods_id"] = goodsId.ToString();
Data["out_goods_id"] = outGoodsId.ToString();
string detailUrl = "";
if (sourceType == 0)
detailUrl = "https://item.taobao.com/item.htm?id=" + outGoodsId;
@@ -129,11 +139,11 @@ namespace TemuKJD.BLL.PddApi
detailUrl = "https://weidian.com/item.html?itemID=" + outGoodsId;
else if (sourceType == 1)
detailUrl = "https://item.jd.com/" + outGoodsId + ".html";
Data.Add("out_detail_url", detailUrl);
Data.Add("out_low_goods_price", minPrice.ToString());
Data.Add("out_high_goods_price", maxPrice.ToString());
Data.Add("source_type", sourceType.ToString());
Data.Add("postage", postAge.ToString());
Data["out_detail_url"] = detailUrl;
Data["out_low_goods_price"] = minPrice.ToString();
Data["out_high_goods_price"] = maxPrice.ToString();
//Data["source_type"] = sourceType.ToString();
Data["postage"] = postAge.ToString();
string html = PddApiRequest(type, Data);
return html;
}
@@ -255,7 +265,7 @@ namespace TemuKJD.BLL.PddApi
#region 设置关联
try
{
string html = this.Relation2603(pddRelation.goods_id.Value, long.Parse(pddRelation.out_goods_id),
string html = this.Relation2603(pddRelation.goods_id.Value, pddRelation.out_goods_id,
(int)pddRelation.out_low_goods_price.Value, (int)pddRelation.out_high_goods_price,
(int)pddRelation.postage.Value, pddRelation.source_type.Value);
if (string.IsNullOrEmpty(html) || !html.Contains("\"is_success\":true"))
@@ -272,10 +282,6 @@ namespace TemuKJD.BLL.PddApi
return upResult;
}
public static string clientId { get; set; } = "ad502ec19e0c49ab9df14f83494e153c";
public static string clientSecret { get; set; } = "bd52aba51737d03fc073711d386b3b0779d010ad";
/// <summary>
///
/// </summary>
@@ -283,18 +289,24 @@ namespace TemuKJD.BLL.PddApi
/// <param name="dict">拼多多接口入参</param>
/// <returns></returns>
static string PddApiRequest(string type, Dictionary<string,object> dict)
{
{
if (string.IsNullOrEmpty(type))
return "{\"success\":false, \"error_msg\":\"调用接口不能为空\"}";
if (dict == null)
return "{\"success\":false, \"error_msg\":\"参数数组不能为空\"}";
if (!dict.Keys.Contains("client_id") || string.IsNullOrEmpty(dict["client_id"].ParseToString()))
return "{\"success\":false, \"error_msg\":\"调用Api编号不能为空\"}";
if (!dict.Keys.Contains("access_token") || string.IsNullOrWhiteSpace(dict["access_token"].ParseToString()))
return "{\"success\":false, \"error_msg\":\"调用令牌不能为空\"}";
var clientSecret = GlobalConfig.PddClentInfoList.FirstOrDefault(c => c.client_id == dict["client_id"].ParseToString())?.client_secret;
if (clientSecret.IsNullOrEmpty())
return "{\"success\":false, \"error_msg\":\"调用密钥不能为空\"}";
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
var timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds;
dict["type"] = type;
dict["client_id"] = clientId;
dict["timestamp"] = timeStamp.ToString();
dict["data_type"] = "JSON";
+125 -16
View File
@@ -1,6 +1,8 @@
using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using AllBase.Model.Result.PDDResult;
using NaiBa.Util;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
@@ -15,15 +17,18 @@ namespace TemuKJD.BLL.PddApi
{
public static void RefreshApi(ShopLoginInfo shop, bool isForceRefresh = false)
{
if (isForceRefresh || (shop.AuthAddTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
if (isForceRefresh || (shop.AuthUpdateTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
{
string errStr = "";
var authInfo = PddApiHelper.GetE57ShopPddToken(shop, out errStr);
if (errStr.IsNullOrEmpty() || (shop.AuthAddTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
if (errStr.IsNullOrEmpty() || (shop.AuthUpdateTime <= DateTime.Now.AddDays(-1) && shop.AuthExpiresTime <= DateTime.Now))
{
shop.ApiAuthInfoList.RemoveAll(a => a.AppKey.IsNullOrEmpty() || a.AppKey == PddApi.clientId);
shop.ApiAuthInfoList.RemoveAll(a => a.AppKey.IsNullOrEmpty() || a.AppKey == authInfo.AppKey);
shop.ApiAuthInfoList.Add(authInfo);
}
if (authInfo != null && !string.IsNullOrEmpty(authInfo.AccessToken))
PddApiHelper.SaveShopClientInfo(authInfo);
}
}
@@ -38,7 +43,8 @@ namespace TemuKJD.BLL.PddApi
public static AuthInfo GetE57ShopPddToken(ShopLoginInfo shop, out string errorStr)
{
errorStr = "";
var url = BaseClass.BuildObjString("shop/e57_get_pdd_shop_token");
var url = BaseClass.BuildPDDObjString("shop/e57_get_pdd_shop_token");
var data = UserLogin.GetSignaturex();
data += "&mall_id=" + shop.MallId;
var html = GetHtml.PostUtf8(url, data);
@@ -53,30 +59,133 @@ namespace TemuKJD.BLL.PddApi
var token = new AuthInfo()
{
ShopId = shop.ShopId,
AddTime = DateTime.Now,
AppKey = PddApi.clientId, // BaseRegex.GetStringJson(ref html, "appKey").ParseToString(),
UpdateTime = DateTime.Now,
AppKey = PddApi.clientId_pi_xiu_guan_jia,
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 };
return new AuthInfo()
{
ShopId = shop.ShopId,
UpdateTime = DateTime.Now,
AppKey = PddApi.clientId_pi_xiu_guan_jia,
AccessToken = "",
ExpiresTime = DateTime.Now,
ApiAuthStatus = "未授权",
};
}
public static List<List<AuthInfo>> LstAuthInfos;
public static void PddGetLocalTokens()
//public static List<List<AuthInfo>> LstAuthInfos { get; set; }
//public static void GetPddLocalTokens()
//{
// if (BaseClass.MainPath == "binxixi")
// {
// LstAuthInfos = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<List<AuthInfo>>>("pdd_shop_api_auth_info_lists");
// if (LstAuthInfos == null)
// LstAuthInfos = new List<List<AuthInfo>>();
// foreach (var shop in GlobalConfig.ShopLoginList)
// {
// shop.ApiAuthInfoList = LstAuthInfos.FirstOrDefault(l => l.FirstOrDefault()?.ShopId == shop.ShopId);
// if (shop.ApiAuthInfoList == null)
// shop.ApiAuthInfoList = new List<AuthInfo>();
// }
// }
//}
public static void GetShopClientInfo(List<ShopLoginInfo> shops = null)
{
if (BaseClass.MainPath == "binxixi")
{
LstAuthInfos = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<List<AuthInfo>>>("pdd_shop_api_auth_info_lists");
if (LstAuthInfos == null)
LstAuthInfos = new List<List<AuthInfo>>();
foreach (var shop in GlobalConfig.ShopLoginList)
ConcurrentList<ShopLoginInfo> shopList = new ConcurrentList<ShopLoginInfo>();
if (shops == null)
shopList.AddRange(GlobalConfig.ShopLoginList);
else
shopList.AddRange(shops);
while (shopList.Count > 0)
{
shop.ApiAuthInfoList = LstAuthInfos.FirstOrDefault(l => l.FirstOrDefault()?.ShopId == shop.ShopId);
if (shop.ApiAuthInfoList == null)
shop.ApiAuthInfoList = new List<AuthInfo>();
var shopTemp = shopList.Take(50).ToList();
var url = BaseClass.BuildPDDObjString("shop/get_shop_client_info");
var data = UserLogin.GetSignaturex();
data += "&shop_ids=" + string.Join(",", shopTemp.Select(s => s.ShopId).Distinct());
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (html.Contains("\"code\":200"))
{
try
{
var dataStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["data"]);
var serverApiAuthList = JsonHelper.DeserializeJsonToList<AuthInfo>(dataStr);
foreach (var serverAuth in serverApiAuthList)
{
var shop = shopList.FirstOrDefault(s => s.ShopId == serverAuth.ShopId);
var auth = shop.ApiAuthInfoList.FirstOrDefault(a => a.AppKey == serverAuth.AppKey);
if (auth == null)
{
auth = new AuthInfo();
shop.ApiAuthInfoList.Add(auth);
}
auth.ShopId = serverAuth.ShopId;
auth.AccessToken = serverAuth.AccessToken;
auth.RefreshToken = serverAuth.RefreshToken;
auth.AppKey = serverAuth.AppKey;
auth.ExpiresTime = serverAuth.ExpiresTime;
auth.UpdateTime = serverAuth.UpdateTime;
auth.ApiAuthStatus = serverAuth.ApiAuthStatus;
auth.AppSecret = serverAuth.AppSecret;
}
}
catch
{
}
}
shopList.RemoveAll(s => shopTemp.Contains(s));
}
}
}
public static string SaveShopClientInfo(AuthInfo auth)
{
var clientUrl = BaseClass.BuildObjString("shop/add_mdy_shop_client_info");
var data = UserLogin.GetSignaturex()
+ "&ShopId=" + auth.ShopId
+ "&AccessToken=" + auth.AccessToken
+ "&RefreshToken=" + auth.RefreshToken
+ "&AppKey=" + auth.AppKey
+ "&ExpiresTime=" + auth.ExpiresTime.ToString("yyyy-MM-dd HH:mm:ss")
+ "&UpdateTime=" + auth.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")
+ "&ApiAuthStatus=" + auth.ApiAuthStatus
+ "&AppSecret=" + auth.AppSecret;
var result = GetHtml.PostUtf8(clientUrl, data);
return result;
}
public static void GetPddClientInfo()
{
if (BaseClass.MainPath == "binxixi")
{
var url = BaseClass.BuildPDDObjString("shop/get_pdd_client_info");
var data = UserLogin.GetSignaturex();
data += "&password=" + BaseClass.PassWord;
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (html.Contains("\"code\":200"))
{
try
{
var clientDataStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["data"]);
GlobalConfig.PddClentInfoList.Clear();
GlobalConfig.PddClentInfoList.AddRange(JsonHelper.DeserializeJsonToList<PddClientInfo>(clientDataStr));
}
catch { }
}
}
}