92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using AllBase;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.DBModel;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Work._29Tools.BLL
|
|
{
|
|
public class WxApiBLL
|
|
{
|
|
private WXShopTokenInfo UpdateShopWxToken(ShopLoginInfo shop)
|
|
{
|
|
var url = BaseClass.Build29WxObjString("shop/e57_get_wx_shop_token");
|
|
var data = UserLogin.GetSignaturex();
|
|
data += "&shop_id=" + shop.ShopId;
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
// 获取失败
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":0"))
|
|
{
|
|
return new WXShopTokenInfo() { shopId = shop.ShopId, accessToken = "", mdyTime = DateTime.Now };
|
|
}
|
|
else
|
|
{
|
|
var token = new WXShopTokenInfo()
|
|
{
|
|
shopId = shop.ShopId,
|
|
accessToken = BaseRegex.GetStringJson(ref html, "accessToken"),
|
|
mdyTime = DateTime.Now,
|
|
};
|
|
return token;
|
|
}
|
|
}
|
|
|
|
public WXShopTokenInfo GetWxToken(ShopLoginInfo shop)
|
|
{
|
|
WXShopTokenInfo token = GlobalConfig.lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId);
|
|
if (token == null)
|
|
token = new WXShopTokenInfo();
|
|
if (token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
|
{
|
|
token = new WxApiBLL().UpdateShopWxToken(shop);
|
|
|
|
if (!string.IsNullOrEmpty(token.accessToken))
|
|
{
|
|
GlobalConfig.lstWXShopTokenInfo.RemoveAll(t => t.shopId == shop.ShopId);
|
|
GlobalConfig.lstWXShopTokenInfo.Add(token);
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_token_list", GlobalConfig.lstWXShopTokenInfo);
|
|
}
|
|
}
|
|
return token;
|
|
}
|
|
|
|
public string WxApiDropshipSearch(ShopLoginInfo shop, string orderId, int status)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(UserLogin.GetSignaturex());
|
|
sb.Append("&token=").Append(GetWxToken(shop).accessToken);
|
|
sb.Append("&order_id=").Append(orderId);
|
|
sb.Append("&status=").Append(status);
|
|
|
|
var url = BaseClass.Build29WxObjString("product/wx_api_dropship_search");
|
|
var data = sb.ToString();
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"errcode\":0"))
|
|
html = GetHtml.PostUtf8(url, data);
|
|
return html;
|
|
}
|
|
|
|
|
|
public string WxApiDropshipAssign(ShopLoginInfo shop, string orderId, string spuId, string skuId, int cnt)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(UserLogin.GetSignaturex());
|
|
sb.Append("&token=").Append(GetWxToken(shop).accessToken);
|
|
sb.Append("&order_id=").Append(orderId);
|
|
sb.Append("&dropship_product_list=").Append("[{\"spu_id\":\"" + spuId + "\",\"sku_id\":\"" + skuId + "\",\"product_cnt\":" + cnt + "}]");
|
|
|
|
var url = BaseClass.Build29WxObjString("product/wx_api_dropship_assign");
|
|
var data = sb.ToString();
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"errcode\":0"))
|
|
html = GetHtml.PostUtf8(url, data);
|
|
return html;
|
|
}
|
|
}
|
|
}
|