|
@@ -16,6 +16,7 @@ using Org.BouncyCastle.Crypto;
|
|
|
using Org.BouncyCastle.Math;
|
|
|
using System.Net.Http;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.IO;
|
|
|
|
|
|
namespace MySystem
|
|
|
{
|
|
@@ -1251,8 +1252,9 @@ namespace MySystem
|
|
|
string lklClientId = "testsit";
|
|
|
string lklClientSecret = "EguwEckByf2I6u6z";
|
|
|
string lklReqUrl = "https://test.wsmsd.cn/sit";
|
|
|
- string lklReqUrl2 = "https://test.wsmsd.cn/sit/htkmerchants/channel/customer/update/fee/";
|
|
|
- string lklPriKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAIo8rqIb543AJFGzWXMThtTKnqfQYxyP2zqUQ8sgRhGkEcIIel8ZnjbZIvAepD3NxTzyUxup+5J9C4mI+E0CoweCZPufaBh/Gi0vfXWXDWobYBElFIjJDegddLoYF72QVFYrwj+xVu5HF5X62hSz03YQ+Mp6q5jbyjGX34BTdTqBAgMBAAECgYAGgLmmlbVWJEn1F7CzVpGg+pXdbzKtYBlME3fPszFGoMsmz3kptnncSsk/ZlKbt22CCyR0lIHJi6U2e2VyUneep+vzSlvZdpdB4EgGZw3gLC7Cvz5bb9Uh3QJwBBoSHMdDBUnx/dYgnJhitCq/akH23LdyBpkYHx037W0EG+XaEQJBAMC9xgukaD2GsbRzspZeTWQToLh7K6Gz7o4VAg0r/ph2Lm/Z/jzjrahXzjcxSdwnMJmFJagDgFbmprZU5PWCMNECQQC3m25z/v3//TkkAzERV1Pjw/+d/h7Nd8I8G9wD9ZLGCO0JqMf+eugVXQ9dRyTC7xSuuV7EQAAMFRDbBGzsyFqxAkEAiPLOk1sgDgd0oMlMbXdX+fHQUwSBfgYBTMc0i/NklSPz3tm/wbfsnh61kZXd6yWVbJ+kn/rM5/I/JnKvtJnq4QJAJXwyPLRenxjPxa5xIh02H1Ywpczv9PrySNtXO+ezI4NHAaXXzvjA0TvCm0SfGL0+970Y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ZFPhutpIHKQchpolbSuC0vgaHpSjO9OUs1fpnK/JjZq9o8DatUsA0n4Fccec9NBbV5dy5yrwro7xmDpsevp1/IeiIssi1+iD+nBWqqVFx7GVQIDAQABAoGAODaXjO3rSePE+h+GNy7FhCZB+lA0JYGyG5bGkJLLTJi7U4Dnm68zdvFDX3fJ43LvRVTqxxnJTimyuy/tXDi4nblrGSnP3P4AMvcAEeBIaC75Xqx/RBD4j1hcXRA2zMT6pZKaizqPj8R64U5+L1OAmj3SbS9royp+55rFHVA1qPECQQDUtU5TOp4T7dl5czeZBn7CeJAWDY7i1zQNmHTbgtrbWLxFxyfU+9BTfxp0QQSGbuO7hx9yHuZ33qfqjJOmvET/AkEAzHnCMiNM9ZFbfrTn1isNmRS7Iu+O9PKk2nkeFtQAbZJ4I9fm8aFll69yqoY6iZFsZ4YqEn16ruwknDc43TNQqwJAEHfhEoyNRJm7pq2G9nAMTF4tOaffEiz7OLo/AefFrgnWuchLiy/b1zsV/z4xbX8UXqZ9hsZhrZItiflMTTJyXQJABaDkY5TtLWVO63H3X8HXofscG54UhVGYkBr9ZQt454s8m1/6D3St4zsFIQSI3/iMz1y2E8Q4eFAvwc0TV6Nt+QJBAIYGAZOh+0VNoiLr8M9XOgrRNYCfA7xKdRdCjjFjBQdCgqQ11E6IsdHZTM/ethaM2BDYuF+M2EKOpxcJV3ktz38=";
|
|
|
+ string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKPK6iG+eNwCRRs1lzE4bUyp6n0GMcj9s6lEPLIEYRpBHCCHpfGZ422SLwHqQ9zcU88lMbqfuSfQuJiPhNAqMHgmT7n2gYfxotL311lw1qG2ARJRSIyQ3oHXS6GBe9kFRWK8I/sVbuRxeV+toUs9N2EPjKequY28oxl9+AU3U6gQIDAQAB";
|
|
|
|
|
|
public string LkLGetToken()
|
|
|
{
|
|
@@ -1285,77 +1287,160 @@ namespace MySystem
|
|
|
req.Add("target", target);
|
|
|
string reqStr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
|
|
|
function.WriteLog("请求参数\n" + reqStr, "拉卡拉设置服务费");
|
|
|
- reqStr = LklEncrypt(reqStr);
|
|
|
+ reqStr = "{\"data\":\"" + LklEncrypt(reqStr) + "\"}";
|
|
|
function.WriteLog("加密参数\n" + reqStr, "拉卡拉设置服务费");
|
|
|
- string result = function.PostWebRequest(lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", reqStr, headers, "application/json");
|
|
|
+ function.WriteLog("请求地址\n" + lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", "拉卡拉设置服务费");
|
|
|
+ string result = PostWebRequest(lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", reqStr, headers);
|
|
|
function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉设置服务费");
|
|
|
return result;
|
|
|
}
|
|
|
- public string LkLSetFee(string sn, decimal rate = 0.6M, int fee = 0)
|
|
|
+ public string LkLSetFee(string merNo, decimal rate = 0.6M, int fee = 0)
|
|
|
{
|
|
|
List<Dictionary<string, string>> innerParamList = new List<Dictionary<string, string>>();
|
|
|
Dictionary<string, string> item = new Dictionary<string, string>();
|
|
|
- item.Add("feeType", "R1012");
|
|
|
+ item.Add("feeType", "CREDIT_CARD");
|
|
|
item.Add("fee", rate.ToString("f2"));
|
|
|
innerParamList.Add(item);
|
|
|
Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
- headers.Add("Authorization", "bearer " + LkLGetToken());
|
|
|
- headers.Add("X-Trace", function.get_Random(32));
|
|
|
- function.WriteLog("请求地址\n" + lkbReqUrl2, "来客吧L吧设置费率");
|
|
|
+ headers.Add("Authorization", "bearer a54b216a-18b7-4a0b-b6b7-b37eee813b6e");// + LkLGetToken());
|
|
|
+ function.WriteLog("请求地址\n" + lkbReqUrl2, "拉卡拉设置费率");
|
|
|
Dictionary<string, object> obj = new Dictionary<string, object>();
|
|
|
- obj.Add("factorySequenceNo", sn);
|
|
|
- obj.Add("productCode", "100");
|
|
|
- obj.Add("productName", "来客吧");
|
|
|
+ obj.Add("productCode", "");
|
|
|
obj.Add("fees", innerParamList);
|
|
|
string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
|
|
- function.WriteLog("明文参数\n" + content, "来客吧L吧设置费率");
|
|
|
- content = LkbEncrypt2(content);
|
|
|
- string signstr = LkbSign(content);
|
|
|
- headers.Add("X-Sign", signstr);
|
|
|
- string req = "{\"param\":\"" + content + "\"}";
|
|
|
- function.WriteLog("加密参数\n" + req, "来客吧L吧设置费率");
|
|
|
- string result = function.PostWebRequest(lkbReqUrl2, req, headers, "application/json");
|
|
|
- function.WriteLog("返回报文\n" + result + "\n\n\n", "来客吧L吧设置费率");
|
|
|
+ function.WriteLog("明文参数\n" + content, "拉卡拉设置费率");
|
|
|
+ content = LklEncrypt(content);
|
|
|
+ string req = "{\"dto\":\"" + content + "\"}";
|
|
|
+ function.WriteLog("加密参数\n" + req, "拉卡拉设置费率");
|
|
|
+ string result = function.PostWebRequest(lklReqUrl + "/htkmerchants/channel/customer/update/fee/" + merNo, req, headers);
|
|
|
+ function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉设置费率");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public string LklEncrypt(string data)
|
|
|
{
|
|
|
- var rsa = RSA.Create();
|
|
|
- var key = Convert.FromBase64String(lklPriKey);
|
|
|
- var content = Encoding.UTF8.GetBytes(data);
|
|
|
- rsa.ImportPkcs8PrivateKey(key, out _);
|
|
|
+ // var rsa = RSA.Create();
|
|
|
+ // var key = Convert.FromBase64String(lklPriKey);
|
|
|
+ // var content = Encoding.UTF8.GetBytes(data);
|
|
|
+ // rsa.ImportPkcs8PrivateKey(key, out _);
|
|
|
+ // // rsa.ImportParameters(ImportPublicKey(lklPriKey));
|
|
|
|
|
|
- var result = LklEncryptData(rsa, content);
|
|
|
+ // // var result = LklEncryptData(rsa, content);
|
|
|
+ // var result = rsa.Encrypt(content, RSAEncryptionPadding.Pkcs1);
|
|
|
|
|
|
- return Convert.ToBase64String(result);
|
|
|
- // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, lklPriKey).Encrypt(data);
|
|
|
+ // return Convert.ToBase64String(result);
|
|
|
+ // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, lklPriKey).Encrypt2(data);
|
|
|
+
|
|
|
+ // byte[] publicKey = Encoding.UTF8.GetBytes(lklPriKey);
|
|
|
+ // using (var x509 = new X509Certificate2(publicKey))
|
|
|
+ // {
|
|
|
+ // using (var rsa = x509.GetRSAPrivateKey())
|
|
|
+ // {
|
|
|
+ // var buff = rsa.Encrypt(Encoding.UTF8.GetBytes(data), RSAEncryptionPadding.Pkcs1);
|
|
|
+ // return Convert.ToBase64String(buff);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ return new RSAForJava().EncryptByPrivateKey(data, lklPriKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string LklDecrypt(string data)
|
|
|
+ {
|
|
|
+ // var rsa = RSA.Create();
|
|
|
+ // var key = Convert.FromBase64String(lklPubKey);
|
|
|
+ // var content = Convert.FromBase64String(data);
|
|
|
+ // rsa.ImportSubjectPublicKeyInfo(key, out _);
|
|
|
+
|
|
|
+ // string result = "";
|
|
|
+ // List<byte> cache = new List<byte>();
|
|
|
+ // for (int i = 0; i < content.Length; i++)
|
|
|
+ // {
|
|
|
+ // cache.Add(content[i]);
|
|
|
+ // if ((i + 1) % 128 == 0 || i + 1 == content.Length)
|
|
|
+ // {
|
|
|
+ // var ContentArray = rsa.Decrypt(cache.ToArray(), RSAEncryptionPadding.OaepSHA1);
|
|
|
+ // result += System.Text.Encoding.UTF8.GetString(ContentArray);
|
|
|
+ // cache.Clear();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return result;
|
|
|
+
|
|
|
+
|
|
|
+ // 解码Base64编码的公钥和数据
|
|
|
+ // byte[] keyBytes = Convert.FromBase64String(lklPubKey);
|
|
|
+ // byte[] dataBytes = Convert.FromBase64String(data);
|
|
|
+
|
|
|
+ // // 创建RSA对象并初始化为解密模式
|
|
|
+ // using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
|
|
|
+ // {
|
|
|
+ // rsa.ImportSubjectPublicKeyInfo(keyBytes, out _);
|
|
|
+
|
|
|
+ // int blockSize = rsa.KeySize / 8;
|
|
|
+ // using (MemoryStream ms = new MemoryStream())
|
|
|
+ // {
|
|
|
+ // for (int i = 0, offset = 0, length = dataBytes.Length; length - offset > 0; i++, offset = i * blockSize)
|
|
|
+ // {
|
|
|
+ // int chunkSize = Math.Min(blockSize, length - offset);
|
|
|
+ // byte[] decryptedChunk = rsa.Decrypt(dataBytes.AsSpan(offset, chunkSize).ToArray(), false);
|
|
|
+ // ms.Write(decryptedChunk, 0, decryptedChunk.Length);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return Encoding.UTF8.GetString(ms.ToArray());
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return new RSAHelper(RSAType.RSA, System.Text.Encoding.UTF8, "", lklPubKey).Decrypt2(data);
|
|
|
+ return new RSAForJava().DecryptByPublicKey(data, lklPubKey);
|
|
|
}
|
|
|
|
|
|
public byte[] LklEncryptData(RSA rsa, byte[] data)
|
|
|
{
|
|
|
- using var memoryStream = new System.IO.MemoryStream();
|
|
|
- int offset = 0;
|
|
|
- byte[] buffer;
|
|
|
-
|
|
|
- while (offset < data.Length)
|
|
|
+ // using var memoryStream = new System.IO.MemoryStream();
|
|
|
+ // int offset = 0;
|
|
|
+ // byte[] buffer;
|
|
|
+
|
|
|
+ // while (offset < data.Length)
|
|
|
+ // {
|
|
|
+ // if (offset + 64 < data.Length)
|
|
|
+ // {
|
|
|
+ // buffer = data.AsSpan(offset, 64).ToArray();
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // buffer = data.AsSpan(offset, data.Length - offset).ToArray();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // byte[] encrypted = rsa.Encrypt(buffer, RSAEncryptionPadding.Pkcs1);
|
|
|
+ // memoryStream.Write(encrypted);
|
|
|
+
|
|
|
+ // offset += buffer.Length;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return memoryStream.ToArray();
|
|
|
+ int inputLen = data.Length;
|
|
|
+ var memoryStream = new System.IO.MemoryStream();
|
|
|
+ int offSet = 0;
|
|
|
+ byte[] cache;
|
|
|
+ int i = 0;
|
|
|
+ // 对数据分段加密
|
|
|
+ while (inputLen - offSet > 0)
|
|
|
{
|
|
|
- if (offset + 117 < data.Length)
|
|
|
+ if (inputLen - offSet > 117)
|
|
|
{
|
|
|
- buffer = data.AsSpan(offset, 117).ToArray();
|
|
|
+ cache = data.AsSpan(offSet, 117).ToArray();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- buffer = data.AsSpan(offset, data.Length - offset).ToArray();
|
|
|
+ cache = data.AsSpan(offSet, inputLen - offSet).ToArray();
|
|
|
}
|
|
|
-
|
|
|
- byte[] encrypted = rsa.Encrypt(buffer, RSAEncryptionPadding.Pkcs1);
|
|
|
+ byte[] encrypted = rsa.Encrypt(cache, RSAEncryptionPadding.OaepSHA1);
|
|
|
memoryStream.Write(encrypted);
|
|
|
-
|
|
|
- offset += buffer.Length;
|
|
|
+ i++;
|
|
|
+ offSet = i * 117;
|
|
|
}
|
|
|
-
|
|
|
- return memoryStream.ToArray();
|
|
|
+ byte[] encryptedData = memoryStream.ToArray();
|
|
|
+ return encryptedData;
|
|
|
}
|
|
|
|
|
|
#endregion
|