dataHelper.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. using BizCom;
  2. using Castle.ActiveRecord.Framework.Internal;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.POIFS.Properties;
  7. using NPOI.SS.Formula.Functions;
  8. using NPOI.SS.UserModel;
  9. using SiteCore.Handler;
  10. using SiteCore.Redis;
  11. using SiteCore.taobao;
  12. using SiteCore.taoObj;
  13. using SQLData;
  14. using System;
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using System.Collections.Specialized;
  18. using System.Data;
  19. using System.Diagnostics;
  20. using System.Linq;
  21. using System.Net;
  22. using System.Net.Http;
  23. using System.Net.Http.Headers;
  24. using System.Reflection;
  25. using System.Runtime.Remoting.Messaging;
  26. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  27. using System.Security.Cryptography;
  28. using System.Security.Policy;
  29. using System.Security.Principal;
  30. using System.Text;
  31. using System.Threading.Tasks;
  32. using System.Web;
  33. using System.Web.Routing;
  34. using System.Web.UI.WebControls;
  35. using Utils.Serialization;
  36. using static SiteCore.taoObj.dataShopResponseVo;
  37. using static SiteCore.taoObj.dataSpuInfoResponseVo;
  38. using static SiteCore.taoObj.work_core_vo;
  39. namespace SiteCore.Handler
  40. {
  41. public class dataHelper : BaseHandler, IHttpHandler
  42. {
  43. public void ProcessRequest(HttpContext context)
  44. {
  45. if (UrlParmsCheck("t"))
  46. {
  47. String tname = GetString("t");
  48. MethodInfo method;
  49. Type type = this.GetType();
  50. method = type.GetMethod(tname);
  51. con = context;
  52. if (method == null)
  53. {
  54. conError("找不到对应方法,服务器返回错误");
  55. return;
  56. }
  57. successFlag = false;
  58. context.Response.ContentType = "application/json";
  59. context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
  60. try
  61. {
  62. method.Invoke(this, null);
  63. }
  64. catch (Exception ex)
  65. {
  66. conError("处理接口错误,服务器返回错误");
  67. }
  68. finally
  69. {
  70. }
  71. }
  72. }
  73. public static string GetMD5Hash(string input)
  74. {
  75. // 创建一个MD5对象
  76. using (MD5 md5 = MD5.Create())
  77. {
  78. // 将输入字符串转换为字节数组
  79. byte[] inputBytes = Encoding.UTF8.GetBytes(input);
  80. // 计算输入字节数组的哈希值
  81. byte[] hashBytes = md5.ComputeHash(inputBytes);
  82. // 将字节数组转换为字符串
  83. StringBuilder hashString = new StringBuilder();
  84. foreach (byte b in hashBytes)
  85. {
  86. hashString.AppendFormat("{0:x2}", b);
  87. }
  88. return hashString.ToString();
  89. }
  90. }
  91. Dictionary<string, string> keysMap = new Dictionary<string, string>()
  92. {
  93. {"UzJwXAhiD9","GFyIeZLRIATXMJYnsc5nZPAwK9" },
  94. };
  95. public void productInfo()
  96. {
  97. bool result = checkParams();
  98. if (!result)
  99. {
  100. return;
  101. }
  102. string productName = GetPostString("productName");
  103. string id = GetPostString("id");
  104. if (string.IsNullOrEmpty(productName))
  105. {
  106. returnErrorMsg("参数没有产品名称");
  107. return;
  108. }
  109. if (string.IsNullOrEmpty(id))
  110. {
  111. returnErrorMsg("参数没有产品id");
  112. return;
  113. }
  114. CeErpProduct ceErpProduct = CeErpProduct.GetByName(id);
  115. bool isCreate = false;
  116. if (ceErpProduct == null)
  117. {
  118. ceErpProduct = new CeErpProduct();
  119. isCreate = true;
  120. }
  121. ceErpProduct.uuid = id;
  122. ceErpProduct.PType = productName;
  123. ceErpProduct.UpdateTime = DateTime.Now;
  124. ceErpProduct.UpdateUserName = "朱义义";
  125. if (!isCreate)
  126. {
  127. ceErpProduct.Update();
  128. }
  129. else
  130. {
  131. ceErpProduct.CreateTime = ceErpProduct.UpdateTime;
  132. ceErpProduct.CreateUserName = ceErpProduct.UpdateUserName;
  133. ceErpProduct.Create();
  134. }
  135. returnSuccessMsg("创建成功!");
  136. }
  137. public bool checkParams()
  138. {
  139. string appKey = GetPostString("appKey");
  140. string appSecret = "";
  141. if (!keysMap.ContainsKey(appKey))
  142. {
  143. returnErrorMsg("appKey不存在");
  144. return false;
  145. }
  146. keysMap.TryGetValue(appKey, out appSecret);
  147. if (appSecret == "")
  148. {
  149. returnErrorMsg("appSecret不存在");
  150. return false;
  151. }
  152. double timestamp = GetPostDouble("timestamp");//秒级时间戳
  153. if (timestamp == 0)
  154. {
  155. returnErrorMsg("时间戳不存在");
  156. return false;
  157. }
  158. DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
  159. dtDateTime = dtDateTime.AddSeconds(timestamp).ToLocalTime();
  160. if (dtDateTime != null && dtDateTime.CompareTo(DateTime.Now.AddMinutes(-5)) < 0)
  161. {
  162. returnErrorMsg("请求失效");
  163. return false;
  164. }
  165. string sign = GetPostString("sign");
  166. if (string.IsNullOrEmpty(sign))
  167. {
  168. returnErrorMsg("签名不存在");
  169. return false;
  170. }
  171. string param = appKey + timestamp + appSecret;
  172. string localSign = GetMD5Hash(param);
  173. if (!localSign.Equals(sign))
  174. {
  175. returnErrorMsg("签名错误");
  176. return false;
  177. }
  178. return true;
  179. }
  180. //http://47.114.150.226:88/Handler/dataHelper.ashx?t=get_order_info post请求参数(参数放body中):string tid(淘宝订单号)
  181. public void get_order_info()
  182. {
  183. bool result = checkParams();
  184. if (!result)
  185. {
  186. return;
  187. }
  188. string code = GetPostString("code");
  189. if (string.IsNullOrEmpty(code))
  190. {
  191. returnErrorMsg("参数错误");
  192. return;
  193. }
  194. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(code);
  195. if (ceErpTradeCell == null)
  196. {
  197. returnErrorMsg("查无订单");
  198. return;
  199. }
  200. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  201. Dictionary<string, object> data = new Dictionary<string, object>();
  202. data.Add("ctid", ceErpTradeCell.ctid);
  203. data.Add("isSF", ceErpTradeCell.IsSF);
  204. if (ceErpTrade != null)
  205. {
  206. data.Add("province", ceErpTrade.receiver_state);
  207. }
  208. ReturnSuccess(JsonConvert.SerializeObject(data));
  209. return;
  210. }
  211. //http://47.114.150.226:88/Handler/dataHelper.ashx?t=get_cell_info post请求参数(参数放body中):string tid(淘宝订单号)
  212. public void get_shop_code()
  213. {
  214. bool result = checkParams();
  215. if (!result)
  216. {
  217. return;
  218. }
  219. string name = GetPostString("name");
  220. if (string.IsNullOrEmpty(name))
  221. {
  222. returnErrorMsg("参数错误");
  223. return;
  224. }
  225. string code = "";
  226. string key = "shopName_code_" + name;
  227. if (RedisHelper.HasKey(key))
  228. {
  229. code = RedisHelper.StringGet(key).ToString();
  230. }
  231. if (code == "")
  232. {
  233. CeErpShop shop = CeErpShop.GetShopIdByName(name);
  234. if (shop == null)
  235. {
  236. returnErrorMsg("无店铺");
  237. return;
  238. }
  239. code = shop.SName;
  240. RedisHelper.StringSet(key, code);
  241. }
  242. Dictionary<string, object> data = new Dictionary<string, object>();
  243. data.Add("code", code);
  244. ReturnSuccess(JsonConvert.SerializeObject(data));
  245. return;
  246. }
  247. public void getOrderInfo()
  248. {
  249. string ctid = GetPostString("ctid");
  250. if (string.IsNullOrEmpty(ctid))
  251. {
  252. returnErrorMsg("参数错误");
  253. return;
  254. }
  255. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  256. if (ceErpTradeCell == null)
  257. {
  258. returnErrorMsg("查无订单");
  259. return;
  260. }
  261. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  262. CeErpProduct ceErpProduct = CeErpProduct.Get(ceErpTradeCell.ProductId);
  263. Dictionary<string, object> data = new Dictionary<string, object>();
  264. data.Add("orderNumber", ctid);
  265. data.Add("customerName", ceErpTrade.buyer_nick);
  266. DateTime dateTime = (DateTime)ceErpTradeCell.pay_time;
  267. data.Add("orderTime", dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  268. data.Add("commodityName", ceErpProduct.PType);
  269. data.Add("storeName", ceErpTrade.seller_nick);
  270. data.Add("orderRemark", ceErpTradeCell.seller_memo);
  271. string sql = string.Format("SELECT tid FROM [dbo].[view_ErpTradeCell] WITH(NOLOCK) WHERE (buyer_id = '{0}') and seller_nick = '{1}' and OrderState < 5 and IsSample = 0 ", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  272. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  273. int orderCount = 1;
  274. if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0)
  275. {
  276. orderCount = dataTable.Rows.Count;
  277. }
  278. data.Add("orderCount", orderCount);
  279. ReturnSuccess(JsonConvert.SerializeObject(data));
  280. return;
  281. }
  282. //http://47.114.150.226:88/Handler/dataHelper.ashx?t=get_cell_info post请求参数(参数放body中):string tid(淘宝订单号)
  283. public void get_cell_info()
  284. {
  285. string tid = GetPostString("tid");
  286. string name = GetPostString("nickName");
  287. string where = "";
  288. List<string> rows = new List<string>();
  289. if (!string.IsNullOrEmpty(tid))
  290. {
  291. rows.Add(string.Format(" tid = '{0}' ", tid));
  292. }
  293. if (!string.IsNullOrEmpty(name))
  294. {
  295. rows.Add(string.Format(" buyer_nick = '{0}' ", name));
  296. }
  297. where = string.Join("and", rows);
  298. if (where == "")
  299. {
  300. returnErrorMsg("缺少必要参数");
  301. return;
  302. }
  303. string sql = string.Format("SELECT tid,ctid,payment,ProductName,OrderState,Material,Craft,ProductSize,ShopId,ProductCount,posCode,seller_nick,buyer_nick,buyer_id,FinishDesignTime FROM [dbo].[view_ErpTradeCell] WHERE {0}", where);
  304. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  305. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  306. if (dataTable != null && dataTable.Rows.Count > 0)
  307. {
  308. string shopCode = "";
  309. Dictionary<string, object> data = new Dictionary<string, object>();
  310. foreach (DataRow row in dataTable.Rows)
  311. {
  312. int OrderState = Convert.ToInt32(row["OrderState"]);
  313. string state = "";
  314. if (OrderState < 7)
  315. {
  316. state = "待发货";
  317. }
  318. else if (OrderState == 7)
  319. {
  320. state = "已发货";
  321. }
  322. else if (OrderState == 8)
  323. {
  324. state = "交易完成";
  325. }
  326. else if (OrderState == 9)
  327. {
  328. state = "交易关闭";
  329. }
  330. data = new Dictionary<string, object>();
  331. data.Add("tid", row["tid"]);
  332. data.Add("OrderState", state);
  333. data.Add("state", OrderState);
  334. data.Add("shopCode", row["posCode"]);
  335. data.Add("buyerNick", row["buyer_nick"]);
  336. data.Add("buyerId", row["buyer_id"]);
  337. data.Add("shopName", row["seller_nick"]);
  338. data.Add("ctid", row["ctid"]);
  339. data.Add("payment", row["payment"]);
  340. data.Add("Material", row["Material"]);
  341. data.Add("Craft", row["Craft"]);
  342. data.Add("ProductSize", row["ProductSize"]);
  343. data.Add("ProductCount", row["ProductCount"]);
  344. data.Add("ProductName", row["ProductName"]);
  345. data.Add("FinishDesignTime", row["FinishDesignTime"]);
  346. if (string.IsNullOrEmpty(row["posCode"].ToString()) && !string.IsNullOrEmpty(shopCode))
  347. {
  348. data["shopCode"] = shopCode;
  349. }
  350. if (!string.IsNullOrEmpty(row["ShopId"].ToString()) && string.IsNullOrEmpty(shopCode) && string.IsNullOrEmpty(row["posCode"].ToString()))
  351. {
  352. string shopsql = string.Format("SELECT top 1 tid FROM [dbo].[CE_ErpTradeCell] WHERE ShopId = {0} AND OrderState = 8 and IsOffLineOrder =0", row["ShopId"]);
  353. DataTable shopData = DbHelper.DbConn.ExecuteDataset(shopsql).Tables[0];
  354. if (shopData != null && shopData.Rows.Count > 0)
  355. {
  356. CeErpTrade ceErpTrade = CeErpTrade.Get(shopData.Rows[0]["tid"].ToString());
  357. if (ceErpTrade != null)
  358. {
  359. data["shopCode"] = ceErpTrade.posCode;
  360. }
  361. }
  362. }
  363. shopCode = data["shopCode"].ToString();
  364. list.Add(data);
  365. }
  366. }
  367. ReturnSuccess(JsonConvert.SerializeObject(list));
  368. return;
  369. }
  370. //http://47.114.150.226:88/Handler/dataHelper.ashx?t=set_sys_price post请求参数(参数放body中):string tid(淘宝订单号)
  371. public void set_sys_price()
  372. {
  373. string data = GetPostString("data");
  374. if (!string.IsNullOrEmpty(data))
  375. {
  376. List<SysPriceResponseVo> list = JsonConvert.DeserializeObject<List<SysPriceResponseVo>>(data);
  377. List<Dictionary<string, string>> message = new List<Dictionary<string, string>>();
  378. foreach (SysPriceResponseVo item in list)
  379. {
  380. Dictionary<string, string> map = new Dictionary<string, string>();
  381. try
  382. {
  383. string ordersn = item.ordersn;
  384. double price = item.price;
  385. string sysPriceContent = item.sysContent;
  386. map.Add("ordersn", item.ordersn);
  387. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(ordersn);
  388. if (ceErpTradeCell == null)
  389. {
  390. ceErpTradeCell = CeErpTradeCell.GetByCtid(ordersn);
  391. }
  392. if (ceErpTradeCell == null)
  393. {
  394. map.Add("message", "查无订单");
  395. message.Add(map);
  396. continue;
  397. }
  398. CeErpTradeCellExtend ce = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  399. if (ce == null)
  400. {
  401. ce = new CeErpTradeCellExtend();
  402. ce.ctid = ceErpTradeCell.ctid;
  403. }
  404. ce.sysPrice = price;
  405. ce.sysPriceContent = sysPriceContent;
  406. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid ='{0}' and IsSample = 2", ceErpTradeCell.tid);
  407. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  408. if (dt_price != null && dt_price.Rows.Count > 0)
  409. {
  410. double diffPirce = 0;
  411. foreach (DataRow dr in dt_price.Rows)
  412. {
  413. if (Convert.IsDBNull(dr["payment"]))
  414. {
  415. diffPirce += Convert.ToDouble(dr["payment"]);
  416. }
  417. }
  418. ce.differentAmount = diffPirce;
  419. }
  420. ce.sysDiffPrice = ce.differentAmount + ceErpTradeCell.payment - price;
  421. if (price != 0)
  422. {
  423. ce.sysPriceRate = Math.Round((ce.differentAmount + ceErpTradeCell.payment) / price * 100, 2);
  424. }
  425. if (ce.ID != 0)
  426. {
  427. ce.Update();
  428. }
  429. else
  430. {
  431. ce.Create();
  432. }
  433. }
  434. catch (Exception ex)
  435. {
  436. map.Add("message", "系统错误");
  437. message.Add(map);
  438. XLog.SaveLog(0, "set_sys_price:" + JsonConvert.SerializeObject(map) + ":" + ex.Message);
  439. continue;
  440. }
  441. }
  442. if (message.Count > 0)
  443. {
  444. ReturnSuccess(JsonConvert.SerializeObject(message));
  445. }
  446. else
  447. {
  448. returnSuccessMsg("修改成功!");
  449. }
  450. return;
  451. }
  452. returnErrorMsg("缺少必要参数");
  453. }
  454. public static void get_sys_price(CeErpTradeCell ceErpTradeCell)
  455. {
  456. CeErpProduct product = CeErpProduct.GetById(ceErpTradeCell.ProductId);
  457. string param = "[{ \"product_type\": \"" + product.PType + "\", \"remark\": \"" + ceErpTradeCell.seller_memo + "\" }]";
  458. string result = sysHttpClient(param);
  459. }
  460. public static string sysHttpClient(string param)
  461. {
  462. var client = new HttpClient();
  463. var request = new HttpRequestMessage
  464. {
  465. Method = HttpMethod.Post,
  466. RequestUri = new Uri("http://47.122.57.102:11004/quotations/batch"),
  467. Content = new StringContent(param)
  468. {
  469. Headers =
  470. {
  471. ContentType = new MediaTypeHeaderValue("application/json")
  472. }
  473. }
  474. };
  475. var task = Task.Run(() =>
  476. {
  477. try
  478. {
  479. var response = client.SendAsync(request).Result;
  480. response.EnsureSuccessStatusCode();
  481. return response.Content.ReadAsStringAsync().Result;
  482. }
  483. catch (Exception e)
  484. {
  485. return "";
  486. }
  487. });
  488. return task.Result;
  489. }
  490. public void getOrderInvoiceInfo()
  491. {
  492. string tids = GetPostString("tids");
  493. List<string> list = tids.Split(',').ToList();
  494. return;
  495. }
  496. //http://47.114.150.226:88/Handler/dataHelper.ashx?t=update_spu_info post请求参数(参数放body中):string spuId(淘宝订单号)
  497. public void update_spu_info()
  498. {
  499. string spuId = GetPostString("spuId");
  500. string category = GetPostString("category");
  501. string serialNumber = GetPostString("serialNumber");
  502. string operate = GetPostString("operate");
  503. string designer = GetPostString("designer");
  504. string atta = GetPostString("atta");
  505. string upTime = GetPostString("upTime");
  506. int shopId = GetPostInt("shopId");
  507. if (!string.IsNullOrEmpty(spuId))
  508. {
  509. CeErpTradeSpu spu = CeErpTradeSpu.GetBySpuId(spuId);
  510. if (spu == null)
  511. {
  512. returnErrorMsg("找不到对应id");
  513. return;
  514. }
  515. spu.category = category;
  516. spu.serialNumber = serialNumber;
  517. spu.operate = operate;
  518. spu.designer = designer;
  519. spu.atta = atta;
  520. spu.shopId = shopId;
  521. spu.upTime = DateTime.Parse(upTime);
  522. spu.Update();
  523. returnSuccess("修改成功!");
  524. return;
  525. }
  526. returnErrorMsg("缺少必要参数");
  527. }
  528. static string pUrl = "http://36.140.138.139:688/api/";
  529. static string CLIENT_Id = "xclient";
  530. static string CLIENT_SECRET = "0a417ecce58c31b32364ce19ca8fcd15";
  531. static string USER_ID = "ca2d316357fa4e09b9c2aa9f7b2ca3d9";
  532. public static string getSaleOrderSn()
  533. {
  534. string orderSn = "";
  535. string post_url = "http://api.presales.lingtao8.com/open/order/generateSplitOrderUniqueNos/1";
  536. try
  537. {
  538. string remoteInfo = httpSaleContent(HttpMethod.Get, post_url, new Dictionary<string, string>());
  539. saleOrderResponse dataTokenBean = JsonConvert.DeserializeObject<saleOrderResponse>(remoteInfo);
  540. if ("200".Equals(dataTokenBean.code))
  541. {
  542. orderSn = dataTokenBean.data[0];
  543. }
  544. }
  545. catch (Exception ex)
  546. {
  547. XLog.SaveLog(0, "getSaleOrderSn:" + ex.Message);
  548. }
  549. return orderSn;
  550. }
  551. public static void api_orderBack(string orderNumber, string state, string content)
  552. {
  553. string post_url = "http://api.presales.lingtao8.com/open/order/orderProcessReturn";
  554. //string post_url = "http://admin.lingtao.zmht888.com/prod-api/open/order/orderProcessReturn";
  555. string remoteInfo = "";
  556. string param = JsonConvert.SerializeObject(new
  557. {
  558. orderSplitNo = orderNumber,
  559. errorStatus = state,
  560. reason = content
  561. });
  562. Dictionary<string, string> map = new Dictionary<string, string>();
  563. map.Add("orderSplitNo", orderNumber);
  564. map.Add("errorStatus", state);
  565. map.Add("reason", content);
  566. try
  567. {
  568. remoteInfo = httpSaleContent(HttpMethod.Post, post_url, map);
  569. }
  570. catch (Exception ex)
  571. {
  572. XLog.SaveLog(0, "api_orderBack:" + ex.Message);
  573. }
  574. }
  575. public static long GetTimeStamp()
  576. {
  577. return DateTimeOffset.Now.ToUnixTimeSeconds();
  578. }
  579. public static string getToken()
  580. {
  581. //return "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiYXBpIl0sInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE3MzU5NjU0ODAsImF1dGhvcml0aWVzIjpbIm9wZW5hcGkiXSwianRpIjoiYjY4NTRhZjctZjNmMy00OTU0LTk4ZmUtZDRlZTE4ZDllNzQyIiwiY2xpZW50X2lkIjoieGNsaWVudCJ9.E6U0NVMZPcUypl4P7L5718J1X8UxSJg9R7vZX_oMkuEJ-yelNXuYwu7-eAi1JTgIJ0GuuviQu-KEAH-W7sHb7t-JJJc-wLPMsLKmpwQDG2EpiRK5hW5ZmyUgL8rPuTUawKVP5k8SGrN60sVyXA2zKm4ztEQ39EGudXnam1Lld2w";
  582. string token = "";
  583. if (RedisHelper.HasKey("xclient_token"))
  584. {
  585. token = RedisHelper.StringGet("xclient_token").ToString();
  586. if (RedisHelper.HasKey("token_end"))
  587. {
  588. string token_end = RedisHelper.StringGet("token_end").ToString();
  589. long token_endtime = Convert.ToInt64(token_end);
  590. long currentTime = GetTimeStamp();
  591. if (currentTime <= token_endtime)
  592. {
  593. return token;
  594. }
  595. }
  596. }
  597. string post_url = pUrl + "oauth/token";
  598. WebClient wc = new WebClient();
  599. wc.Encoding = Encoding.GetEncoding("utf-8");
  600. List<string> headers = new List<string>();
  601. headers.Add("grant_type=client_credentials");
  602. headers.Add("client_id=" + CLIENT_Id);
  603. headers.Add("client_secret=" + CLIENT_SECRET);
  604. post_url += "?" + string.Join("&", headers);
  605. NameValueCollection PostVars = new NameValueCollection();
  606. string remoteInfo = "";
  607. try
  608. {
  609. byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
  610. remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
  611. //remoteInfo = "{\"access_token\":\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiYXBpIl0sInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE3MjM3OTk0MTUsImF1dGhvcml0aWVzIjpbIm9wZW5hcGkiXSwianRpIjoiZjdhOGVjNmMtOWUyMS00MDZhLWEzNzktYjI0MTU3OTE0ODJmIiwiY2xpZW50X2lkIjoieGNsaWVudCJ9.EL-El6M9AVXvH_hp9E4wqM17sHwynyJBDcZJHYw4AYdJrYAWHEu78-Gn3Hj4FyfDaIkqNk641XSAfVpTiH_sFeTSl8-glSJEeD7OFKSkoJjrj0_Ft7kFZZs0XAhbgo4m5rI3Qbeq_87_0K5wKqRcygjUee82MFcIDueTcUg3p9c\",\"token_type\":\"bearer\",\"expires_in\":2052,\"scope\":\"read write\",\"jti\":\"f7a8ec6c-9e21-406a-a379-b2415791482f\",\"aud\":[\"api\"],\"exp\":1723799415,\"authorities\":[\"openapi\"],\"client_id\":\"xclient\"}";
  612. dataTokenBean dataTokenBean = JsonConvert.DeserializeObject<dataTokenBean>(remoteInfo);
  613. token = dataTokenBean.access_token;
  614. string timeEnd = dataTokenBean.exp;
  615. RedisHelper.StringSet("xclient_token", token);
  616. RedisHelper.StringSet("token_end", timeEnd);
  617. }
  618. catch (Exception ex)
  619. {
  620. }
  621. return token;
  622. }
  623. /// <summary>
  624. /// 获取店铺信息
  625. /// </summary>
  626. /// <param name="shopId"></param>
  627. /// <returns></returns>
  628. public static shopInfo getShopDataInfo(string shopId)
  629. {
  630. try
  631. {
  632. string post_url = pUrl + "openapi/v3/bo/list";
  633. string param = JsonConvert.SerializeObject(new
  634. {
  635. schemaCode = "Store_01",
  636. userId = USER_ID,
  637. queryCondition = new
  638. {
  639. operatorType = 1,
  640. propertyCode = "ErpshopId",
  641. propertyValue = shopId
  642. }
  643. });
  644. string data = httpContent(post_url, param);
  645. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  646. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  647. {
  648. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  649. {
  650. return dataResponseVos.data.bizObjectPage.content[0].data;
  651. }
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. }
  657. return null;
  658. }
  659. /// <summary>
  660. /// 获取spu信息
  661. /// </summary>
  662. /// <param name="spuId"></param>
  663. /// <returns></returns>
  664. public static spuInfo getSpuInfo(string spuId)
  665. {
  666. try
  667. {
  668. string post_url = pUrl + "openapi/v3/bo/list";
  669. string param = JsonConvert.SerializeObject(new
  670. {
  671. schemaCode = "lianjieku_01_01",
  672. userId = USER_ID,
  673. queryCondition = new
  674. {
  675. operatorType = 1,
  676. propertyCode = "ShortText1728890649488",
  677. propertyValue = spuId
  678. }
  679. });
  680. string data = httpContent(post_url, param);
  681. dataSpuInfoResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataSpuInfoResponseVo>(data);
  682. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  683. {
  684. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  685. {
  686. return dataResponseVos.data.bizObjectPage.content[0].data;
  687. }
  688. }
  689. }
  690. catch (Exception ex)
  691. {
  692. }
  693. return null;
  694. }
  695. /// <summary>
  696. /// 订单发货是否存在
  697. /// </summary>
  698. /// <param name="dataSendOrderBean"></param>
  699. /// <returns></returns>
  700. public static string checkOrderAlready(dataSendOrderBean dataSendOrderBean)
  701. {
  702. try
  703. {
  704. string post_url = pUrl + "openapi/v3/bo/list";
  705. string param = JsonConvert.SerializeObject(new
  706. {
  707. schemaCode = "dingdanfahuo_01",
  708. userId = USER_ID,
  709. queryCondition = new
  710. {
  711. operatorType = 1,
  712. propertyCode = "ShortText1723707899761",
  713. propertyValue = dataSendOrderBean.ShortText1723707899761
  714. }
  715. });
  716. string data = httpContent(post_url, param);
  717. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  718. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  719. {
  720. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  721. {
  722. return dataResponseVos.data.bizObjectPage.content[0].bizObjectId;
  723. }
  724. return "";
  725. }
  726. }
  727. catch (Exception ex)
  728. {
  729. }
  730. return "";
  731. }
  732. /// <summary>
  733. /// 车间id获取信息
  734. /// </summary>
  735. /// <param name="supplerId"></param>
  736. /// <returns></returns>
  737. public static string getSupplerDataInfo(string supplerId)
  738. {
  739. try
  740. {
  741. string post_url = pUrl + "openapi/v3/bo/list";
  742. string param = JsonConvert.SerializeObject(new
  743. {
  744. schemaCode = "gongyingshang_01",
  745. userId = USER_ID,
  746. queryCondition = new
  747. {
  748. operatorType = 1,
  749. propertyCode = "ErpSupplierId",
  750. propertyValue = supplerId
  751. }
  752. });
  753. string data = httpContent(post_url, param);
  754. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  755. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  756. {
  757. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  758. {
  759. return dataResponseVos.data.bizObjectPage.content[0].data.id;
  760. }
  761. }
  762. }
  763. catch (Exception ex)
  764. {
  765. }
  766. return "";
  767. }
  768. /// <summary>
  769. /// 推送发货信息
  770. /// </summary>
  771. /// <param name="dataSendOrderBean"></param>
  772. /// <returns></returns>
  773. public static dataResponseVo CreateBoFahuo(dataSendOrderBean dataSendOrderBean)
  774. {
  775. string post_url = pUrl + "openapi/v3/bo/create";
  776. shopInfo shop = getShopDataInfo(dataSendOrderBean.RelevanceForm1723191239149);
  777. if (shop != null)
  778. {
  779. dataSendOrderBean.RelevanceForm1723191239149 = shop.id;
  780. }
  781. dataSendOrderBean.RelevanceForm1723191634028 = getSupplerDataInfo(dataSendOrderBean.RelevanceForm1723191634028);
  782. string bizObjectId = checkOrderAlready(dataSendOrderBean);
  783. if (!string.IsNullOrEmpty(bizObjectId))
  784. {
  785. post_url = pUrl + "openapi/v3/bo/update";
  786. dataSendOrderBean.id = bizObjectId;
  787. }
  788. string param = JsonConvert.SerializeObject(new
  789. {
  790. schemaCode = "dingdanfahuo_01",
  791. userId = USER_ID,
  792. data = dataSendOrderBean
  793. });
  794. dataResponseVo dataResponseVos = null;
  795. try
  796. {
  797. string data = httpContent(post_url, param);
  798. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  799. return dataResponseVos;
  800. }
  801. catch (Exception ex)
  802. {
  803. dataResponseVos = new dataResponseVo();
  804. dataResponseVos.errcode = "1";
  805. dataResponseVos.errmsg = ex.Message;
  806. }
  807. return dataResponseVos;
  808. }
  809. /// <summary>
  810. /// 推送spu信息
  811. /// </summary>
  812. /// <param name="bean"></param>
  813. /// <returns></returns>
  814. public static dataResponseVo sendSpuInfo(dataSendSpuBean bean)
  815. {
  816. string post_url = pUrl + "openapi/v3/bo/create";
  817. shopInfo shop = getShopDataInfo(bean.shopId);
  818. if (shop != null)
  819. {
  820. bean.RelevanceForm1728891053364 = shop.id;
  821. bean.operation = shop.operation;
  822. }
  823. spuInfo info = getSpuInfo(bean.ShortText1728890649488);
  824. if (info != null)
  825. {
  826. return null;
  827. bean.StaffSingle1728891078584 = info.StaffSingle1728891078584;
  828. bean.Date1728891021647 = info.Date1728891021647;
  829. bean.ShortText1729677042659 = info.ShortText1729677067460;
  830. bean.ShortText1728891031267 = info.ShortText1728891031267;
  831. }
  832. string param = JsonConvert.SerializeObject(new
  833. {
  834. schemaCode = "lianjieku_01",
  835. userId = USER_ID,
  836. data = bean
  837. });
  838. dataResponseVo dataResponseVos = null;
  839. try
  840. {
  841. string data = httpContent(post_url, param);
  842. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  843. return dataResponseVos;
  844. }
  845. catch (Exception ex)
  846. {
  847. dataResponseVos = new dataResponseVo();
  848. dataResponseVos.errcode = "1";
  849. dataResponseVos.errmsg = ex.Message;
  850. }
  851. return dataResponseVos;
  852. }
  853. /// <summary>
  854. /// 主订单数据
  855. /// </summary>
  856. /// <param name="bean"></param>
  857. /// <returns></returns>
  858. public static dataResponseVo sendErpTradeInfo(dataSendTradeBean bean)
  859. {
  860. string post_url = pUrl + "openapi/v3/bo/create";
  861. string bizObjectId = checkErpTradeAlready(bean);
  862. if (!string.IsNullOrEmpty(bizObjectId))
  863. {
  864. post_url = pUrl + "openapi/v3/bo/update";
  865. bean.id = bizObjectId;
  866. }
  867. string param = JsonConvert.SerializeObject(new
  868. {
  869. schemaCode = "zhudingdan_01",
  870. userId = USER_ID,
  871. data = bean
  872. });
  873. dataResponseVo dataResponseVos = null;
  874. try
  875. {
  876. string data = httpContent(post_url, param);
  877. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  878. return dataResponseVos;
  879. }
  880. catch (Exception ex)
  881. {
  882. dataResponseVos = new dataResponseVo();
  883. dataResponseVos.errcode = "1";
  884. dataResponseVos.errmsg = ex.Message;
  885. }
  886. return dataResponseVos;
  887. }
  888. /// <summary>
  889. /// 校验主订单是否存在
  890. /// </summary>
  891. /// <param name="dataSendOrderBean"></param>
  892. /// <returns></returns>
  893. public static string checkErpTradeAlready(dataSendTradeBean dataSendOrderBean)
  894. {
  895. try
  896. {
  897. string post_url = pUrl + "openapi/v3/bo/list";
  898. string param = JsonConvert.SerializeObject(new
  899. {
  900. schemaCode = "zhudingdan_01",
  901. userId = USER_ID,
  902. queryCondition = new
  903. {
  904. operatorType = 1,
  905. propertyCode = "ShortText1724739958776",
  906. propertyValue = dataSendOrderBean.ShortText1724739958776
  907. }
  908. });
  909. string data = httpContent(post_url, param);
  910. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  911. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  912. {
  913. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  914. {
  915. return dataResponseVos.data.bizObjectPage.content[0].bizObjectId;
  916. }
  917. return "";
  918. }
  919. }
  920. catch (Exception ex)
  921. {
  922. }
  923. return "";
  924. }
  925. /// <summary>
  926. /// 拆订单数据
  927. /// </summary>
  928. /// <param name="bean"></param>
  929. /// <returns></returns>
  930. public static dataResponseVo sendErpTradeCellInfo(dataSendTradeCellBean bean)
  931. {
  932. string post_url = pUrl + "openapi/v3/bo/create";
  933. string bizObjectId = checkErpTradeCellAlready(bean);
  934. if (!string.IsNullOrEmpty(bizObjectId))
  935. {
  936. post_url = pUrl + "openapi/v3/bo/update";
  937. bean.id = bizObjectId;
  938. }
  939. string tid_id = checkErpTradeAlready(new dataSendTradeBean(bean.tid));
  940. if (!string.IsNullOrEmpty(tid_id))
  941. {
  942. bean.RelevanceForm1724834153527 = tid_id;
  943. }
  944. shopInfo shop = getShopDataInfo(bean.shopId);
  945. if (shop != null)
  946. {
  947. bean.RelevanceForm1717742363336 = shop.id;
  948. }
  949. string param = JsonConvert.SerializeObject(new
  950. {
  951. schemaCode = "orders_01",
  952. userId = USER_ID,
  953. data = bean
  954. });
  955. dataResponseVo dataResponseVos = null;
  956. try
  957. {
  958. string data = httpContent(post_url, param);
  959. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  960. return dataResponseVos;
  961. }
  962. catch (Exception ex)
  963. {
  964. dataResponseVos = new dataResponseVo();
  965. dataResponseVos.errcode = "1";
  966. dataResponseVos.errmsg = ex.Message;
  967. }
  968. return dataResponseVos;
  969. }
  970. /// <summary>
  971. /// 校验拆订单是否存在
  972. /// </summary>
  973. /// <param name="dataSendOrderBean"></param>
  974. /// <returns></returns>
  975. public static string checkErpTradeCellAlready(dataSendTradeCellBean dataSendOrderBean)
  976. {
  977. try
  978. {
  979. string post_url = pUrl + "openapi/v3/bo/list";
  980. string param = JsonConvert.SerializeObject(new
  981. {
  982. schemaCode = "orders_01",
  983. userId = USER_ID,
  984. queryCondition = new
  985. {
  986. operatorType = 1,
  987. propertyCode = "ShortText1717720509648",
  988. propertyValue = dataSendOrderBean.ShortText1717720509648
  989. }
  990. });
  991. string data = httpContent(post_url, param);
  992. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  993. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  994. {
  995. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  996. {
  997. return dataResponseVos.data.bizObjectPage.content[0].bizObjectId;
  998. }
  999. return "";
  1000. }
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. }
  1005. return "";
  1006. }
  1007. /// <summary>
  1008. /// 更新数据
  1009. /// </summary>
  1010. /// <param name="map"></param>
  1011. /// <param name="ctid"></param>
  1012. /// <returns></returns>
  1013. public static dataResponseVo updateErpTradeCell(Dictionary<string, string> map, string ctid)
  1014. {
  1015. return null;
  1016. string post_url = pUrl + "openapi/v3/bo/update";
  1017. dataResponseVo dataResponseVos = null;
  1018. dataSendTradeCellBean bean = new dataSendTradeCellBean();
  1019. if (string.IsNullOrEmpty(ctid))
  1020. {
  1021. dataResponseVos = new dataResponseVo();
  1022. dataResponseVos.errcode = "1";
  1023. dataResponseVos.errmsg = "未找到订单";
  1024. return dataResponseVos;
  1025. }
  1026. bean.ShortText1717720509648 = ctid;
  1027. string bizObjectId = checkErpTradeCellAlready(bean);
  1028. if (string.IsNullOrEmpty(bizObjectId))
  1029. {
  1030. dataResponseVos = new dataResponseVo();
  1031. dataResponseVos.errcode = "1";
  1032. dataResponseVos.errmsg = "未找到订单";
  1033. return dataResponseVos;
  1034. }
  1035. map.Add("id", bizObjectId);
  1036. string param = JsonConvert.SerializeObject(new
  1037. {
  1038. schemaCode = "orders_01",
  1039. userId = USER_ID,
  1040. data = map
  1041. });
  1042. try
  1043. {
  1044. string data = httpContent(post_url, param);
  1045. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  1046. return dataResponseVos;
  1047. }
  1048. catch (Exception ex)
  1049. {
  1050. dataResponseVos = new dataResponseVo();
  1051. dataResponseVos.errcode = "1";
  1052. dataResponseVos.errmsg = ex.Message;
  1053. }
  1054. return dataResponseVos;
  1055. }
  1056. /// <summary>
  1057. /// 子订单数据
  1058. /// </summary>
  1059. /// <param name="bean"></param>
  1060. /// <returns></returns>
  1061. public static dataResponseVo sendErpTradeOrderInfo(dataSendTradeOrderBean bean)
  1062. {
  1063. string post_url = pUrl + "openapi/v3/bo/create";
  1064. string bizObjectId = checkErpTradeOrderAlready(bean);
  1065. if (!string.IsNullOrEmpty(bizObjectId))
  1066. {
  1067. post_url = pUrl + "openapi/v3/bo/update";
  1068. bean.id = bizObjectId;
  1069. }
  1070. string tid_id = checkErpTradeAlready(new dataSendTradeBean(bean.ShortText1724898549414));
  1071. if (!string.IsNullOrEmpty(tid_id))
  1072. {
  1073. bean.RelevanceForm1724898561483 = tid_id;
  1074. }
  1075. string param = JsonConvert.SerializeObject(new
  1076. {
  1077. schemaCode = "zidingdan_01",
  1078. userId = USER_ID,
  1079. data = bean
  1080. });
  1081. dataResponseVo dataResponseVos = null;
  1082. try
  1083. {
  1084. string data = httpContent(post_url, param);
  1085. dataResponseVos = JsonConvert.DeserializeObject<dataResponseVo>(data);
  1086. return dataResponseVos;
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. dataResponseVos = new dataResponseVo();
  1091. dataResponseVos.errcode = "1";
  1092. dataResponseVos.errmsg = ex.Message;
  1093. }
  1094. return dataResponseVos;
  1095. }
  1096. /// <summary>
  1097. /// 校验子订单是否存在
  1098. /// </summary>
  1099. /// <param name="dataSendOrderBean"></param>
  1100. /// <returns></returns>
  1101. public static string checkErpTradeOrderAlready(dataSendTradeOrderBean dataSendOrderBean)
  1102. {
  1103. try
  1104. {
  1105. string post_url = pUrl + "openapi/v3/bo/list";
  1106. string param = JsonConvert.SerializeObject(new
  1107. {
  1108. schemaCode = "zidingdan_01",
  1109. userId = USER_ID,
  1110. queryCondition = new
  1111. {
  1112. operatorType = 1,
  1113. propertyCode = "ShortText1724898595268",
  1114. propertyValue = dataSendOrderBean.ShortText1724898595268
  1115. }
  1116. });
  1117. string data = httpContent(post_url, param);
  1118. dataShopResponseVo dataResponseVos = JsonConvert.DeserializeObject<dataShopResponseVo>(data);
  1119. if (dataResponseVos != null && "0".Equals(dataResponseVos.errcode))
  1120. {
  1121. if (dataResponseVos.data.bizObjectPage.content.Count > 0)
  1122. {
  1123. return dataResponseVos.data.bizObjectPage.content[0].bizObjectId;
  1124. }
  1125. return "";
  1126. }
  1127. }
  1128. catch (Exception ex)
  1129. {
  1130. }
  1131. return "";
  1132. }
  1133. static HttpClient client = new HttpClient();
  1134. private static string httpSaleContent(HttpMethod httpMethod, string post_url, Dictionary<string, string> map)
  1135. {
  1136. var request = new HttpRequestMessage
  1137. {
  1138. Method = httpMethod,
  1139. RequestUri = new Uri(post_url),
  1140. Headers =
  1141. {
  1142. { "token", "Zk2ncXqH8hFyA6Rj"},
  1143. }
  1144. };
  1145. if (map.Keys.Count > 0)
  1146. {
  1147. request.Content = new FormUrlEncodedContent(map);
  1148. }
  1149. var task = Task.Run(() =>
  1150. {
  1151. try
  1152. {
  1153. var response = client.SendAsync(request).Result;
  1154. response.EnsureSuccessStatusCode();
  1155. return response.Content.ReadAsStringAsync().Result;
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. return "";
  1160. }
  1161. });
  1162. return task.Result;
  1163. }
  1164. private static string httpContent(string post_url, string content)
  1165. {
  1166. string token = getToken();
  1167. var request = new HttpRequestMessage
  1168. {
  1169. Method = HttpMethod.Post,
  1170. RequestUri = new Uri(post_url),
  1171. Headers =
  1172. {
  1173. { "Authorization", "Bearer " + token },
  1174. },
  1175. Content = new StringContent(content)
  1176. {
  1177. Headers =
  1178. {
  1179. ContentType = new MediaTypeHeaderValue("application/json")
  1180. }
  1181. }
  1182. };
  1183. var task = Task.Run(() =>
  1184. {
  1185. try
  1186. {
  1187. var response = client.SendAsync(request).Result;
  1188. response.EnsureSuccessStatusCode();
  1189. return response.Content.ReadAsStringAsync().Result;
  1190. }
  1191. catch (Exception e)
  1192. {
  1193. return "";
  1194. }
  1195. });
  1196. return task.Result;
  1197. }
  1198. }
  1199. }