SetDepositPostService.cs 86 KB

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