SetDepositPostService.cs 84 KB

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