You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetLibrary;
using System.Net;
using System.IO;
using NetLibrary.Log;
namespace ApiNew
{
public class WishYouNew
{
public string 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 "OK";
else return result;
}
catch (Exception ex)
{
return ex.Message;
}
}
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=US&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=US&key=" + access_token + "&ship_note=" + ship_note;
string ErrMessage = "";
string XmlContent =HttpRequest2(URL, "Post", null, null, System.Net.HttpVersion.Version10, null, out ErrMessage);
if (ErrMessage != "") return ErrMessage;
return XmlContent;
}
#region Http请求2
public string HttpRequest2(string url, string Method, string ContentType, List<string> ListHeader, Version ver, byte[] bytes, out string ErrorMessage)
{
if (string.IsNullOrEmpty(ContentType) == true) ContentType = "application/x-www-form-urlencoded";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
try
{
ErrorMessage = "";
myRequest.Method = Method; //GET,POST
myRequest.ContentType = ContentType;
myRequest.KeepAlive = true;
//myRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
// myRequest.Headers.Add("Accept-Language: zh-CN");
// myRequest.Headers["Pragma"] = "no-cache"; //禁用缓存
// myRequest.Headers["Cache-Control"] = "no-cache"; //禁用缓存
myRequest.Timeout = 3 * 60 * 1000;
myRequest.ProtocolVersion = ver;
if (ListHeader != null)
{
foreach (var item in ListHeader)
{
myRequest.Headers.Add(item);
}
}
if (bytes != null && bytes.Length > 0)
{
//myRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
Stream stream = myRequest.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
}
//获得接口返回值
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream myResponseStream = myResponse.GetResponseStream();
StreamReader reader = new StreamReader(myResponseStream, Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
myResponseStream.Close();
myRequest.Abort();
myResponse.Close();
return content;
}
catch (WebException ex)
{
ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message);
Stream myResponseStream = ex.Response.GetResponseStream();
StreamReader reader = new StreamReader(myResponseStream, Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
ErrorMessage = ex.Message;
if (string.IsNullOrEmpty(content) == false)
{
ErrorMessage = ex.Message + content;
}
}
return "";
}
#endregion
}
}