Ver Fonte

对接拉卡拉费率和服务器

lcl há 1 dia atrás
pai
commit
a198ebbccc

+ 9 - 0
AppStart/Helper/ChangePosFeeQueue.cs

@@ -127,6 +127,15 @@ public class ChangePosFeeQueue
                         else if (Deposit == "299") Deposit = "299";
                         ChangePosFeeUtil.SetPosPDeposit(PosSnId.ToString(), Deposit);
                     }
+                    //拉卡拉
+                    if (bId == 30 || bId == 31)
+                    { 
+                        if (Deposit == "0") Deposit = "0";
+                        else if (Deposit == "99") Deposit = "99";
+                        else if (Deposit == "199") Deposit = "199";
+                        else if (Deposit == "299") Deposit = "299";
+                        ChangePosFeeUtil.SetLKLDeposit(PosSnId.ToString(), Deposit);
+                    }
                 }
                 else
                 {

+ 62 - 1
AppStart/Helper/ChangePosFeeUtil.cs

@@ -636,7 +636,68 @@ namespace MySystem
     
     
     
-    
+        #region 拉卡拉-设置押金
+        public static string SetLKLDeposit(string SnIds, string DepositId)
+        {
+            string check = RedisDbconn.Instance.Get<string>("SetLKLPosDepositWait:" + SnIds);
+            if (!string.IsNullOrEmpty(check))
+            {
+                return "操作频繁,请稍后再试";
+            }
+            RedisDbconn.Instance.Set("SetLKLPosDepositWait:" + SnIds, SnIds);
+            RedisDbconn.Instance.SetExpire("SetLKLPosDepositWait:" + SnIds, 10);
+            WebCMSEntities db = new WebCMSEntities();
+            Dictionary<string, object> Obj = new Dictionary<string, object>();
+            string[] SnIdList = SnIds.Split(',');
+            foreach (string SnId in SnIdList)
+            {
+                int SnIdNum = int.Parse(SnId);
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
+                if (pos == null)
+                {
+                    return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
+                }
+                //判断是否存在关联数据
+                string content = "";
+                function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "拉卡拉-设置押金-返回报文");
+                content = PublicImportDataService.Instance.LkLSetDeposit(pos.PosSn, decimal.Parse(DepositId));
+                function.WriteLog(DateTime.Now.ToString() + "\n" + content, "拉卡拉-设置押金-返回报文");
+                if (content == "fail")
+                {
+                    return "机具" + pos.PosSn + "设置失败";
+                }
+                JsonData jsonObj = JsonMapper.ToObject(content);
+                if (jsonObj["code"].ToString() != "000000")
+                {
+                    return jsonObj["message"].ToString();
+                }
+                content = jsonObj["data"].ToString();
+                content = PublicImportDataService.Instance.LklDecrypt(content);
+                if (!content.ToLower().Contains("success"))
+                {
+                    return content;
+                }
+                function.WriteLog(DateTime.Now.ToString() + "\n" + content, "拉卡拉-设置押金-返回报文");
+                var BeforeDeposit = 0;
+                if (string.IsNullOrEmpty(pos.PrizeParams))
+                {
+                    BeforeDeposit = 299;
+                }
+                else
+                {
+                    BeforeDeposit = (int)decimal.Parse(pos.PrizeParams);
+                }
+                decimal amount = decimal.Parse(DepositId);
+                pos.PrizeParams = amount.ToString("f0");
+                db.SaveChanges();
+
+                //设置押金添加记录
+                PublicFunction.MerchantDepositSet(pos.BrandId, pos.BuyUserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content);
+            }
+            db.Dispose();
+            return "设置成功";
+        }
+        #endregion
     
     
     

+ 35 - 88
AppStart/Helper/PublicImportDataService.cs

@@ -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+nX8h6IiyyLX6IP6cFaqpUXHsZVAgMBAAECgYA4NpeM7etJ48T6H4Y3LsWEJkH6UDQlgbIblsaQkst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7Iu+O9PKk2nkeFtQAbZJ4I9fm8aFll69yqoY6iZFsZ4YqEn16ruwknDc43TNQqwJAEHfhEoyNRJm7pq2G9nAMTF4tOaffEiz7OLo/AefFrgnWuchLiy/b1zsV/z4xbX8UXqZ9hsZhrZItiflMTTJyXQJABaDkY5TtLWVO63H3X8HXofscG54UhVGYkBr9ZQt454s8m1/6D3St4zsFIQSI3/iMz1y2E8Q4eFAvwc0TV6Nt+QJBAIYGAZOh+0VNoiLr8M9XOgrRNYCfA7xKdRdCjjFjBQdCgqQ11E6IsdHZTM/ethaM2BDYuF+M2EKOpxcJV3ktz38=";
-        string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKPK6iG+eNwCRRs1lzE4bUyp6n0GMcj9s6lEPLIEYRpBHCCHpfGZ422SLwHqQ9zcU88lMbqfuSfQuJiPhNAqMHgmT7n2gYfxotL311lw1qG2ARJRSIyQ3oHXS6GBe9kFRWK8I/sVbuRxeV+toUs9N2EPjKequY28oxl9+AU3U6gQIDAQAB";
+        string lklPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp5aV3ZiXG2R8Yd8Nxocv+cF7VAUHBc0TF4MNne7mI8wM2yEP2QgI+rK1qDf6G7ZFPhu 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);
         }
 

