1810 lines
75 KiB
C#
1810 lines
75 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using AllBase;
|
|
using Work.CollectClass;
|
|
using System.Text.RegularExpressions;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Work.Api
|
|
{
|
|
public class PinduoduoApiGetProduct
|
|
{
|
|
public ShopChatBase Shop;
|
|
public string Type, Name;
|
|
public Dictionary<string, string> Data = new Dictionary<string, string>();
|
|
public static Dictionary<long, string> OutId = new Dictionary<long, string>();
|
|
public static Dictionary<string, List<ProductBase>> Product = new Dictionary<string, List<ProductBase>>();
|
|
public static bool isSelf = true;
|
|
public bool UserCache = true;
|
|
/// <summary>
|
|
/// 是否是微店转换商品
|
|
/// </summary>
|
|
public bool FromWeiDian { get; set; } = false;
|
|
/// <summary>
|
|
/// 是否是商品同步模块同步非拼多多上家商品且商品加价比例低于8%
|
|
/// </summary>
|
|
public bool IsProdSyncNotPdd1_08 { get; set; } = false;
|
|
public List<ProuctBase> ids = new List<ProuctBase>();
|
|
//存储当前shop,失效的clientId
|
|
public static Dictionary<string, List<string>> ShopInvalidClientID = new Dictionary<string, List<string>>();
|
|
public static Dictionary<string, List<string>> successClient = new Dictionary<string, List<string>>();
|
|
public static Dictionary<string, string> ServiceApiDic = new Dictionary<string, string>();
|
|
public PinduoduoApiGetProduct(ShopChatBase shop)
|
|
{
|
|
Shop = shop;
|
|
}
|
|
/// <summary>
|
|
/// 获取编辑ID详情
|
|
/// </summary>
|
|
/// <param name="cid"></param>
|
|
/// <returns></returns>
|
|
public string GetCommitDetail(long cid)
|
|
{
|
|
Type = "pdd.goods.commit.detail.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_commit_id", cid.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 获取Cps全店佣金
|
|
/// </summary>
|
|
/// <param name="cid"></param>
|
|
/// <returns></returns>
|
|
public string GetCpsShopSet()
|
|
{
|
|
Type = "pdd.goods.cps.mall.unit.query";
|
|
Data = new Dictionary<string, string>();
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 获取分类
|
|
/// </summary>
|
|
/// <param name="cid"></param>
|
|
/// <returns></returns>
|
|
public string GetCatTemp(long cid)
|
|
{
|
|
Type = "pdd.goods.cat.template.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("cat_id", cid.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 获取运费模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetTemplate()
|
|
{
|
|
Type = "pdd.goods.logistics.template.get";
|
|
Data = new Dictionary<string, string>();
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 删除运费模板
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string DelTemplate(string template_id)
|
|
{
|
|
Type = "pdd.goods.logistics.template.delete";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("template_id", template_id);
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 获取分类
|
|
/// </summary>
|
|
/// <param name="cid"></param>
|
|
/// <returns></returns>
|
|
public string GetCatProperty(long cid, long pid, string name)
|
|
{
|
|
Type = "pdd.goods.template.property.value.search";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("cat_id", cid.ToString());
|
|
Data.Add("template_pid", pid.ToString());
|
|
Data.Add("value", name.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取编辑ID详情
|
|
/// </summary>
|
|
/// <param name="cid"></param>
|
|
/// <returns></returns>
|
|
public string DeleteCommitDetail(long cid)
|
|
{
|
|
Type = "pdd.delete.draft.commit";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_commit_id", cid.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
public string DeleteCpsProduct(long id)
|
|
{
|
|
Type = "pdd.goods.cps.unit.delete";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", id.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 关闭批次接口
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public string CloseCoupon(long id)
|
|
{
|
|
Type = "pdd.promotion.coupon.close";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("batch_id", id.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 修改商品推广
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="rate"></param>
|
|
/// <param name="coupon_id"></param>
|
|
/// <param name="coupon_start_time"></param>
|
|
/// <param name="coupon_end_time"></param>
|
|
/// <param name="discount"></param>
|
|
/// <param name="init_quantity"></param>
|
|
/// <param name="remain_quantity"></param>
|
|
/// <returns></returns>
|
|
public string ChangeCpsProduct(long id, int rate, long coupon_id, string coupon_start_time, string coupon_end_time, int discount, int init_quantity, int remain_quantity)
|
|
{
|
|
Type = "pdd.goods.cps.unit.change";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", id.ToString());
|
|
Data.Add("rate", rate.ToString());
|
|
Data.Add("coupon_id", coupon_id.ToString());
|
|
Data.Add("coupon_start_time", coupon_start_time.ToString());
|
|
Data.Add("coupon_end_time", coupon_end_time.ToString());
|
|
Data.Add("discount", discount.ToString());
|
|
Data.Add("init_quantity", init_quantity.ToString());
|
|
Data.Add("remain_quantity", remain_quantity.ToString());
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 关联
|
|
/// </summary>
|
|
/// <param name="pid"></param>
|
|
/// <param name="fromId"></param>
|
|
/// <param name="minPrice">最低价 分</param>
|
|
/// <param name="maxPrice">最高价 分</param>
|
|
/// <param name="postAge">邮费 元</param>
|
|
/// <param name="fromSite">内部来源ID</param>
|
|
/// <returns></returns>
|
|
public string Relation(long pid, long fromId, int minPrice, int maxPrice, int postAge, int fromSite)
|
|
{
|
|
Type = "pdd.goods.relation.set";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
Data.Add("out_goods_id", fromId.ToString());
|
|
Data.Add("out_detail_url", "https://item.taobao.com/item.htm?id=" + fromId);
|
|
Data.Add("out_low_goods_price", minPrice.ToString());
|
|
Data.Add("out_high_goods_price", maxPrice.ToString());
|
|
Data.Add("source_type", fromSite.ToString());
|
|
Data.Add("postage", postAge.ToString());
|
|
string html = GetData();
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("is_success"))
|
|
html = GetData();
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("is_success"))
|
|
html = GetData();
|
|
return html;
|
|
}
|
|
/// <summary>
|
|
/// 淘宝分类自动识别为拼多多分类
|
|
/// </summary>
|
|
/// <param name="catId">淘宝分类ID</param>
|
|
/// <param name="catName">淘宝分类名</param>
|
|
/// <param name="title">商品名</param>
|
|
/// <returns></returns>
|
|
public string GetCatId(int catId, string catName, string title)
|
|
{
|
|
Type = "pdd.goods.outer.cat.mapping.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("outer_cat_id", catId.ToString());
|
|
Data.Add("outer_cat_name", catName);
|
|
Data.Add("outer_goods_name", title);
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关联
|
|
/// </summary>
|
|
/// <param name="pid"></param>
|
|
/// <param name="fromId"></param>
|
|
/// <param name="minPrice">最低价 分</param>
|
|
/// <param name="maxPrice">最高价 分</param>
|
|
/// <param name="postAge">邮费 元</param>
|
|
/// <param name="fromSite">内部来源ID</param>
|
|
/// <returns></returns>
|
|
public string Relationx(long pid, long fromId, int minPrice, int maxPrice, decimal postAge, int fromSite)
|
|
{
|
|
int pddSiteId = 7;
|
|
string fromIdx = fromId.ToString();
|
|
switch (fromSite)
|
|
{
|
|
case 1:
|
|
pddSiteId = 0;
|
|
break;
|
|
case 2:
|
|
pddSiteId = 7;
|
|
//临时启用
|
|
fromIdx = "5" + Randomx.GetNumber(11);
|
|
pddSiteId = 0;
|
|
break;
|
|
case 3:
|
|
pddSiteId = 2;
|
|
break;
|
|
case 4:
|
|
pddSiteId = 1;
|
|
break;
|
|
case 5:
|
|
pddSiteId = 4;
|
|
break;
|
|
case 6:
|
|
pddSiteId = 8;
|
|
break;
|
|
default:
|
|
pddSiteId = 0;
|
|
break;
|
|
}
|
|
int expressPrice = (int)(postAge * 100);
|
|
|
|
Type = "pdd.goods.relation.set";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
Data.Add("out_goods_id", fromIdx);
|
|
Data.Add("out_low_goods_price", minPrice.ToString());
|
|
Data.Add("out_high_goods_price", maxPrice.ToString());
|
|
Data.Add("source_type", pddSiteId.ToString());
|
|
Data.Add("postage", expressPrice.ToString());
|
|
if (pddSiteId == 8)
|
|
Data.Add("out_detail_url", "https://weidian.com/item.html?itemID=" + fromId);
|
|
if (pddSiteId == 0)
|
|
Data.Add("out_detail_url", "https://item.taobao.com/item.htm?id=" + fromId);
|
|
if (pddSiteId == 1)
|
|
Data.Add("out_detail_url", "https://item.jd.com/" + fromId + ".html");
|
|
if (pddSiteId == 2)
|
|
Data.Add("out_detail_url", "https://detail.1688.com/offer/" + fromId + ".html");
|
|
if (pddSiteId == 4)
|
|
Data.Add("out_detail_url", "https://product.suning.com/0000000000/" + fromId + ".html");
|
|
|
|
string html = GetData();
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("is_success"))
|
|
html = GetData();
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("is_success"))
|
|
html = GetData();
|
|
return html;
|
|
}
|
|
|
|
public string GetRelation(string pid)
|
|
{
|
|
Type = "pdd.goods.get.relation";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("pdd_goods_id", "[" + pid.ToString() + "]");
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取订单详情
|
|
/// </summary>
|
|
/// <param name="status">状态:1:待发货,2:已发货待签收,3:已签收 5:全部</param>
|
|
/// <param name="refund_status">售后状态 1:无售后或售后关闭,2:售后处理中,3:退款中,4: 退款成功 5:全部</param>
|
|
/// <returns></returns>
|
|
public string GetOrderList(int status, int refund_status, DateTime begen, DateTime end, int page)
|
|
{
|
|
int start = BaseClass.GetTime(begen);
|
|
int after = BaseClass.GetTime(end);
|
|
Type = "pdd.order.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("order_status", status.ToString());
|
|
Data.Add("refund_status", refund_status.ToString());
|
|
Data.Add("start_confirm_at", start.ToString());
|
|
Data.Add("end_confirm_at", after.ToString());
|
|
Data.Add("page", page.ToString());
|
|
Data.Add("page_size", "100");
|
|
return GetData();
|
|
}
|
|
/// <summary>
|
|
/// 获取订单详情
|
|
/// </summary>
|
|
/// <param name="orderId"></param>
|
|
/// <returns></returns>
|
|
public string GetOrderDetail(string orderId)
|
|
{
|
|
Type = "pdd.order.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("order_sn", orderId);
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取运费模板
|
|
/// </summary>
|
|
/// <param name="orderId"></param>
|
|
/// <returns></returns>
|
|
public string GetLogisticsTemplate()
|
|
{
|
|
Type = "pdd.goods.logistics.template.get";
|
|
Data = new Dictionary<string, string>();
|
|
return GetData();
|
|
}
|
|
|
|
public void GetProductList(int isOnsale = 1)
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
if (string.IsNullOrEmpty(shopName) || Product.ContainsKey(shopName) && Product[shopName].Count > 0)
|
|
return;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
|
|
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", "1");
|
|
if (isOnsale == 1)
|
|
Data.Add("is_onsale", "1");
|
|
if (isOnsale == 0)
|
|
Data.Add("is_onsale", "0");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
string html = GetData();
|
|
int count = BaseRegex.GetIntJson(ref html, "total_count");
|
|
int page = count / 100 + 1;
|
|
for (int i = 1; i <= page; i++)
|
|
{
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", i.ToString());
|
|
if (isOnsale == 1)
|
|
Data.Add("is_onsale", "1");
|
|
if (isOnsale == 0)
|
|
Data.Add("is_onsale", "0");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
if (i > 1)
|
|
html = GetData();
|
|
MatchCollection m = null;
|
|
if (isOnsale == 1)
|
|
m = BaseRegex.GetMatchRegex(ref html, @"{""is_more_sku"":[\s\S]+?""is_onsale"":1}");
|
|
else if (isOnsale == 0)
|
|
m = BaseRegex.GetMatchRegex(ref html, @"{""is_more_sku"":[\s\S]+?""is_onsale"":0}");
|
|
else
|
|
m = BaseRegex.GetMatchRegex(ref html, @"{""is_more_sku"":[\s\S]+?""is_onsale"":[\s\S]+?}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
long id = BaseRegex.GetLongJson(ref list, "goods_id");
|
|
int onsale = BaseRegex.GetIntJson(ref list, "is_onsale");
|
|
var mm = BaseRegex.GetMatchRegex(ref list, @"""outer_goods_id"":""[\s]*([^""]+?)""");
|
|
string outId = "";
|
|
if (mm != null && mm.Count > 0)
|
|
outId = mm[mm.Count - 1].Groups[1].Value;
|
|
//if (string.IsNullOrEmpty(outId))
|
|
// outId = BaseRegex.GetStringJson(ref list, "");
|
|
if (!OutId.ContainsKey(id))
|
|
{
|
|
try
|
|
{
|
|
OutId.Add(id, outId);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
ProductBase p = new ProductBase();
|
|
p.Title = BaseRegex.GetStringJson(ref list, "goods_name");
|
|
p.Id = id;
|
|
p.onSale = onsale;
|
|
p.OuterId = outId;
|
|
if (!string.IsNullOrEmpty(outId))
|
|
{
|
|
JumpUpProductNew ju = new JumpUpProductNew(Shop);
|
|
ju.GetUrl(id.ToString());
|
|
p.UpId = ju.UpId.ProductIdFrom;
|
|
}
|
|
pros.Add(p);
|
|
}
|
|
LogSave.Add(Name, "正在获取店铺" + Shop.ShopName + "商品第" + i + "页");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Product.ContainsKey(shopName))
|
|
Product.Add(shopName, pros);
|
|
else
|
|
Product[shopName] = pros;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public void GetInvalidProductList()
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
if (string.IsNullOrEmpty(shopName) || Product.ContainsKey(shopName) && Product[shopName].Count > 0)
|
|
return;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
|
|
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", "1");
|
|
Data.Add("is_onsale", "1");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
string html = GetData();
|
|
int count = BaseRegex.GetIntJson(ref html, "total_count");
|
|
int page = count / 100 + 1;
|
|
for (int i = 1; i <= page; i++)
|
|
{
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", i.ToString());
|
|
Data.Add("is_onsale", "1");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
if (i > 1)
|
|
html = GetData();
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"{""is_more_sku"":[\s\S]+?""is_onsale"":1}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
long id = BaseRegex.GetLongJson(ref list, "goods_id");
|
|
var mm = BaseRegex.GetMatchRegex(ref list, @"""outer_goods_id"":""[\s]*([^""]+?)""");
|
|
string outId = "";
|
|
if (mm != null && mm.Count > 0)
|
|
outId = mm[mm.Count - 1].Groups[1].Value;
|
|
//if (string.IsNullOrEmpty(outId))
|
|
// outId = BaseRegex.GetStringJson(ref list, "");
|
|
if (!OutId.ContainsKey(id))
|
|
{
|
|
try
|
|
{
|
|
OutId.Add(id, outId);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
ProductBase p = new ProductBase();
|
|
p.Title = BaseRegex.GetStringJson(ref list, "goods_name");
|
|
p.Id = id;
|
|
p.OuterId = outId;
|
|
//if (!string.IsNullOrEmpty(outId))
|
|
//{
|
|
// JumpUpProductNew ju = new JumpUpProductNew(Shop);
|
|
// ju.GetUrl(id.ToString());
|
|
// p.UpId = ju.UpId.ProductIdFrom;
|
|
//}
|
|
pros.Add(p);
|
|
}
|
|
LogSave.Add(Name, "正在获取店铺" + Shop.ShopName + "商品第" + i + "页");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Product.ContainsKey(shopName))
|
|
Product.Add(shopName, pros);
|
|
else
|
|
Product[shopName] = pros;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取上架或下架的商品
|
|
/// </summary>
|
|
/// <param name="is_onsale"></param>
|
|
public void GetOnOrOffProductList(bool is_onsale)
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
//if (string.IsNullOrEmpty(shopName) || Product.ContainsKey(shopName) && Product[shopName].Count > 0)
|
|
// return;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
|
|
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", "1");
|
|
Data.Add("is_onsale", is_onsale ? "1" : "0");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
string html = GetData();
|
|
int count = BaseRegex.GetIntJson(ref html, "total_count");
|
|
int page = count / 100 + 1;
|
|
for (int i = 1; i <= page; i++)
|
|
{
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", i.ToString());
|
|
Data.Add("is_onsale", is_onsale ? "1" : "0");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
if (i > 1)
|
|
html = GetData();
|
|
int onflag = is_onsale ? 1 : 0;
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"{""is_more_sku"":[\s\S]+?""is_onsale"":" + onflag + "}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
long id = BaseRegex.GetLongJson(ref list, "goods_id");
|
|
|
|
var mm = BaseRegex.GetMatchRegex(ref list, @"""outer_id"":""[\s]*([^""]+?)""");
|
|
string outId = "";
|
|
if (mm != null && mm.Count > 0)
|
|
outId = mm[mm.Count - 1].Groups[1].Value;
|
|
//if (string.IsNullOrEmpty(outId))
|
|
// outId = BaseRegex.GetStringJson(ref list, "");
|
|
if (!OutId.ContainsKey(id) && !outId.Contains("wait:"))
|
|
{
|
|
try
|
|
{
|
|
OutId.Add(id, outId);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
ProductBase p = new ProductBase();
|
|
p.Title = BaseRegex.GetStringJson(ref list, "goods_name");
|
|
p.Id = id;
|
|
p.OuterId = outId;
|
|
//if (!string.IsNullOrEmpty(outId))
|
|
//{
|
|
// JumpUpProductNew ju = new JumpUpProductNew(Shop);
|
|
// ju.GetUrl(id.ToString());
|
|
// p.UpId = ju.UpId.ProductIdFrom;
|
|
//}
|
|
pros.Add(p);
|
|
}
|
|
LogSave.Add(Name, "正在获取店铺" + Shop.ShopName + "商品第" + i + "页");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Product.ContainsKey(shopName))
|
|
Product.Add(shopName, pros);
|
|
else
|
|
Product[shopName] = pros;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public void GetSellOutProductList()
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
if (string.IsNullOrEmpty(shopName) || Product.ContainsKey(shopName) && Product[shopName].Count > 0)
|
|
return;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
|
|
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", "1");
|
|
Data.Add("is_onsale", "1");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
string html = GetData();
|
|
int count = BaseRegex.GetIntJson(ref html, "total_count");
|
|
int page = count / 100 + 1;
|
|
for (int i = 1; i <= page; i++)
|
|
{
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", i.ToString());
|
|
Data.Add("is_onsale", "1");
|
|
//Data.Add("page_size", "50");
|
|
//Data.Add("outer_id", "");
|
|
if (i > 1)
|
|
html = GetData();
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"\{""goods_id"":([\w\W]+?)\]\}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
long id = BaseRegex.GetLongJson(ref list, "goods_id");
|
|
var mm = BaseRegex.GetMatchRegex(ref list, @"""outer_goods_id"":""[\s]*([^""]+?)""");
|
|
var goods_quantity = BaseRegex.GetLongJson(ref list, "goods_quantity");
|
|
string outId = "";
|
|
if (mm != null && mm.Count > 0)
|
|
outId = mm[mm.Count - 1].Groups[1].Value;
|
|
//if (string.IsNullOrEmpty(outId))
|
|
// outId = BaseRegex.GetStringJson(ref list, "");
|
|
if (!OutId.ContainsKey(id))
|
|
{
|
|
try
|
|
{
|
|
OutId.Add(id, outId);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
ProductBase p = new ProductBase();
|
|
p.Title = BaseRegex.GetStringJson(ref list, "goods_name");
|
|
p.Id = id;
|
|
p.OuterId = outId;
|
|
if (!string.IsNullOrEmpty(outId))
|
|
{
|
|
JumpUpProductNew ju = new JumpUpProductNew(Shop);
|
|
ju.GetUrl(id.ToString());
|
|
p.UpId = ju.UpId.ProductIdFrom;
|
|
}
|
|
if (goods_quantity == 0)
|
|
{
|
|
pros.Add(p);
|
|
}
|
|
}
|
|
LogSave.Add(Name, "正在获取店铺" + Shop.ShopName + "商品第" + i + "页");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Product.ContainsKey(shopName))
|
|
Product.Add(shopName, pros);
|
|
else
|
|
Product[shopName] = pros;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public void GetLifeBallProductList()
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
if (string.IsNullOrEmpty(shopName) || Product.ContainsKey(shopName) && Product[shopName].Count > 0)
|
|
return;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", "1");
|
|
Data.Add("is_onsale", "1");
|
|
string html = GetData();
|
|
int count = BaseRegex.GetIntJson(ref html, "total_count");
|
|
int page = count / 100 + 1;
|
|
for (int i = 1; i <= page; i++)
|
|
{
|
|
Type = "pdd.goods.list.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("page", i.ToString());
|
|
Data.Add("is_onsale", "1");
|
|
if (i > 1)
|
|
html = GetData();
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"\{""goods_id"":([\w\W]+?)\]\}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
if (list.Contains("TJM") || list.Contains("PBB") || list.Contains("TJH") || list.Contains("\"sku_list\":[]"))
|
|
{
|
|
var p = new ProuctBase();
|
|
p.Id = BaseRegex.GetLongJson(ref list, "goods_id");
|
|
string htmlx = GetProduct(p.Id);
|
|
if (list.Contains("TJM") || list.Contains("PBB") || list.Contains("TJH"))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
var mm = BaseRegex.GetMatchRegex(ref htmlx, @"\{""sku_id"":([\d]+)([^\}]+)?\}");
|
|
int priceMax = 0;
|
|
int priceMin = int.MaxValue;
|
|
for (int k = 0; k < mm.Count; k++)
|
|
{
|
|
string listx = mm[k].Groups[0].Value;
|
|
int price = BaseRegex.GetIntJson(ref listx, "multi_price");
|
|
if (price < priceMin)
|
|
priceMin = price;
|
|
if (priceMax < price)
|
|
priceMax = price;
|
|
}
|
|
p.PriceMax = priceMax / 100m;
|
|
p.PriceMin = priceMin / 100m;
|
|
ids.Add(p);
|
|
Shop.ProductCount = ids.Count;
|
|
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
|
|
LogSave.Add("超级替换", "分析商品: " + p.Id);
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
LogSave.Add("超级替换", "获取在线产品 " + shopName + ",分页:" + i);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置上下架
|
|
/// </summary>
|
|
/// <param name="pid"></param>
|
|
/// <param name="online"></param>
|
|
/// <returns></returns>
|
|
public string SetOnline(long pid, bool online)
|
|
{
|
|
Type = "pdd.goods.sale.status.set";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
Data.Add("is_onsale", online ? "1" : "0");
|
|
return GetData();
|
|
}
|
|
/// <summary>
|
|
/// 设置库存
|
|
/// </summary>
|
|
/// <param name="sku_id"></param>
|
|
/// <param name="quantity"></param>
|
|
/// <returns></returns>
|
|
public string SetSku(long sku_id, int quantity)
|
|
{
|
|
Type = "pdd.goods.sku.stock.update";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("sku_id", sku_id.ToString());
|
|
Data.Add("quantity", quantity.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置库存
|
|
/// </summary>
|
|
/// <param name="sku_id"></param>
|
|
/// <param name="quantity"></param>
|
|
/// <returns></returns>
|
|
public string SetGoodSku(long goods_id, long sku_id, int quantity)
|
|
{
|
|
Type = "pdd.goods.quantity.update";
|
|
Data = new Dictionary<string, string>();//pdd.goods.quantity.update
|
|
Data.Add("goods_id", goods_id.ToString());
|
|
Data.Add("sku_id", sku_id.ToString());
|
|
Data.Add("quantity", quantity.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
public string GetProduct(long pid)
|
|
{
|
|
Type = "pdd.goods.detail.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
return GetData()?.Replace("\\/", "/");
|
|
}
|
|
|
|
public void GetOnOrOffProductListById(List<string> pidList, bool is_onsale = true)
|
|
{
|
|
string shopName = Shop == null ? BaseClass.ShopName : Shop.ShopName;
|
|
List<ProductBase> pros = new List<ProductBase>();
|
|
LogSave.Add(Name, "正在获取店铺" + Shop.ShopName + "商品");
|
|
|
|
foreach (var pid in pidList)
|
|
{
|
|
Type = "pdd.goods.detail.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
string html = GetData();
|
|
|
|
int status = BaseRegex.GetIntJson(ref html, "status");
|
|
if ((is_onsale && status != 1 && status != 3) || (!is_onsale && status != 2))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
long id = BaseRegex.GetLongJson(ref html, "goods_id");
|
|
var mm = BaseRegex.GetMatchRegex(ref html, @"""outer_id"":""[\s]*([^""]+?)""");
|
|
if (mm == null || mm.Count == 0)
|
|
mm = BaseRegex.GetMatchRegex(ref html, @"""outer_goods_id"":""[\s]*([^""]+?)""");
|
|
string outId = "";
|
|
if (mm != null && mm.Count > 0)
|
|
outId = mm[mm.Count - 1].Groups[1].Value;
|
|
if (!OutId.ContainsKey(id) && !outId.Contains("wait:"))
|
|
{
|
|
try
|
|
{
|
|
OutId.Add(id, outId);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
ProductBase p = new ProductBase();
|
|
p.Title = BaseRegex.GetStringJson(ref html, "goods_name");
|
|
p.Id = id;
|
|
p.OuterId = outId;
|
|
pros.Add(p);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Product.ContainsKey(shopName))
|
|
Product.Add(shopName, pros);
|
|
else
|
|
Product[shopName] = pros;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public string GetProductInfor(long pid)
|
|
{
|
|
Type = "pdd.goods.detail.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", pid.ToString());
|
|
return GetData();
|
|
}
|
|
/// <summary>
|
|
/// 添加商品
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string Add()
|
|
{
|
|
return "\"error_msg\":\"请清空备用数据,使用新版转化数据\"";
|
|
Type = "pdd.goods.add";
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
public string Updata()
|
|
{
|
|
return "\"error_msg\":\"请清空备用数据,使用新版转化数据\"";
|
|
Type = "pdd.goods.information.update";
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加商品
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string AddNew()
|
|
{
|
|
Type = "pdd.goods.add";
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加商品到草稿箱
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string AddDraft()
|
|
{
|
|
Type = "pdd.goods.edit.goods.commit";
|
|
string html = GetData();
|
|
return html;
|
|
}
|
|
|
|
|
|
public string UpdataNew()
|
|
{
|
|
Type = "pdd.goods.information.update";
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新商品,然后设置关联映射(更新成功必须设置映射关系)。
|
|
/// 拼多多要求所有的商品必须与淘宝商品ID关联,且拼多多每个SKU价格小于等于淘宝价格*1.08。
|
|
/// 如果有以下情况:1.上家为拼多多商品、2.加价大于8%、3.单独有增加邮费,则去淘宝查找同款,获取单价大于当前加价后价格93%的
|
|
/// 淘宝ID,然后把价格和淘宝ID通过接口影射修改商品接口。其他情况,使用拼多多查询之前的映射关系,再次映射。如果无法通过以上
|
|
/// 办法获取映射,则想尽所有办法做一个正确的,甚至虚假的映射。
|
|
/// </summary>
|
|
/// <param name="pddRelation">关联参数类</param>
|
|
/// <returns></returns>
|
|
public string UpdataThenRelation(PinduoduoRelation pddRelation)
|
|
{
|
|
Dictionary<string, string> dataTemp = new Dictionary<string, string>();
|
|
foreach (var keyValue in this.Data)
|
|
{
|
|
dataTemp.Add(keyValue.Key, keyValue.Value);
|
|
}
|
|
string upResult = string.Empty;
|
|
|
|
#region 先判断是否有基本数据足以关联,不足直接退出
|
|
if (pddRelation == null)
|
|
pddRelation = new PinduoduoRelation();
|
|
if (pddRelation.goods_id == null)
|
|
{
|
|
if (dataTemp.ContainsKey("goods_id"))
|
|
{
|
|
try
|
|
{
|
|
pddRelation.goods_id = Convert.ToInt64(dataTemp["goods_id"]);
|
|
}
|
|
catch
|
|
{
|
|
LogSave.Add(Name, "拼多多id获取失败,跳过");
|
|
return "拼多多id获取失败";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogSave.Add(Name, "拼多多id获取失败,跳过");
|
|
return "拼多多id获取失败";
|
|
}
|
|
}
|
|
if (pddRelation.out_low_goods_price == null || pddRelation.out_high_goods_price == null)
|
|
{
|
|
pddRelation.out_low_goods_price = int.MaxValue;
|
|
pddRelation.out_high_goods_price = 0;
|
|
if (dataTemp.ContainsKey("sku_list"))
|
|
{
|
|
var skuJson = dataTemp["sku_list"];
|
|
var mPriceMatches = BaseRegex.GetMatchRegex(skuJson, "\"multi_price\":\"([\\s\\S]*?)\"");
|
|
if (mPriceMatches.Count > 0)
|
|
{
|
|
foreach (Match mPriceMatch in mPriceMatches)
|
|
{
|
|
try
|
|
{
|
|
string strPrice = BaseRegex.GetMatchRegexString(mPriceMatch.ToString(), "\"multi_price\":\"([\\s\\S]*?)\"");
|
|
long price = Convert.ToInt64(strPrice);
|
|
if (price < pddRelation.out_low_goods_price)
|
|
pddRelation.out_low_goods_price = price;
|
|
if (price > pddRelation.out_high_goods_price)
|
|
pddRelation.out_high_goods_price = price;
|
|
}
|
|
catch { }
|
|
}
|
|
pddRelation.out_low_goods_price = (long)(pddRelation.out_low_goods_price * 0.93);
|
|
pddRelation.out_high_goods_price = (long)(pddRelation.out_high_goods_price * 0.93);
|
|
}
|
|
}
|
|
if (pddRelation.out_low_goods_price == int.MaxValue)
|
|
return "关联价格获取失败";
|
|
}
|
|
#endregion
|
|
|
|
#region 获取其他关联数据
|
|
|
|
#region 通过服务器缓存获取关联数据
|
|
//// 内部获取上家id
|
|
//string idx = "";
|
|
//var re = new JumpUpProductNew(Shop).GetServerId(pddRelation.goods_id.Value, out idx);
|
|
#endregion
|
|
|
|
#region 通过接口获取关联数据
|
|
if (pddRelation.out_goods_id == null || pddRelation.source_type == null)
|
|
{
|
|
string html = GetRelation(pddRelation.goods_id.ToString());
|
|
// 有获取到对应的上家id
|
|
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
|
|
{
|
|
if (pddRelation.out_goods_id == null)
|
|
pddRelation.out_goods_id = BaseRegex.GetLongJson(ref html, "out_goods_id").ToString();
|
|
if (pddRelation.source_type == null)
|
|
pddRelation.source_type = BaseRegex.GetIntJson(ref html, "out_goods_platform");
|
|
}
|
|
else
|
|
{
|
|
// 未获取到上家id的情况,随机淘宝id,临时使用
|
|
pddRelation.out_goods_id = "5" + Randomx.GetNumber(11);
|
|
pddRelation.source_type = 0;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
if (pddRelation.postage == null)
|
|
pddRelation.postage = 0;
|
|
#endregion
|
|
|
|
#region 更新商品
|
|
this.Data = dataTemp;
|
|
upResult = this.UpdataNew();
|
|
// 调用失败直接返回结果,不设置关联
|
|
if (string.IsNullOrEmpty(upResult) || !upResult.Contains("\"is_success\":true"))
|
|
return upResult;
|
|
#endregion
|
|
|
|
#region 设置关联
|
|
try
|
|
{
|
|
string html = this.Relation(pddRelation.goods_id.Value, long.Parse(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"))
|
|
LogSave.Add(Name, "关联设置失败,商品id是" + pddRelation.goods_id);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
return upResult;
|
|
}
|
|
|
|
public KeyValuePair<string, string> AddThenRelation(long pid, long fromId, int minPrice, int maxPrice, int postAge, int fromSite)
|
|
{
|
|
string adResult = this.Add();
|
|
string reResult = this.Relation(pid, fromId, minPrice, maxPrice, postAge, fromSite);
|
|
return new KeyValuePair<string, string>(adResult, reResult);
|
|
}
|
|
|
|
public string ExpressSend(string order_sn, int logistics_id, string tracking_number)
|
|
{
|
|
Sync(order_sn, logistics_id, tracking_number);
|
|
Type = "pdd.logistics.online.send";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("order_sn", order_sn);
|
|
Data.Add("logistics_id", logistics_id.ToString());
|
|
Data.Add("tracking_number", tracking_number);
|
|
return GetData();
|
|
}
|
|
public string Sync(string order_sn, int logistics_id, string tracking_number)
|
|
{
|
|
Type = "pdd.erp.order.sync";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("order_sn", order_sn);
|
|
Data.Add("order_state", "1");
|
|
Data.Add("logistics_id", logistics_id.ToString());
|
|
Data.Add("waybill_no", tracking_number);
|
|
return GetData();
|
|
}
|
|
|
|
public string UploadImage(byte[] bytes)
|
|
{
|
|
Type = "pdd.goods.image.upload";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("image", "data:image/jpeg;base64, " + Convert.ToBase64String(bytes));
|
|
return GetData()?.Replace("\\/", "/");
|
|
}
|
|
/// <summary>
|
|
/// 获取分类
|
|
/// </summary>
|
|
/// <param name="parentId"></param>
|
|
/// <returns></returns>
|
|
public string GetCat(int parentId)
|
|
{
|
|
Type = "pdd.goods.cats.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("parent_cat_id", parentId.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
public string GetSpecId(string parentSpecId, string specName)
|
|
{
|
|
Type = "pdd.goods.spec.id.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("parent_spec_id", parentSpecId);
|
|
Data.Add("spec_name", specName);
|
|
return GetData();
|
|
}
|
|
|
|
public string GetProductInfoByCatAndPrice(int catId, decimal price)
|
|
{
|
|
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
|
var timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds;
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
dict.Add("client_id", "5f253ea926d740da96e7fc4df94b21f4");
|
|
dict.Add("data_type", "JSON");
|
|
dict.Add("timestamp", timeStamp);
|
|
dict.Add("cat_id", catId.ToString());
|
|
dict.Add("page_size", "10");
|
|
List<object> rangeList = new List<object>();
|
|
dict.Add("range_list", rangeList);
|
|
rangeList.Add(new
|
|
{
|
|
range_id = 0,
|
|
range_from = 0,
|
|
range_to = price * 100
|
|
});
|
|
//价格从低到高
|
|
dict.Add("sort_type", 3);
|
|
dict.Add("type", "pdd.ddk.goods.search");
|
|
|
|
var paramsDic = SignHelper.BuildSign(dict, SignHelper.DESDecrypt("1C076D6C0CDA77C7EDA6993F80FBA91730935E5E82F8A2F3E9F405CA02F7A55EEBF81E15D931A12B321102C80B3AD36E"));
|
|
var jsonBody = JsonConvert.SerializeObject(paramsDic);
|
|
string result = GetHtml.PostUtf8("http://gw-api.pinduoduo.com/api/router", jsonBody, "application/json");
|
|
return result;
|
|
}
|
|
|
|
public string DelGoods(string goodIds)
|
|
{
|
|
Type = "pdd.delete.goods.commit";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_ids", goodIds.ToString());
|
|
return GetData();
|
|
}
|
|
public string TemplateGetID(string catId)
|
|
{
|
|
Type = "pdd.goods.cat.template.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("cat_id", catId.ToString());
|
|
return GetData();
|
|
}
|
|
//查询商品推广API
|
|
public string JinBaoExtension(string goods_id)
|
|
{
|
|
Type = "pdd.goods.cps.unit.query";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", goods_id.ToString());
|
|
return GetData();
|
|
}
|
|
//修改商品推广API
|
|
public string UpdateExtension(string goods_id, long rate)
|
|
{
|
|
Type = "pdd.goods.cps.unit.change";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("goods_id", goods_id.ToString());
|
|
Data.Add("rate", rate.ToString());
|
|
Data.Add("coupon_id", "");
|
|
Data.Add("coupon_start_time", "");
|
|
Data.Add("coupon_end_time", "");
|
|
Data.Add("discount", "");
|
|
Data.Add("init_quantity", "");
|
|
Data.Add("remain_quantity", "");
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置全店推广API
|
|
/// </summary>
|
|
/// <param name="rate">千分比</param>
|
|
/// <returns></returns>
|
|
public string CreateJinBaoExtension(long rate)
|
|
{
|
|
Type = "pdd.goods.cps.mall.unit.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("rate", rate.ToString());
|
|
//string[] l = "01,02,03,04,05,07,09,10,11,12,13,14,15,16,17,19,20".Split(',');
|
|
//Data.Add("erp_code", "ERP0"+l[Randomx.GetId(l.Length)]);
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改进宝全店佣金
|
|
/// </summary>
|
|
/// <param name="rate"></param>
|
|
/// <returns></returns>
|
|
public string ChangeJinBaoExtension(long rate)
|
|
{
|
|
Type = "pdd.goods.cps.mall.unit.change";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("rate", rate.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置单品推广API
|
|
/// </summary>
|
|
/// <param name="units">多个字段</param>
|
|
/// <returns></returns>
|
|
public string CreateGoodExtension(string units)
|
|
{
|
|
Type = "pdd.goods.cps.unit.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("units", units.ToString());
|
|
return GetData();
|
|
}
|
|
/// <summary>
|
|
/// 创建优惠券批次ID
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string CreateProCoupon()
|
|
{
|
|
Type = "pdd.promotion.goods.coupon.create";
|
|
return GetData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建优惠券
|
|
/// </summary>
|
|
/// <param name="batch_desc">名称</param>
|
|
/// <param name="batch_start_time">时间戳 毫秒</param>
|
|
/// <param name="batch_end_time"></param>
|
|
/// <param name="discount">优惠金额 分</param>
|
|
/// <param name="init_quantity">总数</param>
|
|
/// <param name="user_limit">单用户领取</param>
|
|
/// <param name="goods_id">商品ID</param>
|
|
/// <returns></returns>
|
|
public string CreateGoodsCoupon(string batch_desc, long batch_start_time, long batch_end_time, int discount, int init_quantity, int user_limit, long goods_id)
|
|
{
|
|
Type = "pdd.promotion.goods.coupon.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("batch_desc", batch_desc.ToString());
|
|
Data.Add("batch_start_time", batch_start_time.ToString());
|
|
Data.Add("batch_end_time", batch_end_time.ToString());
|
|
Data.Add("discount", discount.ToString());
|
|
Data.Add("init_quantity", init_quantity.ToString());
|
|
Data.Add("user_limit", user_limit.ToString());
|
|
Data.Add("goods_id", goods_id.ToString());
|
|
return GetData();
|
|
}
|
|
//创建优惠券
|
|
public string CreateAddQuantity()
|
|
{
|
|
Type = "pdd.promotion.coupon.quantity.add";
|
|
return GetData();
|
|
}
|
|
|
|
//新建推广计划
|
|
public string CreatePlan(string planName)
|
|
{
|
|
Type = "pdd.ad.plan.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("scene_type", "0");
|
|
Data.Add("plan_name", planName);
|
|
return GetData();
|
|
}
|
|
//新建推广单元
|
|
public string CreateUnit(long planId, long goodsId, string keywords, string creativeList)
|
|
{
|
|
Type = "pdd.ad.unit.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("scene_type", "0");
|
|
Data.Add("plan_id", planId.ToString());
|
|
Data.Add("goods_id", goodsId.ToString());
|
|
Data.Add("keywords", keywords.ToString());
|
|
Data.Add("creative_list", creativeList.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
//根据ID,获取系统关键词
|
|
public string RcomKey(long goodsId)
|
|
{
|
|
Type = "pdd.ad.keyword.rcommended.get";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("scene_type", "0");
|
|
Data.Add("goods_id", goodsId.ToString());
|
|
return GetData();
|
|
}
|
|
|
|
//推广单元,添加关键词
|
|
public string CreateKeyword(long unitId, string keywords)
|
|
{
|
|
Type = "pdd.ad.keyword.create";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("scene_type", "0");
|
|
Data.Add("unit_id", unitId.ToString());
|
|
Data.Add("keywords", keywords);
|
|
return GetData();
|
|
}
|
|
//多多进宝推广位
|
|
public string CreateGenPid(int num)
|
|
{
|
|
Type = "pdd.ddk.goods.pid.generate";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("number", num.ToString());
|
|
return GetData();
|
|
}
|
|
//多多进宝推广链接
|
|
public string CreateGenPro(string p_id, long[] goods_id_list)
|
|
{
|
|
Type = "pdd.ddk.goods.promotion.url.generate";
|
|
Data = new Dictionary<string, string>();
|
|
Data.Add("p_id", p_id.ToString());
|
|
Data.Add("goods_id_list", goods_id_list.ToString());
|
|
return GetData();
|
|
}
|
|
/// <summary>
|
|
/// 获取店铺信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetShopInfo()
|
|
{
|
|
Type = "pdd.mall.info.get";
|
|
return GetData();
|
|
}
|
|
public void GetServiceApi()
|
|
{
|
|
string datax = UserLogin.GetSignaturex() + "";
|
|
string urlx = BaseClass.BuildObjString("config&act=get_service_url");
|
|
string htmlx = GetHtml.PostUtf8(urlx, datax);
|
|
var serArr = BaseRegex.GetMatchRegex(ref htmlx, "(\"[\\s\\S]+?\":\"[\\s\\S]+?\")");
|
|
if (serArr.Count > 0)
|
|
{
|
|
for (int i = 0; i < serArr.Count; i++)
|
|
{
|
|
var item = serArr[i].ToString();
|
|
string cliId = BaseRegex.GetMatchRegexString(ref item, "\"([\\s\\S]+?)\":");
|
|
string cliIdUrl = BaseRegex.GetMatchRegexString(ref item, ":\"([\\s\\S]+?)\"");
|
|
if (!ServiceApiDic.ContainsKey(cliId))
|
|
ServiceApiDic.Add(cliId, cliIdUrl);
|
|
}
|
|
}
|
|
}
|
|
public string GetData()
|
|
{
|
|
Shop.ClientId = String.IsNullOrEmpty(Shop.ClientId) ? BaseClass.ClientId : Shop.ClientId;
|
|
if (string.IsNullOrEmpty(Shop.ClientId))
|
|
Shop.ClientId = "7feaefdf527d45129219ca398c922bb0";
|
|
if (ServiceApiDic.Count == 0)
|
|
{
|
|
GetServiceApi();
|
|
}
|
|
string html = "";
|
|
var diclst = ServiceApiDic.ToList();
|
|
for (int i = 0; i < diclst.Count; i++)
|
|
{
|
|
var key = diclst[i].Key;
|
|
var val = diclst[i].Value;
|
|
if (key == Shop.ClientId)
|
|
{
|
|
html = GetDataSelf(val);
|
|
break;
|
|
}
|
|
}
|
|
return html;
|
|
}
|
|
|
|
public string GetDataPinduoduo()
|
|
{
|
|
int invalidCount = 0;
|
|
string client_id = String.IsNullOrEmpty(Shop.ClientId) ? BaseClass.ClientId : Shop.ClientId;
|
|
if (!BaseClass.UserApi)
|
|
return "";
|
|
try
|
|
{
|
|
bool error = false;
|
|
Agein:
|
|
if (Shop.ClientId == "7feaefdf527d45129219ca398c922bb0" && isSelf)
|
|
{
|
|
return GetDataSelf("http://px.jindouduo.com");
|
|
}
|
|
if (Shop.ClientId == "f4a3e3bb0253448d8272537726299621" && isSelf)
|
|
{
|
|
return GetDataSelf("http://nbzlw.e57.cn");
|
|
}
|
|
if (Shop.ClientId == "b1981defcd704a7d88c8a734358fb065" && isSelf)//途途上货助手
|
|
{
|
|
return GetDataSelf("http://tt.deifei.cn");
|
|
}
|
|
if (Shop.ClientId == "81fd2bbabbd54ec5bf312e05401a0343" && isSelf)//微木ERP
|
|
{
|
|
return GetDataSelf("http://dd.pinsubao.com");
|
|
}
|
|
if (Shop.ClientId == "911bd1c0c0a0403da88334e24ca288a2" && isSelf)//蛮牛工具
|
|
{
|
|
return GetDataSelf("http://wdt.qimake.cn");
|
|
}
|
|
if (Shop.ClientId == "5d755c0cf97a4cbdb8aa958beea25011" && isSelf)//微木订单
|
|
{
|
|
return GetDataSelf("http://wnm.pinsubao.com ");
|
|
}
|
|
if (Shop.ClientId == "3069c1c325e44e85bcf5b6295694bdae" && isSelf)//点金工具箱
|
|
{
|
|
return GetDataSelf("http://dianjin.6nt.cn");
|
|
}
|
|
if (Shop.ClientId == "9558f920cf77403bb475243fe44482ad" && isSelf)//拼商宝
|
|
{
|
|
return GetDataSelf("http://psbx.9u99.com/index.php?s=");
|
|
}
|
|
if (Shop.ClientId == "88d6ef134c3b4a07b7a22d8bbef9b1b4" && isSelf)//凯达工具
|
|
{
|
|
return GetDataSelf("http://kd.qimake.cn");
|
|
}
|
|
if (Shop.ClientId == "f23bda7f6d9c4b6c8751268891779660" && isSelf)//飓风管家
|
|
{
|
|
return GetDataSelf("http://jfgj.qixiaoker.com");
|
|
}
|
|
if (Shop.ClientId == "9f7d0ce6460b46e7a3833ac2e8325519" && isSelf)//飓风发货
|
|
{
|
|
return GetDataSelf("http://jffh.qixiaoker.com");
|
|
}
|
|
if (Shop.ClientId == "716a6bcc69d7441d856905eb79b892fd" && isSelf)//运筹erp
|
|
{
|
|
return GetDataSelf("http://yc.kanwailian.com");
|
|
}
|
|
string token = Shop == null ? BaseClass.AccessToken : Shop.AccessToken;
|
|
string reflesh = Shop.RefreshToken;
|
|
string sid = Shop == null ? BaseClass.ShopId : Shop.ShopId;
|
|
if (Data == null)
|
|
Data = new Dictionary<string, string>();
|
|
if (Data.ContainsKey("type"))
|
|
Data["type"] = Type;
|
|
else
|
|
Data.Add("type", Type);
|
|
if ((Type.Contains(".cps.") || Type.Contains(".coupon.")) && !string.IsNullOrEmpty(Shop.CpsShop.AccessToken)) // 进宝和优惠券
|
|
{
|
|
client_id = "911bd1c0c0a0403da88334e24ca288a2";//蛮牛ERP
|
|
token = Shop.CpsShop.AccessToken;
|
|
}
|
|
if (!Data.ContainsKey("type"))
|
|
Data.Add("data_type", "JSON");
|
|
if (Data.ContainsKey("timestamp"))
|
|
Data["timestamp"] = BaseClass.GetTime(DateTime.Now).ToString();
|
|
else
|
|
Data.Add("timestamp", BaseClass.GetTime(DateTime.Now).ToString());
|
|
if (Data.ContainsKey("client_id"))
|
|
Data["client_id"] = client_id;
|
|
else
|
|
Data.Add("client_id", client_id);
|
|
if (Type == "pdd.goods.add" || Type == "pdd.goods.information.update")
|
|
{
|
|
// 付费接口必须微店转化过(商品同步非拼多多上家1.08倍以内暂时放行)
|
|
if ((client_id == "88d6ef134c3b4a07b7a22d8bbef9b1b4" || client_id == "716a6bcc69d7441d856905eb79b892fd") && !FromWeiDian && !IsProdSyncNotPdd1_08)
|
|
{
|
|
return "\"error_msg\":\"数据有误,请清空备用数据,使用新版转化数据\"";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(token))
|
|
{
|
|
if (Data.ContainsKey("access_token"))
|
|
Data["access_token"] = token;
|
|
else
|
|
Data.Add("access_token", token);
|
|
}
|
|
if (Data.ContainsKey("sign"))
|
|
Data.Remove("sign");
|
|
string sign = "";
|
|
StringBuilder code = new StringBuilder();
|
|
Dictionary<string, string> nd = Data.OrderBy(d => d.Key).ToDictionary(p => p.Key, o => o.Value);
|
|
foreach (KeyValuePair<string, string> key in nd)
|
|
{
|
|
code.Append(key.Key + key.Value);
|
|
}
|
|
|
|
|
|
string url = BaseClass.BuildObjString("sign&act=get&type=" + Type + "&client_id=" + client_id);
|
|
string date = UserLogin.GetSignaturex(Shop.ShopId, Shop.ShopName) + "&hadid=1&signcode=" +
|
|
GetHtml.UrlEncodeUtf8(code.ToString());
|
|
sign = GetHtml.PostUtf8(url, date);
|
|
Data.Add("sign", sign);
|
|
string json = JsonHelper.SerializeObject(Data);
|
|
|
|
string html = GetPostTaobaoHtml.GetJsonPost(PinduoduoAuth.Gate, PinduoduoAuth.Gate, true, json);
|
|
html = GetHtml.Decode(html);
|
|
if (html.Contains("用户没有授权访问此接口"))
|
|
{
|
|
}
|
|
if (html.Contains("goods_commit_id"))
|
|
{
|
|
if (!successClient.ContainsKey(Shop.ShopName))
|
|
{
|
|
List<string> clientIds = new List<string>();
|
|
clientIds.Add(client_id);
|
|
successClient.Add(Shop.ShopName, clientIds);
|
|
}
|
|
else
|
|
{
|
|
if (!successClient[Shop.ShopName].Contains(client_id))
|
|
successClient[Shop.ShopName].Add(client_id);
|
|
}
|
|
}
|
|
bool isRefresh = false;
|
|
if (html.Contains("access_token") && html.Contains("error_response") && !html.Contains("属性") && successClient.ContainsKey(Shop.ShopName))
|
|
{
|
|
Thread.Sleep(5 * 1000);
|
|
var a = new PinduoduoAuth();
|
|
var clientids = successClient[Shop.ShopName];
|
|
for (int i = 0; i < clientids.Count; i++)
|
|
{
|
|
string urlx = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=get_token&shop_name=" + Shop.ShopName + "&" + UserLogin.GetSignaturex();
|
|
string htmlx = GetHtml.Utf8(urlx);
|
|
if (!string.IsNullOrEmpty(htmlx) && htmlx.Contains("access_token"))
|
|
{
|
|
string AccessToken = BaseRegex.GetStringJson(ref htmlx, "access_token");
|
|
string RefreshToken = BaseRegex.GetStringJson(ref htmlx, "refresh_token");
|
|
if (a.ReFresh(RefreshToken, clientids[i]))
|
|
{
|
|
isRefresh = true;
|
|
Shop.RefreshToken = RefreshToken;
|
|
Shop.AccessToken = AccessToken;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(html) && isRefresh && html.Contains("access_token已过期"))
|
|
{
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
goto Agein;
|
|
}
|
|
if (html.Contains("签名失败"))
|
|
{
|
|
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")))
|
|
{
|
|
Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] = Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] + 1;
|
|
if (Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
|
html = "\"error_msg\":今日调用次数用完,明天再继续";
|
|
}
|
|
else
|
|
Shop.SignErrorTimes.Add(DateTime.Now.ToString("yyyy-MM-dd"), 1);
|
|
return html;
|
|
}
|
|
|
|
if (html.Contains("签名验证失败"))
|
|
{
|
|
if (invalidCount > 3)
|
|
return html;
|
|
invalidCount++;
|
|
var a = new PinduoduoAuth();
|
|
a.NoCache = true;
|
|
a.MustAuth = true;
|
|
a.IsCps = Type.Contains(".cps.") || Type.Contains(".coupon.");//进宝和优惠券
|
|
bool ok = a.Auth(Shop, ref client_id);
|
|
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
if (!a.IsCps && Type != "pdd.goods.outer.cat.mapping.get")
|
|
Thread.Sleep(3000);
|
|
goto Agein;
|
|
}
|
|
if (!string.IsNullOrEmpty(html) && (html.Contains("access_token") || html.Contains("请选择配送地区") || html.Contains("暂未签署多多进宝") || html.Contains("授权已被取消") || html.Contains("clientId不正确") || html.Contains("access_token")))//&& !error
|
|
{
|
|
if (invalidCount > 3)
|
|
return html;
|
|
invalidCount++;
|
|
var a = new PinduoduoAuth();
|
|
a.NoCache = true;
|
|
a.MustAuth = true;
|
|
a.IsCps = Type.Contains(".cps.") || Type.Contains(".coupon.");//进宝和优惠券
|
|
bool ok = a.Auth(Shop, ref client_id);
|
|
if (!ok && invalidCount > 3)
|
|
return "\"error_msg\":授权失败,请先购买API再上传";
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
if (!a.IsCps && Type != "pdd.goods.outer.cat.mapping.get")
|
|
Thread.Sleep(3000);
|
|
goto Agein;
|
|
}
|
|
return html;
|
|
}
|
|
catch
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
public string GetDataSelf(string domainname)
|
|
{
|
|
int invalidCount = 0;
|
|
string client_id = String.IsNullOrEmpty(Shop.ClientId) ? BaseClass.ClientId : Shop.ClientId;
|
|
if (!BaseClass.UserApi)
|
|
return "";
|
|
try
|
|
{
|
|
bool error = false;
|
|
Agein:
|
|
string token = Shop == null ? BaseClass.AccessToken : Shop.AccessToken;
|
|
string reflesh = Shop.RefreshToken;
|
|
string sid = Shop == null ? BaseClass.ShopId : Shop.ShopId;
|
|
if (Data == null)
|
|
Data = new Dictionary<string, string>();
|
|
if (Data.ContainsKey("type"))
|
|
Data["type"] = Type;
|
|
else
|
|
Data.Add("type", Type);
|
|
if ((Type.Contains(".cps.") || Type.Contains(".coupon.")) && !string.IsNullOrEmpty(Shop.CpsShop.AccessToken)) // 进宝和优惠券
|
|
{
|
|
client_id = "911bd1c0c0a0403da88334e24ca288a2";//蛮牛ERP
|
|
token = Shop.CpsShop.AccessToken;
|
|
}
|
|
if (!Data.ContainsKey("type"))
|
|
Data.Add("data_type", "JSON");
|
|
int time = BaseClass.DateTimeToTimestampSeconds(DateTime.Now) + BaseClass.TimeDifferent;
|
|
if (Data.ContainsKey("timestamp"))
|
|
Data["timestamp"] = time.ToString();//BaseClass.GetTime(DateTime.Now).ToString();
|
|
else
|
|
Data.Add("timestamp", time.ToString());
|
|
if (Data.ContainsKey("client_id"))
|
|
Data["client_id"] = client_id;
|
|
else
|
|
Data.Add("client_id", client_id);
|
|
if (Type == "pdd.goods.add" || Type == "pdd.goods.information.update")
|
|
{
|
|
// 付费接口必须微店转化过(商品同步非拼多多上家1.08倍以内暂时放行)
|
|
if ((client_id == "88d6ef134c3b4a07b7a22d8bbef9b1b4" || client_id == "716a6bcc69d7441d856905eb79b892fd") && !FromWeiDian && !IsProdSyncNotPdd1_08)
|
|
{
|
|
return "\"error_msg\":\"数据有误,请清空备用数据,使用新版转化数据\"";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(token))
|
|
{
|
|
if (Data.ContainsKey("access_token"))
|
|
Data["access_token"] = token;
|
|
else
|
|
Data.Add("access_token", token);
|
|
}
|
|
if (Data.ContainsKey("sign"))
|
|
Data.Remove("sign");
|
|
string sign = "";
|
|
StringBuilder code = new StringBuilder();
|
|
Dictionary<string, string> nd = Data.OrderBy(d => d.Key).ToDictionary(p => p.Key, o => o.Value);
|
|
foreach (KeyValuePair<string, string> key in nd)
|
|
{
|
|
code.Append(key.Key + key.Value);
|
|
}
|
|
//string url = BaseClass.BuildObjString("sign&act=get&type=" + Type + "&client_id=" + client_id);
|
|
//string date = UserLogin.GetSignaturex(Shop.ShopId, Shop.ShopName) + "&hadid=1&signcode=" +
|
|
// GetHtml.UrlEncodeUtf8(code.ToString());
|
|
//sign = GetHtml.PostUtf8(url, date);
|
|
Data.Add("sign", "");
|
|
string time1 = UserLogin.Encryption(time);
|
|
if (Data.ContainsKey("encCode"))
|
|
Data.Remove("encCode");
|
|
Data.Add("encCode", time1);
|
|
if (BaseClass.NewSignatureAuth)
|
|
{
|
|
if (Data.ContainsKey("NbCodeVersion"))
|
|
Data.Remove("NbCodeVersion");
|
|
Data.Add("NbCodeVersion", "1");
|
|
}
|
|
//if (Data.ContainsKey("mall_id"))
|
|
// Data.Remove("mall_id");
|
|
//Data.Add("mall_id", Shop.MallId.ToString());
|
|
var _params = JsonHelper.SerializeObject(Data);
|
|
if (_params.Contains("+"))
|
|
_params = GetHtml.UrlEncodeUtf8(_params);
|
|
string json = "¶ms=" + _params;
|
|
domainname = GetDomain(client_id);//
|
|
string html = GetHtml.PostUtf8(domainname + "index/api/pddTransfer", json);//http://px.jindouduo.com
|
|
html = GetHtml.Decode(html);
|
|
if (html.Contains("goods_commit_id"))
|
|
{
|
|
if (!successClient.ContainsKey(Shop.ShopName))
|
|
{
|
|
List<string> clientIds = new List<string>();
|
|
clientIds.Add(client_id);
|
|
successClient.Add(Shop.ShopName, clientIds);
|
|
}
|
|
else
|
|
{
|
|
if (!successClient[Shop.ShopName].Contains(client_id))
|
|
successClient[Shop.ShopName].Add(client_id);
|
|
}
|
|
}
|
|
bool isRefresh = false;
|
|
if (html.Contains("access_token") && html.Contains("error_response") && !html.Contains("属性") && successClient.ContainsKey(Shop.ShopName))
|
|
{
|
|
Thread.Sleep(5 * 1000);
|
|
var a = new PinduoduoAuth();
|
|
var clientids = successClient[Shop.ShopName];
|
|
for (int i = 0; i < clientids.Count; i++)
|
|
{
|
|
string urlx = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=get_token&shop_name=" + Shop.ShopName + "&" + UserLogin.GetSignaturex();
|
|
string htmlx = GetHtml.Utf8(urlx);
|
|
if (!string.IsNullOrEmpty(htmlx) && htmlx.Contains("access_token"))
|
|
{
|
|
string AccessToken = BaseRegex.GetStringJson(ref htmlx, "access_token");
|
|
string RefreshToken = BaseRegex.GetStringJson(ref htmlx, "refresh_token");
|
|
if (a.ReFresh(RefreshToken, clientids[i]))
|
|
{
|
|
isRefresh = true;
|
|
Shop.RefreshToken = RefreshToken;
|
|
Shop.AccessToken = AccessToken;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty(html) && isRefresh && html.Contains("access_token已过期"))
|
|
{
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
goto Agein;
|
|
}
|
|
if (html.Contains("签名失败"))
|
|
{
|
|
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")))
|
|
{
|
|
Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] = Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] + 1;
|
|
if (Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
|
html = "\"error_msg\":今日调用次数用完,明天再继续";
|
|
}
|
|
else
|
|
Shop.SignErrorTimes.Add(DateTime.Now.ToString("yyyy-MM-dd"), 1);
|
|
return html;
|
|
}
|
|
|
|
if (html.Contains("签名验证失败") || html.Contains("您的应用还未发布到服务市场"))
|
|
{
|
|
if (invalidCount > 3)
|
|
return html;
|
|
invalidCount++;
|
|
var a = new PinduoduoAuth();
|
|
a.NoCache = true;
|
|
a.MustAuth = true;
|
|
a.IsCps = Type.Contains(".cps.") || Type.Contains(".coupon.");//进宝和优惠券
|
|
bool ok = a.Auth(Shop, ref client_id);
|
|
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
if (!a.IsCps && Type != "pdd.goods.outer.cat.mapping.get")
|
|
Thread.Sleep(3000);
|
|
goto Agein;
|
|
}
|
|
if (!string.IsNullOrEmpty(html) && (html.Contains("access_token") || html.Contains("请选择配送地区") || html.Contains("暂未签署多多进宝") || html.Contains("授权已被取消") || html.Contains("clientId不正确") || html.Contains("access_token")))//&& !error
|
|
{
|
|
if (invalidCount > 3 || BaseClass.UserVersion == 110) // 重试三次或者特殊用户版本为110,返回
|
|
return html;
|
|
invalidCount++;
|
|
var a = new PinduoduoAuth();
|
|
a.NoCache = true;
|
|
a.MustAuth = true;
|
|
a.IsCps = Type.Contains(".cps.") || Type.Contains(".coupon.");//进宝和优惠券
|
|
bool ok = a.Auth(Shop, ref client_id);
|
|
if (!ok && invalidCount > 3)
|
|
return "\"error_msg\":授权失败,请先购买API再上传";
|
|
error = true;
|
|
Data.Remove("type");
|
|
Data.Remove("data_type");
|
|
Data.Remove("client_id");
|
|
Data.Remove("timestamp");
|
|
if (Data.ContainsKey("access_token"))
|
|
Data.Remove("access_token");
|
|
Data.Remove("sign");
|
|
if (!a.IsCps && Type != "pdd.goods.outer.cat.mapping.get")
|
|
Thread.Sleep(3000);
|
|
goto Agein;
|
|
}
|
|
return html;
|
|
}
|
|
catch
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
public string GetDomain(string clientid)
|
|
{
|
|
string result = "";
|
|
var diclst = ServiceApiDic.ToList();
|
|
for (int i = 0; i < diclst.Count; i++)
|
|
{
|
|
var key = diclst[i].Key;
|
|
var val = diclst[i].Value;
|
|
if (key == clientid)
|
|
{
|
|
result = val;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
public class ProuctBase
|
|
{
|
|
public long Id;
|
|
public decimal PriceMin;
|
|
public decimal PriceMax;
|
|
}
|
|
}
|