SetDepositPostService.cs 84 KB

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