|
@@ -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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lEPLIEYRpBHCCHpfGZ422SLwHqQ9zcU88lMbqfuSfQuJiPhNAqMHgmT7n2gYfxotL311lw1qG2ARJRSIyQ3oHXS6GBe9kFRWK8I/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");
|
|
|
+ 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 result = LklEncryptData(rsa, content);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- return Convert.ToBase64String(result);
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return new RSAForJava().EncryptByPrivateKey(data, lklPriKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string LklDecrypt(string 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)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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
|