Browse Source

推送好哒交易数据

lcl 5 months ago
parent
commit
361962f19f
7 changed files with 103 additions and 26 deletions
  1. BIN
      .DS_Store
  2. 1 1
      Model/Database/HdBindRecord.cs
  3. 1 1
      Model/Database/HdTradeRecord.cs
  4. 2 0
      Program.cs
  5. 30 15
      Task/HaoDaHelper.cs
  6. 66 0
      Util/HaoDa.cs
  7. 3 9
      appsettings.Development.json

BIN
.DS_Store


+ 1 - 1
Model/Database/HdBindRecord.cs

@@ -14,7 +14,7 @@ namespace Model
         /// <summary>
         /// ID
         /// </summary>
-        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
+        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, ColumnName = "id")]
         public long id { get; set; }
 
 

+ 1 - 1
Model/Database/HdTradeRecord.cs

@@ -14,7 +14,7 @@ namespace Model
         /// <summary>
         /// ID
         /// </summary>
-        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
+        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, ColumnName = "id")]
         public long id { get; set; }
 
 

+ 2 - 0
Program.cs

@@ -108,4 +108,6 @@ app.MapControllers();
 
 app.Urls.Add("http://*:5049");
 
+HaoDaHelper.Instance.Start();
+
 app.Run();

+ 30 - 15
Task/HaoDaHelper.cs

@@ -5,8 +5,11 @@ using System.Text;
 using System.Threading;
 using Common;
 using Infrastructure;
+using LitJson;
+using Microsoft.AspNetCore.Mvc;
 using Model;
 using Services;
