PublicImportDataService.cs 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Security.Cryptography;
  5. using System.Web;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8. using MySystem.Models;
  9. using Library;
  10. using LitJson;
  11. using System.Security.Cryptography.X509Certificates;
  12. using Org.BouncyCastle.Security;
  13. using Org.BouncyCastle.Crypto.Parameters;
  14. using System.Text;
  15. using Org.BouncyCastle.Crypto;
  16. using Org.BouncyCastle.Math;
  17. using System.Net.Http;
  18. using System.Threading.Tasks;
  19. using System.IO;
  20. namespace MySystem
  21. {
  22. public class PublicImportDataService
  23. {
  24. public readonly static PublicImportDataService Instance = new PublicImportDataService();
  25. private PublicImportDataService()
  26. { }
  27. #region 金控
  28. // 开发环境
  29. // string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCy8cg6/tXbSj2i1tyi7VztwJw7uNmqc3bS6sVIZkDYhTmcXhpV17jq4j2zz/tURwX8b3MdK1A1HTR1XRd7hl0w2UF9iFk6UezByJ5tdNDoffMCGJtVSThq+MCV+WQI26tJ/ub6bm7GPrzTR79fntN+nTniRM4trjONN2WzEhHEcwIDAQAB";
  30. // 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";
  31. // string clientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCb861uuey1252WdS8KPeBB+vm5AIBEKclsfBzVLY1cZXiiEbInCmsqT6fSO+A6wjWyJixGCzZICmUxhdBzuo3Du2YTbuo+fRlV6DW1mbguBV8/l2+LJvht0jl87J8N4skFUzvAeYKpWDX6dC6cLzjm5nyI1OrCQq0lsWPEMDCNAwIDAQAB";
  32. // string clientPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJvzrW657LXbnZZ1Lwo94EH6+bkAgEQpyWx8HNUtjVxleKIRsicKaypPp9I74DrCNbImLEYLNkgKZTGF0HO6jcO7ZhNu6j59GVXoNbWZuC4FXz+Xb4sm+G3SOXzsnw3iyQVTO8B5gqlYNfp0LpwvOObmfIjU6sJCrSWxY8QwMI0DAgMBAAECgYAjE0dqo/6NWHu1H14ZG5mYvW31Ihu3OP7Im5GQkNI+ecQMD5bWGQ3JUmkYa8ce8BdLnjJO/q6SvWPNI5+ip87CYPH1SMXKUiSLzaCrw4xMySW9PSnudTzJwhrmlmyjYTAg70tHf2YQC4YkNvtkR+PJ2yf6JEKGFVgP5p2KyeKXgQJBANjGryxyu95QC3jIaggcYmGD36sVO/ns8Uyu8PkAHYOscuXRcV0L8LghIzPolcehj9bTbDLjiuNgeuyjNs2YBvMCQQC4K4uIXt0kVDLYzlJfhN1CsV90vQitcKdD8wTO0JRKfMCQ6UDSumU7lq+z4TxTlRYxmZjpgIqH+N0WohmEiwWxAkBEfuMzBD3gjSJS0+DNF0ruzSCLinYdDoVgWZbC1wp8ZK0ZeQh9AhzZ0X6yFDffkGlG1B9IJSXpmr68rwXOCM+JAkBkrKEUxc6bGk/FRluvDWEqIO2uUdtZfBhjQ4ggSdKWOUXGsUsXJn9KKKAZc4lXo0rDiFQXaIXRuE+bHLdYReqxAkAj0Kol0LkJgdl2PoBAeyQHTpt9nxaeNX56W7CN/srBA1O2wr+aoQiJaKsu9I0EeW3zaMJlLi3VyjU4wnF+yAsB";
  33. // string reqUrl = "https://test-push.mfe88.com/push-service/api/SETSERVICEFEE";
  34. // 生产环境
  35. string merchantNo = "4487378308096";
  36. string clientId = "1243966544896";
  37. string mfe88PublicKey = "MIGfMA0GCSqGSI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aNhLH7B1c0aZ908BQBRDr7XWfW/cLRapBTBm8h7R+VwJBAJAKrZMPN+TuSlaPaFYfNqBE2nC1+q2CCQE6L8QZmJYRwqbN5iuN7CkNGxt3cmNo8bNOhzH6fvFamLCDwDEixbMCQEgaxfAxpJdMoR6LrklSkigHiKfA6SaRWxxShFtBfjk5XcakmLkU/U5lgD/Blu7h4x6bRf4VPTYWdbxtiOK11rY=";
  40. string reqUrl = "https://push.mfe88.com/push-service/api/SETSERVICEFEE";
  41. public string SetDeposit(string sn, decimal serviceFee)
  42. {
  43. serviceFee = serviceFee * 100;
  44. Dictionary<string, string> headers = new Dictionary<string, string>();
  45. headers.Add("X-Client-ID", clientId);
  46. headers.Add("X-Security", "RSA");
  47. string content = "{\"sn\":\"" + sn + "\",\"serviceFee\":\"" + serviceFee.ToString("f0") + "\"}";
  48. content = Encrypt(content);
  49. string signstr = Sign(content);
  50. headers.Add("X-Sign", signstr);
  51. string req = "{\"param\":\"" + content + "\"}";
  52. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  53. return result;
  54. }
  55. public bool Verify()
  56. {
  57. string data = "ZV0BBQ2hNgeZKKAPZ3XXEJGhp/h3+Mq5ejxuCI9SRbrDRls0XtfJRWboT5+J1sfHkb/J3eI4ThkTI/DjRNLK4x7fFYD62coClL7zDXeES42RXrpBik7VHHllUIS5nZFT23QME8kxRdo/6FH7Sv0J7IP5Qtqe70b3syv1jXmv8JozoP6DQjqHnlggpRM+4Ppks5PXorvHW7yI3uOgJL06t0GWDZIh7FRQ6UU41ayDsY0Z8j9o5quD8DSGJ1po6YPdmr2FpbFL5hs+buYhfEwsOwbvU5Aawbt+XuNXlU21wjeyC/8h2/yiPJSpCGjNXzzY4BBIhWDIbyxrbV+7SGIC+gNK2oQV0Ldtq9dXmljqA8e2dWsa8IaGaXmfo/85Ef2W5qIByrn42K+rA1nzhbR+L0WPGd4ugyzx6eiUl6T0oXVMaTIIoM6fndrm7RubsfNRZizrkQ+ocnAraMnGPZq84NpRp0Qs+pg8mlAIrqQ0avDutY1jGkzFXAljYGhiPvN7ntydmn2P2jgiPfh65VWumcXU+cp8d/nTD8eT/HmVbXUNMp/1ckP+VoK2wdowvgmgAruD3Fjfo8EghAfWEfuAVIsErxGxKCF17AUI8ZIqa+JYxxaA9vjxklavLmB9MAovx3JQSGXqXNNTy3LBljb1dZr3yk0ER9Qv8K4Bqc7Ti6gHHBFc7uu+wnqD7kTieMn++TpNo44MR8tGSmN6lzZKrio1czTyLLANLzzH4lBipTalGjgFnKcaNdVloW63DKkpz3qugCeBotRDdkH3T7DtYVz41lmJyLlxToeyFxXzqV0yqopR62QIghRO/vI9DpMDJclQMKEaCs9Py4qgMz2BmTqnESU42XDyNCMY5JVGpClZJgXNPmWLU0xrOu7B/tMEfThj9pNPBqNkbWQkLZ1MaSiMrfoHfQ7krt6TV6B2rhyfwrjKysXex4IHUX0nRTT55HcqQc38FlpeC4+kaTTSRs0HGMteiq+3BfDY0vHxH84x22WeN7oE7JbD/Ttd6Tn4";
  58. string signString = "cuo8Rp0Hhc1pzEkzvx3tlGV6aBhZoD3F+b1FM07IkCTQwTVzz0EzgO0auQt+Wqf9ndWERa7P9jTqHS4JKYQH+LGLXjVgQPekzrePNnIcVVFqjf3VC+xImxSxJLaChHxiF+ufDpU9symoesub51QRCPSUB3xuQ2uP2lSbVmgcjvw=";
  59. // var signer = SignerUtilities.GetSigner("SHA256withRSA");
  60. // var pubkey = Convert.FromBase64String(mfe88PublicKey);
  61. // // var pubkey = StrToToHexByte(mfe88PublicKey);
  62. // var publicKeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(pubkey);
  63. // signer.Init(false, publicKeyParam);
  64. // var signBytes = Convert.FromBase64String(signString);
  65. // var plainBytes = Convert.FromBase64String(data);
  66. // signer.BlockUpdate(plainBytes, 0, plainBytes.Length);
  67. // return signer.VerifySignature(signBytes);
  68. var toDecryptArray = Convert.FromBase64String(data);
  69. var toSignArray = Convert.FromBase64String(signString);
  70. // var pubkey = Encoding.UTF8.GetBytes(mfe88PublicKey);
  71. // using (var x509 = new X509Certificate2(pubkey))
  72. // {
  73. // using (var rsa = x509.GetRSAPublicKey())
  74. // {
  75. // return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  76. // }
  77. // }
  78. var rsa = RSA.Create();
  79. rsa.ImportRSAPublicKey(Convert.FromBase64String(mfe88PublicKey), out _);
  80. return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  81. }
  82. private byte[] StrToToHexByte(string hexString)
  83. {
  84. hexString = hexString.Replace(" ", "");
  85. if ((hexString.Length % 2) != 0)
  86. hexString += " ";
  87. byte[] returnBytes = new byte[hexString.Length / 2];
  88. for (int i = 0; i < returnBytes.Length; i++)
  89. returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
  90. return returnBytes;
  91. }
  92. public string Decrypt(string data)
  93. {
  94. var toDecryptArray = Convert.FromBase64String(data);
  95. var rsa = RSA.Create();
  96. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  97. string result = "";
  98. List<byte> cache = new List<byte>();
  99. for (int i = 0; i < toDecryptArray.Length; i++)
  100. {
  101. cache.Add(toDecryptArray[i]);
  102. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  103. {
  104. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  105. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  106. cache.Clear();
  107. }
  108. }
  109. return result;
  110. }
  111. public string Encrypt(string data)
  112. {
  113. // var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  114. // var rsa = RSA.Create();
  115. // rsa.ImportRSAPublicKey(Convert.FromBase64String(mfe88PublicKey), out _);
  116. // string result = "";
  117. // var buffer = rsa.Encrypt(toEncryptArray, RSAEncryptionPadding.Pkcs1);
  118. // result = Convert.ToBase64String(buffer);
  119. // return result;
  120. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", mfe88PublicKey).Encrypt(data);
  121. }
  122. public string Sign(string data)
  123. {
  124. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  125. var rsa = RSA.Create();
  126. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  127. string result = "";
  128. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  129. result = Convert.ToBase64String(buffer);
  130. return result;
  131. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, clientPrivateKey, "").Sign(data);
  132. }
  133. #endregion
  134. #region 开店宝
  135. //生产环境
  136. string KdbApiUrl = "https://kzy.kdb-tj.com:5055/api";
  137. string KDBAESKEY = "F@xh#sga41c08@pe";
  138. string Kdb_Rsa_PrivateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAl2x9dSSCfNDik6VM2dn/SK1ONSbb7AKyXM1gHw8PMbzWN1pK7YGaPqHlIRbAeFeIvLKVeMxrji+63W6LpB0yDQIDAQABAkAfpHUnCIUYDhJ65f0EPTDCgCyqoL8uN3YMPIKMmvoC22/i7AC6zf/bWk4JdratN+gvvnjGgHQff6HH5dOQ6sbFAiEAxPYSLADzIv374J8O+LluXIcgI5zXm4r4dMtKbCmmWSsCIQDE0BRKsBcBZ9NvJ9Km+m/d1hN9v5hFT842zrkUFJmVpwIgBdYc17z3d3P7QL613NzxzkAazbNaGDvX/O4BOI9LZJ0CICrZElHgXGHV9NYyWU45H7mwLbYmzEPqx/5uqySQB4/pAiBgKYv3RGnsZ8Zm1EKAJjUX7ehdteBgPSA/UgIDZQ4oyw==";
  139. string AgencyId = "3013890129";
  140. //开发环境
  141. // string KdbApiUrl = "https://kzy-test.kdb-tj.com:5056/api";
  142. // string KDBAESKEY = "Ebn4N28MvEXEvPTA";
  143. // string Kdb_Rsa_PrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAsPyH5Y5NySHHKWIgPwxbZFkd33vzuWKv+Kdpug5/qYAnpTShDSMXQ2Ib7gc+B/yvj4uZ/k1A/xHpzHTPl6MzQQIDAQABAkA2sGHhyj45B2n+XKbwNIZNFMiJVUjzoQ4VPM4Lww0pt781GeqBCGgEIgTjmmg/FTGjgwTb7ta1A5G9Qn2nPG0RAiEA4x7W6XKdSL/FyVdlt4jijNQNZfLEqEPy1NnchRWUf40CIQDHfb49KP3pW4ZDX3xS42fYd9p7AGZ+qpVBnJfGGyFrhQIhALk3HCHyowuBwMUKLdw3mDEqeOarzO4/w1cLd8dcKua9AiEAtdPAj9JLDGWljMb9dDddsYockzwcL5ufizwFgkW8QlkCIADYU4+fFKqySLGX3MmEIJ/mU632PRtJAh4LSL8/Ij1H";
  144. // string AgencyId = "3013890202";
  145. // 查询机构政策列表
  146. public string GetPolicyList()
  147. {
  148. string url = KdbApiUrl + "/marketing/plan/query/list";
  149. //[{"id":100014,"name":"韩测试营销方案(韩测试营销方案)"}]
  150. return PostKDB(url, "{}");
  151. }
  152. // 查询政策下的押金
  153. public string GetDepositList(string planId)
  154. {
  155. string url = KdbApiUrl + "/marketing/deposit/query/planId";
  156. string content = "{\"planId\":\"" + planId + "\"}";
  157. //[{"depositId":26,"depositName":"押0返0","amount":0.00},{"depositId":28,"depositName":"押199返199","amount":199.00},{"depositId":29,"depositName":"押299返299","amount":299.00},{"depositId":27,"depositName":"押99返99","amount":99.00}]
  158. return PostKDB(url, content);
  159. }
  160. // 设置政策下的押金金额
  161. public string GetDepositAmount(string DepositId)
  162. {
  163. string content = RedisDbconn.Instance.Get<string>("KdbDepositList");
  164. if (string.IsNullOrEmpty(content))
  165. {
  166. content = PublicImportDataService.Instance.GetPolicyList();
  167. JsonData tops = JsonMapper.ToObject(content);
  168. if (tops.Count > 0)
  169. {
  170. content = PublicImportDataService.Instance.GetDepositList(tops[0]["id"].ToString());
  171. }
  172. RedisDbconn.Instance.Set("KdbDepositList", content);
  173. RedisDbconn.Instance.SetExpire("KdbDepositList", function.get_Random(1800, 5400));
  174. }
  175. JsonData list = JsonMapper.ToObject(content);
  176. for (int i = 0; i < list.Count; i++)
  177. {
  178. JsonData item = list[i];
  179. if (DepositId == item["depositId"].ToString())
  180. {
  181. return item["amount"].ToString();
  182. }
  183. }
  184. return "0";
  185. }
  186. // 修改押金接口
  187. public string ModifyDeposit(string PosSn, string depositId)
  188. {
  189. string url = KdbApiUrl + "/pos/modify/deposit";
  190. string content = "{\"posSnStart\":\"" + PosSn + "\",\"posSnEnd\":\"" + PosSn + "\",\"depositId\":" + depositId + "}";
  191. return PostKDB(url, content);
  192. }
  193. // 修改费率接口
  194. public string ModifyFee(string PosSn, string Fee)
  195. {
  196. string url = KdbApiUrl + "/pos/rate/modify/single/remote";
  197. string content = "{\"posSn\":\"" + PosSn + "\",\"type\":\"贷记卡刷卡\",\"rate\":\"" + Fee + "\",\"d0Fee\":\"0\"}";
  198. return PostKDB(url, content);
  199. }
  200. // 查询费率接口
  201. public string QueryFee(string orderNo)
  202. {
  203. string url = KdbApiUrl + "/pos/rate/change/query/orderno";
  204. string content = "{\"orderNo\":\"" + orderNo + "\"}";
  205. return PostKDB(url, content);
  206. }
  207. public string KDBDecrypt(string data)
  208. {
  209. string result = AesDecrypt(data, KDBAESKEY);
  210. return result;
  211. }
  212. public string AesDecrypt(string str, string key)
  213. {
  214. if (string.IsNullOrEmpty(str)) return null;
  215. byte[] toEncryptArray = Convert.FromBase64String(str);
  216. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  217. {
  218. Key = Encoding.UTF8.GetBytes(key),
  219. Mode = System.Security.Cryptography.CipherMode.ECB,
  220. Padding = System.Security.Cryptography.PaddingMode.PKCS7,
  221. };
  222. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
  223. byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  224. return Encoding.UTF8.GetString(resultArray);
  225. }
  226. public string AesEncrypt(string str)
  227. {
  228. // if (string.IsNullOrEmpty(str)) return null;
  229. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  230. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  231. {
  232. Key = Encoding.UTF8.GetBytes(KDBAESKEY),
  233. Mode = System.Security.Cryptography.CipherMode.ECB,
  234. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  235. };
  236. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  237. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  238. return Convert.ToBase64String(resultArray);
  239. }
  240. public string PostKDB(string url, string content)
  241. {
  242. content = PublicImportDataService.Instance.AesEncrypt(content);
  243. string timestamp = function.GetCurTimestamp().ToString();
  244. string sign = PublicImportDataService.Instance.KDBSign(content + timestamp);
  245. string req = "{\"agencyId\":\"" + AgencyId + "\",\"content\":\"" + content + "\",\"timestamp\":\"" + timestamp + "\",\"sign\":\"" + sign + "\"}";
  246. string result = PostWebRequest(url, req, new Dictionary<string, string>());
  247. return result;
  248. }
  249. private string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> headers)
  250. {
  251. string ret = string.Empty;
  252. try
  253. {
  254. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  255. // 设置提交的相关参数
  256. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  257. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  258. request.Method = "POST";
  259. request.KeepAlive = false;
  260. request.AllowAutoRedirect = true;
  261. request.ContentType = "application/json";
  262. foreach (string key in headers.Keys)
  263. {
  264. request.Headers.Add(key, headers[key]);
  265. }
  266. 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)";
  267. request.ContentLength = postData.Length;
  268. // 提交请求数据
  269. System.IO.Stream outputStream = request.GetRequestStream();
  270. outputStream.Write(postData, 0, postData.Length);
  271. outputStream.Close();
  272. System.Net.HttpWebResponse response;
  273. System.IO.Stream responseStream;
  274. System.IO.StreamReader reader;
  275. string srcString;
  276. response = request.GetResponse() as System.Net.HttpWebResponse;
  277. responseStream = response.GetResponseStream();
  278. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  279. srcString = reader.ReadToEnd();
  280. ret = srcString; //返回值赋值
  281. reader.Close();
  282. }
  283. catch (System.Net.WebException ex)
  284. {
  285. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)ex.Response;
  286. System.IO.Stream myResponseStream = response.GetResponseStream();
  287. //获取响应内容
  288. System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream);
  289. ret = myStreamReader.ReadToEnd();
  290. myResponseStream.Close();
  291. }
  292. catch (Exception ex)
  293. {
  294. ret = "fail";
  295. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求开店宝API异常");
  296. }
  297. return ret;
  298. }
  299. public string KDBSign(string data)
  300. {
  301. var rsa = RSA.Create();
  302. var key = Convert.FromBase64String(Kdb_Rsa_PrivateKey);
  303. var content = Encoding.UTF8.GetBytes(data);
  304. rsa.ImportPkcs8PrivateKey(key, out _);
  305. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  306. return Convert.ToBase64String(result);
  307. }
  308. #endregion
  309. #region 乐刷
  310. 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==";
  311. string LSPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI5Xd35WPkfvVk0djL3EfaliEnZqWsi9xjRoPYL88JF5IQyPxO61+p3S71bmgWy1lwflDofvD38Nxr379w9hh2Qk8zxziq7Nrcs6gvBJjFA0GqFTiNgWOL7QeyIzXvRZSxmcetiRCazJBypzkkMbIvn5QqHsSnNrdau5ELDthftwIDAQAB";
  312. string OrgNo1 = "704067708098457600"; //快联盟电签pos
  313. string OrgNo2 = "704058964878831616"; //快联盟大pos
  314. string LSReqUrl = "https://lfs-org-push.ileshua.com"; //请求url
  315. public string LSDecrypt(string data, string sign)
  316. {
  317. var toDecryptArray = Convert.FromBase64String(sign);
  318. var rsa2 = RSA.Create();
  319. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(LSPrivateKey), out _);
  320. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  321. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  322. return AesDecrypt(data, aeskey);
  323. }
  324. public string LSEncrypt(string sign)
  325. {
  326. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LSPublicKey).Encrypt(sign);
  327. }
  328. public string LSAesEncrypt(string str, string aeskey)
  329. {
  330. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  331. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  332. {
  333. Key = Encoding.UTF8.GetBytes(aeskey),
  334. Mode = System.Security.Cryptography.CipherMode.ECB,
  335. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  336. };
  337. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  338. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  339. return Convert.ToBase64String(resultArray);
  340. }
  341. //设置机具押金
  342. public string SetDepositForLS(string snNo, string oldMarketId, string newMarketId, int BrandId)
  343. {
  344. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  345. return LSReqFunc("/org/pos/updatePosMarket", data, BrandId);
  346. }
  347. //查询配置活动信息
  348. public string QueryActiveForConfig(string snNo, int BrandId)
  349. {
  350. string data = "{\"snNo\":\"" + snNo + "\"}";
  351. return LSReqFunc("/org/pos/getMarketConfig", data, BrandId);
  352. }
  353. //查询营销活动信息
  354. public string QueryActiveForBrand(int marketType, int BrandId)
  355. {
  356. string data = "{\"marketType\":\"" + marketType + "\"}";
  357. return LSReqFunc("/org/pos/marketList", data, BrandId);
  358. }
  359. //终端费率模板查询
  360. public string QueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  361. {
  362. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  363. return LSReqFunc("/org/pos/rateConfigList", data, BrandId);
  364. }
  365. //终端费率查询
  366. public string QueryFeeForBrand(string snNo, int BrandId)
  367. {
  368. string data = "{\"snNo\":\"" + snNo + "\"}";
  369. return LSReqFunc("/org/pos/getRateConfig", data, BrandId);
  370. }
  371. //终端费率模板修改
  372. public string SetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  373. {
  374. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  375. return LSReqFunc("/org/pos/updatePosRate", data, BrandId);
  376. }
  377. public string LSReqFunc(string apiPath, string data, int BrandId)
  378. {
  379. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  380. string req = "{";
  381. if (BrandId == 4)
  382. {
  383. req += "\"orgId\":\"" + OrgNo1 + "\",";
  384. }
  385. else
  386. {
  387. req += "\"orgId\":\"" + OrgNo2 + "\",";
  388. }
  389. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  390. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  391. req += "\"version\":\"1.0\",";
  392. req += "\"data\":\"" + LSAesEncrypt(data, aeskey) + "\",";
  393. req += "\"sign\":\"" + LSEncrypt(aeskey) + "\"";
  394. req += "}";
  395. string result = function.PostWebRequest(LSReqUrl + apiPath, req, "application/json");
  396. return result;
  397. }
  398. #endregion
  399. #region 立刷
  400. string LiSAgentId = "50814834";
  401. string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEp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3kuRdF1hDeB84CVIXUG5hxupEa9E0eQawLvT9PSqjiJLrIRhY72bpzBpLX61my9NuzOc4cMQLsxOjDTGpRuqJ+jlZvTbXNceLVNcIgW9OlxVlnU778IKCnp7khqatdkA4JmqF8gla86BNwRdxJoH/juFGtp6GJA6jsR0+0EjGA4I1AoIBAGl2ITNeGX2dXgvmPEcH8/CARFWMCozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  402. string LiSWeAgentId = "50915020";
  403. string LiSWePrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCV6SuubkIv52S//jbkhLM76JFWOTMKNj4P2jqVSXf6SHfO5ZuBmnjLLYpzm/dtHRW0i4RtbG6LK6I/d4qR2msZvK5bwVkmuCkztA9SY4YHyhTOJeHwy8da79nslr3a797i/WhjcUbgkB2a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1a0weMMTIOdv+Cob6taTj8AlIJt5ZTJwBrAflTR+ICeQuCTJiRZoal+6rwQzEDuxMbLvmfSq5LthA+llVE7kwIUeGHA4u3e0Rg+6kT2XVYmfMMSX5hsaSM3LhIqQt6XCf7CmGLsi0ZpB//J3uQTBx0rCywiZqoQOQWQBTVAoGAEBkTKlLS6o1acrf4c9/GYWiTKWc0/Y6Gf1g7QCez4Tnnx3AgZlA8Tk1rXlpQ/0Mc7AvLqdNS+9i6OnRHIsPo2MIqjJ9G2ySBgSEP+b3ZMx6HNg4GIZKRDTXrXwwTrN3xJwE5vccS3Jrys0ZoCrgrE7i2TRqwPysL8TswXb0BKX0=";
  404. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  405. public string LiSSign(string data)
  406. {
  407. var rsa = RSA.Create();
  408. var key = Convert.FromBase64String(LiSPrivateKey);
  409. var content = Encoding.UTF8.GetBytes(data);
  410. rsa.ImportPkcs8PrivateKey(key, out _);
  411. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  412. return Convert.ToBase64String(result);
  413. }
  414. public string LiSWeSign(string data)
  415. {
  416. var rsa = RSA.Create();
  417. var key = Convert.FromBase64String(LiSWePrivateKey);
  418. var content = Encoding.UTF8.GetBytes(data);
  419. rsa.ImportPkcs8PrivateKey(key, out _);
  420. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  421. return Convert.ToBase64String(result);
  422. }
  423. //设置押金
  424. public string SetLiSDeposit(string sn, int serviceFee)
  425. {
  426. serviceFee = serviceFee * 100;
  427. Dictionary<string, object> dic = new Dictionary<string, object>();
  428. dic.Add("agentId", LiSAgentId);
  429. dic.Add("deviceSn", sn);
  430. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  431. Dictionary<string, object> item = new Dictionary<string, object>();
  432. item.Add("feeCalcType", "N1");
  433. item.Add("fixed", "1");
  434. item.Add("rate", serviceFee);
  435. feeList.Add(item);
  436. dic.Add("feeList", feeList);
  437. dic.Add("signMethod", "02");
  438. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  439. string signstr = LiSSign(content);
  440. dic.Add("signData", signstr);
  441. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  442. function.WriteLog("请求参数:" + req, "设置立刷云电签服务费");
  443. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  444. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷云电签服务费");
  445. return result;
  446. }
  447. public string SetLiSWeDeposit(string sn, int serviceFee)
  448. {
  449. serviceFee = serviceFee * 100;
  450. Dictionary<string, object> dic = new Dictionary<string, object>();
  451. dic.Add("agentId", LiSWeAgentId);
  452. dic.Add("deviceSn", sn);
  453. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  454. Dictionary<string, object> item = new Dictionary<string, object>();
  455. item.Add("feeCalcType", "N1");
  456. item.Add("fixed", "1");
  457. item.Add("rate", serviceFee);
  458. feeList.Add(item);
  459. dic.Add("feeList", feeList);
  460. dic.Add("signMethod", "02");
  461. string content = LiSWeAgentId + sn + "N11" + serviceFee + "02";
  462. string signstr = LiSWeSign(content);
  463. dic.Add("signData", signstr);
  464. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  465. function.WriteLog("请求参数:" + req, "设置立刷微电签服务费");
  466. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  467. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷微电签服务费");
  468. return result;
  469. }
  470. // 设置费率
  471. public string SetLiSFee(string sn, string merchNo, string serviceRate = "0.6", string serviceFee = "0")
  472. {
  473. Dictionary<string, object> dic = new Dictionary<string, object>();
  474. dic.Add("agentId", LiSAgentId);
  475. dic.Add("deviceSn", sn);
  476. dic.Add("merchNo", merchNo);
  477. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  478. Dictionary<string, object> item = new Dictionary<string, object>();
  479. item.Add("feeCalcType", "M5");
  480. item.Add("fixed", "0");
  481. item.Add("rate", serviceRate);
  482. feeList.Add(item);
  483. // item = new Dictionary<string, object>();
  484. // item.Add("feeCalcType", "T0");
  485. // item.Add("fixed", "1");
  486. // item.Add("rate", serviceFee);
  487. // feeList.Add(item);
  488. dic.Add("feeList", item);
  489. dic.Add("signMethod", "02");
  490. string content = LiSAgentId + merchNo + sn + "M50" + serviceRate + "02";
  491. string signstr = LiSSign(content);
  492. dic.Add("signData", signstr);
  493. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  494. function.WriteLog("请求参数:" + req, "设置立刷云电签费率");
  495. string result = PostWebRequest(LiSReqUrl + "FEE002", req, new Dictionary<string, string>());
  496. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷云电签费率");
  497. return result;
  498. }
  499. public string SetLiSWeFee(string sn, string merchNo, string serviceRate = "0.6", string serviceFee = "0")
  500. {
  501. Dictionary<string, object> dic = new Dictionary<string, object>();
  502. dic.Add("agentId", LiSWeAgentId);
  503. dic.Add("deviceSn", sn);
  504. dic.Add("merchNo", merchNo);
  505. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  506. Dictionary<string, object> item = new Dictionary<string, object>();
  507. item.Add("feeCalcType", "M5");
  508. item.Add("fixed", "0");
  509. item.Add("rate", serviceRate);
  510. feeList.Add(item);
  511. item = new Dictionary<string, object>();
  512. item.Add("feeCalcType", "T0");
  513. item.Add("fixed", "1");
  514. item.Add("rate", serviceFee);
  515. feeList.Add(item);
  516. dic.Add("feeList", feeList);
  517. dic.Add("signMethod", "02");
  518. string content = LiSWeAgentId + merchNo + sn + "M50" + serviceRate + "T01" + serviceFee + "02";
  519. string signstr = LiSWeSign(content);
  520. dic.Add("signData", signstr);
  521. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  522. function.WriteLog("请求参数:" + req, "设置立刷微电签费率");
  523. string result = PostWebRequest(LiSReqUrl + "FEE002", req, new Dictionary<string, string>());
  524. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷微电签费率");
  525. return result;
  526. }
  527. public string QueryLiSDeposit(string merchNo, string sn)
  528. {
  529. Dictionary<string, object> dic = new Dictionary<string, object>();
  530. dic.Add("agentId", LiSAgentId);
  531. dic.Add("deviceSn", sn);
  532. dic.Add("merchNo", merchNo);
  533. dic.Add("signMethod", "02");
  534. string content = LiSAgentId + sn + merchNo + "02";
  535. // string content = "{\"agentId\":\"" + LiSAgentId + "\",\"deviceSn\":\"" + sn + "\",\"merchNo\":\"" + merchNo + "\",\"signMethod\":\"02\"}";
  536. string signstr = LiSSign(content);
  537. dic.Add("signData", signstr);
  538. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  539. function.WriteLog("请求地址:" + LiSReqUrl + "FEE001", "查询商户费率");
  540. function.WriteLog("请求参数:" + req, "查询商户费率");
  541. string result = PostWebRequest(LiSReqUrl + "FEE001", req, new Dictionary<string, string>());
  542. function.WriteLog("返回报文:" + result + "\n\n\n", "查询商户费率");
  543. return result;
  544. }
  545. #endregion
  546. #region 盛付通
  547. string SftPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4GqoHzDfRk9ibYJ/8iSDGX4+WH5+8mq/raqA77VcAD+bMrt3Bm59XmaWtjZwDY1zh5sP5jEaxu4lde2xZD80kQ6p1ZydpqnjmWm6NKXSz8j85gRkTQqNALKNANnJb6f1Yy30WirnrhMkqU2dqBzzXxtk3k/2zv9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4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  548. // string SftPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEtC73mdnEQ5b0G93Dseg457m6Rc8lVU9K31SEc0YyK4anN3fgGDOl2CuQT2JIaxwwqCAHoUQp7jLUirc7XUQlh+y0WnYgPre6jmfI9upuJwTD7TmUr+Mqtg2RZTYX1r81OtRL/ELQW/lm4kBcuXeCWVlwhMyAQiJdb9+plkYXIwIDAQAB";
  549. string OrgId = "38844193";
  550. // string SftPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAILFLdmFwfNHCGk3vpwj/FR9XpE9jjVreLlOaIEkSAOWOfzxCF7pMeSy0UDroRLgfLD4nQbUcK5AT7gg8PEM6H99SEHcpBkTKhfK1iI5iU9sN/WGL2Ft5T/uwo+KD7X3CsqMD0HsMQtv/YHJeAz/SPf5zyD5KttwohXXzO8a3P1pAgMBAAECgYAchxl2f6iNAu0Bzyhk9bDBWcw8kRop6zUd7836hkizh51E4ew6kFLTGnNt3zl3XcO187aF2+htCxiZCY6md3NstJod1zshoXf2slxxPWRUK92sS0XzlVT6ahVTdq2tAS3hOY3ldtnfOXMmMQPNn9OqlALQGOH/hJatBV6ZQxpp0QJBAMGKsxJkg3M6sZEO4zUgWgnGN+uS6nwAWpCfBY7eDvYSN78BxGGLgn+t40c0R8M/n85IM8OUmfHxTGWN3hYyGuUCQQCs+Kg1ypul9XLTWrVApyvZxY4ZxjAWG4yW4xqbUtHWUkGyle7Dy8xiYezl0kWN81lJNTz3qrJ4ZvM825+7tPw1AkBDPNxZV3ITZiCqNHHa0xJ0sthajv/HdJgCBjz4FU09T7buNL705HLByLdc1VzZCBGMqKjTGZ0h4KKZ5V9ydpXBAkABpZx0Zql0uxGM0aBILU9Nk4P22tw6WajNBvyJ3hABamcVvDe5xYb8qNIInifrYhXHjKo38XghjVljivPKZb7BAkAt4pCUYLI7LzLeSh/lnVxA7jOaRI3UsngCXn9VA4f+dkNcKAftRQqe7ytudqG07GKoInnDiyjrYe4kTLym8zoc";
  551. // string OrgId = "88031499";
  552. string SftReqUrl = "https://zqb.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  553. public string SftEncrypt(string data)
  554. {
  555. var rsa = RSA.Create();
  556. var key = Convert.FromBase64String(SftPrivateKey);
  557. var content = Encoding.UTF8.GetBytes(data);
  558. rsa.ImportPkcs8PrivateKey(key, out _);
  559. var result = rsa.SignData(content, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
  560. return Convert.ToBase64String(result);
  561. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, SftPrivateKey).Encrypt(data);
  562. }
  563. //设置机具押金
  564. public string SetDepositForSft(string snNo, string policyNo)
  565. {
  566. Dictionary<string, object> req = new Dictionary<string, object>();
  567. req.Add("orgPromoterId", OrgId);
  568. req.Add("promoterId", OrgId);
  569. List<Dictionary<string, object>> snPolicyList = new List<Dictionary<string, object>>();
  570. Dictionary<string, object> item = new Dictionary<string, object>();
  571. item.Add("policyNo", policyNo);
  572. item.Add("sn", snNo);
  573. snPolicyList.Add(item);
  574. req.Add("snPolicyList", snPolicyList);
  575. req.Add("signType", "RSA");
  576. req.Add("charType", "UTF-8");
  577. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  578. req.Add("requestTime", function.GetCurTimestamp());
  579. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  580. string signString = "";
  581. foreach (string key in req.Keys)
  582. {
  583. if (key == "snPolicyList")
  584. {
  585. signString += key + "=" + Newtonsoft.Json.JsonConvert.SerializeObject(req[key]) + "&";
  586. }
  587. else
  588. {
  589. signString += key + "=" + req[key].ToString() + "&";
  590. }
  591. }
  592. signString = signString.TrimEnd('&');
  593. req.Add("mac", SftEncrypt(signString));
  594. string result = function.PostWebRequest(SftReqUrl + "batchUpdateSnPolicyNo", Newtonsoft.Json.JsonConvert.SerializeObject(req), "application/json");
  595. return result;
  596. }
  597. public string SftSnBindOrUnbind(string snNo, string merchantId)
  598. {
  599. Dictionary<string, object> req = new Dictionary<string, object>();
  600. req.Add("orgPromoterId", OrgId);
  601. req.Add("promoterId", OrgId);
  602. req.Add("merchantId", merchantId);
  603. req.Add("terminalId", snNo);
  604. req.Add("sn", snNo);
  605. req.Add("hasServiceFee", "0");
  606. req.Add("signType", "RSA");
  607. req.Add("charType", "UTF-8");
  608. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  609. req.Add("requestTime", function.GetCurTimestamp());
  610. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  611. string signString = "";
  612. foreach (string key in req.Keys)
  613. {
  614. signString += key + "=" + req[key].ToString() + "&";
  615. }
  616. signString = signString.TrimEnd('&');
  617. req.Add("mac", SftEncrypt(signString));
  618. string reqString = Newtonsoft.Json.JsonConvert.SerializeObject(req);
  619. function.WriteLog(DateTime.Now.ToString() + "\n" + reqString, "盛付通商户换绑或解绑日志");
  620. string result = function.PostWebRequest(SftReqUrl + "bindOrUnbindTerminalSn", reqString, "application/json");
  621. function.WriteLog(result + "\n\n\n", "盛付通商户换绑或解绑日志");
  622. return result;
  623. }
  624. #endregion
  625. #region 海科
  626. string HKPrivateKey1 = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK5iJ2q2nF+9jEnof9VYhMdbAgI0ZS4cYmgWTMW2JR61lJhR0GH+A/m6mjN9FsTS6Bq03u/+e6BKdE6VqMGk0q7asi2VZIgD59zj4HubS8EFrcb5ZprwmGLnG71cBga7V5EWnHxSB9BlbFt6rGeQiit8NSbv62NxGh1U+rAVE/a3AgMBAAECgYEApQGxpJNowls8bQ74LytUcMMX0ng7qXcoUq+PM6IX28gb9EmuMZtHrb05fjEGI3YiNGsjbNpTpqftCBMrHRjWVRgb0PDf/zD9YYrxmcP9DWKQjG5f1ygYtQBlnOPEX963Y2SXrsTKr4+szTpI8r6YqFfVbbooKVMesCBtshgg16kCQQDYHGDuCuOzULP84QvGi8z+wHNv0arFpYYxvwitntD7K3iolAh8gTDWeaC03MHruGM43ybCUi9EHhCrcVKjgpK1AkEAzpIUajdmAAwtwGg4G0v7tP/ulmpGhnALVN84gSMAc5f8D6aCnoUyle+GylwRBw9WblHBLxsOtARQIvvdphDrOwJBAIFvXc60zvQTHfoTf84G5VyfP4R1e2atYNZiqHv0Zw5IVxgAsaSAbBPI/SvWHH9mDGd/n+M6/fw6VZmZYfl0txECQQCQB3yifpPpDpTL5h7QsY8EKbqyN9GKpQ7Rk35zU/NZpawDQYcrfhXCQytJZx4cPQ53hxtae9QpoiQ58EEgLAXHAkABzJ/QDS1QfYrkP9t9X+Pny2iEuWGeIHyfsfSKQKr5pv16k1WqiIvlFRyDPl+aw5IOedkYb0vSkcU1KzjMW+Ra";
  627. string HKPublicKey1 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuYidqtpxfvYxJ6H/VWITHWwICNGUuHGJoFkzFtiUetZSYUdBh/gP5upozfRbE0ugatN7v/nugSnROlajB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JWacdQN2+w+MnO7w91nwdItHBj8DHST/7xrs1nxdpi2NL+Jia8XV7hnlqX1p5eAz9GkEuqpFJXoun9L1ku+sHaR7ylBm9ezc/3/Xs6+bQIDAQAB";
  630. string HKOrgNo1 = "747187394495131648"; //快联盟电签pos
  631. string HKOrgNo2 = "747189644974104576"; //快联盟大pos
  632. string HKReqUrl = "https://org-push.juheposp.com"; //请求url
  633. public string HKDecrypt(string data, string sign, int BrandId)
  634. {
  635. var toDecryptArray = Convert.FromBase64String(sign);
  636. var rsa2 = RSA.Create();
  637. string HKPrivateKey = "";
  638. if(BrandId == 8)
  639. {
  640. HKPrivateKey = HKPrivateKey1;
  641. }
  642. else if(BrandId == 9)
  643. {
  644. HKPrivateKey = HKPrivateKey2;
  645. }
  646. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(HKPrivateKey), out _);
  647. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  648. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  649. return AesDecrypt(data, aeskey);
  650. }
  651. public string HKEncrypt(string sign, int BrandId)
  652. {
  653. string HKPublicKey = "";
  654. if(BrandId == 8)
  655. {
  656. HKPublicKey = HKPublicKey1;
  657. }
  658. else if(BrandId == 9)
  659. {
  660. HKPublicKey = HKPublicKey2;
  661. }
  662. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", HKPublicKey).Encrypt(sign);
  663. }
  664. public string HKAesEncrypt(string str, string aeskey)
  665. {
  666. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  667. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  668. {
  669. Key = Encoding.UTF8.GetBytes(aeskey),
  670. Mode = System.Security.Cryptography.CipherMode.ECB,
  671. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  672. };
  673. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  674. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  675. return Convert.ToBase64String(resultArray);
  676. }
  677. //设置机具押金
  678. public string SetDepositForHK(string snNo, string oldMarketId, string newMarketId, int BrandId)
  679. {
  680. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  681. return HKReqFunc("/org/pos/updatePosMarket", data, BrandId);
  682. }
  683. //查询配置活动信息
  684. public string QueryActiveForConfigHK(string snNo, int BrandId)
  685. {
  686. string data = "{\"snNo\":\"" + snNo + "\"}";
  687. return HKReqFunc("/org/pos/getMarketConfig", data, BrandId);
  688. }
  689. //查询营销活动信息
  690. public string QueryActiveForBrandHK(int marketType, int BrandId)
  691. {
  692. string data = "{\"marketType\":\"" + marketType + "\"}";
  693. return HKReqFunc("/org/pos/marketList", data, BrandId);
  694. }
  695. public string HKReqFunc(string apiPath, string data, int BrandId)
  696. {
  697. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  698. string req = "{";
  699. if (BrandId == 8)
  700. {
  701. req += "\"orgId\":\"" + HKOrgNo1 + "\",";
  702. }
  703. else
  704. {
  705. req += "\"orgId\":\"" + HKOrgNo2 + "\",";
  706. }
  707. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  708. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  709. req += "\"version\":\"1.0\",";
  710. req += "\"data\":\"" + HKAesEncrypt(data, aeskey) + "\",";
  711. req += "\"sign\":\"" + HKEncrypt(aeskey, BrandId) + "\"";
  712. req += "}";
  713. string result = function.PostWebRequest(HKReqUrl + apiPath, req, "application/json");
  714. return result;
  715. }
  716. #endregion
  717. #region 联动
  718. //测试环境
  719. // string LDRequestUrl = "http://111.14.221.188:18066/CloudTerminalServiceAction/";
  720. // string AgentNo = "LD110014";
  721. // string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3WG04QXTzWBg2rj4BbSmnXVTqQiCk2lZ7yi2vur2LxsSc+KN0o1W9y2AkCHcFIAk2aAfMEMQYTO3HQ+F/Vcb27BNBSjnaOLfGv0PXNHKyVzC4EQLe4M5Pqd1wMl6NaZK+HnyrPBTnfsGeywhGJc1Ke96ANrydhk7UbwezydC7nQIDAQAB";
  722. // 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==";
  723. //生产环境
  724. string LDRequestUrl = "http://ldys.umpay.com/service_exter/CloudTerminalServiceAction/";
  725. string AgentNo = "LD112692";
  726. string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGtWShTeFEgSSFx3PJXcjCOmS+OgtcUvPOHhpALY3Orm6t7rl1E0n3j7XlM049YwwtGRJI4OWhgrtR4/AnOMBXdyMBoKxF23uay1WQiNekzfUrTwil7/CRrQ+VlGgPe6dr3WQT2/HLbzMnJHeoIZ4KSIj/7pgAwTF4ciL1UC3awwIDAQAB";
  727. 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==";
  728. public string LDEncrypt(string data)
  729. {
  730. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LDPublicKey).Encrypt(data);
  731. }
  732. public string LDDecrypt(string data)
  733. {
  734. var toDecryptArray = Convert.FromBase64String(data);
  735. var toKey = Convert.FromBase64String(LDPrivateKey);
  736. var rsa = RSA.Create();
  737. rsa.ImportPkcs8PrivateKey(toKey, out _);
  738. string result = "";
  739. List<byte> cache = new List<byte>();
  740. for (int i = 0; i < toDecryptArray.Length; i++)
  741. {
  742. cache.Add(toDecryptArray[i]);
  743. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  744. {
  745. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  746. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  747. cache.Clear();
  748. }
  749. }
  750. return result;
  751. }
  752. public string LDServiceFee(string SnList, int ServiceFee, int BrandId)
  753. {
  754. function.WriteLog(DateTime.Now.ToString(), "设置联动机具服务费");
  755. function.WriteLog(SnList, "设置联动机具服务费");
  756. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  757. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  758. string TerminalModeName = BrandId == 10 ? "DZA" : "DZDA";
  759. int PosType = BrandId == 10 ? 2 : 3;
  760. reqdic.Add("rpid", RequestId); //请求流水
  761. reqdic.Add("agentNumber", AgentNo); //代理商编号
  762. reqdic.Add("snList", SnList.Split(',').ToList()); //SN号
  763. reqdic.Add("posType", PosType); //2:电签 3 大pos
  764. reqdic.Add("terminalModeName", TerminalModeName); //终端模式名
  765. reqdic.Add("fwfRate", ServiceFee); //服务费
  766. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  767. function.WriteLog(req, "设置联动机具服务费");
  768. req = LDEncrypt(req);
  769. function.WriteLog(req, "设置联动机具服务费");
  770. Dictionary<string, object> datadic = new Dictionary<string, object>();
  771. datadic.Add("encryptedData", req);
  772. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  773. function.WriteLog("请求地址:" + LDRequestUrl + "terminalSelfDistribute", "设置联动机具服务费");
  774. string result = function.PostWebRequest(LDRequestUrl + "terminalSelfDistribute", data, "application/json");
  775. function.WriteLog(result + "\n\n", "设置联动机具服务费");
  776. return result;
  777. }
  778. #endregion
  779. #region 盒易付
  780. //测试环境
  781. // string BoxRequestUrl = "https://openapi-test.iboxpay.com/api";
  782. // string BoxAppId = "8840021411446784";
  783. // string BoxAppSecret = "xgwGnmYGjVy0GOWOWkQtRk8Hk8ur5tCV";
  784. // string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjMQxp24mjxDTr13uPW0y+tiO1yXFGw7P/pPQ0oZKK7F6KstEaus7pLEywBZ5XRXE5jgkhR2TS7Ne7djJfbpn5yFc6pPlz3ZsOfBVeB88NEwhx6xzCGX2eqSSkO33n8w2G0xc2ss5HpYBarT00NBZWhrwOXpdRPYLOYHKVU3Rl+FA9xDw/wYfoWvrr+JSfHRGn/ENMmQFEdckAbPauKaQMrZD2kz+PRrhq56eWnCuVQPcaz/jroVT8qQEgkg2IsNy+DwfLOIqm8IySEpxnQ5wN/KvsQJc2wXDQNf9F5kvWwjoqSSP0qJS+oPRXET+zJb+WTk2y5M6AYoC9NodwsC4NwIDAQAB";
  785. // string BrhCode = "039001";
  786. //生产环境
  787. string BoxRequestUrl = "https://openapi.iboxpay.com/api";
  788. string BoxAppId = "AP5879017839106039808";
  789. string BoxAppSecret = "DGtftIyl6R3nzwPr5YuV5fnmkfwufXRj";
  790. string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmjoQirIYZBD9Qon2HkF4j/NAINXtJ7Lzq/WXxTF7t7mg7LNARt0+ZZaeWx8caq2fv5zdsGyyoInL23cBtDI5KmFfK69iA0ygQMK0WbiKqsUB1OpPbT3+9zLuadIJAznjA223lY6CIjTpdLZhaRjImNVqc60bdkx6YsQcA+xW+3r1JH4PPHb7yBEbkKIX8OhyX7U4p0TkbDkAobbjHr5YB9gmYLoSFJMOPfTtSExkv7/Y7IVR9poZAHcr3teFoAiXW3RzxelRtnXxIkl/6AUOKoL5fhr/UTUN+Q18uzNljYWr6SwnTI3EmtzgykaewWtZvV85Xdhe/BjiQ5Xor7YbwIDAQAB";
  791. string BrhCode = "039034";
  792. string CybBrhCode = "039034002";
  793. public string BoxServiceFee(string SnList, string ServiceFee, int UserId = 0)
  794. {
  795. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具服务费");
  796. function.WriteLog(SnList, "设置盒易付机具服务费");
  797. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  798. Dictionary<string, string> headdic = new Dictionary<string, string>();
  799. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  800. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  801. headdic.Add("appid", BoxAppId);//开发者id
  802. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  803. headdic.Add("X-Up-AppId", BoxAppId);
  804. headdic.Add("X-Timestamp", timestamp);
  805. headdic.Add("X-Sign-Type", "SHA-256");
  806. reqdic.Add("snList", SnList.Split(',').ToList());//终端列表
  807. if(ServiceFee != "0")
  808. {
  809. ServiceFee += "00";
  810. }
  811. reqdic.Add("depositGear", ServiceFee);//押金档位
  812. reqdic.Add("modelId", "MHN10916");//费率,固定0.6
  813. if(UserId == 123005)
  814. {
  815. reqdic.Add("brhCode", CybBrhCode);//机构号
  816. }
  817. else
  818. {
  819. reqdic.Add("brhCode", BrhCode);//机构号
  820. }
  821. reqdic.Add("batchNo", batchNo);//批次号
  822. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  823. headdic.Add("X-Sign", SHA256Sign(timestamp + BoxAppSecret + req));
  824. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  825. function.WriteLog("请求头\n" + head, "设置盒易付机具服务费");
  826. function.WriteLog("请求参数\n" + req, "设置盒易付机具服务费");
  827. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/register/terms", "设置盒易付机具服务费");
  828. string result = PostWebRequest(BoxRequestUrl + "/inst/register/terms", req, headdic);
  829. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具服务费");
  830. return result;
  831. }
  832. public string BoxFee(string MerNo, string Fee)
  833. {
  834. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具费率");
  835. function.WriteLog(MerNo, "设置盒易付机具费率");
  836. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  837. Dictionary<string, string> headdic = new Dictionary<string, string>();
  838. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  839. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  840. headdic.Add("appid", BoxAppId);//开发者id
  841. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  842. headdic.Add("X-Up-AppId", BoxAppId);
  843. headdic.Add("X-Timestamp", timestamp);
  844. headdic.Add("X-Sign-Type", "SHA-256");
  845. reqdic.Add("mchtNo", MerNo);//终端列表
  846. reqdic.Add("brhCode", BrhCode);//机构号
  847. reqdic.Add("tNDiscId", Fee == "0.6" ? "MHN10916" : "MHN10917");//费率模型
  848. reqdic.Add("effectiveFlag", "1");//立即生效
  849. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  850. headdic.Add("X-Sign", SHA256Sign(timestamp + BoxAppSecret + req));
  851. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  852. function.WriteLog("请求头\n" + head, "设置盒易付机具费率");
  853. function.WriteLog("请求参数\n" + req, "设置盒易付机具费率");
  854. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/mcht/update_disc", "设置盒易付机具费率");
  855. string result = PostWebRequest(BoxRequestUrl + "/inst/mcht/update_disc", req, headdic);
  856. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具费率");
  857. return result;
  858. }
  859. public string SHA256Sign(string toSignStr)
  860. {
  861. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  862. SHA256 sha256 = SHA256.Create();
  863. byte[] signByte = sha256.ComputeHash(toSignByte);
  864. string sign = Convert.ToBase64String(signByte);
  865. return sign;
  866. }
  867. public bool VerifySign(string toSignStr, string signStr)
  868. {
  869. byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
  870. byte[] signByte = Convert.FromBase64String(signStr);
  871. var toKey = Convert.FromBase64String(BoxPublicKey);
  872. var rsaroot = RSA.Create();
  873. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  874. var publicKeyParameters = rsaroot.ExportParameters(false);
  875. using (var rsa = RSA.Create())
  876. {
  877. rsa.ImportParameters(publicKeyParameters);
  878. var sha256 = SHA256.Create();
  879. var hash = sha256.ComputeHash(toSignByte);
  880. return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  881. }
  882. }
  883. public string SignData(string toSignStr)
  884. {
  885. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  886. var toKey = Convert.FromBase64String(BoxPublicKey);
  887. var rsaroot = RSA.Create();
  888. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  889. var publicKeyParameters = rsaroot.ExportParameters(false);
  890. using (var rsa = RSA.Create())
  891. {
  892. rsa.ImportParameters(publicKeyParameters);
  893. var sha256 = SHA256.Create();
  894. var hash = sha256.ComputeHash(toSignByte);
  895. byte[] endByte = rsa.SignData(toSignByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  896. return Convert.ToBase64String(endByte);
  897. }
  898. }
  899. #endregion
  900. #region POSP
  901. //测试环境
  902. // string AesSecret = "6v8cr0uyhtwtawda";
  903. // string PospRequestUrl = "http://120.76.196.209:9221";
  904. //生产环境
  905. string AesSecret = "6v8cr0uyhtwtawda";
  906. string PospRequestUrl = "https://sale.posp.kexiaoshuang.com";
  907. public string PospQueryServiceFee()
  908. {
  909. SortedList<string, string> param = new SortedList<string, string>();
  910. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  911. function.WriteLog("原始数据:" + PushData, "查询POSP机具服务费政策");
  912. string content = EncryptHelper.Encrypt1(param, AesSecret);
  913. string PushDataEncrypt = content;
  914. function.WriteLog("加密数据:" + content, "查询POSP机具服务费政策");
  915. SortedList<string, string> obj = new SortedList<string, string>();
  916. obj.Add("type", "设置服务费");
  917. obj.Add("notice_id", Guid.NewGuid().ToString());
  918. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  919. obj.Add("content", content);
  920. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  921. function.WriteLog("请求参数:" + requestJson, "查询POSP机具服务费政策");
  922. function.WriteLog("请求地址:" + PospRequestUrl + "/pos/deposit/query", "查询POSP机具服务费政策");
  923. string result = function.PostWebRequest(PospRequestUrl + "/pos/deposit/query", requestJson, "application/json");
  924. function.WriteLog("返回报文:" + result, "查询POSP机具服务费政策");
  925. JsonData jsonObj = JsonMapper.ToObject(result);
  926. if(jsonObj["code"].ToString() == "200")
  927. {
  928. result = EncryptHelper.AesDecrypt(jsonObj["content"].ToString(), AesSecret);
  929. function.WriteLog("内容信息:" + result, "查询POSP机具服务费政策");
  930. }
  931. function.WriteLog("\n\n", "查询POSP机具服务费政策");
  932. return result;
  933. }
  934. public string PospQueryFee()
  935. {
  936. SortedList<string, string> param = new SortedList<string, string>();
  937. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  938. function.WriteLog("原始数据:" + PushData, "查询POSP机具费率政策");
  939. string content = EncryptHelper.Encrypt1(param, AesSecret);
  940. string PushDataEncrypt = content;
  941. function.WriteLog("加密数据:" + content, "查询POSP机具费率政策");
  942. SortedList<string, string> obj = new SortedList<string, string>();
  943. obj.Add("type", "设置服务费");
  944. obj.Add("notice_id", Guid.NewGuid().ToString());
  945. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  946. obj.Add("content", content);
  947. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  948. function.WriteLog("请求参数:" + requestJson, "查询POSP机具费率政策");
  949. function.WriteLog("请求地址:" + PospRequestUrl + "/marketing/plan/query", "查询POSP机具费率政策");
  950. string result = function.PostWebRequest(PospRequestUrl + "/marketing/plan/query", requestJson, "application/json");
  951. function.WriteLog("返回报文:" + result, "查询POSP机具费率政策");
  952. JsonData jsonObj = JsonMapper.ToObject(result);
  953. if(jsonObj["code"].ToString() == "200")
  954. {
  955. result = EncryptHelper.AesDecrypt(jsonObj["content"].ToString(), AesSecret);
  956. function.WriteLog("内容信息:" + result, "查询POSP机具费率政策");
  957. }
  958. function.WriteLog("\n\n", "查询POSP机具费率政策");
  959. return result;
  960. }
  961. public string PospServiceFee(List<string> pos_no, string deposit_id, string deposit_name)
  962. {
  963. SortedList<string, object> param = new SortedList<string, object>();
  964. param.Add("pos_no", pos_no); //商户号
  965. param.Add("deposit_id", deposit_id); //政策ID
  966. param.Add("deposit_name", deposit_name); //政策名称
  967. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  968. function.WriteLog("原始数据:" + PushData, "设置POSP机具服务费");
  969. string[] signData = EncryptHelper.Encrypt1(param, AesSecret);
  970. string content = signData[0];
  971. string sign = signData[1];
  972. function.WriteLog("加密数据:" + content, "设置POSP机具服务费");
  973. SortedList<string, string> obj = new SortedList<string, string>();
  974. obj.Add("type", "设置服务费");
  975. obj.Add("notice_id", Guid.NewGuid().ToString());
  976. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  977. obj.Add("content", content);
  978. obj.Add("sign", sign);
  979. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  980. function.WriteLog("请求参数:" + requestJson, "设置POSP机具服务费");
  981. function.WriteLog("请求地址:" + PospRequestUrl + "/pos/deposit/modify", "设置POSP机具服务费");
  982. string result = function.PostWebRequest(PospRequestUrl + "/pos/deposit/modify", requestJson, "application/json");
  983. function.WriteLog("返回报文:" + result, "设置POSP机具服务费");
  984. function.WriteLog("\n\n", "设置POSP机具服务费");
  985. return result;
  986. }
  987. public string PospFee(List<string> merch_no, string plan_id, string plan_name)
  988. {
  989. SortedList<string, object> param = new SortedList<string, object>();
  990. param.Add("merch_no", merch_no); //商户号
  991. param.Add("plan_id", plan_id); //政策ID
  992. param.Add("plan_name", plan_name); //政策名称
  993. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  994. function.WriteLog("原始数据:" + PushData, "设置POSP机具费率");
  995. string[] signData = EncryptHelper.Encrypt1(param, AesSecret);
  996. string content = signData[0];
  997. string sign = signData[1];
  998. function.WriteLog("加密数据:" + content, "设置POSP机具费率");
  999. SortedList<string, string> obj = new SortedList<string, string>();
  1000. obj.Add("type", "设置费率");
  1001. obj.Add("notice_id", Guid.NewGuid().ToString());
  1002. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  1003. obj.Add("content", content);
  1004. obj.Add("sign", sign);
  1005. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  1006. function.WriteLog("请求参数:" + requestJson, "设置POSP机具费率");
  1007. function.WriteLog("请求地址:" + PospRequestUrl + "/marketing/plan/modify", "设置POSP机具费率");
  1008. string result = function.PostWebRequest(PospRequestUrl + "/marketing/plan/modify", requestJson, "application/json");
  1009. function.WriteLog("返回报文:" + result, "设置POSP机具费率");
  1010. function.WriteLog("\n\n", "设置POSP机具费率");
  1011. return result;
  1012. }
  1013. #endregion
  1014. #region 来客吧L版
  1015. // 生产环境
  1016. string lkbClientId = "80000177";
  1017. string lkbMfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9w73juFDZe2n+D4Izav/B3VmkjP1b4wkc/4rv72DeK8uwGx1qWuEm+S5le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eza8diEzhqtav4+K3wlmj2YBknNp1mc8o++d0MFrO01jAPdG3PAkBvAD3lZvd4m10Q92ikomH79IeQRh5mEBxfUsDXk+khHzjONmYgpo46TQBZ1okNW0amIemQhBbs/bEZZUGukPdn";
  1020. string lkbReqUrl = "https://lkb-fire-api.ileshua.com/channel-app/api/terminal/serviceFeeSet";
  1021. string lkbReqUrl2 = "https://lkb-fire-api.ileshua.com/channel-app/api/rate/update";
  1022. public bool LkbVerify()
  1023. {
  1024. string data = "ZV0BBQ2hNgeZKKAPZ3XXEJGhp/h3+Mq5ejxuCI9SRbrDRls0XtfJRWboT5+J1sfHkb/J3eI4ThkTI/DjRNLK4x7fFYD62coClL7zDXeES42RXrpBik7VHHllUIS5nZFT23QME8kxRdo/6FH7Sv0J7IP5Qtqe70b3syv1jXmv8JozoP6DQjqHnlggpRM+4Ppks5PXorvHW7yI3uOgJL06t0GWDZIh7FRQ6UU41ayDsY0Z8j9o5quD8DSGJ1po6YPdmr2FpbFL5hs+buYhfEwsOwbvU5Aawbt+XuNXlU21wjeyC/8h2/yiPJSpCGjNXzzY4BBIhWDIbyxrbV+7SGIC+gNK2oQV0Ldtq9dXmljqA8e2dWsa8IaGaXmfo/85Ef2W5qIByrn42K+rA1nzhbR+L0WPGd4ugyzx6eiUl6T0oXVMaTIIoM6fndrm7RubsfNRZizrkQ+ocnAraMnGPZq84NpRp0Qs+pg8mlAIrqQ0avDutY1jGkzFXAljYGhiPvN7ntydmn2P2jgiPfh65VWumcXU+cp8d/nTD8eT/HmVbXUNMp/1ckP+VoK2wdowvgmgAruD3Fjfo8EghAfWEfuAVIsErxGxKCF17AUI8ZIqa+JYxxaA9vjxklavLmB9MAovx3JQSGXqXNNTy3LBljb1dZr3yk0ER9Qv8K4Bqc7Ti6gHHBFc7uu+wnqD7kTieMn++TpNo44MR8tGSmN6lzZKrio1czTyLLANLzzH4lBipTalGjgFnKcaNdVloW63DKkpz3qugCeBotRDdkH3T7DtYVz41lmJyLlxToeyFxXzqV0yqopR62QIghRO/vI9DpMDJclQMKEaCs9Py4qgMz2BmTqnESU42XDyNCMY5JVGpClZJgXNPmWLU0xrOu7B/tMEfThj9pNPBqNkbWQkLZ1MaSiMrfoHfQ7krt6TV6B2rhyfwrjKysXex4IHUX0nRTT55HcqQc38FlpeC4+kaTTSRs0HGMteiq+3BfDY0vHxH84x22WeN7oE7JbD/Ttd6Tn4";
  1025. string signString = "cuo8Rp0Hhc1pzEkzvx3tlGV6aBhZoD3F+b1FM07IkCTQwTVzz0EzgO0auQt+Wqf9ndWERa7P9jTqHS4JKYQH+LGLXjVgQPekzrePNnIcVVFqjf3VC+xImxSxJLaChHxiF+ufDpU9symoesub51QRCPSUB3xuQ2uP2lSbVmgcjvw=";
  1026. var toDecryptArray = Convert.FromBase64String(data);
  1027. var toSignArray = Convert.FromBase64String(signString);
  1028. var rsa = RSA.Create();
  1029. rsa.ImportRSAPublicKey(Convert.FromBase64String(lkbMfe88PublicKey), out _);
  1030. return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1031. }
  1032. private byte[] LkbStrToToHexByte(string hexString)
  1033. {
  1034. hexString = hexString.Replace(" ", "");
  1035. if ((hexString.Length % 2) != 0)
  1036. hexString += " ";
  1037. byte[] returnBytes = new byte[hexString.Length / 2];
  1038. for (int i = 0; i < returnBytes.Length; i++)
  1039. returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
  1040. return returnBytes;
  1041. }
  1042. public string LkbDecrypt(string data)
  1043. {
  1044. var toDecryptArray = Convert.FromBase64String(data);
  1045. var rsa2 = RSA.Create();
  1046. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(lkbClientPrivateKey), out _);
  1047. string result = "";
  1048. List<byte> cache = new List<byte>();
  1049. for (int i = 0; i < toDecryptArray.Length; i++)
  1050. {
  1051. cache.Add(toDecryptArray[i]);
  1052. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  1053. {
  1054. var ContentArray = rsa2.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  1055. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  1056. cache.Clear();
  1057. }
  1058. }
  1059. return result;
  1060. }
  1061. public string LkbSetDeposit(string sn, decimal serviceFee)
  1062. {
  1063. serviceFee = serviceFee * 100;
  1064. Dictionary<string, string> headers = new Dictionary<string, string>();
  1065. headers.Add("X-Client", lkbClientId);
  1066. headers.Add("X-Security", "RSA");
  1067. DateTimeOffset currentTime = DateTimeOffset.UtcNow;
  1068. string rfc1123FormattedTime = currentTime.ToString("r");
  1069. headers.Add("X-Time", rfc1123FormattedTime);
  1070. headers.Add("X-Trace", function.get_Random(32));
  1071. function.WriteLog("请求地址\n" + lkbReqUrl, "来客吧L吧设置服务费");
  1072. string content = "{\"factorySequenceNo\":\"" + sn + "\",\"serviceFee\":\"" + serviceFee.ToString("f0") + "\",\"agencyNo\":\"" + lkbClientId + "\"}";
  1073. function.WriteLog("明文参数\n" + content, "来客吧L吧设置服务费");
  1074. content = LkbEncrypt(content);
  1075. string signstr = LkbSign(content);
  1076. headers.Add("X-Sign", signstr);
  1077. string req = "{\"param\":\"" + content + "\"}";
  1078. function.WriteLog("加密参数\n" + req, "来客吧L吧设置服务费");
  1079. string result = function.PostWebRequest(lkbReqUrl, req, headers, "application/json");
  1080. function.WriteLog("返回报文\n" + result + "\n\n\n", "来客吧L吧设置服务费");
  1081. return result;
  1082. }
  1083. public string LkbSetFee(string sn, decimal rate = 0.6M, int fee = 0)
  1084. {
  1085. List<Dictionary<string, string>> innerParamList = new List<Dictionary<string, string>>();
  1086. Dictionary<string, string> item = new Dictionary<string, string>();
  1087. item.Add("rateNo", "R1012");
  1088. item.Add("rateName", "刷卡交易手续费");
  1089. item.Add("rateValue", rate.ToString("f2"));
  1090. innerParamList.Add(item);
  1091. item = new Dictionary<string, string>();
  1092. item.Add("rateNo", "R1013");
  1093. item.Add("rateName", "刷卡结算手续费");
  1094. item.Add("rateValue", fee.ToString());
  1095. innerParamList.Add(item);
  1096. item = new Dictionary<string, string>();
  1097. item.Add("rateNo", "R1014");
  1098. item.Add("rateName", "扫码交易手续费");
  1099. item.Add("rateValue", "0.38");
  1100. innerParamList.Add(item);
  1101. item = new Dictionary<string, string>();
  1102. item.Add("rateNo", "R1015");
  1103. item.Add("rateName", "扫码结算手续费");
  1104. item.Add("rateValue", "0");
  1105. innerParamList.Add(item);
  1106. item = new Dictionary<string, string>();
  1107. item.Add("rateNo", "R1016");
  1108. item.Add("rateName", "借记卡封顶手续费");
  1109. item.Add("rateValue", "2500");
  1110. innerParamList.Add(item);
  1111. Dictionary<string, string> headers = new Dictionary<string, string>();
  1112. headers.Add("X-Client", lkbClientId);
  1113. headers.Add("X-Security", "RSA");
  1114. DateTimeOffset currentTime = DateTimeOffset.UtcNow;
  1115. string rfc1123FormattedTime = currentTime.ToString("r");
  1116. headers.Add("X-Time", rfc1123FormattedTime);
  1117. headers.Add("X-Trace", function.get_Random(32));
  1118. function.WriteLog("请求地址\n" + lkbReqUrl2, "来客吧L吧设置费率");
  1119. Dictionary<string, object> obj = new Dictionary<string, object>();
  1120. obj.Add("factorySequenceNo", sn);
  1121. obj.Add("productCode", "100");
  1122. obj.Add("productName", "来客吧");
  1123. obj.Add("innerParamList", innerParamList);
  1124. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  1125. function.WriteLog("明文参数\n" + content, "来客吧L吧设置费率");
  1126. content = LkbEncrypt2(content);
  1127. string signstr = LkbSign(content);
  1128. headers.Add("X-Sign", signstr);
  1129. string req = "{\"param\":\"" + content + "\"}";
  1130. function.WriteLog("加密参数\n" + req, "来客吧L吧设置费率");
  1131. string result = function.PostWebRequest(lkbReqUrl2, req, headers, "application/json");
  1132. function.WriteLog("返回报文\n" + result + "\n\n\n", "来客吧L吧设置费率");
  1133. return result;
  1134. }
  1135. public string LkbEncrypt(string data)
  1136. {
  1137. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", lkbMfe88PublicKey).Encrypt(data);
  1138. }
  1139. public string LkbEncrypt2(string data)
  1140. {
  1141. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", lkbMfe88PublicKey).Encrypt(data);
  1142. }
  1143. public string LkbSign(string data)
  1144. {
  1145. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  1146. var rsa = RSA.Create();
  1147. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(lkbClientPrivateKey), out _);
  1148. string result = "";
  1149. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1150. result = Convert.ToBase64String(buffer);
  1151. return result;
  1152. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, clientPrivateKey, "").Sign(data);
  1153. }
  1154. #endregion
  1155. #region 拉卡拉
  1156. // 生产环境
  1157. string lklClientId = "testsit";
  1158. string lklClientSecret = "EguwEckByf2I6u6z";
  1159. string lklReqUrl = "https://test.wsmsd.cn/sit";
  1160. string lklPriKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKnlpXdmJcbZHxh3w3Ghy/5wXtUBQcFzRMXgw2d7uYjzAzbIQ/ZCAj6srWoN/obtkU+G62kgcpByGmiVtK4LS+BoelKM705SzV+mcr8mNmr2jwNq1SwDSfgVxx5z00FtXl3LnKvCujvGYOmx6+nX8h6IiyyLX6IP6cFaqpUXHsZVAgMBAAECgYA4NpeM7etJ48T6H4Y3LsWEJkH6UDQlgbIblsaQkstMmLtTgOebrzN28UNfd8njcu9FVOrHGclOKbK7L+1cOLiduWsZKc/c/gAy9wAR4EhoLvlerH9EEPiPWFxdEDbMxPqlkpqLOo+PxHrhTn4vU4CaPdJtL2ujKn7nmsUdUDWo8QJBANS1TlM6nhPt2XlzN5kGfsJ4kBYNjuLXNA2YdNuC2ttYvEXHJ9T70FN/GnRBBIZu47uHH3Ie5nfep+qMk6a8RP8CQQDMecIyI0z1kVt+tOfWKw2ZFLsi74708qTaeR4W1ABtkngj1+bxoWWXr3KqhjqJkWxnhioSfXqu7CScNzjdM1CrAkAQd+ESjI1EmbumrYb2cAxMXi05p98SLPs4uj8B58WuCda5yEuLL9vXOxX/PjFtfxRepn2GxmGtki2J+UxNMnJdAkAFoORjlO0tZU7rcfdfwdeh+xwbnhSFUZiQGv1lC3jnizybX/oPdK3jOwUhBIjf+IzPXLYTxDh4UC/BzRNXo235AkEAhgYBk6H7RU2iIuvwz1c6CtE1gJ8DvEp1F0KOMWMFB0KCpDXUToix0dlMz962FozYENi4X4zYQo6nFwlXeS3Pfw==";
  1161. string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp5aV3ZiXG2R8Yd8Nxocv+cF7VAUHBc0TF4MNne7mI8wM2yEP2QgI+rK1qDf6G7ZFPhu tpIHKQchpolbSuC0vgaHpSjO9OUs1fpnK/JjZq9o8DatUsA0n4Fccec9NBbV5dy5yrwro7xmDpsevp1/IeiIssi1+iD+nBWqqVFx7GVQIDAQAB"; //解密api接口返回报文
  1162. // string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKPK6iG+eNwCRRs1lzE4bUyp6n0GMcj9s6lEPLIEYRpBHCCHpfGZ422SLwHqQ9zcU88lMbqfuSfQuJiPhNAqMHgmT7n2gYfxotL311lw1qG2ARJRSIyQ3oHXS6GBe9kFRWK8I/sVbuRxeV+toUs9N2EPjKequY28oxl9+AU3U6gQIDAQAB"; //解密推送消息
  1163. public string LkLGetToken()
  1164. {
  1165. string access_token = RedisDbconn.Instance.Get<string>("LkLApiToken");
  1166. if(string.IsNullOrEmpty(access_token))
  1167. {
  1168. Dictionary<string, string> headers = new Dictionary<string, string>();
  1169. headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(lklClientId + ":" + lklClientSecret)));
  1170. // Dictionary<string, string> req = new Dictionary<string, string>();
  1171. // req.Add("grant_type", "client_credentials");
  1172. // req.Add("client_id", lklClientId);
  1173. // req.Add("client_secret", lklClientSecret);
  1174. // string reqStr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
  1175. // function.WriteLog("请求参数\n" + reqStr, "拉卡拉获取Token");
  1176. // reqStr = LklEncrypt(reqStr);
  1177. // function.WriteLog("加密参数\n" + reqStr, "拉卡拉获取Token");
  1178. string result = function.PostWebRequest(lklReqUrl + "/htkauth/oauth/token?grant_type=client_credentials&client_id=" + lklClientId + "&client_secret=" + lklClientSecret, "", headers, "application/json");
  1179. function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉获取Token");
  1180. JsonData jsonObj = JsonMapper.ToObject(result);
  1181. if(result.Contains("\"access_token\""))
  1182. {
  1183. access_token = jsonObj["access_token"].ToString();
  1184. string expires_in = jsonObj["expires_in"].ToString();
  1185. RedisDbconn.Instance.Set("LkLApiToken", access_token);
  1186. RedisDbconn.Instance.SetExpire("LkLApiToken", int.Parse(function.CheckInt(expires_in)));
  1187. }
  1188. }
  1189. return access_token;
  1190. //{"access_token":"a54b216a-18b7-4a0b-b6b7-b37eee813b6e","token_type":"bearer","expires_in":872822,"scope":"all"}
  1191. }
  1192. public string LkLSetDeposit(string sn, decimal serviceFee)
  1193. {
  1194. string target = "ZC0801TEST1HD1";
  1195. if(serviceFee == 0) target = "22NHTK4GDQPOSFYHDAB";
  1196. if(serviceFee == 99) target = "ZC0801TEST1HD1";
  1197. if(serviceFee == 199) target = "0426_YJ199_1";
  1198. if(serviceFee == 299) target = "ZC0801TEST1HD1";
  1199. Dictionary<string, string> headers = new Dictionary<string, string>();
  1200. headers.Add("Authorization", "bearer " + LkLGetToken());
  1201. Dictionary<string, string> req = new Dictionary<string, string>();
  1202. req.Add("posSn", sn);
  1203. req.Add("type", "ACTIVITY");
  1204. req.Add("target", target);
  1205. string reqStr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
  1206. function.WriteLog("请求参数\n" + reqStr, "拉卡拉设置服务费");
  1207. reqStr = "{\"data\":\"" + LklEncrypt(reqStr) + "\"}";
  1208. function.WriteLog("加密参数\n" + reqStr, "拉卡拉设置服务费");
  1209. function.WriteLog("请求地址\n" + lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", "拉卡拉设置服务费");
  1210. string result = PostWebRequest(lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", reqStr, headers);
  1211. function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉设置服务费");
  1212. return result;
  1213. //{"code":"000000","data":"Oa4NF8tNLKthg9Q9klCLxyWtNJdAuL8n7NH5yM8VgM2eekpkzJ8/sFiY31NBo8qXGDcNi9GAiALsTZcEO5PAAZPsErhYQTeHoZ/cRkySVXm50r1aZ0osZfXysjrwvkP3lPLZzjeB21JldrUKviJ4k7YQunWC+B2Y4MX1ApZoTCw=","message":"SUCCESS","timestamp":1731552629806,"success":true,"fail":false}
  1214. }
  1215. public string LkLSetFee(string merNo, decimal rate = 0.6M, int fee = 0)
  1216. {
  1217. List<Dictionary<string, string>> innerParamList = new List<Dictionary<string, string>>();
  1218. Dictionary<string, string> item = new Dictionary<string, string>();
  1219. item.Add("feeType", "CREDIT_CARD");
  1220. item.Add("fee", rate.ToString("f2"));
  1221. innerParamList.Add(item);
  1222. Dictionary<string, string> headers = new Dictionary<string, string>();
  1223. headers.Add("Authorization", "bearer " + LkLGetToken());
  1224. function.WriteLog("请求地址\n" + lklReqUrl + "/htkmerchants/channel/customer/update/fee/" + merNo, "拉卡拉设置费率");
  1225. Dictionary<string, object> obj = new Dictionary<string, object>();
  1226. // obj.Add("productCode", "");
  1227. obj.Add("fees", innerParamList);
  1228. string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  1229. function.WriteLog("明文参数\n" + content, "拉卡拉设置费率");
  1230. content = LklEncrypt(content);
  1231. string req = "{\"dto\":\"" + content + "\"}";
  1232. function.WriteLog("加密参数\n" + req, "拉卡拉设置费率");
  1233. string result = function.PostWebRequest(lklReqUrl + "/htkmerchants/channel/customer/update/fee/" + merNo, req, headers);
  1234. function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉设置费率");
  1235. return result;
  1236. }
  1237. public string LklEncrypt(string data)
  1238. {
  1239. return new RSAForJava().EncryptByPrivateKey(data, lklPriKey);
  1240. }
  1241. public string LklDecrypt(string data)
  1242. {
  1243. return new RSAForJava().DecryptByPublicKey(data, lklPubKey);
  1244. }
  1245. public byte[] LklEncryptData(RSA rsa, byte[] data)
  1246. {
  1247. // using var memoryStream = new System.IO.MemoryStream();
  1248. // int offset = 0;
  1249. // byte[] buffer;
  1250. // while (offset < data.Length)
  1251. // {
  1252. // if (offset + 64 < data.Length)
  1253. // {
  1254. // buffer = data.AsSpan(offset, 64).ToArray();
  1255. // }
  1256. // else
  1257. // {
  1258. // buffer = data.AsSpan(offset, data.Length - offset).ToArray();
  1259. // }
  1260. // byte[] encrypted = rsa.Encrypt(buffer, RSAEncryptionPadding.Pkcs1);
  1261. // memoryStream.Write(encrypted);
  1262. // offset += buffer.Length;
  1263. // }
  1264. // return memoryStream.ToArray();
  1265. int inputLen = data.Length;
  1266. var memoryStream = new System.IO.MemoryStream();
  1267. int offSet = 0;
  1268. byte[] cache;
  1269. int i = 0;
  1270. // 对数据分段加密
  1271. while (inputLen - offSet > 0)
  1272. {
  1273. if (inputLen - offSet > 117)
  1274. {
  1275. cache = data.AsSpan(offSet, 117).ToArray();
  1276. }
  1277. else
  1278. {
  1279. cache = data.AsSpan(offSet, inputLen - offSet).ToArray();
  1280. }
  1281. byte[] encrypted = rsa.Encrypt(cache, RSAEncryptionPadding.OaepSHA1);
  1282. memoryStream.Write(encrypted);
  1283. i++;
  1284. offSet = i * 117;
  1285. }
  1286. byte[] encryptedData = memoryStream.ToArray();
  1287. return encryptedData;
  1288. }
  1289. #endregion
  1290. }
  1291. }