优化了微店商品上传 优化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 { }
}
}
}
+104 -67
View File
@@ -274,6 +274,11 @@ namespace TemuKJD.BLL.VDian
{
vDToken = vDianShop.Wdtoken;
vDCookie = vDianShop.Cookies;
if (vDToken.IsNullOrEmpty())
{
vDToken = "" + BaseRegex.GetMatchRegexString(ref vDCookie, "wdtoken=([^;]+?);");
vDianShop.Wdtoken = vDToken;
}
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
bool useCache = false;
@@ -289,54 +294,54 @@ namespace TemuKJD.BLL.VDian
// 商品标题赋值
vDianProduct.itemName = prod.ProductTitle;
var allAttrResult = "";
for (int i = 0; !allAttrResult.Contains("\"message\":\"OK\"") && i < 20; i++)
{
allAttrResult = request_vdian_all_attr_com();
Thread.Sleep(Randomx.GetId(300, 500));
}
if (allAttrResult.Contains("\"message\":\"OK\""))
{
var AttrMatches = BaseRegex.GetMatchRegex(ref allAttrResult, "\"attr_id\":([\\s\\S]*?),");
List<string> lst = new List<string>();
foreach (Match match in AttrMatches)
{
var attr = BaseRegex.GetMatchRegexString(match.ToString(), "\"attr_id\":([\\s\\S]*?),");
lst.Add(attr);
if (lst.Count >= 100)
{
var hideAttrResult = request_vdian_hideAttr_com(lst);
if (!hideAttrResult.Contains("\"message\":\"OK\""))
{
prod.MappingResult = BaseRegex.GetMatchRegexString(hideAttrResult, "\"message\":\"([\\s\\S]+?)\"");
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = hideAttrResult;
if (hideAttrResult.Contains("LOGIN ERROR"))
{
vDianShop.LoginStatus = 2;
vDianShop.UpGoodAuth = "请先登录";
prod.MappingResult = "店铺 " + vDianShop.ShopName + " 未登录";
}
prod.MappingResult = "转换失败,删除attribute出错" + prod.MappingResult;
LogSave.Add("[微店批量删除店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
return null;
}
Thread.Sleep(500);
lst.Clear();
}
}
}
else
{
prod.MappingResult = BaseRegex.GetMatchRegexString(allAttrResult, "\"message\":\"([\\s\\S]+?)\"");
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = allAttrResult;
prod.MappingResult = "转换失败,获取attribute出错" + prod.MappingResult;
LogSave.Add("[微店获取店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
return null;
}
//var allAttrResult = "";
//for (int i = 0; !allAttrResult.Contains("\"message\":\"OK\"") && i < 20; i++)
//{
// allAttrResult = request_vdian_all_attr_com();
// Thread.Sleep(Randomx.GetId(300, 500));
//}
//if (allAttrResult.Contains("\"message\":\"OK\""))
//{
// var AttrMatches = BaseRegex.GetMatchRegex(ref allAttrResult, "\"attr_id\":([\\s\\S]*?),");
// List<string> lst = new List<string>();
// foreach (Match match in AttrMatches)
// {
// var attr = BaseRegex.GetMatchRegexString(match.ToString(), "\"attr_id\":([\\s\\S]*?),");
// lst.Add(attr);
// if (lst.Count >= 100)
// {
// var hideAttrResult = request_vdian_hideAttr_com(lst);
// if (!hideAttrResult.Contains("\"message\":\"OK\""))
// {
// prod.MappingResult = BaseRegex.GetMatchRegexString(hideAttrResult, "\"message\":\"([\\s\\S]+?)\"");
// if (string.IsNullOrEmpty(prod.MappingResult))
// prod.MappingResult = hideAttrResult;
// if (hideAttrResult.Contains("LOGIN ERROR"))
// {
// vDianShop.LoginStatus = 2;
// vDianShop.UpGoodAuth = "请先登录";
// prod.MappingResult = "店铺 " + vDianShop.ShopName + " 未登录";
// }
// prod.MappingResult = "转换失败,删除attribute出错" + prod.MappingResult;
// LogSave.Add("[微店批量删除店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
// + " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
// return null;
// }
// Thread.Sleep(500);
// lst.Clear();
// }
// }
//}
//else
//{
// prod.MappingResult = BaseRegex.GetMatchRegexString(allAttrResult, "\"message\":\"([\\s\\S]+?)\"");
// if (string.IsNullOrEmpty(prod.MappingResult))
// prod.MappingResult = allAttrResult;
// prod.MappingResult = "转换失败,获取attribute出错" + prod.MappingResult;
// LogSave.Add("[微店获取店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
// + " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
// return null;
//}
// 商品属性
retry:
@@ -372,10 +377,27 @@ namespace TemuKJD.BLL.VDian
// 上传属性获取属性ID
if (wdAttrList.Count > 0)
{
Thread.Sleep(Randomx.GetId(2000, 5000));
List<VDianParam.VDianAttr> wdAttrList_New = new List<VDianParam.VDianAttr>();
var res = this.upLoadAttrx(prod, vDianShop, wdAttrList, wdAttrList_New);
if (!res) return null;
//var res = this.upLoadAttrx(prod, vDianShop, wdAttrList, wdAttrList_New);
//if (!res) return null;
var inAttr = JsonHelper.SerializeObject(wdAttrList);
var outAttr = JsonHelper.SerializeObject(wdAttrList_New);
wdAttrList_New = JsonHelper.DeserializeJsonToList<VDianParam.VDianAttr>(JsonHelper.SerializeObject(wdAttrList));
foreach (var wdAttr in wdAttrList_New)
{
int id = 0;
foreach (var atv in wdAttr.attr_values)
{
id++;
atv.attr_id = id;
atv.attr_title = wdAttr.attr_title;
}
}
wdAttrList = wdAttrList_New;
vDianProduct.attrList = wdAttrList_New;
@@ -431,7 +453,8 @@ namespace TemuKJD.BLL.VDian
}
}
}
vDianSku.price = ((sku.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price).ToString();
int priceFen = (((sku.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price) * 100).ParseToInt();
vDianSku.price = (priceFen * 0.01m).ToString();
vDianSku.stock = sku.number > 999999 ? 999999.ToString() : sku.number.ToString();
if (vDianSku.stock == "0")
vDianSku.stock = "1";
@@ -446,7 +469,7 @@ namespace TemuKJD.BLL.VDian
var wdMaxPrice = 0M;
try
{
wdMaxPrice = (product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price;
//wdMaxPrice = (product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price;
wdMaxPrice = vDianProduct.sku.Max(wd => Convert.ToDecimal(wd.price));
}
catch
@@ -628,15 +651,15 @@ namespace TemuKJD.BLL.VDian
if (mainImgResult.Contains("\"message\":\"SUCCESS\""))
{
var imgUrl = BaseRegex.GetMatchRegexString(mainImgResult, "\"url\":\"([\\s\\S]*?)\"");
//if (!string.IsNullOrEmpty(imgUrl))
//{
// bigImages.Add(imgUrl);
if (!string.IsNullOrEmpty(imgUrl))
{
bigImages.Add(imgUrl);
// // 写图片缓存
// var url = BaseClass.LoginApiUrl + "?obj=upshopid/image_weidian&act=weidian_add";
// var data = UserLogin.GetSignaturex() + "&data=" + item.Item2.Key + "," + imgUrl + ";";
// var html = GetHtml.PostUtf8(url, data);
//}
//// 写图片缓存
//var url = BaseClass.LoginApiUrl + "?obj=upshopid/image_weidian&act=weidian_add";
//var data = UserLogin.GetSignaturex() + "&data=" + item.Item2.Key + "," + imgUrl + ";";
//var html = GetHtml.PostUtf8(url, data);
}
}
else
{
@@ -753,7 +776,7 @@ namespace TemuKJD.BLL.VDian
if (++timesx > 1 || !IsUploadLimitedFailed(tmp_detailId)) break;
Thread.Sleep(Randomx.GetId(2000, 3000));
}
if (tmp_detailId.Contains("\"message\":\"OK\""))
if (tmp_detailId.ParseToString().Contains("\"message\":\"OK\""))
{
tmp_detailId = BaseRegex.GetMatchRegexString(tmp_detailId, "\"tmp_detail_id\":\"([\\s\\S]*?)\"");
vDianProduct.tmpDetailId = tmp_detailId;
@@ -763,7 +786,7 @@ namespace TemuKJD.BLL.VDian
prod.MappingResult = BaseRegex.GetMatchRegexString(tmp_detailId, "\"message\":\"([\\s\\S]+?)\"");
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = tmp_detailId;
if (tmp_detailId.Contains("LOGIN ERROR"))
if (tmp_detailId.ParseToString().Contains("LOGIN ERROR"))
{
vDianShop.LoginStatus = 2;
vDianShop.UpGoodAuth = "请先登录";
@@ -824,20 +847,27 @@ namespace TemuKJD.BLL.VDian
vDianProduct.bgCateId = 50023878;
}
vDianProduct.merchantCode = product.out_goods_sn;
// 上货上传商品
var jsonStr = JsonHelper.SerializeObject(vDianProduct);
var result = "";
int timesxx = 0;
while (true)
{
//Thread.Sleep(15000);
Thread.Sleep(Randomx.GetId(8000, 11000));
var ua = getUa(vDianShop);
Thread.Sleep(Randomx.GetId(8000, 11000));
if (string.IsNullOrEmpty(ua))
ua = getUa(vDianShop);
if (string.IsNullOrEmpty(ua))
LogSave.Add("[微店获取Ua失败]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
Thread.Sleep(15000);
//JObject obj = JsonHelper.JObjectParse(jsonStr);
//(obj["attrList"] as JArray).RemoveAt(0);
//var str1 = JsonHelper.SerializeObject(obj);
result = request_vdian_product_com(jsonStr, ua);
if (string.IsNullOrEmpty(result))
@@ -895,7 +925,7 @@ namespace TemuKJD.BLL.VDian
}
if (result.Contains("创建商品过于频繁"))
{
prod.MappingResult = "商品驳回,请更换其它商品转换";
prod.MappingResult = "过于频繁,商品驳回,请更换其它商品转换";
}
prod.MappingResult = "转换失败,上传商品出错:" + prod.MappingResult;
LogSave.Add("[微店上传商品出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
@@ -1009,7 +1039,8 @@ namespace TemuKJD.BLL.VDian
request.KeepAlive = true;
request.Accept = "application/json, */*";
request.Headers.Add("Origin", @"https://d.weidian.com");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundaryl8PNkxxP0AKTlrpf";
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
@@ -1117,6 +1148,7 @@ Content-Disposition: form-data; name=""wdtoken""
isGetAttrId = true;
string param = attrList;
//https://thor.weidian.com/wditem/itemSearch.searchAttrs/1.0
string url = "https://thor.weidian.com/wditem/itemWrite.updateAttrList/1.0";
var result = request_vdian_common(url, param);
@@ -1165,7 +1197,8 @@ Content-Disposition: form-data; name=""wdtoken""
request.KeepAlive = true;
request.Accept = "application/json, */*";
request.Headers.Add("Origin", @"https://d.weidian.com");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
@@ -1261,7 +1294,8 @@ Content-Disposition: form-data; name=""wdtoken""
request.Headers.Add("sec-ch-ua", @"""Google Chrome"";v=""89"", ""Chromium"";v=""89"", "";Not A Brand"";v=""99""");
request.Accept = "application/json, */*";
request.Headers.Add("sec-ch-ua-mobile", @"?0");
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36";
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("Origin", @"https://d.weidian.com");
request.Headers.Add("Sec-Fetch-Site", @"same-site");
@@ -1453,6 +1487,7 @@ Content-Disposition: form-data; name=""wdtoken""
request.Accept = "application/json, */*";
request.Headers.Add("Origin", @"https://d.weidian.com");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
@@ -1658,6 +1693,8 @@ Content-Disposition: form-data; name=""wdtoken""
/// <returns></returns>
private static bool IsUploadLimitedFailed(string result)
{
if (result == null)
result = "";
return result.Contains("无法连接到远程服务器") || result.Contains("操作超时") || result.Contains("基础连接已经关闭")
|| result.Contains("远程主机强迫关闭") || result.Contains("Unable to write data") || result.Contains("现在人太多了, 请稍后重试");
}