SetDepositPostService.cs 85 KB

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