微信调用外部插件修改订单,拼多多获取token等部分功能

This commit is contained in:
wule committed 2026-03-31 09:51:15 +08:00
1 parent 81d5107b32
commit ff42506091
24 files changed
+2728 -193

No files matched your search

+193
View File
@@ -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>
+27 -2
View File
@@ -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 };
}
}
}
+2
View File
@@ -22,6 +22,7 @@ namespace TemuKJD.BLL
+ "&login_pass=" + GetHtml.UrlEncodeUtf8(_shop.Password)
+ "&shop_id=" + _shop.ShopId
+ "&shop_account=" + _shop.ShopAccount
+ "&mall_id" + _shop.MallId
+ "&cookie=" + _shop.Cookies
+ "&cookie2=" + _shop.Cookies2
+ "&group_name=" + GetHtml.UrlEncodeUtf8(_shop.GroupName)
@@ -289,6 +290,7 @@ namespace TemuKJD.BLL
shop.ad_seller_unique_id = BaseRegex.GetStringJson(ref shopStr, "ad_seller_unique_id");
shop.ad_url = BaseRegex.GetStringJson(ref shopStr, "ad_url");
shop.pddid = BaseRegex.GetStringJson(ref shopStr, "pddid");
shop.MallId = BaseRegex.GetStringJson(ref shopStr, "mall_id");
shop.openid = BaseRegex.GetStringJson(ref shopStr, "openid");
shop.jit_expire_time = BaseRegex.GetStringJson(ref shopStr, "jit_expire_time") == null ? new DateTime?() : Convert.ToDateTime(BaseRegex.GetStringJson(ref shopStr, "jit_expire_time"));
shop.AddTime = BaseRegex.GetStringJson(ref shopStr, "add_time") == null ? DateTime.MinValue : Convert.ToDateTime(BaseRegex.GetStringJson(ref shopStr, "add_time"));
+78
View File
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TemuKJD.BLL.Tools
{
public class DownloadBLL
{
public static string downloadFile(string url, string fileName, Control ctrl)
{
if (ctrl == null)
ctrl = new Control();
//string StrFileName = "d:\\wgscd.zip"; //根据实际情况设置
//string StrUrl = "https://files.cnblogs.com/files/wgscd/xxx.zip"; //根据实际情况设置
string StrFileName = fileName;
string StrUrl = url;
//打开上次下载的文件或新建文件
long lStartPos = 0;
System.IO.FileStream fs;
if (System.IO.File.Exists(StrFileName))//另外如果文件已经下载完毕,就不需要再断点续传了,不然请求的range 会不合法会抛出异常。
{
fs = System.IO.File.OpenWrite(StrFileName);
lStartPos = fs.Length;
fs.Seek(lStartPos, System.IO.SeekOrigin.Current); //移动文件流中的当前指针
}
else
{
fs = new System.IO.FileStream(StrFileName, System.IO.FileMode.Create);
lStartPos = 0;
}
//打开网络连接
try
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(StrUrl);
if (lStartPos > 0)
{
request.AddRange((int)lStartPos); // 设置Range值
}
System.Net.WebResponse response = request.GetResponse();
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = response.GetResponseStream();
long totalSize = response.ContentLength;
long hasDownSize = 0;
byte[] nbytes = new byte[512];//521,2048 etc
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, nbytes.Length);
while (nReadSize > 0)
{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, 512);
hasDownSize += nReadSize;
ctrl.Invoke(new Action(() =>
{
//ctrl.Text = "" + hasDownSize + "/" + totalSize + " (" + (((double)hasDownSize * 100 / totalSize).ToString("0.00")) + "%)"; // 显示下载百分比
ctrl.Text = "正在下载模块 " + ((double)(hasDownSize + lStartPos) * 100 / (totalSize + lStartPos)).ToString("0.00") + "%"; // 显示下载百分比
}));
//Application.DoEvents();
}
fs.Close();
ns.Close();
ctrl.Invoke(new Action(() =>
{
ctrl.Text = "模块下载完成 " + ((double)(hasDownSize + lStartPos) * 100 / (totalSize + lStartPos)).ToString("0.00") + "%"; // 显示下载百分比
}));
return "下载完成";
}
catch (Exception ex)
{
fs.Close();
return "下载过程中出现错误:" + ex.ToString();
}
}
}
}
+3 -1
View File
@@ -15,13 +15,15 @@ namespace TemuKJD.BLL
{
public class WxApiBLL
{
public WXShopTokenInfo GetRandomWxToken()
public WXShopTokenInfo GetRandomWxToken(bool isShowErrorDlg = true)
{
if (GlobalConfig.WxTokenList.Count == 0 || GlobalConfig.WxTokenList.All(t => t.isExpire == true))
{
var url = BaseClass.BuildObjString("shop/e57_get_wx_tokens");
var data = UserLogin.GetSignaturex();
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
BaseMsgForm.ShowError("获取授权失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));