微信调用外部插件修改订单,拼多多获取token等部分功能
This commit is contained in:
1 parent
81d5107b32
commit
ff42506091
24 files changed
+2728
-193
No files matched your search
@@ -1,12 +1,15 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Result;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Work.CollectClass;
|
||||
|
||||
namespace TemuKJD.BLL.PddApi
|
||||
{
|
||||
@@ -74,6 +77,196 @@ namespace TemuKJD.BLL.PddApi
|
||||
return html;
|
||||
}
|
||||
|
||||
public string PddGoodsGetRelation(string pid = "")
|
||||
{
|
||||
string type = "pdd.goods.get.relation";
|
||||
if (!string.IsNullOrEmpty(pid))
|
||||
Data["pdd_goods_id"] = "[" + pid.ToString() + "]";
|
||||
string html = PddApiRequest(type, Data);
|
||||
return html;
|
||||
}
|
||||
|
||||
public string PddPopAuthTokenCreate()
|
||||
{
|
||||
string type = "pdd.pop.auth.token.create";
|
||||
if (!Data.Keys.Contains("code"))
|
||||
Data["code"] = "83be994d5ed04e6cb9643a423094a3296bf8827a";
|
||||
string html = PddApiRequest(type, Data);
|
||||
return html;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联
|
||||
/// </summary>
|
||||
/// <param name="pid"></param>
|
||||
/// <param name="outGoodsId"></param>
|
||||
/// <param name="minPrice">最低价 分</param>
|
||||
/// <param name="maxPrice">最高价 分</param>
|
||||
/// <param name="postAge">邮费 元</param>
|
||||
/// <param name="sourceType">
|
||||
/// 外部平台枚举值, 0-淘宝/天猫 ,1-京东,2-1688,3-唯品会,4-苏宁,5-亚马逊,6-网易,
|
||||
/// 8-微店,9-网商园,10-蘑菇街,11-vvic搜款网,12-搜鞋网,13-一起做网店17zwd,14-杭州女装网,
|
||||
/// 15-折800,16-当当,17-青创网,18-开山网,19-新款网
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public string Relation2603(long pid, long 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());
|
||||
string detailUrl = "";
|
||||
if (sourceType == 0)
|
||||
detailUrl = "https://item.taobao.com/item.htm?id=" + outGoodsId;
|
||||
if (sourceType == 2)
|
||||
detailUrl = "https://detail.1688.com/offer/" + outGoodsId + ".html";
|
||||
else if (sourceType == 8)
|
||||
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());
|
||||
string html = PddApiRequest(type, Data);
|
||||
return html;
|
||||
}
|
||||
|
||||
/// <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, object> dataTemp = new Dictionary<string, object>();
|
||||
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.ParseToString(), "\"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 = PddGoodsGetRelation(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.PddGoodsInformationUpdate();
|
||||
// 调用失败直接返回结果,不设置关联
|
||||
if (string.IsNullOrEmpty(upResult) || !upResult.Contains("\"is_success\":true"))
|
||||
return upResult;
|
||||
#endregion
|
||||
|
||||
#region 设置关联
|
||||
try
|
||||
{
|
||||
string html = this.Relation2603(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);
|
||||
return "关联设置失败,商品id是" + pddRelation.goods_id;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
return upResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,38 @@
|
||||
using System;
|
||||
using AllBase;
|
||||
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 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,
|
||||
AppKey = BaseClass.GetFileMd5(BaseRegex.GetStringJson(ref html, "appKey").ParseToString()),
|
||||
AccessToken = BaseRegex.GetStringJson(ref html, "accessToken"),
|
||||
ExpiresTime = BaseClass.StampToDateTime(BaseRegex.GetIntJson(ref html, "tokenExpiresTime")),
|
||||
};
|
||||
return token;
|
||||
}
|
||||
return new AuthInfo() { ShopId = shop.ShopId, AccessToken = "", ExpiresTime = DateTime.Now };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user