+using Util;
 
 public class HaoDaHelper
 {
@@ -41,23 +44,35 @@ public class HaoDaHelper
     {
         try
         {
-            var item = Newtonsoft.Json.JsonConvert.DeserializeObject<HdTradeRecord>(content);
-            var tradeService = App.GetService<IHdTradeRecordService>();
-            tradeService.addHdTradeRecord(item);
-            // 商户号,设备号,终端类型,订单号,支付方式,交易类型,交易金额,交易手续费,交易时间,结算周期,费率
-            // {"agentId": "039034", "merchId": "015110201559354", "merchName": "测试商户号", "ordId": "20230324H00030016535Y", "transAmt": "100.0", "feeAmt": "0.65", "feeRate": "0.65", "cardType": "C", "devId": "00000002213MDE119333", "transStat": "S", "transType": "51", "paymentMethod": "0", "settleType": "0", "transDate": "20230324", "transTime": "20230324111954", "quickPassFlag": "0", "simFee": "36.00", "servFee": "36.65"}
-            string paymentMethod = item.paymentMethod;
-            if(paymentMethod == "0") paymentMethod = "刷卡";
-            if(paymentMethod == "1") paymentMethod = "微信";
-            if(paymentMethod == "2") paymentMethod = "支付宝";
-            if(paymentMethod == "7") paymentMethod = "银联二维码";
+            string[] dataArray = content.Split(new string[]{ "#cut#" }, StringSplitOptions.None);
+            JsonData header = JsonMapper.ToObject(dataArray[0]);
+            content = dataArray[1];
+            string signstr = header["X-Sign"][0].ToString();
+            SortedList<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<SortedList<string, string>>(content);
+            string sign = Function.BuildQueryString(dic);
+            bool checkSign = HaoDa.Instance.VerifySign(sign, signstr);
+            if(checkSign)
+            {
+                var item = Newtonsoft.Json.JsonConvert.DeserializeObject<HdTradeRecord>(content);
+                var tradeService = App.GetService<IHdTradeRecordService>();
+                tradeService.addHdTradeRecord(item);
+                // 商户号,设备号,终端类型,订单号,支付方式,交易类型,交易金额,交易手续费,交易时间,结算周期,费率
+                // {"agentId": "039034", "merchId": "015110201559354", "merchName": "测试商户号", "ordId": "20230324H00030016535Y", "transAmt": "100.0", "feeAmt": "0.65", "feeRate": "0.65", "cardType": "C", "devId": "00000002213MDE119333", "transStat": "S", "transType": "51", "paymentMethod": "0", "settleType": "0", "transDate": "20230324", "transTime": "20230324111954", "quickPassFlag": "0", "simFee": "36.00", "servFee": "36.65"}
+                string paymentMethod = item.paymentMethod;
+                if(paymentMethod == "0") paymentMethod = "刷卡";
+                if(paymentMethod == "1") paymentMethod = "微信";
+                if(paymentMethod == "2") paymentMethod = "支付宝";
+                if(paymentMethod == "7") paymentMethod = "银联二维码";
+
+                string settleType = item.settleType;
+                if(settleType == "0") settleType = "S0";
+                if(settleType == "1") settleType = "T1";
+                if(settleType == "2") settleType = "D1";
 
-            string settleType = item.settleType;
-            if(settleType == "0") settleType = "S0";
-            if(settleType == "1") settleType = "T1";
-            if(settleType == "2") settleType = "D1";
+                string data = item.merchId + "," + item.devId + ",好哒设备," + item.ordId + "," + paymentMethod + "," + item.transType + "," + item.transAmt + "," + item.feeAmt + "," + item.transTime + "," + settleType + "," + item.feeRate;
 
-            string data = item.merchId + "," + item.devId + ",好哒二维码,G2250516C03502752529," + paymentMethod + "," + item.transType + "," + item.transAmt + "," + item.feeAmt + "," + item.transTime + "," + settleType + "," + item.feeRate;
+                RedisServer.Cache.LPush("ListenTradeDataByOneQueue", data);
+            }
         }
         catch (Exception ex)
         {

+ 66 - 0
Util/HaoDa.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading;
+using Common;
+using Infrastructure;
+using LitJson;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using Services;
+
+namespace Util
+{
+    public class HaoDa
+    {
+        public readonly static HaoDa Instance = new HaoDa();
+        private HaoDa()
+        { }
+        
+        #region 好哒
+
+        //测试环境
+        string PublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjMQxp24mjxDTr13uPW0y+tiO1yXFGw7P/pPQ0oZKK7F6KstEaus7pLEywBZ5XRXE5jgkhR2TS7Ne7djJfbpn5yFc6pPlz3ZsOfBVeB88NEwhx6xzCGX2eqSSkO33n8w2G0xc2ss5HpYBarT00NBZWhrwOXpdRPYLOYHKVU3Rl+FA9xDw/wYfoWvrr+JSfHRGn/ENMmQFEdckAbPauKaQMrZD2kz+PRrhq56eWnCuVQPcaz/jroVT8qQEgkg2IsNy+DwfLOIqm8IySEpxnQ5wN/KvsQJc2wXDQNf9F5kvWwjoqSSP0qJS+oPRXET+zJb+WTk2y5M6AYoC9NodwsC4NwIDAQAB";
+
+        //生产环境
+        // string PublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmjoQirIYZBD9Qon2HkF4j/NAINXtJ7Lzq/WXxTF7t7mg7LNARt0+ZZaeWx8caq2fv5zdsGyyoInL23cBtDI5KmFfK69iA0ygQMK0WbiKqsUB1OpPbT3+9zLuadIJAznjA223lY6CIjTpdLZhaRjImNVqc60bdkx6YsQcA+xW+3r1JH4PPHb7yBEbkKIX8OhyX7U4p0TkbDkAobbjHr5YB9gmYLoSFJMOPfTtSExkv7/Y7IVR9poZAHcr3teFoAiXW3RzxelRtnXxIkl/6AUOKoL5fhr/UTUN+Q18uzNljYWr6SwnTI3EmtzgykaewWtZvV85Xdhe/BjiQ5Xor7YbwIDAQAB";
+        
+        public bool VerifySign(string toSignStr, string signStr)
+        {
+            return true;
+            byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
+            byte[] signByte = Convert.FromBase64String(signStr);
+            var toKey = Convert.FromBase64String(PublicKey);
+            var rsaroot = RSA.Create();
+            rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
+            var publicKeyParameters = rsaroot.ExportParameters(false);
+            using (var rsa = RSA.Create())
+            {
+                rsa.ImportParameters(publicKeyParameters);
+                var sha256 = SHA256.Create();
+                var hash = sha256.ComputeHash(toSignByte);
+                return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
+            }
+        }
+
+        // public bool VerifySign(string toSignStr, string signStr)
+        // {
+        //     byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
+        //     byte[] signByte = Convert.FromBase64String(signStr);
+        //     var toKey = Convert.FromBase64String(PublicKey);
+        //     var rsaroot = RSA.Create();
+        //     rsaroot.ImportRSAPublicKey(toKey, out _);
+        //     using (var rsa = RSA.Create())
+        //     {
+        //         var sha256 = SHA256.Create();
+        //         var hash = sha256.ComputeHash(toSignByte);
+        //         return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
+        //     }
+        // }
+
+        #endregion
+
+    }
+}

+ 3 - 9
appsettings.Development.json

@@ -14,22 +14,16 @@
   },
   "dbConfigs": [
     {
-      "Conn": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsConfigServer;charset=utf8;",
+      "Conn": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsSpServer;charset=utf8;",
       "DbType": 0,
       "ConfigId": "0",
       "IsAutoCloseConnection": true
-    },
-    {
-      "Conn": "server=47.108.62.166;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=KxsMainServer;charset=utf8;",
-      "DbType": 0,
-      "ConfigId": "kxs",
-      "IsAutoCloseConnection": true
     }
   ],
   "RedisServer": {
     "open": 1,
-    "Cache": "47.109.31.237:6379,password=klm@redis,defaultDatabase=13,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
-    "Session": "47.109.31.237:6379,password=klm@redis,defaultDatabase=13,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
+    "Cache": "47.108.62.166:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,ssl=false,writeBuffer=10240,prefix=cache:",
+    "Session": "47.108.62.166:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,ssl=false,writeBuffer=10240,prefix=session:"
   },
   "OssConfigs": {
     "Host": "http://kxs-app-sources.oss-cn-chengdu.aliyuncs.com/",