SetDepositPostService.cs 84 KB

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