|
|
using NetLibrary;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Web.Script.Serialization;
|
|
|
using System.Net.Security;
|
|
|
using System.Security.Authentication;
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
using System.Net;
|
|
|
using System.IO;
|
|
|
using NetLibrary.Data;
|
|
|
using System.Data.Common;
|
|
|
using System.Data;
|
|
|
using NetLibrary.OnlineTrade;
|
|
|
|
|
|
|
|
|
namespace TradeManageNew
|
|
|
{
|
|
|
public class WishNew
|
|
|
{
|
|
|
public string client_id { get; set; }
|
|
|
public string client_secret { get; set; }
|
|
|
public string code { get; set; }
|
|
|
public string grant_type { get; set; }
|
|
|
public string redirect_uri { get; set; }
|
|
|
public Int32 ShopId { get; set; }
|
|
|
public string Appkey { get; set; }
|
|
|
public string DeveKey { get; set; }
|
|
|
public string RefreshToken { get; set; }
|
|
|
public string AccessToken { get; set; }
|
|
|
public DateTime? AccessTokenUpdateTime { get; set; }
|
|
|
public DateTime? RefreshTokenSaveTime { get; set; }
|
|
|
JavaScriptSerializer JsonConvert = null;
|
|
|
public WishNew()
|
|
|
{
|
|
|
//验证服务器证书回调自动验证
|
|
|
ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
|
|
|
JsonConvert = new JavaScriptSerializer();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public List<OrderModel> GetOrders(string Token, out string ErrorMessage)
|
|
|
{
|
|
|
ErrorMessage = "";
|
|
|
string URL = "https://merchant.wish.com/api/v1/order/get-fulfill?start=0&limit=50&key=" + Token;
|
|
|
string ErrMessage = "";
|
|
|
string XmlContent = CustomIO.HttpRequest2(URL, "GET", "text/html", null, System.Net.HttpVersion.Version10, null, out ErrMessage);
|
|
|
if (string.IsNullOrEmpty(ErrMessage) == false)
|
|
|
{
|
|
|
ErrorMessage = ErrMessage;
|
|
|
return null;
|
|
|
}
|
|
|
WishOrderResult Model = JsonConvert.Deserialize<WishOrderResult>(XmlContent);
|
|
|
if (string.IsNullOrEmpty(Model.message) == false)
|
|
|
{
|
|
|
ErrorMessage = Model.message;
|
|
|
return null;
|
|
|
}
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
foreach (var item in Model.data)
|
|
|
{
|
|
|
OrderModel model = item.Order.ToOrderModel();
|
|
|
ListModel.Add(model);
|
|
|
}
|
|
|
if (Model.paging != null && string.IsNullOrEmpty(Model.paging.next) == false)
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
XmlContent = CustomIO.HttpRequest(Model.paging.next, "POST", out ErrMessage);
|
|
|
if (string.IsNullOrEmpty(ErrMessage) == false)
|
|
|
{
|
|
|
ErrorMessage = ErrMessage;
|
|
|
return null;
|
|
|
}
|
|
|
Model = JsonConvert.Deserialize<WishOrderResult>(XmlContent);
|
|
|
if (string.IsNullOrEmpty(Model.message) == false)
|
|
|
{
|
|
|
ErrorMessage = Model.message;
|
|
|
return null;
|
|
|
}
|
|
|
foreach (var item in Model.data)
|
|
|
{
|
|
|
OrderModel model = item.Order.ToOrderModel();
|
|
|
ListModel.Add(model);
|
|
|
}
|
|
|
if (Model.data == null || Model.paging == null || Model.data.Count < 50) break;
|
|
|
}
|
|
|
}
|
|
|
return ListModel;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<OrderModel> GetOrdersNew(out string ErrorMessage)
|
|
|
{
|
|
|
//if (RefreshToken == null || RefreshToken == "")
|
|
|
//{
|
|
|
// GetToken(out ErrorMessage);
|
|
|
|
|
|
//}
|
|
|
//else
|
|
|
if (AccessTokenUpdateTime == null || AccessTokenUpdateTime.Value < DateTime.Now.AddDays(-29))
|
|
|
{
|
|
|
GetReshTokenV3(out ErrorMessage);
|
|
|
}
|
|
|
ErrorMessage = "";
|
|
|
string URL = "https://merchant.wish.com/api/v2/order/get-fulfill?access_token=" + AccessToken + "&start=0&count=50";
|
|
|
string ErrMessage = "";
|
|
|
string XmlContent = CustomIO.HttpRequest2(URL, "GET", "text/html", null, System.Net.HttpVersion.Version10, null, out ErrMessage);
|
|
|
if (string.IsNullOrEmpty(ErrMessage) == false)
|
|
|
{
|
|
|
ErrorMessage = ErrMessage;
|
|
|
return null;
|
|
|
}
|
|
|
WishOrderResult Model = JsonConvert.Deserialize<WishOrderResult>(XmlContent);
|
|
|
if (string.IsNullOrEmpty(Model.message) == false)
|
|
|
{
|
|
|
ErrorMessage = Model.message;
|
|
|
return null;
|
|
|
}
|
|
|
List<OrderModel> ListModel = new List<OrderModel>();
|
|
|
foreach (var item in Model.data)
|
|
|
{
|
|
|
OrderModel model = item.Order.ToOrderModel();
|
|
|
ListModel.Add(model);
|
|
|
}
|
|
|
if (Model.paging != null && string.IsNullOrEmpty(Model.paging.next) == false)
|
|
|
{
|
|
|
while (true)
|
|
|
{
|
|
|
XmlContent = CustomIO.HttpRequest(Model.paging.next, "POST", out ErrMessage);
|
|
|
if (string.IsNullOrEmpty(ErrMessage) == false)
|
|
|
{
|
|
|
ErrorMessage = ErrMessage;
|
|
|
return null;
|
|
|
}
|
|
|
Model = JsonConvert.Deserialize<WishOrderResult>(XmlContent);
|
|
|
if (string.IsNullOrEmpty(Model.message) == false)
|
|
|
{
|
|
|
ErrorMessage = Model.message;
|
|
|
return null;
|
|
|
}
|
|
|
foreach (var item in Model.data)
|
|
|
{
|
|
|
OrderModel model = item.Order.ToOrderModel();
|
|
|
ListModel.Add(model);
|
|
|
}
|
|
|
if (Model.data == null || Model.paging == null || Model.data.Count < 50) break;
|
|
|
}
|
|
|
}
|
|
|
return ListModel;
|
|
|
}
|
|
|
|
|
|
public bool UpTrackTOWish(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//string key = "";
|
|
|
// var checkkey = cl.Where(o => o.group == group);
|
|
|
// if (checkkey.Count() == 0) return false;
|
|
|
|
|
|
// key = checkkey.First().key;
|
|
|
|
|
|
string result = GetBack(key, orderno, ysfs, trackno, ship_note);
|
|
|
if (result.Contains("success"))
|
|
|
return true;
|
|
|
else return false;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string GetBack(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
string URL = "";
|
|
|
if (ship_note == "")
|
|
|
{
|
|
|
URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
}
|
|
|
else URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key + "&ship_note=" + ship_note;
|
|
|
//string URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
|
request.Method = "POST";
|
|
|
request.ContentType = "text/html";
|
|
|
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
|
request.Headers.Add("Accept-Language: zh-CN");
|
|
|
request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
|
request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
string josn = myStreamReader.ReadToEnd();
|
|
|
|
|
|
myStreamReader.Close();
|
|
|
myResponseStream.Close();
|
|
|
response.Close();
|
|
|
|
|
|
return josn;
|
|
|
}
|
|
|
public bool ModifyTrackTOWish2(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// string key = "";
|
|
|
//var checkkey = cl.Where(o => o.group == group);
|
|
|
// if (checkkey.Count() == 0) return false;
|
|
|
|
|
|
// key = checkkey.First().key;
|
|
|
if (ysfs == "DeYou")
|
|
|
ysfs = "DHL";
|
|
|
if (ysfs == "China Post Air Mail")
|
|
|
ysfs = "ChinaAirPost";
|
|
|
if (ysfs == "EUB")
|
|
|
ysfs = "EPacket";
|
|
|
if (ysfs == "SF Express")
|
|
|
ysfs = "SFExpress";
|
|
|
string result = GetModifyBackNew(key, orderno, ysfs, trackno, ship_note);
|
|
|
if (result.Contains("success"))
|
|
|
return true;
|
|
|
else return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string ModifyTrackTOWish5(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// string key = "";
|
|
|
//var checkkey = cl.Where(o => o.group == group);
|
|
|
// if (checkkey.Count() == 0) return false;
|
|
|
|
|
|
// key = checkkey.First().key;
|
|
|
if (ysfs == "DeYou")
|
|
|
ysfs = "DHL";
|
|
|
if (ysfs == "China Post Air Mail")
|
|
|
ysfs = "ChinaAirPost";
|
|
|
if (ysfs == "EUB")
|
|
|
ysfs = "EPacket";
|
|
|
if (ysfs == "SF Express")
|
|
|
ysfs = "SFExpress";
|
|
|
if (ysfs.Contains("Wish"))
|
|
|
ysfs = "WishPost";
|
|
|
string result = GetModifyBackNew(key, orderno, ysfs, trackno, ship_note);
|
|
|
if (result.Contains("success"))
|
|
|
return "OK";
|
|
|
else return result;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return ex.Message;
|
|
|
}
|
|
|
}
|
|
|
public bool ModifyTrackTOWish(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// string key = "";
|
|
|
//var checkkey = cl.Where(o => o.group == group);
|
|
|
// if (checkkey.Count() == 0) return false;
|
|
|
|
|
|
// key = checkkey.First().key;
|
|
|
if (ysfs == "DeYou")
|
|
|
ysfs = "DHL";
|
|
|
if (ysfs == "China Post Air Mail")
|
|
|
ysfs = "ChinaAirPost";
|
|
|
if (ysfs == "EUB")
|
|
|
ysfs = "EPacket";
|
|
|
if (ysfs == "SF Express")
|
|
|
ysfs = "SFExpress";
|
|
|
string result = GetModifyBack(key, orderno, ysfs, trackno, ship_note);
|
|
|
if (result.Contains("success"))
|
|
|
return true;
|
|
|
else return false;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string GetModifyBack(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
string URL = "";
|
|
|
if (ship_note == "")
|
|
|
{
|
|
|
URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
}
|
|
|
else URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key + "&ship_note=" + ship_note;
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
|
request.Method = "POST";
|
|
|
request.ContentType = "text/html";
|
|
|
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
|
request.Headers.Add("Accept-Language: zh-CN");
|
|
|
request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
|
request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
string josn = myStreamReader.ReadToEnd();
|
|
|
|
|
|
myStreamReader.Close();
|
|
|
myResponseStream.Close();
|
|
|
response.Close();
|
|
|
|
|
|
return josn;
|
|
|
}
|
|
|
private string GetModifyBackNew(string access_token, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
string URL = "";
|
|
|
//if (ship_note == "")
|
|
|
//{
|
|
|
// URL = "https://china-merchant.wish.com/api/v2/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&origin_country_code=CN&access_token=" + access_token;
|
|
|
//}
|
|
|
//else URL = "https://china-merchant.wish.com/api/v2/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&origin_country_code=CN&key=" + access_token + "&ship_note=" + ship_note;
|
|
|
|
|
|
if (ship_note == "")
|
|
|
{
|
|
|
URL = "https://merchant.wish.com/api/v2/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&origin_country_code=CN&access_token=" + access_token;
|
|
|
}
|
|
|
else URL = "https://merchant.wish.com/api/v2/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&origin_country_code=CN&key=" + access_token + "&ship_note=" + ship_note;
|
|
|
string ErrMessage = "";
|
|
|
string XmlContent = CustomIO.HttpRequest2(URL, "Post", null, null, System.Net.HttpVersion.Version10, null, out ErrMessage);
|
|
|
if (ErrMessage != "") return ErrMessage;
|
|
|
|
|
|
return XmlContent;
|
|
|
}
|
|
|
|
|
|
|
|
|
public string GetMultipleCampaigns(string access_token)
|
|
|
{
|
|
|
|
|
|
string URL = "https://merchant.wish.com/api/v2/product-boost/campaign/multi-get?start_time=2019-03-01&access_token=" + access_token + "";
|
|
|
string ErrMessage = "";
|
|
|
string XmlContent = CustomIO.HttpRequest2(URL, "GET", "application/x-www-form-urlencoded", null, System.Net.HttpVersion.Version10, null, out ErrMessage);
|
|
|
if (string.IsNullOrEmpty(ErrMessage) == false)
|
|
|
{
|
|
|
//ErrorMessage = ErrMessage;
|
|
|
return null;
|
|
|
}
|
|
|
WishOrder_CampaignOrder Model = JsonConvert.Deserialize<WishOrder_CampaignOrder>(XmlContent);
|
|
|
|
|
|
return XmlContent;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private string GetModify(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
{
|
|
|
string URL = "";
|
|
|
if (ship_note == "")
|
|
|
{
|
|
|
URL = "https://merchant.wish.com/api/v1/order/modify-tracking?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
}
|
|
|
else URL = "https://merchant.wish.com/api/v1/order/modify-tracking?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key + "&ship_note=" + ship_note;
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
|
request.Method = "POST";
|
|
|
request.ContentType = "text/html";
|
|
|
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
|
request.Headers.Add("Accept-Language: zh-CN");
|
|
|
request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
|
request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
string josn = myStreamReader.ReadToEnd();
|
|
|
|
|
|
myStreamReader.Close();
|
|
|
myResponseStream.Close();
|
|
|
response.Close();
|
|
|
|
|
|
return josn;
|
|
|
}
|
|
|
|
|
|
public string GetOneOrder(string key, string orderno)
|
|
|
{
|
|
|
string URL = "https://merchant.wish.com/api/v1/order?" + "id=" + orderno + "&key=" + key;
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
|
request.Method = "POST";
|
|
|
request.ContentType = "text/html";
|
|
|
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
|
request.Headers.Add("Accept-Language: zh-CN");
|
|
|
request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
|
request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
string josn = myStreamReader.ReadToEnd();
|
|
|
|
|
|
myStreamReader.Close();
|
|
|
myResponseStream.Close();
|
|
|
response.Close();
|
|
|
|
|
|
return josn;
|
|
|
}
|
|
|
//private string GetBack(string key, string orderno, string ysfs, string trackno, string ship_note)
|
|
|
//{
|
|
|
// string URL = "";
|
|
|
// if (ship_note == "")
|
|
|
// {
|
|
|
// URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
// }
|
|
|
// else URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key + "&ship_note=" + ship_note;
|
|
|
// //string URL = "https://merchant.wish.com/api/v1/order/fulfill-one?tracking_provider=" + ysfs + "&tracking_number=" + trackno + "&id=" + orderno + "&key=" + key;
|
|
|
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
|
// request.Method = "POST";
|
|
|
// request.ContentType = "text/html";
|
|
|
// request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
|
// request.Headers.Add("Accept-Language: zh-CN");
|
|
|
// request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
|
// request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
|
|
|
|
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
// Stream myResponseStream = response.GetResponseStream();
|
|
|
// StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
|
// string josn = myStreamReader.ReadToEnd();
|
|
|
|
|
|
// myStreamReader.Close();
|
|
|
// myResponseStream.Close();
|
|
|
// response.Close();
|
|
|
|
|
|
// return josn;
|
|
|
//}
|
|
|
#region 当长时令牌超过25天,那么重新请求
|
|
|
public string GetToken(out string ErrorMessage)
|
|
|
{
|
|
|
|
|
|
Dictionary<string, string> paramDic = new Dictionary<string, string>();
|
|
|
//client_id:app注册时,分配给app的唯一标示,又称appKey
|
|
|
paramDic.Add("client_id", client_id);
|
|
|
paramDic.Add("client_secret", client_secret);
|
|
|
paramDic.Add("code", code);
|
|
|
paramDic.Add("grant_type", grant_type);
|
|
|
paramDic.Add("redirect_uri", redirect_uri);
|
|
|
|
|
|
string URL = "https://merchant.wish.com/api/v2/oauth/access_token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&grant_type=" + grant_type + "&redirect_uri=" + redirect_uri;
|
|
|
//URL += "&_aop_signature=" + signature;
|
|
|
string XmlContent = CustomIO.HttpRequest(URL, "POST", out ErrorMessage);
|
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return ErrorMessage;
|
|
|
//RequestNum++;
|
|
|
WishOrderResult2 Model = JsonConvert.Deserialize<WishOrderResult2>(XmlContent);
|
|
|
|
|
|
|
|
|
if (Model.code == 0)
|
|
|
{
|
|
|
AccessToken = Model.data.access_token;
|
|
|
RefreshToken = Model.data.refresh_token;
|
|
|
RefreshTokenSaveTime = DateTime.Now;
|
|
|
AccessTokenUpdateTime = DateTime.Now;
|
|
|
UpdateShopToken();
|
|
|
return Model.data.access_token;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
ErrorMessage = Model.message;
|
|
|
}
|
|
|
// RefreshToken = matchtemp1.Groups[1].Value;
|
|
|
// RefreshTokenSaveTime = DateTime.Now;
|
|
|
// AccessTokenUpdateTime = DateTime.Now;
|
|
|
return ErrorMessage;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 当长时令牌超过25天,那么重新请求
|
|
|
public string GetTokenV3(out string ErrorMessage)
|
|
|
{
|
|
|
|
|
|
Dictionary<string, string> paramDic = new Dictionary<string, string>();
|
|
|
//client_id:app注册时,分配给app的唯一标示,又称appKey
|
|
|
paramDic.Add("client_id", client_id);
|
|
|
paramDic.Add("client_secret", client_secret);
|
|
|
paramDic.Add("code", code);
|
|
|
paramDic.Add("grant_type", grant_type);
|
|
|
paramDic.Add("redirect_uri", redirect_uri);
|
|
|
|
|
|
string URL = "https://merchant.wish.com/api/v3/oauth/access_token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&grant_type=" + grant_type + "&redirect_uri=" + redirect_uri;
|
|
|
//URL += "&_aop_signature=" + signature;
|
|
|
string XmlContent = CustomIO.HttpRequest(URL, "GET", out ErrorMessage);
|
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return ErrorMessage;
|
|
|
//RequestNum++;
|
|
|
WishOrderResult3 Model = JsonConvert.Deserialize<WishOrderResult3>(XmlContent);
|
|
|
|
|
|
|
|
|
if (Model.code == 0)
|
|
|
{
|
|
|
AccessToken = Model.data.access_token;
|
|
|
RefreshToken = Model.data.refresh_token;
|
|
|
Appkey = Model.data.merchant_id;
|
|
|
RefreshTokenSaveTime = DateTime.Now;
|
|
|
AccessTokenUpdateTime = DateTime.Now;
|
|
|
UpdateShopToken();
|
|
|
return Model.data.access_token;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
ErrorMessage = Model.message;
|
|
|
}
|
|
|
// RefreshToken = matchtemp1.Groups[1].Value;
|
|
|
// RefreshTokenSaveTime = DateTime.Now;
|
|
|
// AccessTokenUpdateTime = DateTime.Now;
|
|
|
return ErrorMessage;
|
|
|
}
|
|
|
#endregion
|
|
|
#region 当长时令牌超过25天,那么重新请求
|
|
|
public void GetReshTokenV3(out string ErrorMessage)
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
string URL = "https://merchant.wish.com/api/v3/oauth/refresh_token?client_id=" + client_id + "&client_secret=" + client_secret + "&refresh_token=" + RefreshToken + "&grant_type=refresh_token";
|
|
|
//URL += "&_aop_signature=" + signature;
|
|
|
string XmlContent = CustomIO.HttpRequest(URL, "GET", out ErrorMessage);
|
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
|
WishOrderResult3 Model = JsonConvert.Deserialize<WishOrderResult3>(XmlContent);
|
|
|
|
|
|
if (Model.code == 0)
|
|
|
{
|
|
|
AccessToken = Model.data.access_token;
|
|
|
RefreshToken = Model.data.refresh_token;
|
|
|
Appkey = Model.data.merchant_id;
|
|
|
RefreshTokenSaveTime = DateTime.Now;
|
|
|
AccessTokenUpdateTime = DateTime.Now;
|
|
|
UpdateShopToken();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
ErrorMessage = Model.message;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
#region 当长时令牌超过25天,那么重新请求
|
|
|
public void GetReshToken(out string ErrorMessage)
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
string URL = "https://merchant.wish.com/api/v2/oauth/refresh_token?client_id=" + client_id + "&client_secret=" + client_secret + "&refresh_token=" + RefreshToken + "&grant_type=refresh_token";
|
|
|
//URL += "&_aop_signature=" + signature;
|
|
|
string XmlContent = CustomIO.HttpRequest(URL, "POST", out ErrorMessage);
|
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
|
WishOrderResult2 Model = JsonConvert.Deserialize<WishOrderResult2>(XmlContent);
|
|
|
|
|
|
if (Model.code == 0)
|
|
|
{
|
|
|
AccessToken = Model.data.access_token;
|
|
|
RefreshToken = Model.data.refresh_token;
|
|
|
RefreshTokenSaveTime = DateTime.Now;
|
|
|
AccessTokenUpdateTime = DateTime.Now;
|
|
|
UpdateShopToken();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
ErrorMessage = Model.message;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
#region 修改tocken
|
|
|
public void UpdateShopToken()
|
|
|
{
|
|
|
string tsql = @"
|
|
|
Update [JC_Shop] set Appkey=@Appkey,[RefreshToken]=@RefreshToken,[AccessToken]=@AccessToken,[RefreshTokenSaveTime]=@RefreshTokenSaveTime,[AccessTokenUpdateTime]=@AccessTokenUpdateTime,ReUrl=@ReUrl where ShopId=@ShopId
|
|
|
";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
DbCommand cmd = db.GetSqlStringCommand(tsql);
|
|
|
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
|
|
|
db.AddInParameter(cmd, "@RefreshToken", DbType.String, RefreshToken);
|
|
|
db.AddInParameter(cmd, "@Appkey", DbType.String, Appkey);
|
|
|
db.AddInParameter(cmd, "@AccessToken", DbType.String, AccessToken);
|
|
|
db.AddInParameter(cmd, "@RefreshTokenSaveTime", DbType.DateTime, RefreshTokenSaveTime);
|
|
|
db.AddInParameter(cmd, "@AccessTokenUpdateTime", DbType.DateTime, AccessTokenUpdateTime);
|
|
|
db.AddInParameter(cmd, "@ReUrl", DbType.String, redirect_uri);
|
|
|
db.ExecuteNonQuery(cmd);
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
public class WishOrderResult3
|
|
|
{
|
|
|
public string message { get; set; }
|
|
|
public int code { get; set; }
|
|
|
public WishOrder3 data { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder3
|
|
|
{
|
|
|
public string access_token { get; set; }
|
|
|
public string refresh_token { get; set; }
|
|
|
// public int expires_in { get; set; }
|
|
|
public string expiry_time { get; set; }
|
|
|
public string merchant_id { get; set; }
|
|
|
}
|
|
|
public class WishOrderResult2
|
|
|
{
|
|
|
public string message { get; set; }
|
|
|
public int code { get; set; }
|
|
|
public WishOrder2 data { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder2
|
|
|
{
|
|
|
public string access_token { get; set; }
|
|
|
public string refresh_token { get; set; }
|
|
|
public int expires_in { get; set; }
|
|
|
public int expiry_time { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrderResult
|
|
|
{
|
|
|
public string message { get; set; }
|
|
|
public int code { get; set; }
|
|
|
public List<WishOrder> data { get; set; }
|
|
|
public WishPaging paging { get; set; }
|
|
|
}
|
|
|
public class WishOrder
|
|
|
{
|
|
|
public WishOrder_Order Order { get; set; }
|
|
|
}
|
|
|
public class WishOrder_Order
|
|
|
{
|
|
|
public string sku { get; set; }
|
|
|
public string buyer_id { get; set; }
|
|
|
public string last_updated { get; set; }
|
|
|
public string product_id { get; set; }
|
|
|
public string order_time { get; set; }
|
|
|
public string quantity { get; set; }
|
|
|
public string color { get; set; }
|
|
|
public string price { get; set; }
|
|
|
public string shipping_cost { get; set; }
|
|
|
public string shipping { get; set; }
|
|
|
public WishOrder_ShippingDetail ShippingDetail { get; set; }
|
|
|
public string order_id { get; set; }
|
|
|
public string state { get; set; }
|
|
|
public string cost { get; set; }
|
|
|
public string currency_code { get; set; }
|
|
|
public string variant_id { get; set; }
|
|
|
public string order_total { get; set; }
|
|
|
public string days_to_fulfill { get; set; }
|
|
|
public string product_image_url { get; set; }
|
|
|
public string product_name { get; set; }
|
|
|
public string transaction_id { get; set; }
|
|
|
public string size { get; set; }
|
|
|
|
|
|
public DateTime? GetDateTime(string dt)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(dt) == true) return null;
|
|
|
dt = dt.Replace("T", " ");
|
|
|
dt = dt.Remove(dt.Length - 1);
|
|
|
return Convert.ToDateTime(dt);
|
|
|
}
|
|
|
|
|
|
#region 转换成统一的订单对象
|
|
|
public OrderModel ToOrderModel()
|
|
|
{
|
|
|
OrderModel model = new OrderModel();
|
|
|
model.OrderCode = this.order_id;
|
|
|
model.TotalPrice = Convert.ToDecimal(this.order_total);
|
|
|
model.MoneyCode = this.currency_code;
|
|
|
model.OrderDate = this.GetDateTime(this.order_time);
|
|
|
model.BuyerID = this.buyer_id;
|
|
|
model.BuyerName = this.ShippingDetail.name;
|
|
|
model.BuyerCountry = this.ShippingDetail.country;
|
|
|
model.BuyerAddr = this.ShippingDetail.street_address1;
|
|
|
if (this.ShippingDetail.street_address2 != null && this.ShippingDetail.street_address2 != "")
|
|
|
model.BuyerAddr += " " + this.ShippingDetail.street_address2;
|
|
|
model.BuyerPhone = this.ShippingDetail.phone_number;
|
|
|
model.BuyerMobile = "";
|
|
|
model.BuyerMail = "";
|
|
|
model.BuyerFax = "";
|
|
|
model.BuyerZip = this.ShippingDetail.zipcode;
|
|
|
model.BuyerProvince = this.ShippingDetail.state;
|
|
|
model.BuyerCity = this.ShippingDetail.city;
|
|
|
model.BuyerArea = "";
|
|
|
model.OrderRemark = ""; //memo
|
|
|
model.LeaveWord = "";
|
|
|
model.PayDate = this.GetDateTime(this.last_updated);
|
|
|
if (this.days_to_fulfill != null)
|
|
|
model.OutOrderDate = DateTime.Today.AddDays(Convert.ToInt32(this.days_to_fulfill));
|
|
|
else
|
|
|
model.OutOrderDate = null;
|
|
|
model.ListModel = new List<OrderDetailModel>();
|
|
|
OrderDetailModel model2 = new OrderDetailModel();
|
|
|
model2.productImgUrl = this.product_image_url;
|
|
|
model2.OrderItemId = this.product_id;
|
|
|
model2.GoodsNum = Convert.ToInt32(this.quantity);
|
|
|
model2.GoodsPrice = Convert.ToDecimal(this.price);
|
|
|
model2.MoneyCode = null;
|
|
|
model2.GoodsName = this.product_name;
|
|
|
model2.GoodsSKU = this.sku;
|
|
|
model2.PostInfo = ""; //快递信息
|
|
|
model.ListModel.Add(model2);
|
|
|
return model;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
public class WishOrder_ShippingDetail
|
|
|
{
|
|
|
public string phone_number { get; set; }
|
|
|
public string city { get; set; }
|
|
|
public string state { get; set; }
|
|
|
public string name { get; set; }
|
|
|
public string country { get; set; }
|
|
|
public string zipcode { get; set; }
|
|
|
public string street_address1 { get; set; }
|
|
|
public string street_address2 { get; set; }
|
|
|
}
|
|
|
public class WishPaging
|
|
|
{
|
|
|
public string next { get; set; }
|
|
|
}
|
|
|
public class WishOrder_CampaignOrder
|
|
|
{
|
|
|
public string message { get; set; }
|
|
|
public Int32? code { get; set; }
|
|
|
public List<WishOrder_Campaigndata> data { get; set; }
|
|
|
public WishOrder_Campaignpaging paging { get; set; }
|
|
|
}
|
|
|
|
|
|
public class WishOrder_Campaignpaging
|
|
|
{
|
|
|
public string next { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder_Campaigndata
|
|
|
{
|
|
|
public WishOrder_Campaign Campaign { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder_Campaign
|
|
|
{
|
|
|
public string campaign_max_budget { get; set; }
|
|
|
|
|
|
public string auto_renew { get; set; }
|
|
|
public string start_time { get; set; }
|
|
|
public string campaign_id { get; set; }
|
|
|
public string is_simple_boost { get; set; }
|
|
|
public string last_updated_time { get; set; }
|
|
|
public string sales { get; set; }
|
|
|
public string campaign_name { get; set; }
|
|
|
public string merchant_id { get; set; }
|
|
|
public string campaign_state { get; set; }
|
|
|
public string can_edit { get; set; }
|
|
|
public string discount_ratio { get; set; }
|
|
|
public string total_impression_fees_charged { get; set; }
|
|
|
public string total_campaign_spend { get; set; }
|
|
|
public string paid_impressions { get; set; }
|
|
|
public List<WishOrder_products> products { get; set; }
|
|
|
public string end_time { get; set; }
|
|
|
public string total_enrollment_fees_charged { get; set; }
|
|
|
public string gmv { get; set; }
|
|
|
public List<WishOrder_breakdown> impression_fees_breakdown { get; set; }
|
|
|
|
|
|
|
|
|
}
|
|
|
public class WishOrder_products
|
|
|
{
|
|
|
public WishOrder_Product Product { get; set; }
|
|
|
|
|
|
|
|
|
}
|
|
|
public class WishOrder_Product
|
|
|
{
|
|
|
public string actual_charge_rate { get; set; }
|
|
|
// public string[] keywords { get; set; }
|
|
|
public string merchant_bid_rate { get; set; }
|
|
|
public string product_id { get; set; }
|
|
|
public string enrollment_fee { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder_breakdown
|
|
|
{
|
|
|
|
|
|
public WishOrder_ImpressionFee ImpressionFee { get; set; }
|
|
|
|
|
|
}
|
|
|
public class WishOrder_ImpressionFee
|
|
|
{
|
|
|
public string amount { get; set; }
|
|
|
public string start_time { get; set; }
|
|
|
public string fee_state { get; set; }
|
|
|
public string end_time { get; set; }
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|