SetDepositPostService.cs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. using System.Security.Cryptography;
  10. using System.Text;
  11. namespace MySystem
  12. {
  13. public class SetDepositPostService
  14. {
  15. public readonly static SetDepositPostService Instance = new SetDepositPostService();
  16. private SetDepositPostService()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(dosomething);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void dosomething()
  25. {
  26. while (true)
  27. {
  28. string data = RedisDbconn.Instance.RPop<string>("SetDepositPostQueue");
  29. if (!string.IsNullOrEmpty(data))
  30. {
  31. try
  32. {
  33. WebCMSEntities db = new WebCMSEntities();
  34. JsonData jsonObj = JsonMapper.ToObject(data);
  35. string PosIds = jsonObj["PosId"].ToString();
  36. int Kind = int.Parse(function.CheckInt(jsonObj["Kind"].ToString()));
  37. int RecordId = 0;
  38. if(data.Contains("\"RecordId\""))
  39. {
  40. RecordId = int.Parse(function.CheckInt(jsonObj["RecordId"].ToString()));
  41. }
  42. string OpMan = jsonObj["OpMan"].ToString();
  43. if(!string.IsNullOrEmpty(PosIds) && Kind > 0)
  44. {
  45. List<int> ids = new List<int>();
  46. string[] PosIdList = PosIds.Split(',');
  47. foreach(string sub in PosIdList)
  48. {
  49. ids.Add(int.Parse(sub));
  50. }
  51. List<KqProducts> brands = db.KqProducts.ToList();
  52. List<PosMachinesTwo> poslist = db.PosMachinesTwo.Where(m => ids.Contains(m.Id)).ToList();
  53. List<int> mids = poslist.Select(m => m.BindMerchantId).ToList();
  54. List<PosMerchantInfo> merchantlist = db.PosMerchantInfo.Where(m => mids.Contains(m.Id)).ToList();
  55. foreach(PosMachinesTwo pos in poslist)
  56. {
  57. PosMerchantInfo merchant = merchantlist.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  58. if(merchant != null)
  59. {
  60. decimal Fee = 0.63M;
  61. int addRate = 0;
  62. if(pos.BrandId != 12 && pos.BrandId != 13 && pos.BrandId != 15)
  63. {
  64. if(Kind == 1)
  65. {
  66. addRate = 3;
  67. }
  68. else
  69. {
  70. addRate = 0;
  71. if(Kind == 3)
  72. {
  73. Fee = 0.6M;
  74. }
  75. }
  76. }
  77. if(pos.BrandId == 12 || pos.BrandId == 13 || pos.BrandId == 15)
  78. {
  79. if(Kind == 1) Kind = 2;
  80. if(Kind == 3) Fee = 0.6M;
  81. }
  82. if(pos.BrandId == 1 || pos.BrandId == 3) //金控
  83. {
  84. addRate = addRate * 100;
  85. // string content = function.GetWebRequest("http://connect.kexiaoshuang.com/home/setfee?merNo=" + merchant.KqMerNo + "&sn=" + pos.PosSn + "&fee=" + Fee + "&addRate=" + addRate);
  86. string content = SetFee(merchant.KqMerNo, pos.PosSn, Fee, addRate);
  87. JsonData obj = JsonMapper.ToObject(content);
  88. if (obj["code"].ToString() == "000000")
  89. {
  90. JsonData subobj = JsonMapper.ToObject(Decrypt(obj["data"].ToString()));
  91. if(subobj["errorCode"].ToString() == "0000")
  92. {
  93. pos.SeoDescription = "设置成功";
  94. SetRecordResult(db, RecordId, 1, "设置成功");
  95. db.SaveChanges();
  96. }
  97. else
  98. {
  99. string msg = subobj["errorCodeDesc"].ToString();
  100. pos.SeoDescription = msg;
  101. SetRecordResult(db, RecordId, -1, msg);
  102. db.SaveChanges();
  103. }
  104. }
  105. else
  106. {
  107. string msg = obj["message"].ToString();
  108. pos.SeoDescription = msg;
  109. SetRecordResult(db, RecordId, -1, msg);
  110. db.SaveChanges();
  111. }
  112. }
  113. else if(pos.BrandId == 2) //开店宝
  114. {
  115. Fee = Fee / 100;
  116. string content = ModifyFee(pos.PosSn, Fee, addRate.ToString());
  117. JsonData obj = JsonMapper.ToObject(content);
  118. if(content.Contains("orderNo"))
  119. {
  120. pos.SeoDescription = "提交成功|" + obj["orderNo"].ToString() + "|" + RecordId;
  121. // SetRecordResult(db, RecordId, 1, "设置成功");
  122. db.SaveChanges();
  123. }
  124. else
  125. {
  126. string msg = obj["msg"].ToString();
  127. pos.SeoDescription = msg;
  128. SetRecordResult(db, RecordId, -1, msg);
  129. db.SaveChanges();
  130. }
  131. }
  132. else if(pos.BrandId == 4 || pos.BrandId == 5) //乐刷
  133. {
  134. // 电签
  135. // 电签标准0.63 729702301652492288
  136. // 电签优惠0.63 729702442300088320
  137. // 电签pos不加 696339175297294336
  138. // 大POS
  139. // PY-传统POS标准0.63 554666598481842176
  140. // PY-传统POS优惠0.63 683857388021264384
  141. // 大pos不加 698228081038991360
  142. // 大POS
  143. // 大POS标准0.6:713806109336940544
  144. // 大POS优惠0.6:713806774515802112
  145. // 电签POS
  146. // 电签标准0.6:712391426860134400
  147. // 电签优惠0.6:712391668250718208
  148. // S0电签pos不加:696339175297294336
  149. string bzConfigId = "", yhConfigId = "", surfeeConfigId = "";
  150. if(pos.BrandId == 4)
  151. {
  152. if(Kind == 1)
  153. {
  154. bzConfigId = "729702301652492288";
  155. yhConfigId = "729702442300088320";
  156. surfeeConfigId = "696339175297294336";
  157. }
  158. else
  159. {
  160. bzConfigId = "712391426860134400";
  161. yhConfigId = "712391668250718208";
  162. surfeeConfigId = "696339175297294336";
  163. }
  164. }
  165. else
  166. {
  167. if(Kind == 1)
  168. {
  169. bzConfigId = "554666598481842176";
  170. yhConfigId = "683857388021264384";
  171. surfeeConfigId = "698228081038991360";
  172. }
  173. else
  174. {
  175. bzConfigId = "713806109336940544";
  176. yhConfigId = "713806774515802112";
  177. surfeeConfigId = "698228081038991360";
  178. }
  179. }
  180. string content = SetFeeForBrand(pos.PosSn, bzConfigId, yhConfigId, surfeeConfigId, pos.BrandId);
  181. JsonData obj = JsonMapper.ToObject(content);
  182. if(obj["code"].ToString() == "0")
  183. {
  184. pos.SeoDescription = "设置成功";
  185. SetRecordResult(db, RecordId, 1, "设置成功");
  186. db.SaveChanges();
  187. }
  188. else
  189. {
  190. string msg = obj["msg"].ToString();
  191. pos.SeoDescription = msg;
  192. SetRecordResult(db, RecordId, -1, msg);
  193. db.SaveChanges();
  194. }
  195. }
  196. else if(pos.BrandId == 7) //盛付通
  197. {
  198. string content = SetFeeForSft(merchant.KqMerNo, Fee.ToString("f4"), addRate.ToString());
  199. JsonData obj = JsonMapper.ToObject(content);
  200. if(obj["respCode"].ToString() == "00")
  201. {
  202. pos.SeoDescription = "设置成功";
  203. SetRecordResult(db, RecordId, 1, "设置成功");
  204. db.SaveChanges();
  205. }
  206. else
  207. {
  208. string msg = obj["errorMsg"].ToString();
  209. pos.SeoDescription = msg;
  210. SetRecordResult(db, RecordId, -1, msg);
  211. db.SaveChanges();
  212. }
  213. }
  214. // else if(pos.BrandId == 6) //立刷
  215. // {
  216. // string content = SetLiSFee(pos.PosSn, Fee);
  217. // JsonData obj = JsonMapper.ToObject(content);
  218. // if (obj["ret_code"].ToString() == "00")
  219. // {
  220. // if(Kind == 1)
  221. // {
  222. // pos.UpFeeFlag = 1;
  223. // pos.UpFeeMan = OpMan;
  224. // pos.UpFeeDate = DateTime.Now;
  225. // }
  226. // else if(Kind == 2)
  227. // {
  228. // pos.DownFeeFlag = 1;
  229. // pos.DownFeeMan = OpMan;
  230. // pos.DownFeeDate = DateTime.Now;
  231. // SetRecordResult(db, RecordId, 1);
  232. // }
  233. // db.SaveChanges();
  234. // }
  235. // else
  236. // {
  237. // string msg = obj["ret_msg"].ToString();
  238. // pos.SeoDescription = msg;
  239. // SetRecordResult(db, RecordId, -1, msg);
  240. // db.SaveChanges();
  241. // }
  242. // }
  243. else if(pos.BrandId == 8 || pos.BrandId == 9) //海科
  244. {
  245. // 【融通金宝大POS】
  246. // 584068951081226240 大POS标准贷0.60|借0.50
  247. // 584070145207963648 大POS优惠贷0.60|借0.5
  248. // 574600660289888256 大POS不加
  249. // 691739824478494720 大POS标准贷0.63|借0.50
  250. // 691740128238383104 大POS优惠贷0.63|借0.50
  251. // 574600660289888256 大POS不加
  252. // 【融通金宝电签POS】
  253. // 585167132691009536 电签POS标准贷0.60|借0.50
  254. // 579355312831074304 电签POS优惠贷0.6|借0.5
  255. // 570331704834170880 电签POS不加
  256. // 684753829778436096 电签POS标准贷0.63|借0.50
  257. // 684754046342934528 电签POS优惠贷0.63|借0.5
  258. // 570331704834170880 电签POS不加
  259. string bzConfigId = "", yhConfigId = "", surfeeConfigId = "";
  260. if(pos.BrandId == 8)
  261. {
  262. if(Kind == 1)
  263. {
  264. bzConfigId = "684753829778436096";
  265. yhConfigId = "684754046342934528";
  266. surfeeConfigId = "570331704834170880";
  267. }
  268. else
  269. {
  270. bzConfigId = "585167132691009536";
  271. yhConfigId = "579355312831074304";
  272. surfeeConfigId = "570331704834170880";
  273. }
  274. }
  275. else
  276. {
  277. if(Kind == 1)
  278. {
  279. bzConfigId = "691739824478494720";
  280. yhConfigId = "691740128238383104";
  281. surfeeConfigId = "574600660289888256";
  282. }
  283. else
  284. {
  285. bzConfigId = "584068951081226240";
  286. yhConfigId = "584070145207963648";
  287. surfeeConfigId = "574600660289888256";
  288. }
  289. }
  290. string content = HKSetFeeForBrand(pos.PosSn, bzConfigId, yhConfigId, surfeeConfigId, pos.BrandId);
  291. JsonData obj = JsonMapper.ToObject(content);
  292. if(obj["code"].ToString() == "0")
  293. {
  294. pos.SeoDescription = "设置成功";
  295. SetRecordResult(db, RecordId, 1, "设置成功");
  296. db.SaveChanges();
  297. }
  298. else
  299. {
  300. string msg = obj["msg"].ToString();
  301. pos.SeoDescription = msg;
  302. SetRecordResult(db, RecordId, -1, msg);
  303. db.SaveChanges();
  304. }
  305. }
  306. else if(pos.BrandId == 10 || pos.BrandId == 11) //联动
  307. {
  308. decimal LastFee = Fee / 100;
  309. string content = LDFeeRate(merchant.KqMerNo, LastFee.ToString("f4"), pos.BrandId, addRate);
  310. JsonData obj = JsonMapper.ToObject(content);
  311. if(obj["code"].ToString() == "000000")
  312. {
  313. pos.SeoDescription = "设置成功";
  314. SetRecordResult(db, RecordId, 1, "设置成功");
  315. db.SaveChanges();
  316. }
  317. else
  318. {
  319. string msg = obj["msg"].ToString();
  320. pos.SeoDescription = msg;
  321. SetRecordResult(db, RecordId, -1, msg);
  322. db.SaveChanges();
  323. }
  324. }
  325. else if(pos.BrandId == 12 || pos.BrandId == 13) //盒易付
  326. {
  327. string content = BoxFee(merchant.KqMerNo, Fee.ToString("f2"));
  328. JsonData obj = JsonMapper.ToObject(content);
  329. if(obj["resultCode"].ToString() == "1")
  330. {
  331. pos.SeoDescription = "设置成功";
  332. SetRecordResult(db, RecordId, 1, "设置成功");
  333. db.SaveChanges();
  334. }
  335. else
  336. {
  337. string msg = obj["errorDesc"].ToString();
  338. pos.SeoDescription = msg;
  339. SetRecordResult(db, RecordId, -1, msg);
  340. db.SaveChanges();
  341. }
  342. }
  343. else if(pos.BrandId == 15 || pos.BrandId == 16) //联客宝
  344. {
  345. List<string> merno = new List<string>();
  346. merno.Add(merchant.KqMerNo);
  347. string policy_code = "";
  348. string policy_name = "";
  349. if(Kind == 1)
  350. {
  351. policy_code = "LKB_0.63+3";
  352. policy_name = "联客宝";
  353. }
  354. else if(Kind == 2)
  355. {
  356. policy_code = "LKB_0.63+0";
  357. policy_name = "联客宝0.63+0";
  358. }
  359. else if(Kind == 3)
  360. {
  361. policy_code = "LKB_0.6+0";
  362. policy_name = "联客宝0.6+0";
  363. }
  364. string content = PublicImportDataService.Instance.PospFee(merno, policy_code, policy_name);
  365. JsonData obj = JsonMapper.ToObject(content);
  366. if(obj["code"].ToString() == "200")
  367. {
  368. pos.SeoDescription = "设置成功";
  369. SetRecordResult(db, RecordId, 1, "设置成功");
  370. db.SaveChanges();
  371. }
  372. else
  373. {
  374. string msg = obj["msg"].ToString();
  375. pos.SeoDescription = msg;
  376. SetRecordResult(db, RecordId, -1, msg);
  377. db.SaveChanges();
  378. }
  379. }
  380. }
  381. }
  382. }
  383. db.Dispose();
  384. Thread.Sleep(500);
  385. }
  386. catch (Exception ex)
  387. {
  388. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置费率到支付平台异常");
  389. }
  390. }
  391. else
  392. {
  393. Thread.Sleep(500);
  394. }
  395. }
  396. }
  397. private void SetRecordResult(WebCMSEntities db, int RecordId, int Status, string Note = "")
  398. {
  399. if(RecordId > 0)
  400. {
  401. PosMachinesFeeChangeRecord record = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == RecordId);
  402. if(record != null)
  403. {
  404. record.Status = Status;
  405. record.SeoDescription = Note;
  406. }
  407. }
  408. }
  409. public void StartKdb()
  410. {
  411. Thread th = new Thread(StartKdbDo);
  412. th.IsBackground = true;
  413. th.Start();
  414. }
  415. private void StartKdbDo()
  416. {
  417. while (true)
  418. {
  419. try
  420. {
  421. WebCMSEntities db = new WebCMSEntities();
  422. var poslist = db.PosMachinesTwo.Select(m => new { m.Id, m.BrandId, m.SeoDescription }).Where(m => m.BrandId == 2 && m.SeoDescription.StartsWith("提交成功|")).ToList();
  423. foreach (var pos in poslist)
  424. {
  425. string[] datalist = pos.SeoDescription.Split('|');
  426. string orderNo = datalist[1];
  427. int RecordId = int.Parse(datalist[2]);
  428. string content = QueryFee(orderNo);
  429. JsonData obj = JsonMapper.ToObject(content);
  430. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.Id);
  431. if(edit != null)
  432. {
  433. if(obj["status"].ToString() == "HANDLE_STATUS_COMPLETE")
  434. {
  435. edit.SeoDescription = "设置成功";
  436. SetRecordResult(db, RecordId, 1, "设置成功");
  437. db.SaveChanges();
  438. }
  439. else if(obj["status"].ToString() == "HANDLE_STATUS_FAIL")
  440. {
  441. edit.SeoDescription = "设置失败";
  442. SetRecordResult(db, RecordId, -1, "设置失败");
  443. db.SaveChanges();
  444. }
  445. }
  446. }
  447. db.Dispose();
  448. }
  449. catch(Exception ex)
  450. {
  451. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "开店宝费率异步获取结果异常");
  452. }
  453. Thread.Sleep(5000);
  454. }
  455. }
  456. #region 金控
  457. // 开发环境
  458. // string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCy8cg6/tXbSj2i1tyi7VztwJw7uNmqc3bS6sVIZkDYhTmcXhpV17jq4j2zz/tURwX8b3MdK1A1HTR1XRd7hl0w2UF9iFk6UezByJ5tdNDoffMCGJtVSThq+MCV+WQI26tJ/ub6bm7GPrzTR79fntN+nTniRM4trjONN2WzEhHEcwIDAQAB";
  459. // string mfe88PrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALLxyDr+1dtKPaLW3KLtXO3AnDu42apzdtLqxUhmQNiFOZxeGlXXuOriPbPP+1RHBfxvcx0rUDUdNHVdF3uGXTDZQX2IWTpR7MHInm100Oh98wIYm1VJOGr4wJX5ZAjbq0n+5vpubsY+vNNHv1+e036dOeJEzi2uM403ZbMSEcRzAgMBAAECgYAeRbb4/AmTypB4zt6OlZdGBXKoy9HO+y+b6OmtINdRieBAKs9LvG3lFpcXp1S+YjGKDhSsV5p/EczBGhmR5R44j52886h6OoU0HskifeEJs152gMXLEFya/1QWnf1Ev+ugzuto+CxuHlGHE0T43uFkuATZp4sfXX/03um99FIKmQJBAOrYJX+VmKdNbmwNKMXkFBAw6FM4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yu95QC3jIaggcYmGD36sVO/ns8Uyu8PkAHYOscuXRcV0L8LghIzPolcehj9bTbDLjiuNgeuyjNs2YBvMCQQC4K4uIXt0kVDLYzlJfhN1CsV90vQitcKdD8wTO0JRKfMCQ6UDSumU7lq+z4TxTlRYxmZjpgIqH+N0WohmEiwWxAkBEfuMzBD3gjSJS0+DNF0ruzSCLinYdDoVgWZbC1wp8ZK0ZeQh9AhzZ0X6yFDffkGlG1B9IJSXpmr68rwXOCM+JAkBkrKEUxc6bGk/FRluvDWEqIO2uUdtZfBhjQ4ggSdKWOUXGsUsXJn9KKKAZc4lXo0rDiFQXaIXRuE+bHLdYReqxAkAj0Kol0LkJgdl2PoBAeyQHTpt9nxaeNX56W7CN/srBA1O2wr+aoQiJaKsu9I0EeW3zaMJlLi3VyjU4wnF+yAsB";
  462. // string reqUrl = "https://test-push.mfe88.com/push-service/api/MODIFYPERPOSFEE";
  463. // 生产环境
  464. string merchantNo = "4487378308096";
  465. string clientId = "1243966544896";
  466. string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2HxPVZ5ZIxIWfr24qB45PAz9WfjN9CiF1x9Lz3P/tVvIXFdBaUw+9zxCAPRDGQxJId7anjEjCOuAIKpFOiTPhVqHTHd3075FFsW5fL7lFCOFJELTj+mVamAIbKalAuRzIX0m0VQUXd+madB+yRQSBjkOIboAMYQ9amf99SqI9KwIDAQAB";
  467. string clientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrSrNKkBt/X8Fkd7viGpTMk+GdJgE+SvoA4PSjccpZoLWnwxXsC8K/7pfm9uGxPjte9e4RznXE5nuhSrcfls4lDWhTrGd/lj3Id8OCM+yEG+xilJs1lvXJjHDhL6/wa+TE5NSzWoKgXnyeHF3TSHMbUefLLtoKqL3j4h4lPqrjiQIDAQAB";
  468. string clientPrivateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKtKs0qQG39fwWR3u+IalMyT4Z0mAT5K+gDg9KNxylmgtafDFewLwr/ul+b24bE+O1717hHOdcTme6FKtx+WziUNaFOsZ3+WPch3w4Iz7IQb7GKUmzWW9cmMcOEvr/Br5MTk1LNagqBefJ4cXdNIcxtR58su2gqovePiHiU+quOJAgMBAAECgYBQIIyIR6slRWTRG5V/KlIK9O5oNbwFKMuUF6c4weUXUi9Hv+GEXugGIpVaTIi9AdCCFmb8W2kJ54tTowDQvRnGxVpr7repYwJv2jHh5ug3oreBghfbfbaOaRMXisp2x1CLi+8Q5BNjpe9KdurRtg7jt8bqgWels5aV2PbjPHHwBQJBANjqYXbapz6xUPdI0kyEQhdxHt7jOmysTY3vT+/UcgU2sf37hWh8JlTtVlFZns3JBocc9rMtBEAh0Cy5faMQXKMCQQDKJ9eYWQvb1GyB5IdDlkOuByyuwFfosZ0Qp+QNtnz1VAHHgQRM7RGNv3nYDJNEJ+qIhIzZppG5yDbAN7PYyTXjAkEAq8a4VkIDbZ9HyfxOJbAbEqtPUhzJ+KNea0cXm4o2nTBaNhLH7B1c0aZ908BQBRDr7XWfW/cLRapBTBm8h7R+VwJBAJAKrZMPN+TuSlaPaFYfNqBE2nC1+q2CCQE6L8QZmJYRwqbN5iuN7CkNGxt3cmNo8bNOhzH6fvFamLCDwDEixbMCQEgaxfAxpJdMoR6LrklSkigHiKfA6SaRWxxShFtBfjk5XcakmLkU/U5lgD/Blu7h4x6bRf4VPTYWdbxtiOK11rY=";
  469. string reqUrl = "https://push.mfe88.com/push-service/api/MODIFYPERPOSFEE";
  470. public string SetFee(string merNo, string sn, decimal addRate, int fee)
  471. {
  472. // 2021092711IpAreT 降费特惠…刷卡交易手续费
  473. // 2020032508Nu0QCG 刷卡交易手续费
  474. // 2020032508Nx8oyW 借记卡封顶手续费
  475. // 2020032508O4EWB6 刷卡结算手续费
  476. List<SetDepositList> rateDOs = new List<SetDepositList>();
  477. rateDOs.Add(new SetDepositList()
  478. {
  479. productSubType = "2020032508Nu0QCG",
  480. updateValue = addRate,
  481. updateType = 0
  482. });
  483. // rateDOs.Add(new SetDepositList()
  484. // {
  485. // productSubType = "2020032508Nx8oyW",
  486. // updateValue = fee,
  487. // updateType = 0
  488. // });
  489. rateDOs.Add(new SetDepositList()
  490. {
  491. productSubType = "2020032508O4EWB6",
  492. updateValue = fee,
  493. updateType = 0
  494. });
  495. Dictionary<string, string> headers = new Dictionary<string, string>();
  496. headers.Add("X-Client-ID", "4487378308096");
  497. headers.Add("X-Security", "RSA");
  498. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  499. Dictionary<string, object> obj = new Dictionary<string, object>();
  500. obj.Add("merNo", merNo);
  501. obj.Add("sn", sn);
  502. obj.Add("batchUpdateType", 2);
  503. obj.Add("rateDOs", rateDOs);
  504. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  505. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  506. function.WriteLog(content, "设置金控机具费率");
  507. content = Encrypt(content);
  508. string signstr = Sign(content);
  509. headers.Add("X-Sign", signstr);
  510. string headerString = Newtonsoft.Json.JsonConvert.SerializeObject(headers);
  511. function.WriteLog(headerString, "设置金控机具费率");
  512. string req = "{\"param\":\"" + content + "\"}";
  513. function.WriteLog(req, "设置金控机具费率");
  514. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  515. function.WriteLog(result, "设置金控机具费率");
  516. return result;
  517. }
  518. public string SetJkFee(string merNo, string sn, decimal fee = 0.6M)
  519. {
  520. List<SetDepositList> rateDOs = new List<SetDepositList>();
  521. rateDOs.Add(new SetDepositList()
  522. {
  523. productSubType = "2020032007vz7Ux6",
  524. updateValue = fee,
  525. updateType = 0
  526. });
  527. Dictionary<string, string> headers = new Dictionary<string, string>();
  528. headers.Add("X-Client-ID", clientId);
  529. headers.Add("X-Security", "RSA");
  530. Dictionary<string, object> obj = new Dictionary<string, object>();
  531. obj.Add("merNo", merNo);
  532. obj.Add("sn", sn);
  533. obj.Add("batchUpdateType", 2);
  534. obj.Add("rateDOs", rateDOs);
  535. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  536. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  537. function.WriteLog(content, "设置金控机具费率");
  538. content = Encrypt(content);
  539. string signstr = Sign(content);
  540. headers.Add("X-Sign", signstr);
  541. string req = "{\"param\":\"" + content + "\"}";
  542. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  543. function.WriteLog(result, "设置金控机具费率");
  544. return result;
  545. }
  546. public string Decrypt(string data)
  547. {
  548. var toDecryptArray = Convert.FromBase64String(data);
  549. var rsa = RSA.Create();
  550. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  551. string result = "";
  552. List<byte> cache = new List<byte>();
  553. for (int i = 0; i < toDecryptArray.Length; i++)
  554. {
  555. cache.Add(toDecryptArray[i]);
  556. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  557. {
  558. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  559. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  560. cache.Clear();
  561. }
  562. }
  563. return result;
  564. }
  565. public string Encrypt(string data)
  566. {
  567. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", mfe88PublicKey).Encrypt(data);
  568. }
  569. public string Sign(string data)
  570. {
  571. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  572. var rsa = RSA.Create();
  573. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  574. string result = "";
  575. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  576. result = Convert.ToBase64String(buffer);
  577. return result;
  578. }
  579. #endregion
  580. #region 开店宝
  581. //生产环境
  582. string KdbApiUrl = "https://kzy.kdb-tj.com:5055/api";
  583. string KDBAESKEY = "F@xh#sga41c08@pe";
  584. string Kdb_Rsa_PrivateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAl2x9dSSCfNDik6VM2dn/SK1ONSbb7AKyXM1gHw8PMbzWN1pK7YGaPqHlIRbAeFeIvLKVeMxrji+63W6LpB0yDQIDAQABAkAfpHUnCIUYDhJ65f0EPTDCgCyqoL8uN3YMPIKMmvoC22/i7AC6zf/bWk4JdratN+gvvnjGgHQff6HH5dOQ6sbFAiEAxPYSLADzIv374J8O+LluXIcgI5zXm4r4dMtKbCmmWSsCIQDE0BRKsBcBZ9NvJ9Km+m/d1hN9v5hFT842zrkUFJmVpwIgBdYc17z3d3P7QL613NzxzkAazbNaGDvX/O4BOI9LZJ0CICrZElHgXGHV9NYyWU45H7mwLbYmzEPqx/5uqySQB4/pAiBgKYv3RGnsZ8Zm1EKAJjUX7ehdteBgPSA/UgIDZQ4oyw==";
  585. string AgencyId = "3013890129";
  586. //开发环境
  587. // string KdbApiUrl = "https://kzy-test.kdb-tj.com:5056/api";
  588. // string KDBAESKEY = "Ebn4N28MvEXEvPTA";
  589. // string Kdb_Rsa_PrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAsPyH5Y5NySHHKWIgPwxbZFkd33vzuWKv+Kdpug5/qYAnpTShDSMXQ2Ib7gc+B/yvj4uZ/k1A/xHpzHTPl6MzQQIDAQABAkA2sGHhyj45B2n+XKbwNIZNFMiJVUjzoQ4VPM4Lww0pt781GeqBCGgEIgTjmmg/FTGjgwTb7ta1A5G9Qn2nPG0RAiEA4x7W6XKdSL/FyVdlt4jijNQNZfLEqEPy1NnchRWUf40CIQDHfb49KP3pW4ZDX3xS42fYd9p7AGZ+qpVBnJfGGyFrhQIhALk3HCHyowuBwMUKLdw3mDEqeOarzO4/w1cLd8dcKua9AiEAtdPAj9JLDGWljMb9dDddsYockzwcL5ufizwFgkW8QlkCIADYU4+fFKqySLGX3MmEIJ/mU632PRtJAh4LSL8/Ij1H";
  590. // string AgencyId = "3013890202";
  591. // 修改费率接口
  592. public string ModifyFee(string PosSn, decimal Rate, string Fee = "0")
  593. {
  594. string url = KdbApiUrl + "/pos/rate/modify/single/remote";
  595. string content = "{\"posSn\":\"" + PosSn + "\",\"type\":\"贷记卡刷卡\",\"rate\":\"" + Rate + "\",\"d0Fee\":\"0\"}";
  596. return PostKDB(url, content);
  597. }
  598. // 查询费率接口
  599. public string QueryFee(string orderNo)
  600. {
  601. string url = KdbApiUrl + "/pos/rate/change/query/orderno";
  602. string content = "{\"orderNo\":\"" + orderNo + "\"}";
  603. return PostKDB(url, content);
  604. }
  605. public string KDBDecrypt(string data)
  606. {
  607. string result = AesDecrypt(data, KDBAESKEY);
  608. return result;
  609. }
  610. public string AesDecrypt(string str, string key)
  611. {
  612. if (string.IsNullOrEmpty(str)) return null;
  613. byte[] toEncryptArray = Convert.FromBase64String(str);
  614. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  615. {
  616. Key = Encoding.UTF8.GetBytes(key),
  617. Mode = System.Security.Cryptography.CipherMode.ECB,
  618. Padding = System.Security.Cryptography.PaddingMode.PKCS7,
  619. };
  620. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
  621. byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  622. return Encoding.UTF8.GetString(resultArray);
  623. }
  624. public string AesEncrypt(string str)
  625. {
  626. // if (string.IsNullOrEmpty(str)) return null;
  627. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  628. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  629. {
  630. Key = Encoding.UTF8.GetBytes(KDBAESKEY),
  631. Mode = System.Security.Cryptography.CipherMode.ECB,
  632. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  633. };
  634. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  635. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  636. return Convert.ToBase64String(resultArray);
  637. }
  638. public string PostKDB(string url, string content)
  639. {
  640. content = AesEncrypt(content);
  641. string timestamp = function.GetCurTimestamp().ToString();
  642. string sign = KDBSign(content + timestamp);
  643. string req = "{\"agencyId\":\"" + AgencyId + "\",\"content\":\"" + content + "\",\"timestamp\":\"" + timestamp + "\",\"sign\":\"" + sign + "\"}";
  644. string result = PostWebRequestKdb(url, req, new Dictionary<string, string>());
  645. return result;
  646. }
  647. private string PostWebRequestKdb(string postUrl, string paramData, Dictionary<string, string> headers)
  648. {
  649. string ret = string.Empty;
  650. try
  651. {
  652. function.WriteLog(DateTime.Now.ToString(), "请求开店宝API日志");
  653. function.WriteLog(postUrl, "请求开店宝API日志");
  654. function.WriteLog(paramData, "请求开店宝API日志");
  655. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  656. // 设置提交的相关参数
  657. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  658. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  659. request.Method = "POST";
  660. request.KeepAlive = false;
  661. request.AllowAutoRedirect = true;
  662. request.ContentType = "application/json";
  663. foreach (string key in headers.Keys)
  664. {
  665. request.Headers.Add(key, headers[key]);
  666. }
  667. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  668. request.ContentLength = postData.Length;
  669. // 提交请求数据
  670. System.IO.Stream outputStream = request.GetRequestStream();
  671. outputStream.Write(postData, 0, postData.Length);
  672. outputStream.Close();
  673. System.Net.HttpWebResponse response;
  674. System.IO.Stream responseStream;
  675. System.IO.StreamReader reader;
  676. string srcString;
  677. response = request.GetResponse() as System.Net.HttpWebResponse;
  678. responseStream = response.GetResponseStream();
  679. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  680. srcString = reader.ReadToEnd();
  681. ret = srcString; //返回值赋值
  682. reader.Close();
  683. function.WriteLog(srcString, "请求开店宝API日志");
  684. }
  685. catch (System.Net.WebException ex)
  686. {
  687. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)ex.Response;
  688. if(response != null)
  689. {
  690. System.IO.Stream myResponseStream = response.GetResponseStream();
  691. //获取响应内容
  692. System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream);
  693. ret = myStreamReader.ReadToEnd();
  694. myResponseStream.Close();
  695. }
  696. }
  697. catch (Exception ex)
  698. {
  699. ret = "fail";
  700. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求开店宝API异常");
  701. }
  702. return ret;
  703. }
  704. public string KDBSign(string data)
  705. {
  706. var rsa = RSA.Create();
  707. var key = Convert.FromBase64String(Kdb_Rsa_PrivateKey);
  708. var content = Encoding.UTF8.GetBytes(data);
  709. rsa.ImportPkcs8PrivateKey(key, out _);
  710. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  711. return Convert.ToBase64String(result);
  712. }
  713. #endregion
  714. #region 乐刷
  715. string LSPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMjld3flY+R+9WTR2MvcR9qWISdmpayL3GNGg9gvzwkXkhDI/E7rX6ndLvVuaBbLWXB+UOh+8Pfw3Gvfv3D2GHZCTzPHOKrs2tyzqC8EmMUDQaoVOI2BY4vtB7IjNe9FlLGZx62JEJrMkHKnOSQxsi+flCoexKc2t1q7kQsO2F+3AgMBAAECgYBmQ7EB/mpQOXSPYucaN0L4eW3dEbqKUBPbEV0yInwgo7f+BWGyhsyGuooZ857W46Leyd5Dy8K8ZAbAfwCD7zJZsSzWsuvWQE991f+n0V7AAnKc3h4OsHa4oITUNo2nD3PvOpWfQx8vSuQuSFQgx0ExdnywS3So16mG2X6J2k87wQJBAPTfV10MNpA1e5oRdX4D4lQ2tVyg5GW72NMhUGWct/FvgcEW3V7xZ0z/gSLfFcGI8c4LGYWRVPIsBnWFx0LSZ6ECQQDSBoqXuF/LobfFFT3D47ixL8d+qDbOJ+ro3p4+iCkdxxJ/ncaqouxsr3fBbkSWh4t+UkbbihO/isPdBwLPZihXAkAc2jwHAKtlLogTzT7UzExcs92GvoZq3klcBy7b6i1aS1M0lycaSsNrNSfYHgUIOsSTDIfDTy59ImbYbhzeaMBBAkEAyfz6i4IJt3jXmZadKWk4NkhiT6CN3OUtGjsH69Hd4UKUuuFNsMwyHzD+NqzLEA5aDOoqNXftGDjnuAnHHRn9zwJAHqPHR5ZOKDN/ujeAIUTwmFFJh8vx6ujv7UTesBbtTsFYW6bZln+X6aS2G3Kdvz3e2cxQyH8ncc0yIh64a1fqyg==";
  716. string LSPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI5Xd35WPkfvVk0djL3EfaliEnZqWsi9xjRoPYL88JF5IQyPxO61+p3S71bmgWy1lwflDofvD38Nxr379w9hh2Qk8zxziq7Nrcs6gvBJjFA0GqFTiNgWOL7QeyIzXvRZSxmcetiRCazJBypzkkMbIvn5QqHsSnNrdau5ELDthftwIDAQAB";
  717. string OrgNo1 = "704067708098457600"; //快联盟电签pos
  718. string OrgNo2 = "704058964878831616"; //快联盟大pos
  719. string LSReqUrl = "https://lfs-org-push.ileshua.com"; //请求url
  720. public string LSDecrypt(string data, string sign)
  721. {
  722. var toDecryptArray = Convert.FromBase64String(sign);
  723. var rsa2 = RSA.Create();
  724. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(LSPrivateKey), out _);
  725. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  726. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  727. return AesDecrypt(data, aeskey);
  728. }
  729. public string LSEncrypt(string sign)
  730. {
  731. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LSPublicKey).Encrypt(sign);
  732. }
  733. public string LSAesEncrypt(string str, string aeskey)
  734. {
  735. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  736. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  737. {
  738. Key = Encoding.UTF8.GetBytes(aeskey),
  739. Mode = System.Security.Cryptography.CipherMode.ECB,
  740. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  741. };
  742. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  743. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  744. return Convert.ToBase64String(resultArray);
  745. }
  746. //设置机具押金
  747. public string SetDepositForLS(string snNo, string oldMarketId, string newMarketId, int BrandId)
  748. {
  749. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  750. return LSReqFunc("/org/pos/updatePosMarket", data, BrandId);
  751. }
  752. //查询配置活动信息
  753. public string QueryActiveForConfig(string snNo, int BrandId)
  754. {
  755. string data = "{\"snNo\":\"" + snNo + "\"}";
  756. return LSReqFunc("/org/pos/getMarketConfig", data, BrandId);
  757. }
  758. //查询营销活动信息
  759. public string QueryActiveForBrand(int marketType, int BrandId)
  760. {
  761. string data = "{\"marketType\":\"" + marketType + "\"}";
  762. return LSReqFunc("/org/pos/marketList", data, BrandId);
  763. }
  764. //终端费率模板查询
  765. public string QueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  766. {
  767. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  768. return LSReqFunc("/org/pos/rateConfigList", data, BrandId);
  769. }
  770. //终端费率查询
  771. public string QueryFeeForBrand(string snNo, int BrandId)
  772. {
  773. string data = "{\"snNo\":\"" + snNo + "\"}";
  774. return LSReqFunc("/org/pos/getRateConfig", data, BrandId);
  775. }
  776. //终端费率模板修改
  777. public string SetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  778. {
  779. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  780. return LSReqFunc("/org/pos/updatePosRate", data, BrandId);
  781. }
  782. public string LSReqFunc(string apiPath, string data, int BrandId)
  783. {
  784. function.WriteLog(DateTime.Now.ToString(), "设置乐刷机具费率");
  785. function.WriteLog(data, "设置乐刷机具费率");
  786. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  787. string req = "{";
  788. if (BrandId == 4)
  789. {
  790. req += "\"orgId\":\"" + OrgNo1 + "\",";
  791. }
  792. else
  793. {
  794. req += "\"orgId\":\"" + OrgNo2 + "\",";
  795. }
  796. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  797. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  798. req += "\"version\":\"1.0\",";
  799. req += "\"data\":\"" + LSAesEncrypt(data, aeskey) + "\",";
  800. req += "\"sign\":\"" + LSEncrypt(aeskey) + "\"";
  801. req += "}";
  802. function.WriteLog(req, "设置乐刷机具费率");
  803. string result = function.PostWebRequest(LSReqUrl + apiPath, req, "application/json");
  804. function.WriteLog(result + "\n\n", "设置乐刷机具费率");
  805. return result;
  806. }
  807. #endregion
  808. #region 立刷
  809. string LiSAgentId = "50814834";
  810. string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZ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86BNwRdxJoH/juFGtp6GJA6jsR0+0EjGA4I1AoIBAGl2ITNeGX2dXgvmPEcH8/CARFWMCozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  811. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  812. public string LiSSign(string data)
  813. {
  814. var rsa = RSA.Create();
  815. var key = Convert.FromBase64String(LiSPrivateKey);
  816. var content = Encoding.UTF8.GetBytes(data);
  817. rsa.ImportPkcs8PrivateKey(key, out _);
  818. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  819. return Convert.ToBase64String(result);
  820. }
  821. // 设置费率
  822. public string SetLiSFee(string sn, decimal serviceFee = 0.6M)
  823. {
  824. Dictionary<string, object> dic = new Dictionary<string, object>();
  825. dic.Add("agentId", LiSAgentId);
  826. dic.Add("deviceSn", sn);
  827. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  828. Dictionary<string, object> item = new Dictionary<string, object>();
  829. item.Add("feeCalcType", "M5");
  830. item.Add("fixed", "0");
  831. item.Add("rate", serviceFee);
  832. feeList.Add(item);
  833. dic.Add("feeList", feeList);
  834. dic.Add("signMethod", "02");
  835. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  836. string signstr = LiSSign(content);
  837. dic.Add("signData", signstr);
  838. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  839. function.WriteLog(DateTime.Now.ToString(), "设置立刷费率");
  840. function.WriteLog(req, "设置立刷费率");
  841. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  842. function.WriteLog(result, "设置立刷费率");
  843. function.WriteLog("\n\n", "设置立刷费率");
  844. return result;
  845. }
  846. public string QueryLiSDeposit(string merchNo, string sn)
  847. {
  848. Dictionary<string, object> dic = new Dictionary<string, object>();
  849. dic.Add("agentId", LiSAgentId);
  850. dic.Add("deviceSn", sn);
  851. dic.Add("merchNo", merchNo);
  852. dic.Add("signMethod", "02");
  853. string content = LiSAgentId + sn + merchNo + "02";
  854. string signstr = LiSSign(content);
  855. dic.Add("signData", signstr);
  856. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  857. string result = PostWebRequest(LiSReqUrl + "FEE001", req, new Dictionary<string, string>());
  858. return result;
  859. }
  860. private string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> headers)
  861. {
  862. string ret = string.Empty;
  863. try
  864. {
  865. function.WriteLog(DateTime.Now.ToString(), "请求立刷API日志");
  866. function.WriteLog(postUrl, "请求立刷API日志");
  867. function.WriteLog(paramData, "请求立刷API日志");
  868. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  869. // 设置提交的相关参数
  870. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  871. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  872. request.Method = "POST";
  873. request.KeepAlive = false;
  874. request.AllowAutoRedirect = true;
  875. request.ContentType = "application/json";
  876. foreach (string key in headers.Keys)
  877. {
  878. request.Headers.Add(key, headers[key]);
  879. }
  880. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  881. request.ContentLength = postData.Length;
  882. // 提交请求数据
  883. System.IO.Stream outputStream = request.GetRequestStream();
  884. outputStream.Write(postData, 0, postData.Length);
  885. outputStream.Close();
  886. System.Net.HttpWebResponse response;
  887. System.IO.Stream responseStream;
  888. System.IO.StreamReader reader;
  889. string srcString;
  890. response = request.GetResponse() as System.Net.HttpWebResponse;
  891. responseStream = response.GetResponseStream();
  892. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  893. srcString = reader.ReadToEnd();
  894. ret = srcString; //返回值赋值
  895. reader.Close();
  896. function.WriteLog(srcString, "请求立刷API日志");
  897. }
  898. catch (Exception ex)
  899. {
  900. ret = "fail";
  901. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求立刷API异常");
  902. }
  903. return ret;
  904. }
  905. #endregion
  906. #region 盛付通
  907. string OrgId = "38844193";
  908. // 生产环境
  909. string SftPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4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CozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  910. string SftReqUrl = "https://zqb.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  911. string SftPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEtC73mdnEQ5b0G93Dseg457m6Rc8lVU9K31SEc0YyK4anN3fgGDOl2CuQT2JIaxwwqCAHoUQp7jLUirc7XUQlh+y0WnYgPre6jmfI9upuJwTD7TmUr+Mqtg2RZTYX1r81OtRL/ELQW/lm4kBcuXeCWVlwhMyAQiJdb9+plkYXIwIDAQAB";
  912. // 测试环境
  913. // string SftPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAILFLdmFwfNHCGk3vpwj/FR9XpE9jjVreLlOaIEkSAOWOfzxCF7pMeSy0UDroRLgfLD4nQbUcK5AT7gg8PEM6H99SEHcpBkTKhfK1iI5iU9sN/WGL2Ft5T/uwo+KD7X3CsqMD0HsMQtv/YHJeAz/SPf5zyD5KttwohXXzO8a3P1pAgMBAAECgYAchxl2f6iNAu0Bzyhk9bDBWcw8kRop6zUd7836hkizh51E4ew6kFLTGnNt3zl3XcO187aF2+htCxiZCY6md3NstJod1zshoXf2slxxPWRUK92sS0XzlVT6ahVTdq2tAS3hOY3ldtnfOXMmMQPNn9OqlALQGOH/hJatBV6ZQxpp0QJBAMGKsxJkg3M6sZEO4zUgWgnGN+uS6nwAWpCfBY7eDvYSN78BxGGLgn+t40c0R8M/n85IM8OUmfHxTGWN3hYyGuUCQQCs+Kg1ypul9XLTWrVApyvZxY4ZxjAWG4yW4xqbUtHWUkGyle7Dy8xiYezl0kWN81lJNTz3qrJ4ZvM825+7tPw1AkBDPNxZV3ITZiCqNHHa0xJ0sthajv/HdJgCBjz4FU09T7buNL705HLByLdc1VzZCBGMqKjTGZ0h4KKZ5V9ydpXBAkABpZx0Zql0uxGM0aBILU9Nk4P22tw6WajNBvyJ3hABamcVvDe5xYb8qNIInifrYhXHjKo38XghjVljivPKZb7BAkAt4pCUYLI7LzLeSh/lnVxA7jOaRI3UsngCXn9VA4f+dkNcKAftRQqe7ytudqG07GKoInnDiyjrYe4kTLym8zoc";
  914. // string OrgId = "88031499";
  915. // string SftReqUrl = "https://zqbtest.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  916. public string SftEncrypt(string data)
  917. {
  918. var rsa = RSA.Create();
  919. var key = Convert.FromBase64String(SftPrivateKey);
  920. var content = Encoding.UTF8.GetBytes(data);
  921. rsa.ImportPkcs8PrivateKey(key, out _);
  922. var result = rsa.SignData(content, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
  923. return Convert.ToBase64String(result);
  924. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, SftPrivateKey).Encrypt(data);
  925. }
  926. //设置机具押金
  927. public string SetFeeForSft(string merchantId, string Rate, string fee = "0")
  928. {
  929. Dictionary<string, object> req = new Dictionary<string, object>();
  930. req.Add("orgPromoterId", OrgId);
  931. req.Add("promoterId", OrgId);
  932. List<Dictionary<string, object>> merchantFeeList = new List<Dictionary<string, object>>();
  933. Dictionary<string, object> item = new Dictionary<string, object>();
  934. item.Add("merchantId", merchantId);
  935. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  936. Dictionary<string, object> feeItem = new Dictionary<string, object>();
  937. feeItem.Add("feeType", "CC");
  938. feeItem.Add("feeRate", Rate);
  939. feeItem.Add("feeDisRate", Rate);
  940. feeList.Add(feeItem);
  941. feeItem = new Dictionary<string, object>();
  942. feeItem.Add("feeType", "T0_CC");
  943. feeItem.Add("feeRate", fee);
  944. feeItem.Add("feeDisRate", fee);
  945. feeList.Add(feeItem);
  946. item.Add("feeList", feeList);
  947. merchantFeeList.Add(item);
  948. req.Add("merchantFeeList", merchantFeeList);
  949. req.Add("signType", "RSA");
  950. req.Add("charType", "UTF-8");
  951. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  952. req.Add("requestTime", function.GetCurTimestamp());
  953. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  954. string signString = "";
  955. foreach (string key in req.Keys)
  956. {
  957. if (key == "merchantFeeList")
  958. {
  959. signString += key + "=" + Newtonsoft.Json.JsonConvert.SerializeObject(req[key]) + "&";
  960. }
  961. else
  962. {
  963. signString += key + "=" + req[key].ToString() + "&";
  964. }
  965. }
  966. signString = signString.TrimEnd('&');
  967. req.Add("mac", SftEncrypt(signString));
  968. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(req), "设置盛付通机具费率");
  969. string result = function.PostWebRequest(SftReqUrl + "batchChangeMerchantFee", Newtonsoft.Json.JsonConvert.SerializeObject(req), "application/json");
  970. function.WriteLog(result + "\n\n", "设置盛付通机具费率");
  971. return result;
  972. }
  973. #endregion
  974. #region 海科
  975. string HKPrivateKey1 = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK5iJ2q2nF+9jEnof9VYhMdbAgI0ZS4cYmgWTMW2JR61lJhR0GH+A/m6mjN9FsTS6Bq03u/+e6BKdE6VqMGk0q7asi2VZIgD59zj4HubS8EFrcb5ZprwmGLnG71cBga7V5EWnHxSB9BlbFt6rGeQiit8NSbv62NxGh1U+rAVE/a3AgMBAAECgYEApQGxpJNowls8bQ74LytUcMMX0ng7qXcoUq+PM6IX28gb9EmuMZtHrb05fjEGI3YiNGsjbNpTpqftCBMrHRjWVRgb0PDf/zD9YYrxmcP9DWKQjG5f1ygYtQBlnOPEX963Y2SXrsTKr4+szTpI8r6YqFfVbbooKVMesCBtshgg16kCQQDYHGDuCuOzULP84QvGi8z+wHNv0arFpYYxvwitntD7K3iolAh8gTDWeaC03MHruGM43ybCUi9EHhCrcVKjgpK1AkEAzpIUajdmAAwtwGg4G0v7tP/ulmpGhnALVN84gSMAc5f8D6aCnoUyle+GylwRBw9WblHBLxsOtARQIvvdphDrOwJBAIFvXc60zvQTHfoTf84G5VyfP4R1e2atYNZiqHv0Zw5IVxgAsaSAbBPI/SvWHH9mDGd/n+M6/fw6VZmZYfl0txECQQCQB3yifpPpDpTL5h7QsY8EKbqyN9GKpQ7Rk35zU/NZpawDQYcrfhXCQytJZx4cPQ53hxtae9QpoiQ58EEgLAXHAkABzJ/QDS1QfYrkP9t9X+Pny2iEuWGeIHyfsfSKQKr5pv16k1WqiIvlFRyDPl+aw5IOedkYb0vSkcU1KzjMW+Ra";
  976. string HKPublicKey1 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuYidqtpxfvYxJ6H/VWITHWwICNGUuHGJoFkzFtiUetZSYUdBh/gP5upozfRbE0ugatN7v/nugSnROlajBpNKu2rItlWSIA+fc4+B7m0vBBa3G+Waa8Jhi5xu9XAYGu1eRFpx8UgfQZWxbeqxnkIorfDUm7+tj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ku+sHaR7ylBm9ezc/3/Xs6+bQIDAQAB";
  979. string HKOrgNo1 = "747187394495131648"; //电签pos
  980. string HKOrgNo2 = "747189644974104576"; //大pos
  981. string HKReqUrl = "https://org-push.juheposp.com"; //请求url
  982. public string HKDecrypt(string data, string sign, int Kind)
  983. {
  984. string HKPrivateKey = Kind == 8 ? HKPrivateKey1 : HKPrivateKey2;
  985. var toDecryptArray = Convert.FromBase64String(sign);
  986. var rsa2 = RSA.Create();
  987. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(HKPrivateKey), out _);
  988. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  989. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  990. return AesDecrypt(data, aeskey);
  991. }
  992. public string HKEncrypt(string sign, int Kind)
  993. {
  994. string HKPrivateKey = Kind == 8 ? HKPrivateKey1 : HKPrivateKey2;
  995. string HKPublicKey = Kind == 8 ? HKPublicKey1 : HKPublicKey2;
  996. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", HKPublicKey).Encrypt(sign);
  997. }
  998. public string HKAesEncrypt(string str, string aeskey)
  999. {
  1000. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  1001. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  1002. {
  1003. Key = Encoding.UTF8.GetBytes(aeskey),
  1004. Mode = System.Security.Cryptography.CipherMode.ECB,
  1005. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  1006. };
  1007. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  1008. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  1009. return Convert.ToBase64String(resultArray);
  1010. }
  1011. //设置机具押金
  1012. public string SetDepositForHK(string snNo, string oldMarketId, string newMarketId, int BrandId)
  1013. {
  1014. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  1015. return HKReqFunc("/org/pos/updatePosMarket", data, BrandId);
  1016. }
  1017. //查询配置活动信息
  1018. public string HKQueryActiveForConfig(string snNo, int BrandId)
  1019. {
  1020. string data = "{\"snNo\":\"" + snNo + "\"}";
  1021. return HKReqFunc("/org/pos/getMarketConfig", data, BrandId);
  1022. }
  1023. //查询营销活动信息
  1024. public string HKQueryActiveForBrand(int marketType, int BrandId)
  1025. {
  1026. string data = "{\"marketType\":\"" + marketType + "\"}";
  1027. return HKReqFunc("/org/pos/marketList", data, BrandId);
  1028. }
  1029. //终端费率模板查询
  1030. public string HKQueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  1031. {
  1032. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  1033. return HKReqFunc("/org/pos/rateConfigList", data, BrandId);
  1034. }
  1035. //终端费率查询
  1036. public string HKQueryFeeForBrand(string snNo, int BrandId)
  1037. {
  1038. string data = "{\"snNo\":\"" + snNo + "\"}";
  1039. return HKReqFunc("/org/pos/getRateConfig", data, BrandId);
  1040. }
  1041. //终端费率模板修改
  1042. public string HKSetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  1043. {
  1044. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  1045. return HKReqFunc("/org/pos/updatePosRate", data, BrandId);
  1046. }
  1047. public string HKReqFunc(string apiPath, string data, int BrandId)
  1048. {
  1049. function.WriteLog(DateTime.Now.ToString(), "设置海科机具费率");
  1050. function.WriteLog(data, "设置海科机具费率");
  1051. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  1052. string req = "{";
  1053. if (BrandId == 8)
  1054. {
  1055. req += "\"orgId\":\"" + HKOrgNo1 + "\",";
  1056. }
  1057. else
  1058. {
  1059. req += "\"orgId\":\"" + HKOrgNo2 + "\",";
  1060. }
  1061. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  1062. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  1063. req += "\"version\":\"1.0\",";
  1064. req += "\"data\":\"" + HKAesEncrypt(data, aeskey) + "\",";
  1065. req += "\"sign\":\"" + HKEncrypt(aeskey, BrandId) + "\"";
  1066. req += "}";
  1067. function.WriteLog(req, "设置海科机具费率");
  1068. string result = function.PostWebRequest(HKReqUrl + apiPath, req, "application/json");
  1069. function.WriteLog(result + "\n\n", "设置海科机具费率");
  1070. return result;
  1071. }
  1072. #endregion
  1073. #region 联动
  1074. //测试环境
  1075. // string LDRequestUrl = "http://111.14.221.188:18066/CloudTerminalServiceAction/";
  1076. // string AgentNo = "LD110014";
  1077. // string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3WG04QXTzWBg2rj4BbSmnXVTqQiCk2lZ7yi2vur2LxsSc+KN0o1W9y2AkCHcFIAk2aAfMEMQYTO3HQ+F/Vcb27BNBSjnaOLfGv0PXNHKyVzC4EQLe4M5Pqd1wMl6NaZK+HnyrPBTnfsGeywhGJc1Ke96ANrydhk7UbwezydC7nQIDAQAB";
  1078. // string LDPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJwUiLkXb6zTpvNmB+zTZtuJi97/XCdGBWgiMn/2ayVEtRuarPOvMUQo0aX4Pb/JrfdFyQccXiXFGtmh/m5Mhfuj03t0pOTC4bniQAy2veytDhnRImL1xY9YjSMX+YRXI44VRcNUSefyNmBjL7V1HgbJOfnq/PmVkcBClTf1gtefAgMBAAECgYBRbYkS/34crWNJUq7JyFS+LllRounh9270r/qmtdmaXOkbmKuoinrqc11E+GjGuSJQghDp68vWaqmiZxhFVRkEqPzaesYyMJr73GB/efXhIRWWGCqQvARs3QgOFmCL2YsC/Vq7niI72mmNLC9jOUFN30vCnJH7xI2PljfQKBLwkQJBAN1/JRJmt+2ms/eeGsI/tgClciCAfHzTtAhPHRs7XL98mzk8IDGFjysKsiSacAym5e0xV1uB6ijsuAm61go4b8cCQQC0ZLVyKdUPadhzXSjyOqtk4HVzorHW6OkDCnMazL0CYLxdJOQzrpicPhww0TB397rqLC+FuGEOEcjrDnYyGQlpAkEAq4OU9VbM/h2kJg4rslcbXAzA/yH/Q7m7IuQAKeIhw7V9jShd1XsSjcXOhEGCmolyaeVXO+ixpdcH+6DNtURWaQJACh5L/ydRiBfLyEzFazDXREVC0UWi7AcMats/MZWiVGvQpPjYw/1bGghx1FsneNMwbMolsD5zUzK0LlsVTiIRYQJAZT0p0Mg3kqSaYO2JlC6fTkI9aHMJ50iDr8qLJ2JnrNFylDxxoHwKfA7GxA2KGotguGTKhw7xCp+IyrXtXiuNrQ==";
  1079. //生产环境
  1080. string LDRequestUrl = "http://ldys.umpay.com/service_exter/CloudTerminalServiceAction/";
  1081. string AgentNo = "LD112692";
  1082. string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGtWShTeFEgSSFx3PJXcjCOmS+OgtcUvPOHhpALY3Orm6t7rl1E0n3j7XlM049YwwtGRJI4OWhgrtR4/AnOMBXdyMBoKxF23uay1WQiNekzfUrTwil7/CRrQ+VlGgPe6dr3WQT2/HLbzMnJHeoIZ4KSIj/7pgAwTF4ciL1UC3awwIDAQAB";
  1083. string LDPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJwUiLkXb6zTpvNmB+zTZtuJi97/XCdGBWgiMn/2ayVEtRuarPOvMUQo0aX4Pb/JrfdFyQccXiXFGtmh/m5Mhfuj03t0pOTC4bniQAy2veytDhnRImL1xY9YjSMX+YRXI44VRcNUSefyNmBjL7V1HgbJOfnq/PmVkcBClTf1gtefAgMBAAECgYBRbYkS/34crWNJUq7JyFS+LllRounh9270r/qmtdmaXOkbmKuoinrqc11E+GjGuSJQghDp68vWaqmiZxhFVRkEqPzaesYyMJr73GB/efXhIRWWGCqQvARs3QgOFmCL2YsC/Vq7niI72mmNLC9jOUFN30vCnJH7xI2PljfQKBLwkQJBAN1/JRJmt+2ms/eeGsI/tgClciCAfHzTtAhPHRs7XL98mzk8IDGFjysKsiSacAym5e0xV1uB6ijsuAm61go4b8cCQQC0ZLVyKdUPadhzXSjyOqtk4HVzorHW6OkDCnMazL0CYLxdJOQzrpicPhww0TB397rqLC+FuGEOEcjrDnYyGQlpAkEAq4OU9VbM/h2kJg4rslcbXAzA/yH/Q7m7IuQAKeIhw7V9jShd1XsSjcXOhEGCmolyaeVXO+ixpdcH+6DNtURWaQJACh5L/ydRiBfLyEzFazDXREVC0UWi7AcMats/MZWiVGvQpPjYw/1bGghx1FsneNMwbMolsD5zUzK0LlsVTiIRYQJAZT0p0Mg3kqSaYO2JlC6fTkI9aHMJ50iDr8qLJ2JnrNFylDxxoHwKfA7GxA2KGotguGTKhw7xCp+IyrXtXiuNrQ==";
  1084. public string LDEncrypt(string data)
  1085. {
  1086. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LDPublicKey).Encrypt(data);
  1087. }
  1088. public string LDDecrypt(string data)
  1089. {
  1090. var toDecryptArray = Convert.FromBase64String(data);
  1091. var toKey = Convert.FromBase64String(LDPrivateKey);
  1092. var rsa = RSA.Create();
  1093. rsa.ImportPkcs8PrivateKey(toKey, out _);
  1094. string result = "";
  1095. List<byte> cache = new List<byte>();
  1096. for (int i = 0; i < toDecryptArray.Length; i++)
  1097. {
  1098. cache.Add(toDecryptArray[i]);
  1099. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  1100. {
  1101. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  1102. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  1103. cache.Clear();
  1104. }
  1105. }
  1106. return result;
  1107. }
  1108. public string LDServiceFee(string SnList, int ServiceFee, int BrandId)
  1109. {
  1110. function.WriteLog(DateTime.Now.ToString(), "设置联动机具服务费");
  1111. function.WriteLog(SnList, "设置联动机具服务费");
  1112. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1113. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1114. string TerminalModeName = BrandId == 10 ? "DZA" : "DZDA";
  1115. int PosType = BrandId == 10 ? 2 : 3;
  1116. reqdic.Add("rpid", RequestId); //请求流水
  1117. reqdic.Add("agentNumber", AgentNo); //代理商编号
  1118. reqdic.Add("snList", SnList.Split(',').ToList()); //SN号
  1119. reqdic.Add("posType", PosType); //2:电签 3 大pos
  1120. reqdic.Add("terminalModeName", TerminalModeName); //终端模式名
  1121. reqdic.Add("fwfRate", ServiceFee); //服务费
  1122. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1123. function.WriteLog(req, "设置联动机具服务费");
  1124. req = LDEncrypt(req);
  1125. function.WriteLog(req, "设置联动机具服务费");
  1126. Dictionary<string, object> datadic = new Dictionary<string, object>();
  1127. datadic.Add("encryptedData", req);
  1128. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  1129. function.WriteLog("请求地址:" + LDRequestUrl + "terminalSelfDistribute", "设置联动机具服务费");
  1130. string result = function.PostWebRequest(LDRequestUrl + "terminalSelfDistribute", data, "application/json");
  1131. function.WriteLog(result + "\n\n", "设置联动机具服务费");
  1132. return result;
  1133. }
  1134. public string LDFeeRate(string MerNo, string Fee, int BrandId, int addRate = 0)
  1135. {
  1136. function.WriteLog(DateTime.Now.ToString(), "设置联动机具费率");
  1137. function.WriteLog(MerNo, "设置联动机具费率");
  1138. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1139. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1140. string MercModel = BrandId == 10 ? "DZA" : "DZDA";
  1141. int PosType = BrandId == 10 ? 2 : 3;
  1142. reqdic.Add("rpid", RequestId); // 请求流水(2字母开头+13位数字)
  1143. reqdic.Add("agentNumber", AgentNo); // 代理编号
  1144. reqdic.Add("mercModel", MercModel); // 商户模式
  1145. reqdic.Add("rate", Fee); // 费率 如 0.0053
  1146. reqdic.Add("addRate", addRate); // 附加费 如0
  1147. reqdic.Add("rateType", "M015"); // 秒刷 M015 扫码 S010 特惠 T015
  1148. reqdic.Add("mercId", MerNo); // 商户编号
  1149. reqdic.Add("cardType", "01"); // 01 贷记卡 02 扫码
  1150. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1151. function.WriteLog(req, "设置联动机具费率");
  1152. req = LDEncrypt(req);
  1153. function.WriteLog(req, "设置联动机具费率");
  1154. Dictionary<string, object> datadic = new Dictionary<string, object>();
  1155. datadic.Add("encryptedData", req);
  1156. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  1157. function.WriteLog("请求地址:" + LDRequestUrl + "updateMercRate", "设置联动机具费率");
  1158. string result = function.PostWebRequest(LDRequestUrl + "updateMercRate", data, "application/json");
  1159. function.WriteLog(result + "\n\n", "设置联动机具费率");
  1160. return result;
  1161. }
  1162. #endregion
  1163. #region 盒易付
  1164. //测试环境
  1165. // string BoxRequestUrl = "https://openapi-test.iboxpay.com/api";
  1166. // string BoxAppId = "8840021411446784";
  1167. // string BoxAppSecret = "xgwGnmYGjVy0GOWOWkQtRk8Hk8ur5tCV";
  1168. // string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjMQxp24mjxDTr13uPW0y+tiO1yXFGw7P/pPQ0oZKK7F6KstEaus7pLEywBZ5XRXE5jgkhR2TS7Ne7djJfbpn5yFc6pPlz3ZsOfBVeB88NEwhx6xzCGX2eqSSkO33n8w2G0xc2ss5HpYBarT00NBZWhrwOXpdRPYLOYHKVU3Rl+FA9xDw/wYfoWvrr+JSfHRGn/ENMmQFEdckAbPauKaQMrZD2kz+PRrhq56eWnCuVQPcaz/jroVT8qQEgkg2IsNy+DwfLOIqm8IySEpxnQ5wN/KvsQJc2wXDQNf9F5kvWwjoqSSP0qJS+oPRXET+zJb+WTk2y5M6AYoC9NodwsC4NwIDAQAB";
  1169. // string BrhCode = "039001";
  1170. //生产环境
  1171. string BoxRequestUrl = "https://openapi.iboxpay.com/api";
  1172. string BoxAppId = "AP5879017839106039808";
  1173. string BoxAppSecret = "DGtftIyl6R3nzwPr5YuV5fnmkfwufXRj";
  1174. string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmjoQirIYZBD9Qon2HkF4j/NAINXtJ7Lzq/WXxTF7t7mg7LNARt0+ZZaeWx8caq2fv5zdsGyyoInL23cBtDI5KmFfK69iA0ygQMK0WbiKqsUB1OpPbT3+9zLuadIJAznjA223lY6CIjTpdLZhaRjImNVqc60bdkx6YsQcA+xW+3r1JH4PPHb7yBEbkKIX8OhyX7U4p0TkbDkAobbjHr5YB9gmYLoSFJMOPfTtSExkv7/Y7IVR9poZAHcr3teFoAiXW3RzxelRtnXxIkl/6AUOKoL5fhr/UTUN+Q18uzNljYWr6SwnTI3EmtzgykaewWtZvV85Xdhe/BjiQ5Xor7YbwIDAQAB";
  1175. string BrhCode = "039004";
  1176. public string BoxFee(string MerNo, string Fee)
  1177. {
  1178. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具费率");
  1179. function.WriteLog(MerNo, "设置盒易付机具费率");
  1180. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1181. Dictionary<string, string> headdic = new Dictionary<string, string>();
  1182. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1183. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1184. headdic.Add("appid", BoxAppId);//开发者id
  1185. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  1186. headdic.Add("X-Up-AppId", BoxAppId);
  1187. headdic.Add("X-Timestamp", timestamp);
  1188. headdic.Add("X-Sign-Type", "SHA-256");
  1189. reqdic.Add("mchtNo", MerNo);//终端列表
  1190. reqdic.Add("brhCode", BrhCode);//机构号
  1191. //MHN10917(贷记0.63%,借记卡0.63%/25) MHN10916(贷记0.60%,借记卡0.60%/25)
  1192. reqdic.Add("tNDiscId", Fee == "0.60" ? "MHN10916" : "MHN10917");//费率模型
  1193. reqdic.Add("effectiveFlag", "1");//立即生效
  1194. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1195. headdic.Add("X-Sign", BoxSHA256Sign(timestamp + BoxAppSecret + req));
  1196. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  1197. function.WriteLog("请求头\n" + head, "设置盒易付机具费率");
  1198. function.WriteLog("请求参数\n" + req, "设置盒易付机具费率");
  1199. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/mcht/update_disc", "设置盒易付机具费率");
  1200. string result = PostWebRequest(BoxRequestUrl + "/inst/mcht/update_disc", req, headdic);
  1201. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具费率");
  1202. return result;
  1203. }
  1204. public string BoxSHA256Sign(string toSignStr)
  1205. {
  1206. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  1207. SHA256 sha256 = SHA256.Create();
  1208. byte[] signByte = sha256.ComputeHash(toSignByte);
  1209. string sign = Convert.ToBase64String(signByte);
  1210. return sign;
  1211. }
  1212. public bool BoxVerifySign(string toSignStr, string signStr)
  1213. {
  1214. byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
  1215. byte[] signByte = Convert.FromBase64String(signStr);
  1216. var toKey = Convert.FromBase64String(BoxPublicKey);
  1217. var rsaroot = RSA.Create();
  1218. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  1219. var publicKeyParameters = rsaroot.ExportParameters(false);
  1220. using (var rsa = RSA.Create())
  1221. {
  1222. rsa.ImportParameters(publicKeyParameters);
  1223. var sha256 = SHA256.Create();
  1224. var hash = sha256.ComputeHash(toSignByte);
  1225. return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1226. }
  1227. }
  1228. public string BoxSignData(string toSignStr)
  1229. {
  1230. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  1231. var toKey = Convert.FromBase64String(BoxPublicKey);
  1232. var rsaroot = RSA.Create();
  1233. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  1234. var publicKeyParameters = rsaroot.ExportParameters(false);
  1235. using (var rsa = RSA.Create())
  1236. {
  1237. rsa.ImportParameters(publicKeyParameters);
  1238. var sha256 = SHA256.Create();
  1239. var hash = sha256.ComputeHash(toSignByte);
  1240. byte[] endByte = rsa.SignData(toSignByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1241. return Convert.ToBase64String(endByte);
  1242. }
  1243. }
  1244. #endregion
  1245. }
  1246. }