|
@@ -1253,34 +1253,47 @@ namespace MySystem
|
|
|
string lklClientSecret = "EguwEckByf2I6u6z";
|
|
|
string lklReqUrl = "https://test.wsmsd.cn/sit";
|
|
|
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==";
|
|
|
- // string lklPriKey = "MIICXAIBAAKBgQCp5aV3ZiXG2R8Yd8Nxocv+cF7VAUHBc0TF4MNne7mI8wM2yEP2QgI+rK1qDf6G7ZFPhutpIHKQchpolbSu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1qDf6G7ZFPhu tpIHKQchpolbSuC0vgaHpSjO9OUs1fpnK/JjZq9o8DatUsA0n4Fccec9NBbV5dy5yrwro7xmDpsevp1/IeiIssi1+iD+nBWqqVFx7GVQIDAQAB"; //解密api接口返回报文
|
|
|
+ // string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKPK6iG+eNwCRRs1lzE4bUyp6n0GMcj9s6lEPLIEYRpBHCCHpfGZ422SLwHqQ9zcU88lMbqfuSfQuJiPhNAqMHgmT7n2gYfxotL311lw1qG2ARJRSIyQ3oHXS6GBe9kFRWK8I/sVbuRxeV+toUs9N2EPjKequY28oxl9+AU3U6gQIDAQAB"; //解密推送消息
|
|
|
|
|
|
public string LkLGetToken()
|
|
|
{
|
|
|
- Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
- headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(lklClientId + ":" + lklClientSecret)));
|
|
|
- // Dictionary<string, string> req = new Dictionary<string, string>();
|
|
|
- // req.Add("grant_type", "client_credentials");
|
|
|
- // req.Add("client_id", lklClientId);
|
|
|
- // req.Add("client_secret", lklClientSecret);
|
|
|
- // string reqStr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
|
|
|
- // function.WriteLog("请求参数\n" + reqStr, "拉卡拉获取Token");
|
|
|
- // reqStr = LklEncrypt(reqStr);
|
|
|
- // function.WriteLog("加密参数\n" + reqStr, "拉卡拉获取Token");
|
|
|
- string result = function.PostWebRequest(lklReqUrl + "/htkauth/oauth/token?grant_type=client_credentials&client_id=" + lklClientId + "&client_secret=" + lklClientSecret, "", headers, "application/json");
|
|
|
- function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉获取Token");
|
|
|
- return result;
|
|
|
+ string access_token = RedisDbconn.Instance.Get<string>("LkLApiToken");
|
|
|
+ if(string.IsNullOrEmpty(access_token))
|
|
|
+ {
|
|
|
+ Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
+ headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(lklClientId + ":" + lklClientSecret)));
|
|
|
+ // Dictionary<string, string> req = new Dictionary<string, string>();
|
|
|
+ // req.Add("grant_type", "client_credentials");
|
|
|
+ // req.Add("client_id", lklClientId);
|
|
|
+ // req.Add("client_secret", lklClientSecret);
|
|
|
+ // string reqStr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
|
|
|
+ // function.WriteLog("请求参数\n" + reqStr, "拉卡拉获取Token");
|
|
|
+ // reqStr = LklEncrypt(reqStr);
|
|
|
+ // function.WriteLog("加密参数\n" + reqStr, "拉卡拉获取Token");
|
|
|
+ string result = function.PostWebRequest(lklReqUrl + "/htkauth/oauth/token?grant_type=client_credentials&client_id=" + lklClientId + "&client_secret=" + lklClientSecret, "", headers, "application/json");
|
|
|
+ function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉获取Token");
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(result);
|
|
|
+ if(result.Contains("\"access_token\""))
|
|
|
+ {
|
|
|
+ access_token = jsonObj["access_token"].ToString();
|
|
|
+ string expires_in = jsonObj["expires_in"].ToString();
|
|
|
+ RedisDbconn.Instance.Set("LkLApiToken", access_token);
|
|
|
+ RedisDbconn.Instance.SetExpire("LkLApiToken", int.Parse(function.CheckInt(expires_in)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return access_token;
|
|
|
+ //{"access_token":"a54b216a-18b7-4a0b-b6b7-b37eee813b6e","token_type":"bearer","expires_in":872822,"scope":"all"}
|
|
|
}
|
|
|
public string LkLSetDeposit(string sn, decimal serviceFee)
|
|
|
{
|
|
|
string target = "ZC0801TEST1HD1";
|
|
|
- if(serviceFee == 0) target = "ZC0801TEST1HD1";
|
|
|
+ if(serviceFee == 0) target = "22NHTK4GDQPOSFYHDAB";
|
|
|
if(serviceFee == 99) target = "ZC0801TEST1HD1";
|
|
|
- if(serviceFee == 199) target = "ZC0801TEST1HD1";
|
|
|
+ if(serviceFee == 199) target = "0426_YJ199_1";
|
|
|
if(serviceFee == 299) target = "ZC0801TEST1HD1";
|
|
|
Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
- headers.Add("Authorization", "bearer a54b216a-18b7-4a0b-b6b7-b37eee813b6e");// + LkLGetToken());
|
|
|
+ headers.Add("Authorization", "bearer " + LkLGetToken());
|
|
|
Dictionary<string, string> req = new Dictionary<string, string>();
|
|
|
req.Add("posSn", sn);
|
|
|
req.Add("type", "ACTIVITY");
|
|
@@ -1293,6 +1306,7 @@ namespace MySystem
|
|
|
string result = PostWebRequest(lklReqUrl + "/htkterminal/open/terminal/change/activity/amount", reqStr, headers);
|
|
|
function.WriteLog("返回报文\n" + result + "\n\n\n", "拉卡拉设置服务费");
|
|
|
return result;
|
|
|
+ //{"code":"000000","data":"Oa4NF8tNLKthg9Q9klCLxyWtNJdAuL8n7NH5yM8VgM2eekpkzJ8/sFiY31NBo8qXGDcNi9GAiALsTZcEO5PAAZPsErhYQTeHoZ/cRkySVXm50r1aZ0osZfXysjrwvkP3lPLZzjeB21JldrUKviJ4k7YQunWC+B2Y4MX1ApZoTCw=","message":"SUCCESS","timestamp":1731552629806,"success":true,"fail":false}
|
|
|
}
|
|
|
public string LkLSetFee(string merNo, decimal rate = 0.6M, int fee = 0)
|
|
|
{
|
|
@@ -1302,10 +1316,10 @@ namespace MySystem
|
|
|
item.Add("fee", rate.ToString("f2"));
|
|
|
innerParamList.Add(item);
|
|
|
Dictionary<string, string> headers = new Dictionary<string, string>();
|
|
|
- headers.Add("Authorization", "bearer a54b216a-18b7-4a0b-b6b7-b37eee813b6e");// + LkLGetToken());
|
|
|
- function.WriteLog("请求地址\n" + lkbReqUrl2, "拉卡拉设置费率");
|
|
|
+ headers.Add("Authorization", "bearer " + LkLGetToken());
|
|
|
+ function.WriteLog("请求地址\n" + lklReqUrl + "/htkmerchants/channel/customer/update/fee/" + merNo, "拉卡拉设置费率");
|
|
|
Dictionary<string, object> obj = new Dictionary<string, object>();
|
|
|
- obj.Add("productCode", "");
|
|
|
+ // obj.Add("productCode", "");
|
|
|
obj.Add("fees", innerParamList);
|
|
|
string content = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
|
|
function.WriteLog("明文参数\n" + content, "拉卡拉设置费率");
|
|
@@ -1319,78 +1333,11 @@ namespace MySystem
|
|
|
|
|
|
public string LklEncrypt(string data)
|
|
|
{
|
|
|
- // 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 = rsa.Encrypt(content, RSAEncryptionPadding.Pkcs1);
|
|
|
-
|
|
|
- // 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);
|
|
|
}
|
|
|
|