PublicImportDataService.cs 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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. namespace MySystem
  20. {
  21. public class PublicImportDataService
  22. {
  23. public readonly static PublicImportDataService Instance = new PublicImportDataService();
  24. private PublicImportDataService()
  25. { }
  26. #region 金控
  27. // 开发环境
  28. // string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCy8cg6/tXbSj2i1tyi7VztwJw7uNmqc3bS6sVIZkDYhTmcXhpV17jq4j2zz/tURwX8b3MdK1A1HTR1XRd7hl0w2UF9iFk6UezByJ5tdNDoffMCGJtVSThq+MCV+WQI26tJ/ub6bm7GPrzTR79fntN+nTniRM4trjONN2WzEhHEcwIDAQAB";
  29. // 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";
  30. // string clientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCb861uuey1252WdS8KPeBB+vm5AIBEKclsfBzVLY1cZXiiEbInCmsqT6fSO+A6wjWyJixGCzZICmUxhdBzuo3Du2YTbuo+fRlV6DW1mbguBV8/l2+LJvht0jl87J8N4skFUzvAeYKpWDX6dC6cLzjm5nyI1OrCQq0lsWPEMDCNAwIDAQAB";
  31. // string clientPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJvzrW657LXbnZZ1Lwo94EH6+bkAgEQpyWx8HNUtjVxleKIRsicKaypPp9I74DrCNbImLEYLNkgKZTGF0HO6jcO7ZhNu6j59GVXoNbWZuC4FXz+Xb4sm+G3SOXzsnw3iyQVTO8B5gqlYNfp0LpwvOObmfIjU6sJCrSWxY8QwMI0DAgMBAAECgYAjE0dqo/6NWHu1H14ZG5mYvW31Ihu3OP7Im5GQkNI+ecQMD5bWGQ3JUmkYa8ce8BdLnjJO/q6SvWPNI5+ip87CYPH1SMXKUiSLzaCrw4xMySW9PSnudTzJwhrmlmyjYTAg70tHf2YQC4YkNvtkR+PJ2yf6JEKGFVgP5p2KyeKXgQJBANjGryxyu95QC3jIaggcYmGD36sVO/ns8Uyu8PkAHYOscuXRcV0L8LghIzPolcehj9bTbDLjiuNgeuyjNs2YBvMCQQC4K4uIXt0kVDLYzlJfhN1CsV90vQitcKdD8wTO0JRKfMCQ6UDSumU7lq+z4TxTlRYxmZjpgIqH+N0WohmEiwWxAkBEfuMzBD3gjSJS0+DNF0ruzSCLinYdDoVgWZbC1wp8ZK0ZeQh9AhzZ0X6yFDffkGlG1B9IJSXpmr68rwXOCM+JAkBkrKEUxc6bGk/FRluvDWEqIO2uUdtZfBhjQ4ggSdKWOUXGsUsXJn9KKKAZc4lXo0rDiFQXaIXRuE+bHLdYReqxAkAj0Kol0LkJgdl2PoBAeyQHTpt9nxaeNX56W7CN/srBA1O2wr+aoQiJaKsu9I0EeW3zaMJlLi3VyjU4wnF+yAsB";
  32. // string reqUrl = "https://test-push.mfe88.com/push-service/api/SETSERVICEFEE";
  33. // 生产环境
  34. string merchantNo = "4487378308096";
  35. string clientId = "1243966544896";
  36. string mfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2HxPVZ5ZIxIWfr24qB45PAz9WfjN9CiF1x9Lz3P/tVvIXFdBaUw+9zxCAPRDGQxJId7anjEjCOuAIKpFOiTPhVqHTHd3075FFsW5fL7lFCOFJELTj+mVamAIbKalAuRzIX0m0VQUXd+madB+yRQSBjkOIboAMYQ9amf99SqI9KwIDAQAB";
  37. string clientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrSrNKkBt/X8Fkd7viGpTMk+GdJgE+SvoA4PSjccpZoLWnwxXsC8K/7pfm9uGxPjte9e4RznXE5nuhSrcfls4lDWhTrGd/lj3Id8OCM+yEG+xilJs1lvXJjHDhL6/wa+TE5NSzWoKgXnyeHF3TSHMbUefLLtoKqL3j4h4lPqrjiQIDAQAB";
  38. 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=";
  39. string reqUrl = "https://push.mfe88.com/push-service/api/SETSERVICEFEE";
  40. public string SetDeposit(string sn, decimal serviceFee)
  41. {
  42. serviceFee = serviceFee * 100;
  43. Dictionary<string, string> headers = new Dictionary<string, string>();
  44. headers.Add("X-Client-ID", clientId);
  45. headers.Add("X-Security", "RSA");
  46. string content = "{\"sn\":\"" + sn + "\",\"serviceFee\":\"" + serviceFee.ToString("f0") + "\"}";
  47. content = Encrypt(content);
  48. string signstr = Sign(content);
  49. headers.Add("X-Sign", signstr);
  50. string req = "{\"param\":\"" + content + "\"}";
  51. string result = function.PostWebRequest(reqUrl, req, headers, "application/json");
  52. return result;
  53. }
  54. public bool Verify()
  55. {
  56. 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";
  57. string signString = "cuo8Rp0Hhc1pzEkzvx3tlGV6aBhZoD3F+b1FM07IkCTQwTVzz0EzgO0auQt+Wqf9ndWERa7P9jTqHS4JKYQH+LGLXjVgQPekzrePNnIcVVFqjf3VC+xImxSxJLaChHxiF+ufDpU9symoesub51QRCPSUB3xuQ2uP2lSbVmgcjvw=";
  58. // var signer = SignerUtilities.GetSigner("SHA256withRSA");
  59. // var pubkey = Convert.FromBase64String(mfe88PublicKey);
  60. // // var pubkey = StrToToHexByte(mfe88PublicKey);
  61. // var publicKeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(pubkey);
  62. // signer.Init(false, publicKeyParam);
  63. // var signBytes = Convert.FromBase64String(signString);
  64. // var plainBytes = Convert.FromBase64String(data);
  65. // signer.BlockUpdate(plainBytes, 0, plainBytes.Length);
  66. // return signer.VerifySignature(signBytes);
  67. var toDecryptArray = Convert.FromBase64String(data);
  68. var toSignArray = Convert.FromBase64String(signString);
  69. // var pubkey = Encoding.UTF8.GetBytes(mfe88PublicKey);
  70. // using (var x509 = new X509Certificate2(pubkey))
  71. // {
  72. // using (var rsa = x509.GetRSAPublicKey())
  73. // {
  74. // return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  75. // }
  76. // }
  77. var rsa = RSA.Create();
  78. rsa.ImportRSAPublicKey(Convert.FromBase64String(mfe88PublicKey), out _);
  79. return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  80. }
  81. private byte[] StrToToHexByte(string hexString)
  82. {
  83. hexString = hexString.Replace(" ", "");
  84. if ((hexString.Length % 2) != 0)
  85. hexString += " ";
  86. byte[] returnBytes = new byte[hexString.Length / 2];
  87. for (int i = 0; i < returnBytes.Length; i++)
  88. returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
  89. return returnBytes;
  90. }
  91. public string Decrypt(string data)
  92. {
  93. var toDecryptArray = Convert.FromBase64String(data);
  94. var rsa = RSA.Create();
  95. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  96. string result = "";
  97. List<byte> cache = new List<byte>();
  98. for (int i = 0; i < toDecryptArray.Length; i++)
  99. {
  100. cache.Add(toDecryptArray[i]);
  101. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  102. {
  103. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  104. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  105. cache.Clear();
  106. }
  107. }
  108. return result;
  109. }
  110. public string Encrypt(string data)
  111. {
  112. // var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  113. // var rsa = RSA.Create();
  114. // rsa.ImportRSAPublicKey(Convert.FromBase64String(mfe88PublicKey), out _);
  115. // string result = "";
  116. // var buffer = rsa.Encrypt(toEncryptArray, RSAEncryptionPadding.Pkcs1);
  117. // result = Convert.ToBase64String(buffer);
  118. // return result;
  119. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", mfe88PublicKey).Encrypt(data);
  120. }
  121. public string Sign(string data)
  122. {
  123. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  124. var rsa = RSA.Create();
  125. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(clientPrivateKey), out _);
  126. string result = "";
  127. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  128. result = Convert.ToBase64String(buffer);
  129. return result;
  130. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, clientPrivateKey, "").Sign(data);
  131. }
  132. #endregion
  133. #region 开店宝
  134. //生产环境
  135. string KdbApiUrl = "https://kzy.kdb-tj.com:5055/api";
  136. string KDBAESKEY = "F@xh#sga41c08@pe";
  137. string Kdb_Rsa_PrivateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAl2x9dSSCfNDik6VM2dn/SK1ONSbb7AKyXM1gHw8PMbzWN1pK7YGaPqHlIRbAeFeIvLKVeMxrji+63W6LpB0yDQIDAQABAkAfpHUnCIUYDhJ65f0EPTDCgCyqoL8uN3YMPIKMmvoC22/i7AC6zf/bWk4JdratN+gvvnjGgHQff6HH5dOQ6sbFAiEAxPYSLADzIv374J8O+LluXIcgI5zXm4r4dMtKbCmmWSsCIQDE0BRKsBcBZ9NvJ9Km+m/d1hN9v5hFT842zrkUFJmVpwIgBdYc17z3d3P7QL613NzxzkAazbNaGDvX/O4BOI9LZJ0CICrZElHgXGHV9NYyWU45H7mwLbYmzEPqx/5uqySQB4/pAiBgKYv3RGnsZ8Zm1EKAJjUX7ehdteBgPSA/UgIDZQ4oyw==";
  138. string AgencyId = "3013890129";
  139. //开发环境
  140. // string KdbApiUrl = "https://kzy-test.kdb-tj.com:5056/api";
  141. // string KDBAESKEY = "Ebn4N28MvEXEvPTA";
  142. // string Kdb_Rsa_PrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAsPyH5Y5NySHHKWIgPwxbZFkd33vzuWKv+Kdpug5/qYAnpTShDSMXQ2Ib7gc+B/yvj4uZ/k1A/xHpzHTPl6MzQQIDAQABAkA2sGHhyj45B2n+XKbwNIZNFMiJVUjzoQ4VPM4Lww0pt781GeqBCGgEIgTjmmg/FTGjgwTb7ta1A5G9Qn2nPG0RAiEA4x7W6XKdSL/FyVdlt4jijNQNZfLEqEPy1NnchRWUf40CIQDHfb49KP3pW4ZDX3xS42fYd9p7AGZ+qpVBnJfGGyFrhQIhALk3HCHyowuBwMUKLdw3mDEqeOarzO4/w1cLd8dcKua9AiEAtdPAj9JLDGWljMb9dDddsYockzwcL5ufizwFgkW8QlkCIADYU4+fFKqySLGX3MmEIJ/mU632PRtJAh4LSL8/Ij1H";
  143. // string AgencyId = "3013890202";
  144. // 查询机构政策列表
  145. public string GetPolicyList()
  146. {
  147. string url = KdbApiUrl + "/marketing/plan/query/list";
  148. //[{"id":100014,"name":"韩测试营销方案(韩测试营销方案)"}]
  149. return PostKDB(url, "{}");
  150. }
  151. // 查询政策下的押金
  152. public string GetDepositList(string planId)
  153. {
  154. string url = KdbApiUrl + "/marketing/deposit/query/planId";
  155. string content = "{\"planId\":\"" + planId + "\"}";
  156. //[{"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}]
  157. return PostKDB(url, content);
  158. }
  159. // 设置政策下的押金金额
  160. public string GetDepositAmount(string DepositId)
  161. {
  162. string content = RedisDbconn.Instance.Get<string>("KdbDepositList");
  163. if (string.IsNullOrEmpty(content))
  164. {
  165. content = PublicImportDataService.Instance.GetPolicyList();
  166. JsonData tops = JsonMapper.ToObject(content);
  167. if (tops.Count > 0)
  168. {
  169. content = PublicImportDataService.Instance.GetDepositList(tops[0]["id"].ToString());
  170. }
  171. RedisDbconn.Instance.Set("KdbDepositList", content);
  172. RedisDbconn.Instance.SetExpire("KdbDepositList", function.get_Random(1800, 5400));
  173. }
  174. JsonData list = JsonMapper.ToObject(content);
  175. for (int i = 0; i < list.Count; i++)
  176. {
  177. JsonData item = list[i];
  178. if (DepositId == item["depositId"].ToString())
  179. {
  180. return item["amount"].ToString();
  181. }
  182. }
  183. return "0";
  184. }
  185. // 修改押金接口
  186. public string ModifyDeposit(string PosSn, string depositId)
  187. {
  188. string url = KdbApiUrl + "/pos/modify/deposit";
  189. string content = "{\"posSnStart\":\"" + PosSn + "\",\"posSnEnd\":\"" + PosSn + "\",\"depositId\":" + depositId + "}";
  190. return PostKDB(url, content);
  191. }
  192. // 修改费率接口
  193. public string ModifyFee(string PosSn, string Fee)
  194. {
  195. string url = KdbApiUrl + "/pos/rate/modify/single/remote";
  196. string content = "{\"posSn\":\"" + PosSn + "\",\"type\":\"贷记卡刷卡\",\"rate\":\"" + Fee + "\",\"d0Fee\":\"0\"}";
  197. return PostKDB(url, content);
  198. }
  199. // 查询费率接口
  200. public string QueryFee(string orderNo)
  201. {
  202. string url = KdbApiUrl + "/pos/rate/change/query/orderno";
  203. string content = "{\"orderNo\":\"" + orderNo + "\"}";
  204. return PostKDB(url, content);
  205. }
  206. public string KDBDecrypt(string data)
  207. {
  208. string result = AesDecrypt(data, KDBAESKEY);
  209. return result;
  210. }
  211. public string AesDecrypt(string str, string key)
  212. {
  213. if (string.IsNullOrEmpty(str)) return null;
  214. byte[] toEncryptArray = Convert.FromBase64String(str);
  215. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  216. {
  217. Key = Encoding.UTF8.GetBytes(key),
  218. Mode = System.Security.Cryptography.CipherMode.ECB,
  219. Padding = System.Security.Cryptography.PaddingMode.PKCS7,
  220. };
  221. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
  222. byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  223. return Encoding.UTF8.GetString(resultArray);
  224. }
  225. public string AesEncrypt(string str)
  226. {
  227. // if (string.IsNullOrEmpty(str)) return null;
  228. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  229. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  230. {
  231. Key = Encoding.UTF8.GetBytes(KDBAESKEY),
  232. Mode = System.Security.Cryptography.CipherMode.ECB,
  233. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  234. };
  235. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  236. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  237. return Convert.ToBase64String(resultArray);
  238. }
  239. public string PostKDB(string url, string content)
  240. {
  241. content = PublicImportDataService.Instance.AesEncrypt(content);
  242. string timestamp = function.GetCurTimestamp().ToString();
  243. string sign = PublicImportDataService.Instance.KDBSign(content + timestamp);
  244. string req = "{\"agencyId\":\"" + AgencyId + "\",\"content\":\"" + content + "\",\"timestamp\":\"" + timestamp + "\",\"sign\":\"" + sign + "\"}";
  245. string result = PostWebRequest(url, req, new Dictionary<string, string>());
  246. return result;
  247. }
  248. private string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> headers)
  249. {
  250. string ret = string.Empty;
  251. try
  252. {
  253. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  254. // 设置提交的相关参数
  255. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  256. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  257. request.Method = "POST";
  258. request.KeepAlive = false;
  259. request.AllowAutoRedirect = true;
  260. request.ContentType = "application/json";
  261. foreach (string key in headers.Keys)
  262. {
  263. request.Headers.Add(key, headers[key]);
  264. }
  265. 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)";
  266. request.ContentLength = postData.Length;
  267. // 提交请求数据
  268. System.IO.Stream outputStream = request.GetRequestStream();
  269. outputStream.Write(postData, 0, postData.Length);
  270. outputStream.Close();
  271. System.Net.HttpWebResponse response;
  272. System.IO.Stream responseStream;
  273. System.IO.StreamReader reader;
  274. string srcString;
  275. response = request.GetResponse() as System.Net.HttpWebResponse;
  276. responseStream = response.GetResponseStream();
  277. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  278. srcString = reader.ReadToEnd();
  279. ret = srcString; //返回值赋值
  280. reader.Close();
  281. }
  282. catch (System.Net.WebException ex)
  283. {
  284. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)ex.Response;
  285. System.IO.Stream myResponseStream = response.GetResponseStream();
  286. //获取响应内容
  287. System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream);
  288. ret = myStreamReader.ReadToEnd();
  289. myResponseStream.Close();
  290. }
  291. catch (Exception ex)
  292. {
  293. ret = "fail";
  294. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求开店宝API异常");
  295. }
  296. return ret;
  297. }
  298. public string KDBSign(string data)
  299. {
  300. var rsa = RSA.Create();
  301. var key = Convert.FromBase64String(Kdb_Rsa_PrivateKey);
  302. var content = Encoding.UTF8.GetBytes(data);
  303. rsa.ImportPkcs8PrivateKey(key, out _);
  304. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  305. return Convert.ToBase64String(result);
  306. }
  307. #endregion
  308. #region 乐刷
  309. 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==";
  310. string LSPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI5Xd35WPkfvVk0djL3EfaliEnZqWsi9xjRoPYL88JF5IQyPxO61+p3S71bmgWy1lwflDofvD38Nxr379w9hh2Qk8zxziq7Nrcs6gvBJjFA0GqFTiNgWOL7QeyIzXvRZSxmcetiRCazJBypzkkMbIvn5QqHsSnNrdau5ELDthftwIDAQAB";
  311. string OrgNo1 = "704067708098457600"; //快联盟电签pos
  312. string OrgNo2 = "704058964878831616"; //快联盟大pos
  313. string LSReqUrl = "https://lfs-org-push.ileshua.com"; //请求url
  314. public string LSDecrypt(string data, string sign)
  315. {
  316. var toDecryptArray = Convert.FromBase64String(sign);
  317. var rsa2 = RSA.Create();
  318. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(LSPrivateKey), out _);
  319. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  320. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  321. return AesDecrypt(data, aeskey);
  322. }
  323. public string LSEncrypt(string sign)
  324. {
  325. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LSPublicKey).Encrypt(sign);
  326. }
  327. public string LSAesEncrypt(string str, string aeskey)
  328. {
  329. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  330. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  331. {
  332. Key = Encoding.UTF8.GetBytes(aeskey),
  333. Mode = System.Security.Cryptography.CipherMode.ECB,
  334. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  335. };
  336. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  337. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  338. return Convert.ToBase64String(resultArray);
  339. }
  340. //设置机具押金
  341. public string SetDepositForLS(string snNo, string oldMarketId, string newMarketId, int BrandId)
  342. {
  343. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  344. return LSReqFunc("/org/pos/updatePosMarket", data, BrandId);
  345. }
  346. //查询配置活动信息
  347. public string QueryActiveForConfig(string snNo, int BrandId)
  348. {
  349. string data = "{\"snNo\":\"" + snNo + "\"}";
  350. return LSReqFunc("/org/pos/getMarketConfig", data, BrandId);
  351. }
  352. //查询营销活动信息
  353. public string QueryActiveForBrand(int marketType, int BrandId)
  354. {
  355. string data = "{\"marketType\":\"" + marketType + "\"}";
  356. return LSReqFunc("/org/pos/marketList", data, BrandId);
  357. }
  358. //终端费率模板查询
  359. public string QueryFeeTmpForBrand(string rateType, string deviceType, int BrandId)
  360. {
  361. string data = "{\"rateType\":\"" + rateType + "\",\"deviceType\":\"" + deviceType + "\"}";
  362. return LSReqFunc("/org/pos/rateConfigList", data, BrandId);
  363. }
  364. //终端费率查询
  365. public string QueryFeeForBrand(string snNo, int BrandId)
  366. {
  367. string data = "{\"snNo\":\"" + snNo + "\"}";
  368. return LSReqFunc("/org/pos/getRateConfig", data, BrandId);
  369. }
  370. //终端费率模板修改
  371. public string SetFeeForBrand(string snNo, string bzConfigId, string yhConfigId, string surfeeConfigId, int BrandId)
  372. {
  373. string data = "{\"snNo\":\"" + snNo + "\",\"bzConfigId\":\"" + bzConfigId + "\",\"yhConfigId\":\"" + yhConfigId + "\",\"surfeeConfigId\":\"" + surfeeConfigId + "\"}";
  374. return LSReqFunc("/org/pos/updatePosRate", data, BrandId);
  375. }
  376. public string LSReqFunc(string apiPath, string data, int BrandId)
  377. {
  378. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  379. string req = "{";
  380. if (BrandId == 4)
  381. {
  382. req += "\"orgId\":\"" + OrgNo1 + "\",";
  383. }
  384. else
  385. {
  386. req += "\"orgId\":\"" + OrgNo2 + "\",";
  387. }
  388. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  389. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  390. req += "\"version\":\"1.0\",";
  391. req += "\"data\":\"" + LSAesEncrypt(data, aeskey) + "\",";
  392. req += "\"sign\":\"" + LSEncrypt(aeskey) + "\"";
  393. req += "}";
  394. string result = function.PostWebRequest(LSReqUrl + apiPath, req, "application/json");
  395. return result;
  396. }
  397. #endregion
  398. #region 立刷
  399. string LiSAgentId = "50814834";
  400. string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4GqoHzDfRk9ibYJ/8iSDGX4+WH5+8mq/raqA77VcAD+bMrt3Bm59XmaW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7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  401. string LiSWeAgentId = "50915020";
  402. string LiSWePrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCV6SuubkIv52S//jbkhLM76JFWOTMKNj4P2jqVSXf6SHfO5ZuBmnjLLYpzm/dtHRW0i4RtbG6LK6I/d4qR2msZvK5bwVkmuCkztA9SY4YHyhTOJeHwy8da79nslr3a797i/WhjcUbgkB2a42AhHONJqTQw6KdU6xV+LZkJn+m2ej4rcUAZzr7bKQv8S3VrTvNCgSon6t8oKY324x8dshYyfRSzyv9orPP9hPYWgUHqL/48RLH/KK/ZO2xw62sJA6PJ02u8sBQEyh1gf+mqrhHbbk7qQhF4LLrTOptSgq1qPy1uDq9/45uRQGRsw3r28qowL0Sb7rZYz+na6sc3to3nAgMBAAECggEAZS1iVfAEq+A4l3w0ADev4JcuwEsKr7G8YWagc3GKkFmowvMk6Ww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OnRHIsPo2MIqjJ9G2ySBgSEP+b3ZMx6HNg4GIZKRDTXrXwwTrN3xJwE5vccS3Jrys0ZoCrgrE7i2TRqwPysL8TswXb0BKX0=";
  403. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  404. public string LiSSign(string data)
  405. {
  406. var rsa = RSA.Create();
  407. var key = Convert.FromBase64String(LiSPrivateKey);
  408. var content = Encoding.UTF8.GetBytes(data);
  409. rsa.ImportPkcs8PrivateKey(key, out _);
  410. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  411. return Convert.ToBase64String(result);
  412. }
  413. public string LiSWeSign(string data)
  414. {
  415. var rsa = RSA.Create();
  416. var key = Convert.FromBase64String(LiSWePrivateKey);
  417. var content = Encoding.UTF8.GetBytes(data);
  418. rsa.ImportPkcs8PrivateKey(key, out _);
  419. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  420. return Convert.ToBase64String(result);
  421. }
  422. //设置押金
  423. public string SetLiSDeposit(string sn, int serviceFee)
  424. {
  425. serviceFee = serviceFee * 100;
  426. Dictionary<string, object> dic = new Dictionary<string, object>();
  427. dic.Add("agentId", LiSAgentId);
  428. dic.Add("deviceSn", sn);
  429. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  430. Dictionary<string, object> item = new Dictionary<string, object>();
  431. item.Add("feeCalcType", "N1");
  432. item.Add("fixed", "1");
  433. item.Add("rate", serviceFee);
  434. feeList.Add(item);
  435. dic.Add("feeList", feeList);
  436. dic.Add("signMethod", "02");
  437. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  438. string signstr = LiSSign(content);
  439. dic.Add("signData", signstr);
  440. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  441. function.WriteLog("请求参数:" + req, "设置立刷云电签服务费");
  442. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  443. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷云电签服务费");
  444. return result;
  445. }
  446. public string SetLiSWeDeposit(string sn, int serviceFee)
  447. {
  448. serviceFee = serviceFee * 100;
  449. Dictionary<string, object> dic = new Dictionary<string, object>();
  450. dic.Add("agentId", LiSWeAgentId);
  451. dic.Add("deviceSn", sn);
  452. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  453. Dictionary<string, object> item = new Dictionary<string, object>();
  454. item.Add("feeCalcType", "N1");
  455. item.Add("fixed", "1");
  456. item.Add("rate", serviceFee);
  457. feeList.Add(item);
  458. dic.Add("feeList", feeList);
  459. dic.Add("signMethod", "02");
  460. string content = LiSWeAgentId + sn + "N11" + serviceFee + "02";
  461. string signstr = LiSWeSign(content);
  462. dic.Add("signData", signstr);
  463. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  464. function.WriteLog("请求参数:" + req, "设置立刷微电签服务费");
  465. string result = PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>());
  466. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷微电签服务费");
  467. return result;
  468. }
  469. // 设置费率
  470. public string SetLiSFee(string sn, string merchNo, string serviceRate = "0.6", string serviceFee = "0")
  471. {
  472. Dictionary<string, object> dic = new Dictionary<string, object>();
  473. dic.Add("agentId", LiSAgentId);
  474. dic.Add("deviceSn", sn);
  475. dic.Add("merchNo", merchNo);
  476. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  477. Dictionary<string, object> item = new Dictionary<string, object>();
  478. item.Add("feeCalcType", "M5");
  479. item.Add("fixed", "0");
  480. item.Add("rate", serviceRate);
  481. feeList.Add(item);
  482. // item = new Dictionary<string, object>();
  483. // item.Add("feeCalcType", "T0");
  484. // item.Add("fixed", "1");
  485. // item.Add("rate", serviceFee);
  486. // feeList.Add(item);
  487. dic.Add("feeList", item);
  488. dic.Add("signMethod", "02");
  489. string content = LiSAgentId + merchNo + sn + "M50" + serviceRate + "02";
  490. string signstr = LiSSign(content);
  491. dic.Add("signData", signstr);
  492. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  493. function.WriteLog("请求参数:" + req, "设置立刷云电签费率");
  494. string result = PostWebRequest(LiSReqUrl + "FEE002", req, new Dictionary<string, string>());
  495. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷云电签费率");
  496. return result;
  497. }
  498. public string SetLiSWeFee(string sn, string merchNo, string serviceRate = "0.6", string serviceFee = "0")
  499. {
  500. Dictionary<string, object> dic = new Dictionary<string, object>();
  501. dic.Add("agentId", LiSWeAgentId);
  502. dic.Add("deviceSn", sn);
  503. dic.Add("merchNo", merchNo);
  504. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  505. Dictionary<string, object> item = new Dictionary<string, object>();
  506. item.Add("feeCalcType", "M5");
  507. item.Add("fixed", "0");
  508. item.Add("rate", serviceRate);
  509. feeList.Add(item);
  510. item = new Dictionary<string, object>();
  511. item.Add("feeCalcType", "T0");
  512. item.Add("fixed", "1");
  513. item.Add("rate", serviceFee);
  514. feeList.Add(item);
  515. dic.Add("feeList", feeList);
  516. dic.Add("signMethod", "02");
  517. string content = LiSWeAgentId + merchNo + sn + "M50" + serviceRate + "T01" + serviceFee + "02";
  518. string signstr = LiSWeSign(content);
  519. dic.Add("signData", signstr);
  520. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  521. function.WriteLog("请求参数:" + req, "设置立刷微电签费率");
  522. string result = PostWebRequest(LiSReqUrl + "FEE002", req, new Dictionary<string, string>());
  523. function.WriteLog("返回报文:" + result + "\n\n\n", "设置立刷微电签费率");
  524. return result;
  525. }
  526. public string QueryLiSDeposit(string merchNo, string sn)
  527. {
  528. Dictionary<string, object> dic = new Dictionary<string, object>();
  529. dic.Add("agentId", LiSAgentId);
  530. dic.Add("deviceSn", sn);
  531. dic.Add("merchNo", merchNo);
  532. dic.Add("signMethod", "02");
  533. string content = LiSAgentId + sn + merchNo + "02";
  534. // string content = "{\"agentId\":\"" + LiSAgentId + "\",\"deviceSn\":\"" + sn + "\",\"merchNo\":\"" + merchNo + "\",\"signMethod\":\"02\"}";
  535. string signstr = LiSSign(content);
  536. dic.Add("signData", signstr);
  537. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  538. function.WriteLog("请求地址:" + LiSReqUrl + "FEE001", "查询商户费率");
  539. function.WriteLog("请求参数:" + req, "查询商户费率");
  540. string result = PostWebRequest(LiSReqUrl + "FEE001", req, new Dictionary<string, string>());
  541. function.WriteLog("返回报文:" + result + "\n\n\n", "查询商户费率");
  542. return result;
  543. }
  544. #endregion
  545. #region 盛付通
  546. 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/+W7bmc25HJtRPuwIDAQABAoICAE7B9GfwTGY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MY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  547. // string SftPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEtC73mdnEQ5b0G93Dseg457m6Rc8lVU9K31SEc0YyK4anN3fgGDOl2CuQT2JIaxwwqCAHoUQp7jLUirc7XUQlh+y0WnYgPre6jmfI9upuJwTD7TmUr+Mqtg2RZTYX1r81OtRL/ELQW/lm4kBcuXeCWVlwhMyAQiJdb9+plkYXIwIDAQAB";
  548. string OrgId = "38844193";
  549. // string SftPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAILFLdmFwfNHCGk3vpwj/FR9XpE9jjVreLlOaIEkSAOWOfzxCF7pMeSy0UDroRLgfLD4nQbUcK5AT7gg8PEM6H99SEHcpBkTKhfK1iI5iU9sN/WGL2Ft5T/uwo+KD7X3CsqMD0HsMQtv/YHJeAz/SPf5zyD5KttwohXXzO8a3P1pAgMBAAECgYAchxl2f6iNAu0Bzyhk9bDBWcw8kRop6zUd7836hkizh51E4ew6kFLTGnNt3zl3XcO187aF2+htCxiZCY6md3NstJod1zshoXf2slxxPWRUK92sS0XzlVT6ahVTdq2tAS3hOY3ldtnfOXMmMQPNn9OqlALQGOH/hJatBV6ZQxpp0QJBAMGKsxJkg3M6sZEO4zUgWgnGN+uS6nwAWpCfBY7eDvYSN78BxGGLgn+t40c0R8M/n85IM8OUmfHxTGWN3hYyGuUCQQCs+Kg1ypul9XLTWrVApyvZxY4ZxjAWG4yW4xqbUtHWUkGyle7Dy8xiYezl0kWN81lJNTz3qrJ4ZvM825+7tPw1AkBDPNxZV3ITZiCqNHHa0xJ0sthajv/HdJgCBjz4FU09T7buNL705HLByLdc1VzZCBGMqKjTGZ0h4KKZ5V9ydpXBAkABpZx0Zql0uxGM0aBILU9Nk4P22tw6WajNBvyJ3hABamcVvDe5xYb8qNIInifrYhXHjKo38XghjVljivPKZb7BAkAt4pCUYLI7LzLeSh/lnVxA7jOaRI3UsngCXn9VA4f+dkNcKAftRQqe7ytudqG07GKoInnDiyjrYe4kTLym8zoc";
  550. // string OrgId = "88031499";
  551. string SftReqUrl = "https://zqb.shengpay.com/cp-bff-thirdparty/v1/thirdparter/pos/"; //请求url
  552. public string SftEncrypt(string data)
  553. {
  554. var rsa = RSA.Create();
  555. var key = Convert.FromBase64String(SftPrivateKey);
  556. var content = Encoding.UTF8.GetBytes(data);
  557. rsa.ImportPkcs8PrivateKey(key, out _);
  558. var result = rsa.SignData(content, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
  559. return Convert.ToBase64String(result);
  560. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, SftPrivateKey).Encrypt(data);
  561. }
  562. //设置机具押金
  563. public string SetDepositForSft(string snNo, string policyNo)
  564. {
  565. Dictionary<string, object> req = new Dictionary<string, object>();
  566. req.Add("orgPromoterId", OrgId);
  567. req.Add("promoterId", OrgId);
  568. List<Dictionary<string, object>> snPolicyList = new List<Dictionary<string, object>>();
  569. Dictionary<string, object> item = new Dictionary<string, object>();
  570. item.Add("policyNo", policyNo);
  571. item.Add("sn", snNo);
  572. snPolicyList.Add(item);
  573. req.Add("snPolicyList", snPolicyList);
  574. req.Add("signType", "RSA");
  575. req.Add("charType", "UTF-8");
  576. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  577. req.Add("requestTime", function.GetCurTimestamp());
  578. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  579. string signString = "";
  580. foreach (string key in req.Keys)
  581. {
  582. if (key == "snPolicyList")
  583. {
  584. signString += key + "=" + Newtonsoft.Json.JsonConvert.SerializeObject(req[key]) + "&";
  585. }
  586. else
  587. {
  588. signString += key + "=" + req[key].ToString() + "&";
  589. }
  590. }
  591. signString = signString.TrimEnd('&');
  592. req.Add("mac", SftEncrypt(signString));
  593. string result = function.PostWebRequest(SftReqUrl + "batchUpdateSnPolicyNo", Newtonsoft.Json.JsonConvert.SerializeObject(req), "application/json");
  594. return result;
  595. }
  596. public string SftSnBindOrUnbind(string snNo, string merchantId)
  597. {
  598. Dictionary<string, object> req = new Dictionary<string, object>();
  599. req.Add("orgPromoterId", OrgId);
  600. req.Add("promoterId", OrgId);
  601. req.Add("merchantId", merchantId);
  602. req.Add("terminalId", snNo);
  603. req.Add("sn", snNo);
  604. req.Add("hasServiceFee", "0");
  605. req.Add("signType", "RSA");
  606. req.Add("charType", "UTF-8");
  607. req.Add("requestId", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  608. req.Add("requestTime", function.GetCurTimestamp());
  609. req = req.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value);
  610. string signString = "";
  611. foreach (string key in req.Keys)
  612. {
  613. signString += key + "=" + req[key].ToString() + "&";
  614. }
  615. signString = signString.TrimEnd('&');
  616. req.Add("mac", SftEncrypt(signString));
  617. string reqString = Newtonsoft.Json.JsonConvert.SerializeObject(req);
  618. function.WriteLog(DateTime.Now.ToString() + "\n" + reqString, "盛付通商户换绑或解绑日志");
  619. string result = function.PostWebRequest(SftReqUrl + "bindOrUnbindTerminalSn", reqString, "application/json");
  620. function.WriteLog(result + "\n\n\n", "盛付通商户换绑或解绑日志");
  621. return result;
  622. }
  623. #endregion
  624. #region 海科
  625. string HKPrivateKey1 = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK5iJ2q2nF+9jEnof9VYhMdbAgI0ZS4cYmgWTMW2JR61lJhR0GH+A/m6mjN9FsTS6Bq03u/+e6BKdE6VqMGk0q7asi2VZIgD59zj4HubS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JP/vGuzWfF2mLY0v4mJrxdXuGeWpfWnl4DP0aQS6qkUlei6f0vWS76wdpHvKUGb17Nz/f9ezr5tAgMBAAECgYBoLhn04Qil67BvKw+BOj+5GGfC7L81TamYrpHF2j8D6ZiLHnNcYjLUp8HfYVw9MT7EhFex/KNjX2ZOPDTKzpIVXofs9or1fqPYwUewBFHD9rwTrThKySdwbKrRAFNw7YXaJvMEdpPaxBBsMvfC5EdvrFejZ80TpGGfXyIXaxuC1QJBAP/6XsinJ4ZgoJj2PRPc5pWRqUssERV2w07LCPEGxxyECoyEzrTIoj7KcwSXYTSx2GGeEiSpijye9rFCHoHUNF8CQQCMg14KaLi3RjddGYatmO4SHr/IFlwpjL16rw+poOHN1WwMmex1qd3JfNab0vi5GEkFg1fAbIMRiwksvXS0ReCzAkB5/dcoJ0lV6D0BSPDIw5D8nQOieKjXotbneSmUvJctxtvEJhLg43E3HYJ9IKvJ0iv+MbgR0t63j0agKZOiagBfAkAuU3ViyynzStQf/rV3cI81LCwgpLaYAE3MMAFi9KbdvPqVoP3jwTBdKKp8z26vX8FbbvU0fNItq4BH3uKmOM+fAkAnBwxmorni7Y6Zs24pevDVqMpcF9SkOigRKsO9Lc1HuAJuxHEoPW5KeascBVe3HfYqgt4HWIxNy/d2MvpvNaWo";
  628. string HKPublicKey2 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMgEb8k2LxpXnb/uBNw/BcbEtO6Zs2WCZCHVsaL/8QKQejG9gVT+gZIbEcqMklmxMomJWacdQN2+w+MnO7w91nwdItHBj8DHST/7xrs1nxdpi2NL+Jia8XV7hnlqX1p5eAz9GkEuqpFJXoun9L1ku+sHaR7ylBm9ezc/3/Xs6+bQIDAQAB";
  629. string HKOrgNo1 = "747187394495131648"; //快联盟电签pos
  630. string HKOrgNo2 = "747189644974104576"; //快联盟大pos
  631. string HKReqUrl = "https://org-push.juheposp.com"; //请求url
  632. public string HKDecrypt(string data, string sign, int BrandId)
  633. {
  634. var toDecryptArray = Convert.FromBase64String(sign);
  635. var rsa2 = RSA.Create();
  636. string HKPrivateKey = "";
  637. if(BrandId == 8)
  638. {
  639. HKPrivateKey = HKPrivateKey1;
  640. }
  641. else if(BrandId == 9)
  642. {
  643. HKPrivateKey = HKPrivateKey2;
  644. }
  645. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(HKPrivateKey), out _);
  646. var ContentArray = rsa2.Decrypt(toDecryptArray, RSAEncryptionPadding.Pkcs1);
  647. string aeskey = System.Text.Encoding.UTF8.GetString(ContentArray);
  648. return AesDecrypt(data, aeskey);
  649. }
  650. public string HKEncrypt(string sign, int BrandId)
  651. {
  652. string HKPublicKey = "";
  653. if(BrandId == 8)
  654. {
  655. HKPublicKey = HKPublicKey1;
  656. }
  657. else if(BrandId == 9)
  658. {
  659. HKPublicKey = HKPublicKey2;
  660. }
  661. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", HKPublicKey).Encrypt(sign);
  662. }
  663. public string HKAesEncrypt(string str, string aeskey)
  664. {
  665. Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
  666. System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
  667. {
  668. Key = Encoding.UTF8.GetBytes(aeskey),
  669. Mode = System.Security.Cryptography.CipherMode.ECB,
  670. Padding = System.Security.Cryptography.PaddingMode.PKCS7
  671. };
  672. System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
  673. Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
  674. return Convert.ToBase64String(resultArray);
  675. }
  676. //设置机具押金
  677. public string SetDepositForHK(string snNo, string oldMarketId, string newMarketId, int BrandId)
  678. {
  679. string data = "{\"snNo\":\"" + snNo + "\",\"marketType\":\"400\",\"oldMarketId\":\"" + oldMarketId + "\",\"newMarketId\":\"" + newMarketId + "\"}";
  680. return HKReqFunc("/org/pos/updatePosMarket", data, BrandId);
  681. }
  682. //查询配置活动信息
  683. public string QueryActiveForConfigHK(string snNo, int BrandId)
  684. {
  685. string data = "{\"snNo\":\"" + snNo + "\"}";
  686. return HKReqFunc("/org/pos/getMarketConfig", data, BrandId);
  687. }
  688. //查询营销活动信息
  689. public string QueryActiveForBrandHK(int marketType, int BrandId)
  690. {
  691. string data = "{\"marketType\":\"" + marketType + "\"}";
  692. return HKReqFunc("/org/pos/marketList", data, BrandId);
  693. }
  694. public string HKReqFunc(string apiPath, string data, int BrandId)
  695. {
  696. string aeskey = function.MD5_16(Guid.NewGuid().ToString());
  697. string req = "{";
  698. if (BrandId == 8)
  699. {
  700. req += "\"orgId\":\"" + HKOrgNo1 + "\",";
  701. }
  702. else
  703. {
  704. req += "\"orgId\":\"" + HKOrgNo2 + "\",";
  705. }
  706. req += "\"requestId\":\"" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8) + "\",";
  707. req += "\"timeStamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
  708. req += "\"version\":\"1.0\",";
  709. req += "\"data\":\"" + HKAesEncrypt(data, aeskey) + "\",";
  710. req += "\"sign\":\"" + HKEncrypt(aeskey, BrandId) + "\"";
  711. req += "}";
  712. string result = function.PostWebRequest(HKReqUrl + apiPath, req, "application/json");
  713. return result;
  714. }
  715. #endregion
  716. #region 联动
  717. //测试环境
  718. // string LDRequestUrl = "http://111.14.221.188:18066/CloudTerminalServiceAction/";
  719. // string AgentNo = "LD110014";
  720. // string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3WG04QXTzWBg2rj4BbSmnXVTqQiCk2lZ7yi2vur2LxsSc+KN0o1W9y2AkCHcFIAk2aAfMEMQYTO3HQ+F/Vcb27BNBSjnaOLfGv0PXNHKyVzC4EQLe4M5Pqd1wMl6NaZK+HnyrPBTnfsGeywhGJc1Ke96ANrydhk7UbwezydC7nQIDAQAB";
  721. // 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==";
  722. //生产环境
  723. string LDRequestUrl = "http://ldys.umpay.com/service_exter/CloudTerminalServiceAction/";
  724. string AgentNo = "LD112692";
  725. string LDPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCGtWShTeFEgSSFx3PJXcjCOmS+OgtcUvPOHhpALY3Orm6t7rl1E0n3j7XlM049YwwtGRJI4OWhgrtR4/AnOMBXdyMBoKxF23uay1WQiNekzfUrTwil7/CRrQ+VlGgPe6dr3WQT2/HLbzMnJHeoIZ4KSIj/7pgAwTF4ciL1UC3awwIDAQAB";
  726. 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==";
  727. public string LDEncrypt(string data)
  728. {
  729. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", LDPublicKey).Encrypt(data);
  730. }
  731. public string LDDecrypt(string data)
  732. {
  733. var toDecryptArray = Convert.FromBase64String(data);
  734. var toKey = Convert.FromBase64String(LDPrivateKey);
  735. var rsa = RSA.Create();
  736. rsa.ImportPkcs8PrivateKey(toKey, out _);
  737. string result = "";
  738. List<byte> cache = new List<byte>();
  739. for (int i = 0; i < toDecryptArray.Length; i++)
  740. {
  741. cache.Add(toDecryptArray[i]);
  742. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  743. {
  744. var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  745. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  746. cache.Clear();
  747. }
  748. }
  749. return result;
  750. }
  751. public string LDServiceFee(string SnList, int ServiceFee, int BrandId)
  752. {
  753. function.WriteLog(DateTime.Now.ToString(), "设置联动机具服务费");
  754. function.WriteLog(SnList, "设置联动机具服务费");
  755. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  756. string RequestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  757. string TerminalModeName = BrandId == 10 ? "DZA" : "DZDA";
  758. int PosType = BrandId == 10 ? 2 : 3;
  759. reqdic.Add("rpid", RequestId); //请求流水
  760. reqdic.Add("agentNumber", AgentNo); //代理商编号
  761. reqdic.Add("snList", SnList.Split(',').ToList()); //SN号
  762. reqdic.Add("posType", PosType); //2:电签 3 大pos
  763. reqdic.Add("terminalModeName", TerminalModeName); //终端模式名
  764. reqdic.Add("fwfRate", ServiceFee); //服务费
  765. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  766. function.WriteLog(req, "设置联动机具服务费");
  767. req = LDEncrypt(req);
  768. function.WriteLog(req, "设置联动机具服务费");
  769. Dictionary<string, object> datadic = new Dictionary<string, object>();
  770. datadic.Add("encryptedData", req);
  771. string data = Newtonsoft.Json.JsonConvert.SerializeObject(datadic);
  772. function.WriteLog("请求地址:" + LDRequestUrl + "terminalSelfDistribute", "设置联动机具服务费");
  773. string result = function.PostWebRequest(LDRequestUrl + "terminalSelfDistribute", data, "application/json");
  774. function.WriteLog(result + "\n\n", "设置联动机具服务费");
  775. return result;
  776. }
  777. #endregion
  778. #region 盒易付
  779. //测试环境
  780. // string BoxRequestUrl = "https://openapi-test.iboxpay.com/api";
  781. // string BoxAppId = "8840021411446784";
  782. // string BoxAppSecret = "xgwGnmYGjVy0GOWOWkQtRk8Hk8ur5tCV";
  783. // string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjMQxp24mjxDTr13uPW0y+tiO1yXFGw7P/pPQ0oZKK7F6KstEaus7pLEywBZ5XRXE5jgkhR2TS7Ne7djJfbpn5yFc6pPlz3ZsOfBVeB88NEwhx6xzCGX2eqSSkO33n8w2G0xc2ss5HpYBarT00NBZWhrwOXpdRPYLOYHKVU3Rl+FA9xDw/wYfoWvrr+JSfHRGn/ENMmQFEdckAbPauKaQMrZD2kz+PRrhq56eWnCuVQPcaz/jroVT8qQEgkg2IsNy+DwfLOIqm8IySEpxnQ5wN/KvsQJc2wXDQNf9F5kvWwjoqSSP0qJS+oPRXET+zJb+WTk2y5M6AYoC9NodwsC4NwIDAQAB";
  784. // string BrhCode = "039001";
  785. //生产环境
  786. string BoxRequestUrl = "https://openapi.iboxpay.com/api";
  787. string BoxAppId = "AP5879017839106039808";
  788. string BoxAppSecret = "DGtftIyl6R3nzwPr5YuV5fnmkfwufXRj";
  789. string BoxPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmjoQirIYZBD9Qon2HkF4j/NAINXtJ7Lzq/WXxTF7t7mg7LNARt0+ZZaeWx8caq2fv5zdsGyyoInL23cBtDI5KmFfK69iA0ygQMK0WbiKqsUB1OpPbT3+9zLuadIJAznjA223lY6CIjTpdLZhaRjImNVqc60bdkx6YsQcA+xW+3r1JH4PPHb7yBEbkKIX8OhyX7U4p0TkbDkAobbjHr5YB9gmYLoSFJMOPfTtSExkv7/Y7IVR9poZAHcr3teFoAiXW3RzxelRtnXxIkl/6AUOKoL5fhr/UTUN+Q18uzNljYWr6SwnTI3EmtzgykaewWtZvV85Xdhe/BjiQ5Xor7YbwIDAQAB";
  790. string BrhCode = "039034";
  791. string CybBrhCode = "039034002";
  792. public string BoxServiceFee(string SnList, string ServiceFee, int UserId = 0)
  793. {
  794. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具服务费");
  795. function.WriteLog(SnList, "设置盒易付机具服务费");
  796. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  797. Dictionary<string, string> headdic = new Dictionary<string, string>();
  798. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  799. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  800. headdic.Add("appid", BoxAppId);//开发者id
  801. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  802. headdic.Add("X-Up-AppId", BoxAppId);
  803. headdic.Add("X-Timestamp", timestamp);
  804. headdic.Add("X-Sign-Type", "SHA-256");
  805. reqdic.Add("snList", SnList.Split(',').ToList());//终端列表
  806. if(ServiceFee != "0")
  807. {
  808. ServiceFee += "00";
  809. }
  810. reqdic.Add("depositGear", ServiceFee);//押金档位
  811. reqdic.Add("modelId", "MHN10916");//费率,固定0.6
  812. if(UserId == 123005)
  813. {
  814. reqdic.Add("brhCode", CybBrhCode);//机构号
  815. }
  816. else
  817. {
  818. reqdic.Add("brhCode", BrhCode);//机构号
  819. }
  820. reqdic.Add("batchNo", batchNo);//批次号
  821. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  822. headdic.Add("X-Sign", SHA256Sign(timestamp + BoxAppSecret + req));
  823. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  824. function.WriteLog("请求头\n" + head, "设置盒易付机具服务费");
  825. function.WriteLog("请求参数\n" + req, "设置盒易付机具服务费");
  826. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/register/terms", "设置盒易付机具服务费");
  827. string result = PostWebRequest(BoxRequestUrl + "/inst/register/terms", req, headdic);
  828. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具服务费");
  829. return result;
  830. }
  831. public string BoxFee(string MerNo, string Fee)
  832. {
  833. function.WriteLog(DateTime.Now.ToString(), "设置盒易付机具费率");
  834. function.WriteLog(MerNo, "设置盒易付机具费率");
  835. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  836. Dictionary<string, string> headdic = new Dictionary<string, string>();
  837. string batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  838. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  839. headdic.Add("appid", BoxAppId);//开发者id
  840. headdic.Add("appsecret", BoxAppSecret);//开发者密码
  841. headdic.Add("X-Up-AppId", BoxAppId);
  842. headdic.Add("X-Timestamp", timestamp);
  843. headdic.Add("X-Sign-Type", "SHA-256");
  844. reqdic.Add("mchtNo", MerNo);//终端列表
  845. reqdic.Add("brhCode", BrhCode);//机构号
  846. reqdic.Add("tNDiscId", Fee == "0.6" ? "MHN10916" : "MHN10917");//费率模型
  847. reqdic.Add("effectiveFlag", "1");//立即生效
  848. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  849. headdic.Add("X-Sign", SHA256Sign(timestamp + BoxAppSecret + req));
  850. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  851. function.WriteLog("请求头\n" + head, "设置盒易付机具费率");
  852. function.WriteLog("请求参数\n" + req, "设置盒易付机具费率");
  853. function.WriteLog("请求地址:" + BoxRequestUrl + "/inst/mcht/update_disc", "设置盒易付机具费率");
  854. string result = PostWebRequest(BoxRequestUrl + "/inst/mcht/update_disc", req, headdic);
  855. function.WriteLog("返回\n" + result + "\n\n", "设置盒易付机具费率");
  856. return result;
  857. }
  858. public string SHA256Sign(string toSignStr)
  859. {
  860. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  861. SHA256 sha256 = SHA256.Create();
  862. byte[] signByte = sha256.ComputeHash(toSignByte);
  863. string sign = Convert.ToBase64String(signByte);
  864. return sign;
  865. }
  866. public bool VerifySign(string toSignStr, string signStr)
  867. {
  868. byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
  869. byte[] signByte = Convert.FromBase64String(signStr);
  870. var toKey = Convert.FromBase64String(BoxPublicKey);
  871. var rsaroot = RSA.Create();
  872. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  873. var publicKeyParameters = rsaroot.ExportParameters(false);
  874. using (var rsa = RSA.Create())
  875. {
  876. rsa.ImportParameters(publicKeyParameters);
  877. var sha256 = SHA256.Create();
  878. var hash = sha256.ComputeHash(toSignByte);
  879. return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  880. }
  881. }
  882. public string SignData(string toSignStr)
  883. {
  884. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  885. var toKey = Convert.FromBase64String(BoxPublicKey);
  886. var rsaroot = RSA.Create();
  887. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  888. var publicKeyParameters = rsaroot.ExportParameters(false);
  889. using (var rsa = RSA.Create())
  890. {
  891. rsa.ImportParameters(publicKeyParameters);
  892. var sha256 = SHA256.Create();
  893. var hash = sha256.ComputeHash(toSignByte);
  894. byte[] endByte = rsa.SignData(toSignByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  895. return Convert.ToBase64String(endByte);
  896. }
  897. }
  898. #endregion
  899. #region POSP
  900. //测试环境
  901. // string AesSecret = "6v8cr0uyhtwtawda";
  902. // string PospRequestUrl = "http://120.76.196.209:9221";
  903. //生产环境
  904. string AesSecret = "6v8cr0uyhtwtawda";
  905. string PospRequestUrl = "https://sale.posp.kexiaoshuang.com";
  906. public string PospQueryServiceFee()
  907. {
  908. SortedList<string, string> param = new SortedList<string, string>();
  909. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  910. function.WriteLog("原始数据:" + PushData, "查询POSP机具服务费政策");
  911. string content = EncryptHelper.Encrypt1(param, AesSecret);
  912. string PushDataEncrypt = content;
  913. function.WriteLog("加密数据:" + content, "查询POSP机具服务费政策");
  914. SortedList<string, string> obj = new SortedList<string, string>();
  915. obj.Add("type", "设置服务费");
  916. obj.Add("notice_id", Guid.NewGuid().ToString());
  917. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  918. obj.Add("content", content);
  919. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  920. function.WriteLog("请求参数:" + requestJson, "查询POSP机具服务费政策");
  921. function.WriteLog("请求地址:" + PospRequestUrl + "/pos/deposit/query", "查询POSP机具服务费政策");
  922. string result = function.PostWebRequest(PospRequestUrl + "/pos/deposit/query", requestJson, "application/json");
  923. function.WriteLog("返回报文:" + result, "查询POSP机具服务费政策");
  924. JsonData jsonObj = JsonMapper.ToObject(result);
  925. if(jsonObj["code"].ToString() == "200")
  926. {
  927. result = EncryptHelper.AesDecrypt(jsonObj["content"].ToString(), AesSecret);
  928. function.WriteLog("内容信息:" + result, "查询POSP机具服务费政策");
  929. }
  930. function.WriteLog("\n\n", "查询POSP机具服务费政策");
  931. return result;
  932. }
  933. public string PospQueryFee()
  934. {
  935. SortedList<string, string> param = new SortedList<string, string>();
  936. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  937. function.WriteLog("原始数据:" + PushData, "查询POSP机具费率政策");
  938. string content = EncryptHelper.Encrypt1(param, AesSecret);
  939. string PushDataEncrypt = content;
  940. function.WriteLog("加密数据:" + content, "查询POSP机具费率政策");
  941. SortedList<string, string> obj = new SortedList<string, string>();
  942. obj.Add("type", "设置服务费");
  943. obj.Add("notice_id", Guid.NewGuid().ToString());
  944. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  945. obj.Add("content", content);
  946. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  947. function.WriteLog("请求参数:" + requestJson, "查询POSP机具费率政策");
  948. function.WriteLog("请求地址:" + PospRequestUrl + "/marketing/plan/query", "查询POSP机具费率政策");
  949. string result = function.PostWebRequest(PospRequestUrl + "/marketing/plan/query", requestJson, "application/json");
  950. function.WriteLog("返回报文:" + result, "查询POSP机具费率政策");
  951. JsonData jsonObj = JsonMapper.ToObject(result);
  952. if(jsonObj["code"].ToString() == "200")
  953. {
  954. result = EncryptHelper.AesDecrypt(jsonObj["content"].ToString(), AesSecret);
  955. function.WriteLog("内容信息:" + result, "查询POSP机具费率政策");
  956. }
  957. function.WriteLog("\n\n", "查询POSP机具费率政策");
  958. return result;
  959. }
  960. public string PospServiceFee(List<string> pos_no, string deposit_id, string deposit_name)
  961. {
  962. SortedList<string, object> param = new SortedList<string, object>();
  963. param.Add("pos_no", pos_no); //商户号
  964. param.Add("deposit_id", deposit_id); //政策ID
  965. param.Add("deposit_name", deposit_name); //政策名称
  966. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  967. function.WriteLog("原始数据:" + PushData, "设置POSP机具服务费");
  968. string[] signData = EncryptHelper.Encrypt1(param, AesSecret);
  969. string content = signData[0];
  970. string sign = signData[1];
  971. function.WriteLog("加密数据:" + content, "设置POSP机具服务费");
  972. SortedList<string, string> obj = new SortedList<string, string>();
  973. obj.Add("type", "设置服务费");
  974. obj.Add("notice_id", Guid.NewGuid().ToString());
  975. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  976. obj.Add("content", content);
  977. obj.Add("sign", sign);
  978. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  979. function.WriteLog("请求参数:" + requestJson, "设置POSP机具服务费");
  980. function.WriteLog("请求地址:" + PospRequestUrl + "/pos/deposit/modify", "设置POSP机具服务费");
  981. string result = function.PostWebRequest(PospRequestUrl + "/pos/deposit/modify", requestJson, "application/json");
  982. function.WriteLog("返回报文:" + result, "设置POSP机具服务费");
  983. function.WriteLog("\n\n", "设置POSP机具服务费");
  984. return result;
  985. }
  986. public string PospFee(List<string> merch_no, string plan_id, string plan_name)
  987. {
  988. SortedList<string, object> param = new SortedList<string, object>();
  989. param.Add("merch_no", merch_no); //商户号
  990. param.Add("plan_id", plan_id); //政策ID
  991. param.Add("plan_name", plan_name); //政策名称
  992. string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(param);
  993. function.WriteLog("原始数据:" + PushData, "设置POSP机具费率");
  994. string[] signData = EncryptHelper.Encrypt1(param, AesSecret);
  995. string content = signData[0];
  996. string sign = signData[1];
  997. function.WriteLog("加密数据:" + content, "设置POSP机具费率");
  998. SortedList<string, string> obj = new SortedList<string, string>();
  999. obj.Add("type", "设置费率");
  1000. obj.Add("notice_id", Guid.NewGuid().ToString());
  1001. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  1002. obj.Add("content", content);
  1003. obj.Add("sign", sign);
  1004. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  1005. function.WriteLog("请求参数:" + requestJson, "设置POSP机具费率");
  1006. function.WriteLog("请求地址:" + PospRequestUrl + "/marketing/plan/modify", "设置POSP机具费率");
  1007. string result = function.PostWebRequest(PospRequestUrl + "/marketing/plan/modify", requestJson, "application/json");
  1008. function.WriteLog("返回报文:" + result, "设置POSP机具费率");
  1009. function.WriteLog("\n\n", "设置POSP机具费率");
  1010. return result;
  1011. }
  1012. #endregion
  1013. #region 来客吧L版
  1014. // 生产环境
  1015. string lkbClientId = "80000177";
  1016. string lkbMfe88PublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3YYYwaQyl+poYl+CQEFiLjQi7R0LEG73360Wup4frAy0zPZYlch3MwUChA7gPXVND/bUY+6vzJ3mkeoFvFtOkhrV0Wm8PWWnBVzanq3P91rFqMljMQlNxz4nBNeH2yHX9lCf6HQCYfjsYtadrGyUQw3ZMs+b0sMI2nZe/oKZo1wIDAQAB";
  1017. string lkbClientPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3YYYwaQyl+poYl+CQEFiLjQi7R0LEG73360Wup4frAy0zPZYlch3MwUChA7gPXVND/bUY+6vzJ3mkeoFvFtOkhrV0Wm8PWWnBVzanq3P91rFqMljMQlNxz4nBNeH2yHX9lCf6HQCYfjsYtadrGyUQw3ZMs+b0sMI2nZe/oKZo1wIDAQAB";
  1018. string lkbClientPrivateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALdhhjBpDKX6mhiX4JAQWIuNCLtHQsQbvffrRa6nh+sDLTM9liVyHczBQKEDuA9dU0P9tRj7q/MneaR6gW8W06SGtXRabw9ZacFXNqerc/3WsWoyWMxCU3HPicE14fbIdf2UJ/odAJh+Oxi1p2sbJRDDdkyz5vSwwjadl7+gpmjXAgMBAAECgYA4+QKgvbJhSsdfRqhM+dcYnBuPW6dhmCDgCmdeyMvQdu8vET45qgeaGpxCqg4gL+VzpToDZgVZCPWg5TKbWeMsnjHJ4o3e/SYywRufHGDougTjYQcc4jZLjbefbGAbRIoSdZcYoJS9SOlFsSTyk5zkNmvFvxDH1mlw7ooYFmEi8QJBAO5vs6+wxuEwrYxm/y7tRuOUuIRuHv/HfRRPwTZUJMwR7YeQJ8HqWPZr8QukiE2YL+j7pEy/zscgW6tmAZzbNskCQQDE455wVPoWxFADaQvzrksWGF0qEce1ppnqf8DoHHQYQtUF3z8art/Kg8wJ/GbZxytR2REZzzaeqw3uGFyn21KfAkB44QZelqds+OmzGXBbkQ10SSx2bwGmOLNvvbM9YNE66AfcxzdwtucdHsIYXfSAKhx36EN2aXNiPkRbE57Tr8sJAkACPPgrHLwvEBI8x6/sGDogSSyd8s/LX9Z2FPeza8diEzhqtav4+K3wlmj2YBknNp1mc8o++d0MFrO01jAPdG3PAkBvAD3lZvd4m10Q92ikomH79IeQRh5mEBxfUsDXk+khHzjONmYgpo46TQBZ1okNW0amIemQhBbs/bEZZUGukPdn";
  1019. string lkbReqUrl = "https://fire-api.mfe88.com/channel-app/api/terminal/serviceFeeSet";
  1020. string lkbReqUrl2 = "https://fire-api.mfe88.com/channel-app/api/rate/update";
  1021. public bool LkbVerify()
  1022. {
  1023.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M07IkCTQwTVzz0EzgO0auQt+Wqf9ndWERa7P9jTqHS4JKYQH+LGLXjVgQPekzrePNnIcVVFqjf3VC+xImxSxJLaChHxiF+ufDpU9symoesub51QRCPSUB3xuQ2uP2lSbVmgcjvw=";
  1025. var toDecryptArray = Convert.FromBase64String(data);
  1026. var toSignArray = Convert.FromBase64String(signString);
  1027. var rsa = RSA.Create();
  1028. rsa.ImportRSAPublicKey(Convert.FromBase64String(lkbMfe88PublicKey), out _);
  1029. return rsa.VerifyData(toDecryptArray, toSignArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1030. }
  1031. private byte[] LkbStrToToHexByte(string hexString)
  1032. {
  1033. hexString = hexString.Replace(" ", "");
  1034. if ((hexString.Length % 2) != 0)
  1035. hexString += " ";
  1036. byte[] returnBytes = new byte[hexString.Length / 2];
  1037. for (int i = 0; i < returnBytes.Length; i++)
  1038. returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
  1039. return returnBytes;
  1040. }
  1041. public string LkbDecrypt(string data)
  1042. {
  1043. var toDecryptArray = Convert.FromBase64String(data);
  1044. var rsa2 = RSA.Create();
  1045. rsa2.ImportPkcs8PrivateKey(Convert.FromBase64String(lkbClientPrivateKey), out _);
  1046. string result = "";
  1047. List<byte> cache = new List<byte>();
  1048. for (int i = 0; i < toDecryptArray.Length; i++)
  1049. {
  1050. cache.Add(toDecryptArray[i]);
  1051. if ((i + 1) % 128 == 0 || i + 1 == toDecryptArray.Length)
  1052. {
  1053. var ContentArray = rsa2.Decrypt(cache.ToArray(), RSAEncryptionPadding.Pkcs1);
  1054. result += System.Text.Encoding.UTF8.GetString(ContentArray);
  1055. cache.Clear();
  1056. }
  1057. }
  1058. return result;
  1059. }
  1060. public string LkbSetDeposit(string sn, decimal serviceFee)
  1061. {
  1062. serviceFee = serviceFee * 100;
  1063. Dictionary<string, string> headers = new Dictionary<string, string>();
  1064. headers.Add("X-Client", lkbClientId);
  1065. headers.Add("X-Security", "RSA");
  1066. DateTimeOffset currentTime = DateTimeOffset.UtcNow;
  1067. string rfc1123FormattedTime = currentTime.ToString("r");
  1068. headers.Add("X-Time", rfc1123FormattedTime);
  1069. headers.Add("X-Trace", function.get_Random(32));
  1070. string content = "{\"factorySequenceNo\":\"" + sn + "\",\"serviceFee\":\"" + serviceFee.ToString("f0") + "\",\"agencyNo\":\"" + lkbClientId + "\"}";
  1071. content = LkbEncrypt(content);
  1072. string signstr = LkbSign(content);
  1073. headers.Add("X-Sign", signstr);
  1074. string req = "{\"param\":\"" + content + "\"}";
  1075. string result = function.PostWebRequest(lkbReqUrl, req, headers, "application/json");
  1076. return result;
  1077. }
  1078. // public string LkbSetFee(string sn, decimal fee = 0.6M)
  1079. // {
  1080. // List<SetDepositList> rateDOs = new List<SetDepositList>();
  1081. // rateDOs.Add(new SetDepositList()
  1082. // {
  1083. // productSubType = "2020032007vz7Ux6",
  1084. // updateValue = fee,
  1085. // updateType = 0
  1086. // });
  1087. // Dictionary<string, string> headers = new Dictionary<string, string>();
  1088. // headers.Add("X-Client-ID", lkbClientId);
  1089. // headers.Add("X-Security", "RSA");
  1090. // Dictionary<string, object> obj = new Dictionary<string, object>();
  1091. // obj.Add("factorySequenceNo", sn);
  1092. // obj.Add("productCode", 2);
  1093. // obj.Add("productName", 2);
  1094. // obj.Add("rateDOs", rateDOs);
  1095. // string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  1096. // content = LkbEncrypt2(content);
  1097. // string signstr = LkbSign(content);
  1098. // headers.Add("X-Sign", signstr);
  1099. // string req = "{\"param\":\"" + content + "\"}";
  1100. // string result = function.PostWebRequest(lkbReqUrl2, req, headers, "application/json");
  1101. // return result;
  1102. // }
  1103. public string LkbEncrypt(string data)
  1104. {
  1105. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", lkbMfe88PublicKey).Encrypt(data);
  1106. }
  1107. public string LkbEncrypt2(string data)
  1108. {
  1109. return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", lkbMfe88PublicKey).Encrypt(data);
  1110. }
  1111. public string LkbSign(string data)
  1112. {
  1113. var toEncryptArray = System.Text.Encoding.UTF8.GetBytes(data);
  1114. var rsa = RSA.Create();
  1115. rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(lkbClientPrivateKey), out _);
  1116. string result = "";
  1117. var buffer = rsa.SignData(toEncryptArray, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1118. result = Convert.ToBase64String(buffer);
  1119. return result;
  1120. // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, clientPrivateKey, "").Sign(data);
  1121. }
  1122. #endregion
  1123. }
  1124. }