| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using BizCom;
- using Newtonsoft.Json;
- using NPOI.Util;
- using SiteCore.Handler;
- using SiteCore.taoObj;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- namespace SiteCore
- {
- public class banniuApiHelper : BaseHandler, IHttpHandler
- {
- static string API_VERSION = "1.0";
- static string LOGISTICS_ACCESS_TOKEN = "";
- static string LOGISTICS_APP_KEY = "";
- static string LOGISTICS_SECRET_KEY = "";
- static string LOGISTICS_APP_ID = "";//物流同步
- static string REPRINT_LOGISTICS_PROJECT_ID = "";//重印单物流同步
- public void ProcessRequest(HttpContext context)
- {
- if (UrlParmsCheck("t"))
- {
- String tname = GetString("t");
- MethodInfo method;
- Type type = this.GetType();
- method = type.GetMethod(tname);
- con = context;
- if (method == null)
- {
- conError("找不到对应方法,服务器返回错误");
- return;
- }
- successFlag = false;
- context.Response.ContentType = "application/json";
- context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
- try
- {
- method.Invoke(this, null);
- }
- catch (Exception ex)
- {
- conError("处理接口错误,服务器返回错误");
- }
- finally
- {
- }
- }
- }
- //get请求时需要包含所有请求参数 , post请求时只用包含 系统参数
- private static string getSign(Dictionary<string, string> map, string secret)
- {
- List<string> list = map.Keys.ToList();
- list.Sort();
- StringBuilder sb = new StringBuilder(secret);
- foreach (string item in list)
- {
- sb.Append(item).Append(map[item]);
- }
- sb.Append(secret);
- return CalculateMD5(sb.ToString());
- }
- private static string CalculateMD5(string source)
- {
- using (MD5 md5 = MD5.Create())
- {
- byte[] inputBytes = Encoding.UTF8.GetBytes(source);
- byte[] hashBytes = md5.ComputeHash(inputBytes);
- StringBuilder sb = new StringBuilder();
- foreach (byte b in hashBytes)
- {
- sb.Append(b.ToString("x2"));
- }
- return sb.ToString().ToUpperInvariant();
- }
- }
- private static NameValueCollection changeObject(Dictionary<string, string> map)
- {
- NameValueCollection PostVars = new NameValueCollection();
- foreach (string key in map.Keys)
- {
- PostVars.Add(key, map[key]);
- }
- return PostVars;
- }
- private static Dictionary<string, string> getSystemParams(string type)
- {
- Dictionary<string, string> map = new Dictionary<string, string>();
- if ("sendLogistics".Equals(type))
- {
- map.Add("method", "task.create");
- map.Add("access_token", LOGISTICS_ACCESS_TOKEN);
- map.Add("app_key", LOGISTICS_APP_KEY);
- map.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss"));
- map.Add("v", API_VERSION);
- }
- return map;
- }
- string base_url = "https://open.bytenew.com/gateway/api/miniAPI";
- public static BNApiResponseVo sendLogisticsInfo(CeErpTradeCell ceErpTradeCell)
- {
- Dictionary<string, string> map = getSystemParams("sendLogistics");
- string sign = getSign(map, LOGISTICS_SECRET_KEY);
- NameValueCollection PostVars = changeObject(map);
- WebClient wc = new WebClient();
- wc.Encoding = Encoding.GetEncoding("utf-8");
- string result = "";
- BNApiResponseVo response = null;
- try
- {
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "API_GetPrintData_CreateOrder:" + ex.Message);
- }
- return null;
- }
- }
- }
|