Browse Source

测试推送

lcl 2 months ago
parent
commit
3033df6f64
3 changed files with 67 additions and 4 deletions
  1. 59 2
      Controllers/HomeController.cs
  2. 1 1
      Startup.cs
  3. 7 1
      Util/EncryptHelper.cs

+ 59 - 2
Controllers/HomeController.cs

@@ -151,9 +151,66 @@ namespace MySystem.Controllers
         {
             // AliyunPushHelper.Instance.DoSomeThing("{\"Account\":\"14726006947\",\"Device\":\"ANDROID\",\"Title\":\"测试推送\",\"Body\":\"客小爽推送功能即将上线\"}");
             // AliyunPushHelper.Instance.DoSomeThing("{\"Account\":\"14726006947\",\"Device\":\"IOS\",\"Title\":\"测试推送\",\"Body\":\"客小爽推送功能即将上线\"}");
-            string content = "{\"data_type\":\"bind\",\"data_content\":{\"pos_sn\":\"1014BS0023511\",\"mer_no\":\"15608798003\",\"id_card\":null,\"mer_name\":\"15608798003\",\"mer_mobile\":\"15608798003\",\"request_id\":\"2024102310381200098289115\",\"bind_time\":\"2024-10-23 10:38:12\",\"brand\":\"23\"}}";
-            PosPushHelper.Instance.DoSomeThing(content);
+            // string content = "{\"data_type\":\"bind\",\"data_content\":{\"pos_sn\":\"1014BS0023511\",\"mer_no\":\"15608798003\",\"id_card\":null,\"mer_name\":\"15608798003\",\"mer_mobile\":\"15608798003\",\"request_id\":\"2024102310381200098289115\",\"bind_time\":\"2024-10-23 10:38:12\",\"brand\":\"23\"}}";
+            // PosPushHelper.Instance.DoSomeThing(content);
+            // SortedList<string, string> obj = new SortedList<string, string>();
+            // obj.Add("pos_sn", "LDN7HDQM365548961135");
+            // obj.Add("mer_no", "015330849562900");
+            // obj.Add("id_card", "");
+            // obj.Add("mer_name", "");
+            // obj.Add("mer_mobile", "");
+            // obj.Add("request_id", "ac76801a7b0773063ac20ece3f8ca6dc");
+            // obj.Add("bind_time", "2024-12-27 10:16:10");
+            // obj.Add("brand", "29");
+            // jm(obj, "bind");
+
+            // SortedList<string, string> obj = new SortedList<string, string>();
+            // obj.Add("pos_sn", "LDN7HDQM365548961135");
+            // obj.Add("mer_no", "015330849562900");
+            // obj.Add("request_id", "7440225443200e5c52d1a502074915ab");
+            // obj.Add("deposit_amount", "299.00");
+            // obj.Add("trade_time", "2024-12-27 10:17:11");
+            // obj.Add("card_type", "1");
+            // obj.Add("brand", "29");
+            // jm(obj, "deposit");
+
+            SortedList<string, string> obj = new SortedList<string, string>();
+            obj.Add("pos_sn","LDN7HDQM365548961135");
+            obj.Add("mer_no","015330849562900");
+            obj.Add("request_id","G1241227C03142143729");
+            obj.Add("trade_amount","48.00");
+            obj.Add("trade_time","2024-12-27 00:00:27");
+            obj.Add("brand","29");
+            obj.Add("is_act","0");
+            obj.Add("card_type","1");
+            obj.Add("qr_pay_flag","0");
+            obj.Add("fee_rate","0.63");
+            obj.Add("fee_amt","3");
+            jm(obj, "trade");
+
             return "ok";
         }
+
+        public string jm(SortedList<string, string> obj, string type)
+        {
+            string NoticeUrl = "http://61.189.43.58:9092/prod-api/space/open/api/commerce/offline/business/data";
+            string PushData = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
+            LogHelper.Instance.WriteLog("原始数据:" + PushData, "推送数据日志");
+            string content = EncryptHelper.Encrypt1(obj, "KTVpzn70n3Bv7w04");
+            LogHelper.Instance.WriteLog("加密数据:" + content, "推送数据日志");
+            obj = new SortedList<string, string>();
+            obj.Add("type", type);
+            obj.Add("notice_id", Guid.NewGuid().ToString());
+            obj.Add("timestamp", function.getTimeStamp());
+            obj.Add("content", content);
+            string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
+            string PushDataEncrypt = requestJson;
+            LogHelper.Instance.WriteLog("请求参数:" + PushDataEncrypt, "推送数据日志");
+            LogHelper.Instance.WriteLog("请求地址:" + NoticeUrl, "推送数据日志");
+            string result = function.PostWebRequest(NoticeUrl, requestJson, "application/json");
+            LogHelper.Instance.WriteLog("返回报文:" + result + "\n\n", "推送数据日志");
+            
+            return result;
+        }
     }
 }

+ 1 - 1
Startup.cs

@@ -102,7 +102,7 @@ namespace MySystem
                     pattern: "{controller=Home}/{action=Index}/{Id?}");
             });
 
-            StartHelper.Instance.Start(); //开启线程
+            // StartHelper.Instance.Start(); //开启线程
         }
         
     }

+ 7 - 1
Util/EncryptHelper.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using Library;
 using System.Text;
+using System.Linq;
 
 namespace MySystem
 {
@@ -10,7 +11,12 @@ namespace MySystem
 
         public static string Encrypt1(SortedList<string, string> obj, string key)
         {
-            string signstr = function.BuildQueryString(obj) + key;
+            SortedList<string, string> objnew = new SortedList<string, string>();
+            foreach(string field in obj.Keys)
+            {
+                if(!string.IsNullOrEmpty(obj[field])) objnew.Add(field, obj[field]);
+            }
+            string signstr = function.BuildQueryString(objnew) + key;
             string sign = function.MD532(signstr).ToUpper();
             obj.Add("sign", sign);
             return AesEncrypt(Newtonsoft.Json.JsonConvert.SerializeObject(obj), key);