+ 18 - 0
AppStart/Helper/SetDepositPostService.cs

@@ -391,6 +391,24 @@ namespace MySystem
                                             db.SaveChanges();
                                         }
                                     }
+                                    else if(pos.BrandId == 30 || pos.BrandId == 31) //拉卡拉
+                                    {
+                                        string content = PublicImportDataService.Instance.LkLSetFee(merchant.KqMerNo, Fee, addRate);
+                                        JsonData obj = JsonMapper.ToObject(content);
+                                        if (obj["code"].ToString() == "000000")
+                                        {
+                                            pos.SeoDescription = "设置成功";
+                                            SetRecordResult(db, RecordId, 1, "设置成功");
+                                            db.SaveChanges();
+                                        }
+                                        else
+                                        {
+                                            string msg = obj["message"].ToString();
+                                            pos.SeoDescription = msg;
+                                            SetRecordResult(db, RecordId, -1, msg);
+                                            db.SaveChanges();
+                                        }
+                                    }
                                 }
                             }
                         }

+ 3 - 3
Controllers/HomeController.cs

@@ -73,11 +73,11 @@ namespace MySystem.Controllers
             // return PublicImportDataService.Instance.LkbSetDeposit("00000302QRNL15510103", 299);
             // return PublicImportDataService.Instance.LkbSetFee("00000302QRNL20019214", 0.63M, 300);
             
-            // return PublicImportDataService.Instance.LkLSetDeposit("0000010222ATBEL00292", 299);
+            return PublicImportDataService.Instance.LkLSetFee("00007302823221000005", 0.63M, 3);
 
-            string content = "YXzIAh6eQG30ei6iTQiqGpxRNk1gliq/ZpgWmr+HcF9BSKFSunqsJPaeDw7EL1lMvocDewnMaZivCSwlQA4TRxD/KkCBv3WmRRvdGXNz+4n0Dh5XGebhe3Uds2mEdChCDjUPhXIS5sCIT0eYN+8Z4y594qrsetUD/fv5e45lYDRhnEiKUxKTiJ32zYKzri6RU7ssV18KY2tEZnfmhpItO61kGE0UW2eV0WsKmb+YH/8w99i1cTGIvn5MnZu3i01d2uinpcRGPuVLVcKkfNU8fnYYkgDzm0chLu4SSyzVNrHTZuXsJoJ6qxcZCwuqfn6NxMNVh/TKtup7Jk1EwgltVwKxqNGEXmOSuAXytbsh4HIFe4Bd7qHu56iFcJHkoqsh/5m62J4iTZQf/KU6SHpJOX7XXz06DBxCa7YZPrSProoxphV9Xd0KcFw5QvyxdYOLLExU8qaHQAAR/BAF/IXhjLIESjabBvzmq9r77GUyirYkcfBq3ohBpHCaE6F7N8gPAHeSNd8Ox7piYy+Hyqos22Nc+rj4yAlGIgFG21W8QVfFuL0q3NYuCpCkJd58DaIQFfsypY9i1XZEOj7wNyafqtVx95F9Y3Vm4XTfglj27K7EUI6jdbu1xErAo7JjyTM8N/66weR6sX9z2aJYTcJneoPAfxTMz+XoSNGDOj2J76Y=";
+            // string content = "Oa4NF8tNLKthg9Q9klCLxyWtNJdAuL8n7NH5yM8VgM2eekpkzJ8/sFiY31NBo8qXGDcNi9GAiALsTZcEO5PAAZPsErhYQTeHoZ/cRkySVXm50r1aZ0osZfXysjrwvkP3lPLZzjeB21JldrUKviJ4k7YQunWC+B2Y4MX1ApZoTCw=";
             
-            return PublicImportDataService.Instance.LklDecrypt(content);
+            // return PublicImportDataService.Instance.LklDecrypt(content);
         }
     
     }

+ 7 - 7
Startup.cs

@@ -147,14 +147,14 @@ namespace MySystem
             }
             if(Library.ConfigurationManager.EnvironmentFlag == 2)
             {
-                // SetFeeFlagService.Instance.Start(); //85天提前通知创客费率调升消息
-                // SetDepositService.Instance.Start(); //调整费率(通知、标记)
-                // SetDepositPostService.Instance.Start(); //提交支付公司设置费率接口
-                // SetDepositPostService.Instance.StartKdb(); //监控开店宝费率设置结果
-                // ChangePosFeeQueue.Instance.StartEverTime(); //设置服务费
-                // SetSftFeeService.Instance.Start(); //盛付通420天费率加万2
+                SetFeeFlagService.Instance.Start(); //85天提前通知创客费率调升消息
+                SetDepositService.Instance.Start(); //调整费率(通知、标记)
+                SetDepositPostService.Instance.Start(); //提交支付公司设置费率接口
+                SetDepositPostService.Instance.StartKdb(); //监控开店宝费率设置结果
+                ChangePosFeeQueue.Instance.StartEverTime(); //设置服务费
+                SetSftFeeService.Instance.Start(); //盛付通420天费率加万2
 
-                // TmpService.Instance.Start();
+                TmpService.Instance.Start();
             }
         }