SetDepositPostService.cs 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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. 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. if(content.Contains("|"))
  86. {
  87. content = content.Split("|")[1];
  88. JsonData obj = JsonMapper.ToObject(content);
  89. if(obj["errorCode"].ToString() == "0000")
  90. {
  91. pos.SeoDescription = "设置成功";
  92. SetRecordResult(db, RecordId, 1, "设置成功");
  93. db.SaveChanges();
  94. }
  95. else
  96. {
  97. string msg = obj["errorCodeDesc"].ToString();
  98. pos.SeoDescription = msg;
  99. SetRecordResult(db, RecordId, -1, msg);
  100. db.SaveChanges();
  101. }
  102. }
  103. else
  104. {
  105. JsonData obj = JsonMapper.ToObject(content);
  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. }
  343. }
  344. }
  345. db.Dispose();
  346. Thread.Sleep(500);
  347. }
  348. catch (Exception ex)
  349. {
  350. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置费率到支付平台异常");
  351. }
  352. }
  353. else
  354. {
  355. Thread.Sleep(500);
  356. }
  357. }
  358. }
  359. private void SetRecordResult(WebCMSEntities db, int RecordId, int Status, string Note = "")
  360. {
  361. if(RecordId > 0)
  362. {
  363. PosMachinesFeeChangeRecord record = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == RecordId);
  364. if(record != null)
  365. {
  366. record.Status = Status;
  367. record.SeoDescription = Note;
  368. }
  369. }
  370. }
  371. public void StartKdb()
  372. {
  373. Thread th = new Thread(StartKdbDo);
  374. th.IsBackground = true;
  375. th.Start();
  376. }
  377. private void StartKdbDo()
  378. {
  379. while (true)
  380. {
  381. try
  382. {
  383. WebCMSEntities db = new WebCMSEntities();
  384. var poslist = db.PosMachinesTwo.Select(m => new { m.Id, m.BrandId, m.SeoDescription }).Where(m => m.BrandId == 2 && m.SeoDescription.StartsWith("提交成功|")).ToList();
  385. foreach (var pos in poslist)
  386. {
  387. string[] datalist = pos.SeoDescription.Split('|');
  388. string orderNo = datalist[1];
  389. int RecordId = int.Parse(datalist[2]);
  390. string content = QueryFee(orderNo);
  391. JsonData obj = JsonMapper.ToObject(content);
  392. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.Id);
  393. if(edit != null)
  394. {
  395. if(obj["status"].ToString() == "HANDLE_STATUS_COMPLETE")
  396. {
  397. edit.SeoDescription = "设置成功";
  398. SetRecordResult(db, RecordId, 1, "设置成功");
  399. db.SaveChanges();
  400. }
  401. else if(obj["status"].ToString() == "HANDLE_STATUS_FAIL")
  402. {
  403. edit.SeoDescription = "设置失败";
  404. SetRecordResult(db, RecordId, -1, "设置失败");
  405. db.SaveChanges();
  406. }
  407. }
  408. }
  409. db.Dispose();
  410. }
  411. catch(Exception ex)
  412. {
  413. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "开店宝费率异步获取结果异常");
  414. }
  415. Thread.Sleep(5000);
  416. }
  417. }
  418. #region 金控
  419. // 开发环境
  420. // string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCy8cg6/tXbSj2i1tyi7VztwJw7uNmqc3bS6sVIZkDYhTmcXhpV17jq4j2zz/tURwX8b3MdK1A1HTR1XRd7hl0w2UF9iFk6UezByJ5tdNDoffMCGJtVSThq+MCV+WQI26tJ/ub6bm7GPrzTR79fntN+nTniRM4trjONN2WzEhHEcwIDAQAB";
  421. // 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/Xp33eB0gc13kKQy1GlWdAkB6Emn94YesoHda26HWbrgBy18KSfcLH57EuXquX/pOma1TXjaXw1E7kkFz1EPde9WzuSWUmGN2AdJT0ruTOb4C";
  422. // string clientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCb861uuey1252WdS8KPeBB+vm5AIBEKclsfBzVLY1cZXiiEbInCmsqT6fSO+A6wjWyJixGCzZICmUxhdBzuo3Du2YTbuo+fRlV6DW1mbguBV8/l2+LJvht0jl87J8N4skFUzvAeYKpWDX6dC6cLzjm5nyI1OrCQq0lsWPEMDCNAwIDAQAB";
  423. // string clientPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJvzrW657LXbnZZ1Lwo94EH6+bkAgEQpyWx8HNUtjVxleKIRsicKaypPp9I74DrCNbImLEYLNkgKZTGF0HO6jcO7ZhNu6j59GVXoNbWZuC4FXz+Xb4sm+G3SOXzsnw3iyQVTO8B5gqlYNfp0LpwvOObmfIjU6sJCrSWxY8QwMI0DAgMBAAECgYAjE0dqo/6NWHu1H14ZG5mYvW31Ihu3OP7Im5GQkNI+ecQMD5bWGQ3JUmkYa8ce8BdLnjJO/q6SvWPNI5+ip87CYPH1SMXKUiSLzaCrw4xMySW9PSnudTzJwhrmlmyjYTAg70tHf2YQC4YkNvtkR+PJ2yf6JEKGFVgP5p2KyeKXgQJBANjGryxyu95QC3jIaggcYmGD36sVO/ns8Uyu8PkAHYOscuXRcV0L8LghIzPolcehj9bTbDLjiuNgeuyjNs2YBvMCQQC4K4uIXt0kVDLYzlJfhN1CsV90vQitcKdD8wTO0JRKfMCQ6UDSumU7lq+z4TxTlRYxmZjpgIqH+N0WohmEiwWxAkBEfuMzBD3gjSJS0+DNF0ruzSCLinYdDoVgWZbC1wp8ZK0ZeQh9AhzZ0X6yFDffkGlG1B9IJSXpmr68rwXOCM+JAkBkrKEUxc6bGk/FRluvDWEqIO2uUdtZfBhjQ4ggSdKWOUXGsUsXJn9KKKAZc4lXo0rDiFQXaIXRuE+bHLdYReqxAkAj0Kol0LkJgdl2PoBAeyQHTpt9nxaeNX56W7CN/srBA1O2wr+aoQiJaKsu9I0EeW3zaMJlLi3VyjU4wnF+yAsB";
  424. // string reqUrl = "https://test-push.mfe88.com/push-service/api/MODIFYPERPOSFEE";
  425. // 生产环境
  426. string merchantNo = "4487378308096";
  427. string clientId = "1243966544896";
  428. string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2HxPVZ5ZIxIWfr24qB45PAz9WfjN9CiF1x9Lz3P/tVvIXFdBaUw+9zxCAPRDGQxJId7anjEjCOuAIKpFOiTPhVqHTHd3075FFsW5fL7lFCOFJELTj+mVamAIbKalAuRz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klSkigHiKfA6SaRWxxShFtBfjk5XcakmLkU/U5lgD/Blu7h4x6bRf4VPTYWdbxtiOK11rY=";
  431. string reqUrl = "https://push.mfe88.com/push-service/api/MODIFYPERPOSFEE";
  432. public string SetFee(string merNo, string sn, decimal addRate, int fee)
  433. {
  434. // 2021092711IpAreT 降费特惠…刷卡交易手续费
  435. // 2020032508Nu0QCG 刷卡交易手续费
  436. // 2020032508Nx8oyW 借记卡封顶手续费
  437. // 2020032508O4EWB6 刷卡结算手续费
  438. List<SetDepositList> rateDOs = new List<SetDepositList>();
  439. rateDOs.Add(new SetDepositList()
  440. {
  441. productSubType = "2020032508Nu0QCG",
  442. updateValue = addRate,
  443. updateType = 0
  444. });
  445. // rateDOs.Add(new SetDepositList()
  446. // {
  447. // productSubType = "2020032508Nx8oyW",
  448. // updateValue = fee,
  449. // updateType = 0
  450. // });
  451. rateDOs.Add(new SetDepositList()
  452. {
  453. productSubType = "2020032508O4EWB6",
  454. updateValue = fee,
  455. updateType = 0
  456. });
  457. Dictionary<string, string> headers = new Dictionary<string, string>();
  458. headers.Add("X-Client-ID", "4487378308096");
  459. headers.Add("X-Security", "RSA");
  460. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  461. Dictionary<string, object> obj = new Dictionary<string, object>();
  462. obj.Add("merNo", merNo);
  463. obj.Add("sn", sn);
  464. obj.Add("batchUpdateType", 2);
  465. obj.Add("rateDOs", rateDOs);
  466. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  467. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  468. function.WriteLog(content, "设置金控机具费率");
  469. content = Encrypt(content);
  470. string signstr = Sign(content);
  471. headers.Add("X-Sign", signstr);
  472. string headerString = Newtonsoft.Json.JsonConvert.SerializeObject(headers);
  473. function.WriteLog(headerString, "设置金控机具费率");
  474. string req = "{\"param\":\"" + content + "\"}";
  475. function.WriteLog(req, "设置金控机具费率");
  476. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  477. function.WriteLog(result, "设置金控机具费率");
  478. return result;
  479. }
  480. public string SetJkFee(string merNo, string sn, decimal fee = 0.6M)
  481. {
  482. List<SetDepositList> rateDOs = new List<SetDepositList>();
  483. rateDOs.Add(new SetDepositList()
  484. {
  485. productSubType = "2020032007vz7Ux6",
  486. updateValue = fee,
  487. updateType = 0
  488. });
  489. Dictionary<string, string> headers = new Dictionary<string, string>();
  490. headers.Add("X-Client-ID", clientId);
  491. headers.Add("X-Security", "RSA");
  492. Dictionary<string, object> obj = new Dictionary<string, object>();
  493. obj.Add("merNo", merNo);
  494. obj.Add("sn", sn);
  495. obj.Add("batchUpdateType", 2);
  496. obj.Add("rateDOs", rateDOs);
  497. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  498. function.WriteLog(DateTime.Now.ToString(), "设置金控机具费率");
  499. function.WriteLog(content, "设置金控机具费率");
  500. content = Encrypt(content);
  501. string signstr = Sign(content);
  502. headers.Add("X-Sign", signstr);
  503. string req = "{\"param\":\"" + content + "\"}";
  504. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  505. function.WriteLog(result, "设置金控机具费率");
  506. return result;
  507. }
  508. public string Decrypt(string data)
  509. {
  510. var toDecryptArray = Convert.FromBase64String(data);
  511. var rsa = RSA.Create();
  512. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  513. string result = "";
  514. List<byte> cache = new List<byte>();
  515. for (int i = 0; i < toDecryptArray.Length; i++)
  516. {
  517. cache.Add(toDecryptArray[i]);
  518. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  519. {
  520. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  521. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  522. cache.Clear();
  523. }
  524. }
  525. return result;
  526. }
  527. public string Encrypt(string data)
  528. {
  529. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", mfe88PublicKey).Encrypt(data);
  530. }
  531. public string Sign(string data)
  532. {
  533. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  534. var rsa = RSA.Create();
  535. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  536. string result = "";
  537. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  538. result = Convert.ToBase64String(buffer);
  539. return result;
  540. }
  541. #endregion
  542. #region 开店宝
  543. //生产环境
  544. string KdbApiUrl = "https://kzy.kdb-tj.com:5055/api";
  545. string KDBAESKEY = "F@xh#sga41c08@pe";
  546. string Kdb_Rsa_PrivateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAl2x9dSSCfNDik6VM2dn/SK1ONSbb7AKyXM1gHw8PMbzWN1pK7YGaPqHlIRbAeFeIvLKVeMxrji+63W6LpB0yDQIDAQABAkAfpHUnCIUYDhJ65f0EPTDCgCyqoL8uN3YMPIKMmvoC22/i7AC6zf/bWk4JdratN+gvvnjGgHQff6HH5dOQ6sbFAiEAxPYSLADzIv374J8O+LluXIcgI5zXm4r4dMtKbCmmWSsCIQDE0BRKsBcBZ9NvJ9Km+m/d1hN9v5hFT842zrkUFJmVpwIgBdYc17z3d3P7QL613NzxzkAazbNaGDvX/O4BOI9LZJ0CICrZElHgXGHV9NYyWU45H7mwLbYmzEPqx/5uqySQB4/pAiBgKYv3RGnsZ8Zm1EKAJjUX7ehdteBgPSA/UgIDZQ4oyw==";
  547. string AgencyId = "3013890129";
  548. //开发环境
  549. // string KdbApiUrl = "https://kzy-test.kdb-tj.com:5056/api";
  550. // string KDBAESKEY = "Ebn4N28MvEXEvPTA";
  551. // string Kdb_Rsa_PrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAsPyH5Y5NySHHKWIgPwxbZFkd33vzuWKv+Kdpug5/qYAnpTShDSMXQ2Ib7gc+B/yvj4uZ/k1A/xHpzHTPl6MzQQIDAQABAkA2sGHhyj45B2n+XKbwNIZNFMiJVUjzoQ4VPM4Lww0pt781GeqBCGgEIgTjmmg/FTGjgwTb7ta1A5G9Qn2nPG0RAiEA4x7W6XKdSL/FyVdlt4jijNQNZfLEqEPy1NnchRWUf40CIQDHfb49KP3pW4ZDX3xS42fYd9p7AGZ+qpVBnJfGGyFrhQIhALk3HCHyowuBwMUKLdw3mDEqeOarzO4/w1cLd8dcKua9AiEAtdPAj9JLDGWljMb9dDddsYockzwcL5ufizwFgkW8QlkCIADYU4+fFKqySLGX3MmEIJ/mU632PRtJAh4LSL8/Ij1H";
  552. // string AgencyId = "3013890202";
  553. // 修改费率接口
  554. public string ModifyFee(string PosSn, decimal Rate, string Fee = "0")
  555. {
  556. string url = KdbApiUrl + "/pos/rate/modify/single/remote";
  557. string content = "{\"posSn\":\"" + PosSn + "\",\"type\":\"贷记卡刷卡\",\"rate\":\"" + Rate + "\",\"d0Fee\":\"0\"}";
  558. return PostKDB(url, content);
  559. }
  560. // 查询费率接口
  561. public string QueryFee(string orderNo)
  562. {
  563. string url = KdbApiUrl + "/pos/rate/change/query/orderno";
  564. string content = "{\"orderNo\":\"" + orderNo + "\"}";
  565. return PostKDB(url, content);
  566. }
  567. public string KDBDecrypt(string data)
  568. {
  569. string result = AesDecrypt(data, KDBAESKEY);
  570. return result;
  571. }
  572. public string AesDecrypt(string str, string key)
  573. {
  574. if (string.IsNullOrEmpty(str)) return null;
  575. byte[] toEncryptArray = Convert.FromBase64String(str);
  576. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  577. {
  578. Key = Encoding.UTF8.GetBytes(key),
  579. Mode = System.Security.Cryptography.CipherMode.ECB,
  580. Padding = System.Security.Cryptography.PaddingMode.PKCS7,
  581. };
  582. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
  583. byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  584. return Encoding.UTF8.GetString(resultArray);
  585. }
  586. public string AesEncrypt(string str)
  587. {
  588. // if (string.IsNullOrEmpty(str)) return null;
  589. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  590. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  591. {
  592. Key = Encoding.UTF8.GetBytes(KDBAESKEY),
  593. Mode = System.Security.Cryptography.CipherMode.ECB,
  594. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  595. };
  596. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  597. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  598. return Convert.ToBase64String(resultArray);
  599. }
  600. public string PostKDB(string url, string content)
  601. {
  602. content = AesEncrypt(content);
  603. string timestamp = function.GetCurTimestamp().ToString();
  604. string sign = KDBSign(content + timestamp);
  605. string req = "{\"agencyId\":\"" + AgencyId + "\",\"content\":\"" + content + "\",\"timestamp\":\"" + timestamp + "\",\"sign\":\"" + sign + "\"}";
  606. string result = PostWebRequestKdb(url, req, new Dictionary<string, string>());
  607. return result;
  608. }
  609. private string PostWebRequestKdb(string postUrl, string paramData, Dictionary<string, string> headers)
  610. {
  611. string ret = string.Empty;
  612. try
  613. {
  614. function.WriteLog(DateTime.Now.ToString(), "请求开店宝API日志");
  615. function.WriteLog(postUrl, "请求开店宝API日志");
  616. function.WriteLog(paramData, "请求开店宝API日志");
  617. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  618. // 设置提交的相关参数
  619. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  620. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  621. request.Method = "POST";
  622. request.KeepAlive = false;
  623. request.AllowAutoRedirect = true;
  624. request.ContentType = "application/json";
  625. foreach (string key in headers.Keys)
  626. {
  627. request.Headers.Add(key, headers[key]);
  628. }
  629. 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)";
  630. request.ContentLength = postData.Length;
  631. // 提交请求数据
  632. System.IO.Stream outputStream = request.GetRequestStream();
  633. outputStream.Write(postData, 0, postData.Length);
  634. outputStream.Close();
  635. System.Net.HttpWebResponse response;
  636. System.IO.Stream responseStream;
  637. System.IO.StreamReader reader;
  638. string srcString;
  639. response = request.GetResponse() as System.Net.HttpWebResponse;
  640. responseStream = response.GetResponseStream();
  641. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  642. srcString = reader.ReadToEnd();
  643. ret = srcString; //返回值赋值
  644. reader.Close();
  645. function.WriteLog(srcString, "请求开店宝API日志");
  646. }
  647. catch (System.Net.WebException ex)
  648. {
  649. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)ex.Response;
  650. if(response != null)
  651. {
  652. System.IO.Stream myResponseStream = response.GetResponseStream();
  653. //获取响应内容
  654. System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream);
  655. ret = myStreamReader.ReadToEnd();
  656. myResponseStream.Close();
  657. }
  658. }
  659. catch (Exception ex)
  660. {
  661. ret = "fail";
  662. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求开店宝API异常");
  663. }
  664. return ret;
  665. }
  666. public string KDBSign(string data)
  667. {
  668. var rsa = RSA.Create();
  669. var key = Convert.FromBase64String(Kdb_Rsa_PrivateKey);
  670. var content = Encoding.UTF8.GetBytes(data);
  671. rsa.ImportPkcs8PrivateKey(key, out _);
  672. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  673. return Convert.ToBase64String(result);
  674. }
  675. #endregion
  676. #region 乐刷
  677. 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==";
  678. string LSPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI5Xd35WPkfvVk0djL3EfaliEnZqWsi9xjRoPYL88JF5IQyPxO61+p3S71bmgWy1lwflDofvD38Nxr379w9hh2Qk8zxziq7Nrcs6gvBJjFA0GqFTiNgWOL7QeyIzXvRZSxmcetiRCazJBypzkkMbIvn5QqHsSnNrdau5ELDthftwIDAQAB";
  679. string OrgNo1 = "704067708098457600"; //快联盟电签pos
  680. string OrgNo2 = "704058964878831616"; //快联盟大pos
  681. string LSReqUrl = "https://lfs-org-push.ileshua.com"; //请求url
  682. public string LSDecrypt(string data, string sign)
  683. {
  684. var toDecryptArray = Convert.FromBase64String(sign);
  685. var rsa2 = RSA.Create();
  686. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(LSPrivateKey), out _);
  687. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  688. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  689. return AesDecrypt(data, aeskey);
  690. }
  691. public string LSEncrypt(string sign)
  692. {
  693. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LSPublicKey).Encrypt(sign);
  694. }
  695. public string LSAesEncrypt(string str, string aeskey)
  696. {
  697. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  698. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  699. {
  700. Key = Encoding.UTF8.GetBytes(aeskey),
  701. Mode = System.Security.Cryptography.CipherMode.ECB,
  702. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  703. };
  704. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  705. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  706. return Convert.ToBase64String(resultArray);
  707. }
  708. //设置机具押金
  709. public string SetDepositForLS(string snNo, string oldMarketId, string newMarketId, int BrandId)
  710. {
  711. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  712. return LSReqFunc("/org/pos/updatePosMarket", data, BrandId);
  713. }
  714. //查询配置活动信息
  715. public string QueryActiveForConfig(string snNo, int BrandId)
  716. {
  717. string data = "{\"snNo\":\"" + snNo + "\"}";
  718. return LSReqFunc("/org/pos/getMarketConfig", data, BrandId);
  719. }
  720. //查询营销活动信息
  721. public string QueryActiveForBrand(int marketType, int BrandId)
  722. {
  723. string data = "{\"marketType\":\"" + marketType + "\"}";
  724. return LSReqFunc("/org/pos/marketList", data, BrandId);
  725. }
  726. //终端费率模板查询
  727. public string QueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  728. {
  729. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  730. return LSReqFunc("/org/pos/rateConfigList", data, BrandId);
  731. }
  732. //终端费率查询
  733. public string QueryFeeForBrand(string snNo, int BrandId)
  734. {
  735. string data = "{\"snNo\":\"" + snNo + "\"}";
  736. return LSReqFunc("/org/pos/getRateConfig", data, BrandId);
  737. }
  738. //终端费率模板修改
  739. public string SetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  740. {
  741. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  742. return LSReqFunc("/org/pos/updatePosRate", data, BrandId);
  743. }
  744. public string LSReqFunc(string apiPath, string data, int BrandId)
  745. {
  746. function.WriteLog(DateTime.Now.ToString(), "设置乐刷机具费率");
  747. function.WriteLog(data, "设置乐刷机具费率");
  748. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  749. string req = "{";
  750. if (BrandId == 4)
  751. {
  752. req += "\"orgId\":\"" + OrgNo1 + "\",";
  753. }
  754. else
  755. {
  756. req += "\"orgId\":\"" + OrgNo2 + "\",";
  757. }
  758. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  759. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  760. req += "\"version\":\"1.0\",";
  761. req += "\"data\":\"" + LSAesEncrypt(data, aeskey) + "\",";
  762. req += "\"sign\":\"" + LSEncrypt(aeskey) + "\"";
  763. req += "}";
  764. function.WriteLog(req, "设置乐刷机具费率");
  765. string result = function.PostWebRequest(LSReqUrl + apiPath, req, "application/json");
  766. function.WriteLog(result + "\n\n", "设置乐刷机具费率");
  767. return result;
  768. }
  769. #endregion
  770. #region 立刷
  771. string LiSAgentId = "50814834";
  772. string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4GqoHzDfRk9ibYJ/8iSDGX4+WH5+8mq/raqA77VcAD+bMrt3Bm59XmaWtjZwDY1zh5sP5jEaxu4lde2xZD80kQ6p1ZydpqnjmWm6NKXSz8j85gRkTQqNALKNANnJb6f1Yy30WirnrhMkqU2dqBzzXxtk3k/2zv9BENjYs1igrRYpwX3QRx87aTOrIk/PO6cxMaWl249LPigah0OqVyIg5yOvtnUCdU12OqaVELIw5GnZ7rTRn3tAsJ+u1om+3XktbN3GUEpw5RWAT3UAsAU7Vxt9xPCss+JXF+ogXYgo9QpEjanXOfLo5KPv2CkBuzy87d85OId71gXpYcbp0zbKz5eXKZanVP9pwn43jqiPkqtam8N1TLCCmZ4t2cd+gpW2CX/+W7bmc25HJtRPuwIDAQABAoICAE7B9GfwTGYsYN8xewuOySH8n255jrffXMFJRBLmtgo3kNJI/sFbsxPA6dQJ253a2MxvFNj57gNPInkIqfrcOgJZC/52w9GmFJlYX16bnRgMEEPWhdRYOcjL8bz+SRANsNnVh3M1eWE4GBZBm3NmFVnmeRAjPlFzVUP/pk35sKReL6g+DJ0by0lnC6qqCTp8ON2fEQAh/++o5o/uFRMWwG7ezbO5hBdTGA8uOEGU7CspChlqKtTu2UaeRSVLc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LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  774. public string LiSSign(string data)
  775. {
  776. var rsa = RSA.Create();
  777. var key = Convert.FromBase64String(LiSPrivateKey);
  778. var content = Encoding.UTF8.GetBytes(data);
  779. rsa.ImportPkcs8PrivateKey(key, out _);
  780. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  781. return Convert.ToBase64String(result);
  782. }
  783. // 设置费率
  784. public string SetLiSFee(string sn, decimal serviceFee = 0.6M)
  785. {
  786. Dictionary<string, object> dic = new Dictionary<string, object>();
  787. dic.Add("agentId", LiSAgentId);
  788. dic.Add("deviceSn", sn);
  789. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  790. Dictionary<string, object> item = new Dictionary<string, object>();
  791. item.Add("feeCalcType", "M5");
  792. item.Add("fixed", "0");
  793. item.Add("rate", serviceFee);
  794. feeList.Add(item);
  795. dic.Add("feeList", feeList);
  796. dic.Add("signMethod", "02");
  797. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  798. string signstr = LiSSign(content);
  799. dic.Add("signData", signstr);
  800. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  801. function.WriteLog(DateTime.Now.ToString(), "设置立刷费率");
  802. function.WriteLog(req, "设置立刷费率");
  803. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  804. function.WriteLog(result, "设置立刷费率");
  805. function.WriteLog("\n\n", "设置立刷费率");
  806. return result;
  807. }
  808. public string QueryLiSDeposit(string merchNo, string sn)
  809. {
  810. Dictionary<string, object> dic = new Dictionary<string, object>();
  811. dic.Add("agentId", LiSAgentId);
  812. dic.Add("deviceSn", sn);
  813. dic.Add("merchNo", merchNo);
  814. dic.Add("signMethod", "02");
  815. string content = LiSAgentId + sn + merchNo + "02";
  816. string signstr = LiSSign(content);
  817. dic.Add("signData", signstr);
  818. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  819. string result = PostWebRequest(LiSReqUrl + "FEE001", req, new Dictionary<string, string>());
  820. return result;
  821. }
  822. private string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> headers)
  823. {
  824. string ret = string.Empty;
  825. try
  826. {
  827. function.WriteLog(DateTime.Now.ToString(), "请求立刷API日志");
  828. function.WriteLog(postUrl, "请求立刷API日志");
  829. function.WriteLog(paramData, "请求立刷API日志");
  830. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  831. // 设置提交的相关参数
  832. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  833. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  834. request.Method = "POST";
  835. request.KeepAlive = false;
  836. request.AllowAutoRedirect = true;
  837. request.ContentType = "application/json";
  838. foreach (string key in headers.Keys)
  839. {
  840. request.Headers.Add(key, headers[key]);
  841. }
  842. 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)";
  843. request.ContentLength = postData.Length;
  844. // 提交请求数据
  845. System.IO.Stream outputStream = request.GetRequestStream();
  846. outputStream.Write(postData, 0, postData.Length);
  847. outputStream.Close();
  848. System.Net.HttpWebResponse response;
  849. System.IO.Stream responseStream;
  850. System.IO.StreamReader reader;
  851. string srcString;
  852. response = request.GetResponse() as System.Net.HttpWebResponse;
  853. responseStream = response.GetResponseStream();
  854. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  855. srcString = reader.ReadToEnd();
  856. ret = srcString; //返回值赋值
  857. reader.Close();
  858. function.WriteLog(srcString, "请求立刷API日志");
  859. }
  860. catch (Exception ex)
  861. {
  862. ret = "fail";
  863. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求立刷API异常");
  864. }
  865. return ret;
  866. }
  867. #endregion
  868. #region 盛付通
  869. string OrgId = "38844193";
  870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Zm2VdNtr7n9TkH5GazDW7QjsJC5pa8v27k/kdHko2mGAg84N1pe1Z5hDc1p2oO7l1/DaAXEkwbm7eSaTB9FrZOf4mbAlj9chFzBA1ZnEkOdTIXzLaYZvDWF/Y30CkQhsn79srEcjeDtxRNF+JVaRzI3kuRdF1hDeB84CVIXUG5hxupEa9E0eQawLvT9PSqjiJLrIRhY72bpzBpLX61my9NuzOc4cMQLsxOjDTGpRuqJ+jlZvTbXNceLVNcIgW9OlxVlnU778IKCnp7khqatdkA4JmqF8gla86BNwRdxJoH/juFGtp6GJA6jsR0+0EjGA4I1AoIBAGl2ITNeGX2dXgvmPEcH8/CARFWMCozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  872. string SftReqUrl = "https://zqb.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  873. string SftPublicKey =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8zoc";
  876. // string OrgId = "88031499";
  877. // string SftReqUrl = "https://zqbtest.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  878. public string SftEncrypt(string data)
  879. {
  880. var rsa = RSA.Create();
  881. var key = Convert.FromBase64String(SftPrivateKey);
  882. var content = Encoding.UTF8.GetBytes(data);
  883. rsa.ImportPkcs8PrivateKey(key, out _);
  884. var result = rsa.SignData(content, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
  885. return Convert.ToBase64String(result);
  886. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, SftPrivateKey).Encrypt(data);
  887. }
  888. //设置机具押金
  889. public string SetFeeForSft(string merchantId, string Rate, string fee = "0")
  890. {
  891. Dictionary<string, object> req = new Dictionary<string, object>();
  892. req.Add("orgPromoterId", OrgId);
  893. req.Add("promoterId", OrgId);
  894. List<Dictionary<string, object>> merchantFeeList = new List<Dictionary<string, object>>();
  895. Dictionary<string, object> item = new Dictionary<string, object>();
  896. item.Add("merchantId", merchantId);
  897. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  898. Dictionary<string, object> feeItem = new Dictionary<string, object>();
  899. feeItem.Add("feeType", "CC");
  900. feeItem.Add("feeRate", Rate);
  901. feeItem.Add("feeDisRate", Rate);
  902. feeList.Add(feeItem);
  903. feeItem = new Dictionary<string, object>();
  904. feeItem.Add("feeType", "T0_CC");
  905. feeItem.Add("feeRate", fee);
  906. feeItem.Add("feeDisRate", fee);
  907. feeList.Add(feeItem);
  908. item.Add("feeList", feeList);
  909. merchantFeeList.Add(item);
  910. req.Add("merchantFeeList", merchantFeeList);
  911. req.Add("signType", "RSA");
  912. req.Add("charType", "UTF-8");
  913. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  914. req.Add("requestTime", function.GetCurTimestamp());
  915. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  916. string signString = "";
  917. foreach (string key in req.Keys)
  918. {
  919. if (key == "merchantFeeList")
  920. {
  921. signString += key + "=" + Newtonsoft.Json.JsonConvert.SerializeObject(req[key]) + "&";
  922. }
  923. else
  924. {
  925. signString += key + "=" + req[key].ToString() + "&";
  926. }
  927. }
  928. signString = signString.TrimEnd('&');
  929. req.Add("mac", SftEncrypt(signString));
  930. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(req), "设置盛付通机具费率");
  931. string result = function.PostWebRequest(SftReqUrl + "batchChangeMerchantFee", Newtonsoft.Json.JsonConvert.SerializeObject(req), "application/json");
  932. function.WriteLog(result + "\n\n", "设置盛付通机具费率");
  933. return result;
  934. }
  935. #endregion
  936. #region 海科
  937. string HKPrivateKey1 = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK5iJ2q2nF+9jEnof9VYhMdbAgI0ZS4cYmgWTMW2JR61lJhR0GH+A/m6mjN9FsTS6Bq03u/+e6BKdE6VqMGk0q7asi2VZIgD59zj4HubS8EFrcb5ZprwmGLnG71cBga7V5EWnHxSB9BlbFt6rGeQiit8NSbv62NxGh1U+rAVE/a3AgMBAAECgYEApQGxpJNowls8bQ74LytUcMMX0ng7qXcoUq+PM6IX28gb9EmuMZtHrb05fjEGI3YiNGsjbNpTpqftCBMrHRjWVRgb0PDf/zD9YYrxmcP9DWKQjG5f1ygYtQBlnOPEX963Y2SXrsTKr4+szTpI8r6YqFfVbbooKVMesCBtshgg16kCQQDYHGDuCuOzULP84QvGi8z+wHNv0arFpYYxvwitntD7K3iolAh8gTDWeaC03MHruGM43ybCUi9EHhCrcVKjgpK1AkEAzpIUajdmAAwtwGg4G0v7tP/ulmpGhnALVN84gSMAc5f8D6aCnoUyle+GylwRBw9WblHBLxsOtARQIvvdphDrOwJBAIFvXc60zvQTHfoTf84G5VyfP4R1e2atYNZiqHv0Zw5IVxgAsaSAbBPI/SvWHH9mDGd/n+M6/fw6VZmZYfl0txECQQCQB3yifpPpDpTL5h7QsY8EKbqyN9GKpQ7Rk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pLaYAE3MMAFi9KbdvPqVoP3jwTBdKKp8z26vX8FbbvU0fNItq4BH3uKmOM+fAkAnBwxmorni7Y6Zs24pevDVqMpcF9SkOigRKsO9Lc1HuAJuxHEoPW5KeascBVe3HfYqgt4HWIxNy/d2MvpvNaWo";
  940. string HKPublicKey2 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMgEb8k2LxpXnb/uBNw/BcbEtO6Zs2WCZCHVsaL/8QKQejG9gVT+gZIbEcqMklmxMomJWacdQN2+w+MnO7w91nwdItHBj8DHST/7xrs1nxdpi2NL+Jia8XV7hnlqX1p5eAz9GkEuqpFJXoun9L1ku+sHaR7ylBm9ezc/3/Xs6+bQIDAQAB";
  941. string HKOrgNo1 = "747187394495131648"; //电签pos
  942. string HKOrgNo2 = "747189644974104576"; //大pos
  943. string HKReqUrl = "https://org-push.juheposp.com"; //请求url
  944. public string HKDecrypt(string data, string sign, int Kind)
  945. {
  946. string HKPrivateKey = Kind == 8 ? HKPrivateKey1 : HKPrivateKey2;
  947. var toDecryptArray = Convert.FromBase64String(sign);
  948. var rsa2 = RSA.Create();
  949. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(HKPrivateKey), out _);
  950. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  951. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  952. return AesDecrypt(data, aeskey);
  953. }
  954. public string HKEncrypt(string sign, int Kind)
  955. {
  956. string HKPrivateKey = Kind == 8 ? HKPrivateKey1 : HKPrivateKey2;
  957. string HKPublicKey = Kind == 8 ? HKPublicKey1 : HKPublicKey2;
  958. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", HKPublicKey).Encrypt(sign);
  959. }
  960. public string HKAesEncrypt(string str, string aeskey)
  961. {
  962. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  963. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  964. {
  965. Key = Encoding.UTF8.GetBytes(aeskey),
  966. Mode = System.Security.Cryptography.CipherMode.ECB,
  967. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  968. };
  969. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  970. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  971. return Convert.ToBase64String(resultArray);
  972. }
  973. //设置机具押金
  974. public string SetDepositForHK(string snNo, string oldMarketId, string newMarketId, int BrandId)
  975. {
  976. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  977. return HKReqFunc("/org/pos/updatePosMarket", data, BrandId);
  978. }
  979. //查询配置活动信息
  980. public string HKQueryActiveForConfig(string snNo, int BrandId)
  981. {
  982. string data = "{\"snNo\":\"" + snNo + "\"}";
  983. return HKReqFunc("/org/pos/getMarketConfig", data, BrandId);
  984. }
  985. //查询营销活动信息
  986. public string HKQueryActiveForBrand(int marketType, int BrandId)
  987. {
  988. string data = "{\"marketType\":\"" + marketType + "\"}";
  989. return HKReqFunc("/org/pos/marketList", data, BrandId);
  990. }
  991. //终端费率模板查询
  992. public string HKQueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  993. {
  994. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  995. return HKReqFunc("/org/pos/rateConfigList", data, BrandId);
  996. }
  997. //终端费率查询
  998. public string HKQueryFeeForBrand(string snNo, int BrandId)
  999. {
  1000. string data = "{\"snNo\":\"" + snNo + "\"}";
  1001. return HKReqFunc("/org/pos/getRateConfig", data, BrandId);
  1002. }
  1003. //终端费率模板修改
  1004. public string HKSetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  1005. {
  1006. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  1007. return HKReqFunc("/org/pos/updatePosRate", data, BrandId);
  1008. }
  1009. public string HKReqFunc(string apiPath, string data, int BrandId)
  1010. {
  1011. function.WriteLog(DateTime.Now.ToString(), "设置海科机具费率");
  1012. function.WriteLog(data, "设置海科机具费率");
  1013. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  1014. string req = "{";
  1015. if (BrandId == 8)
  1016. {
  1017. req += "\"orgId\":\"" + HKOrgNo1 + "\",";
  1018. }
  1019. else
  1020. {
  1021. req += "\"orgId\":\"" + HKOrgNo2 + "\",";
  1022. }
  1023. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  1024. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  1025. req += "\"version\":\"1.0\",";
  1026. req += "\"data\":\"" + HKAesEncrypt(data, aeskey) + "\",";
  1027. req += "\"sign\":\"" + HKEncrypt(aeskey, BrandId) + "\"";
  1028. req += "}";
  1029. function.WriteLog(req, "设置海科机具费率");
  1030. string result = function.PostWebRequest(HKReqUrl + apiPath, req, "application/json");
  1031. function.WriteLog(result + "\n\n", "设置海科机具费率");
  1032. return result;
  1033. }
  1034. #endregion
  1035. #region 联动
  1036. //测试环境
  1037. // string LDRequestUrl = "http://111.14.221.188:18066/CloudTerminalServiceAction/";
  1038. // string AgentNo = "LD110014";
  1039. // string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3WG04QXTzWBg2rj4BbSmnXVTqQiCk2lZ7yi2vur2LxsSc+KN0o1W9y2AkCHcFIAk2aAfMEMQYTO3HQ+F/Vcb27BNBSjnaOLfGv0PXNHKyVzC4EQLe4M5Pqd1wMl6NaZK+HnyrPBTnfsGeywhGJc1Ke96ANrydhk7UbwezydC7nQIDAQAB";
  1040. // 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==";
  1041. //生产环境
  1042. string LDRequestUrl = "http://ldys.umpay.com/service_exter/CloudTerminalServiceAction/";
  1043. string AgentNo = "LD112692";
  1044. string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGtWShTeFEgSSFx3PJXcjCOmS+OgtcUvPOHhpALY3Orm6t7rl1E0n3j7XlM049YwwtGRJI4OWhgrtR4/AnOMBXdyMBoKxF23uay1WQiNekzfUrTwil7/CRrQ+VlGgPe6dr3WQT2/HLbzMnJHeoIZ4KSIj/7pgAwTF4ciL1UC3awwIDAQAB";
  1045. 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==";
  1046. public string LDEncrypt(string data)
  1047. {
  1048. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LDPublicKey).Encrypt(data);
  1049. }
  1050. public string LDDecrypt(string data)
  1051. {
  1052. var toDecryptArray = Convert.FromBase64String(data);
  1053. var toKey = Convert.FromBase64String(LDPrivateKey);
  1054. var rsa = RSA.Create();
  1055. rsa.ImportPkcs8PrivateKey(toKey, out _);
  1056. string result = "";
  1057. List<byte> cache = new List<byte>();
  1058. for (int i = 0; i < toDecryptArray.Length; i++)
  1059. {
  1060. cache.Add(toDecryptArray[i]);
  1061. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  1062. {
  1063. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  1064. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  1065. cache.Clear();
  1066. }
  1067. }
  1068. return result;
  1069. }
  1070. public string LDServiceFee(string SnList, int ServiceFee, int BrandId)
  1071. {
  1072. function.WriteLog(DateTime.Now.ToString(), "设置联动机具服务费");
  1073. function.WriteLog(SnList, "设置联动机具服务费");
  1074. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1075. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1076. string TerminalModeName = BrandId == 10 ? "DZA" : "DZDA";
  1077. int PosType = BrandId == 10 ? 2 : 3;
  1078. reqdic.Add("rpid", RequestId); //请求流水
  1079. reqdic.Add("agentNumber", AgentNo); //代理商编号
  1080. reqdic.Add("snList", SnList.Split(',').ToList()); //SN号
  1081. reqdic.Add("posType", PosType); //2:电签 3 大pos
  1082. reqdic.Add("terminalModeName", TerminalModeName); //终端模式名
  1083. reqdic.Add("fwfRate", ServiceFee); //服务费
  1084. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1085. function.WriteLog(req, "设置联动机具服务费");
  1086. req = LDEncrypt(req);
  1087. function.WriteLog(req, "设置联动机具服务费");
  1088. Dictionary<string, object> datadic = new Dictionary<string, object>();
  1089. datadic.Add("encryptedData", req);
  1090. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  1091. function.WriteLog("请求地址:" + LDRequestUrl + "terminalSelfDistribute", "设置联动机具服务费");
  1092. string result = function.PostWebRequest(LDRequestUrl + "terminalSelfDistribute", data, "application/json");
  1093. function.WriteLog(result + "\n\n", "设置联动机具服务费");
  1094. return result;
  1095. }
  1096. public string LDFeeRate(string MerNo, string Fee, int BrandId, int addRate = 0)
  1097. {
  1098. function.WriteLog(DateTime.Now.ToString(), "设置联动机具费率");
  1099. function.WriteLog(MerNo, "设置联动机具费率");
  1100. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1101. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1102. string MercModel = BrandId == 10 ? "DZA" : "DZDA";
  1103. int PosType = BrandId == 10 ? 2 : 3;
  1104. reqdic.Add("rpid", RequestId); // 请求流水(2字母开头+13位数字)
  1105. reqdic.Add("agentNumber", AgentNo); // 代理编号
  1106. reqdic.Add("mercModel", MercModel); // 商户模式
  1107. reqdic.Add("rate", Fee); // 费率 如 0.0053
  1108. reqdic.Add("addRate", addRate); // 附加费 如0
  1109. reqdic.Add("rateType", "M015"); // 秒刷 M015 扫码 S010 特惠 T015
  1110. reqdic.Add("mercId", MerNo); // 商户编号
  1111. reqdic.Add("cardType", "01"); // 01 贷记卡 02 扫码
  1112. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1113. function.WriteLog(req, "设置联动机具费率");
  1114. req = LDEncrypt(req);
  1115. function.WriteLog(req, "设置联动机具费率");
  1116. Dictionary<string, object> datadic = new Dictionary<string, object>();
  1117. datadic.Add("encryptedData", req);
  1118. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  1119. function.WriteLog("请求地址:" + LDRequestUrl + "updateMercRate", "设置联动机具费率");
  1120. string result = function.PostWebRequest(LDRequestUrl + "updateMercRate", data, "application/json");
  1121. function.WriteLog(result + "\n\n", "设置联动机具费率");
  1122. return result;
  1123. }
  1124. #endregion
  1125. #region 盒易付
  1126. //测试环境
  1127. // string BoxRequestUrl = "https://openapi-test.iboxpay.com/api";
  1128. // string BoxAppId = "8840021411446784";
  1129. // string BoxAppSecret = "xgwGnmYGjVy0GOWOWkQtRk8Hk8ur5tCV";
  1130. // string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjMQxp24mjxDTr13uPW0y+tiO1yXFGw7P/pPQ0oZKK7F6KstEaus7pLEywBZ5XRXE5jgkhR2TS7Ne7djJfbpn5yFc6pPlz3ZsOfBVeB88NEwhx6xzCGX2eqSSkO33n8w2G0xc2ss5HpYBarT00NBZWhrwOXpdRPYLOYHKVU3Rl+FA9xDw/wYfoWvrr+JSfHRGn/ENMmQFEdckAbPauKaQMrZD2kz+PRrhq56eWnCuVQPcaz/jroVT8qQEgkg2IsNy+DwfLOIqm8IySEpxnQ5wN/KvsQJc2wXDQNf9F5kvWwjoqSSP0qJS+oPRXET+zJb+WTk2y5M6AYoC9NodwsC4NwIDAQAB";
  1131. // string BrhCode = "039001";
  1132. //生产环境
  1133. string BoxRequestUrl = "https://openapi.iboxpay.com/api";
  1134. string BoxAppId = "AP5879017839106039808";
  1135. string BoxAppSecret = "DGtftIyl6R3nzwPr5YuV5fnmkfwufXRj";
  1136. string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmjoQirIYZBD9Qon2HkF4j/NAINXtJ7Lzq/WXxTF7t7mg7LNARt0+ZZaeWx8caq2fv5zdsGyyoInL23cBtDI5KmFfK69iA0ygQMK0WbiKqsUB1OpPbT3+9zLuadIJAznjA223lY6CIjTpdLZhaRjImNVqc60bdkx6YsQcA+xW+3r1JH4PPHb7yBEbkKIX8OhyX7U4p0TkbDkAobbjHr5YB9gmYLoSFJMOPfTtSExkv7/Y7IVR9poZAHcr3teFoAiXW3RzxelRtnXxIkl/6AUOKoL5fhr/UTUN+Q18uzNljYWr6SwnTI3EmtzgykaewWtZvV85Xdhe/BjiQ5Xor7YbwIDAQAB";
  1137. string BrhCode = "039004";
  1138. public string BoxFee(string MerNo, string Fee)
  1139. {
  1140. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具费率");
  1141. function.WriteLog(MerNo, "设置盒易付机具费率");
  1142. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  1143. Dictionary<string, string> headdic = new Dictionary<string, string>();
  1144. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  1145. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1146. headdic.Add("appid", BoxAppId);//开发者id
  1147. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  1148. headdic.Add("X-Up-AppId", BoxAppId);
  1149. headdic.Add("X-Timestamp", timestamp);
  1150. headdic.Add("X-Sign-Type", "SHA-256");
  1151. reqdic.Add("mchtNo", MerNo);//终端列表
  1152. reqdic.Add("brhCode", BrhCode);//机构号
  1153. //MHN10917(贷记0.63%,借记卡0.63%/25) MHN10916(贷记0.60%,借记卡0.60%/25)
  1154. reqdic.Add("tNDiscId", Fee == "0.60" ? "MHN10916" : "MHN10917");//费率模型
  1155. reqdic.Add("effectiveFlag", "1");//立即生效
  1156. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  1157. headdic.Add("X-Sign", BoxSHA256Sign(timestamp + BoxAppSecret + req));
  1158. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  1159. function.WriteLog("请求头\n" + head, "设置盒易付机具费率");
  1160. function.WriteLog("请求参数\n" + req, "设置盒易付机具费率");
  1161. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/mcht/update_disc", "设置盒易付机具费率");
  1162. string result = PostWebRequest(BoxRequestUrl + "/inst/mcht/update_disc", req, headdic);
  1163. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具费率");
  1164. return result;
  1165. }
  1166. public string BoxSHA256Sign(string toSignStr)
  1167. {
  1168. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  1169. SHA256 sha256 = SHA256.Create();
  1170. byte[] signByte = sha256.ComputeHash(toSignByte);
  1171. string sign = Convert.ToBase64String(signByte);
  1172. return sign;
  1173. }
  1174. public bool BoxVerifySign(string toSignStr, string signStr)
  1175. {
  1176. byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
  1177. byte[] signByte = Convert.FromBase64String(signStr);
  1178. var toKey = Convert.FromBase64String(BoxPublicKey);
  1179. var rsaroot = RSA.Create();
  1180. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  1181. var publicKeyParameters = rsaroot.ExportParameters(false);
  1182. using (var rsa = RSA.Create())
  1183. {
  1184. rsa.ImportParameters(publicKeyParameters);
  1185. var sha256 = SHA256.Create();
  1186. var hash = sha256.ComputeHash(toSignByte);
  1187. return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1188. }
  1189. }
  1190. public string BoxSignData(string toSignStr)
  1191. {
  1192. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  1193. var toKey = Convert.FromBase64String(BoxPublicKey);
  1194. var rsaroot = RSA.Create();
  1195. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  1196. var publicKeyParameters = rsaroot.ExportParameters(false);
  1197. using (var rsa = RSA.Create())
  1198. {
  1199. rsa.ImportParameters(publicKeyParameters);
  1200. var sha256 = SHA256.Create();
  1201. var hash = sha256.ComputeHash(toSignByte);
  1202. byte[] endByte = rsa.SignData(toSignByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1203. return Convert.ToBase64String(endByte);
  1204. }
  1205. }
  1206. #endregion
  1207. }
  1208. }