PushHelper.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Linq;
  3. using System.Data;
  4. using System.Threading;
  5. using Library;
  6. using LitJson;
  7. using MySystem.Models.Push;
  8. using System.Collections.Generic;
  9. namespace MySystem
  10. {
  11. public class PushHelper
  12. {
  13. public readonly static PushHelper Instance = new PushHelper();
  14. private PushHelper()
  15. {
  16. }
  17. string NoticeUrl = "http://cybsp.888cyb.com/v1/cybsp/{path}/hd";
  18. string AesSecret = "kvS4TIRh7Yulg4nr";
  19. //要执行的方法
  20. public void Do(SortedList<string, string> obj, string path = "transNotify")
  21. {
  22. try
  23. {
  24. string PushData = "";
  25. string PushDataEncrypt = "";
  26. PushData = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  27. function.WriteLog("原始数据:" + PushData, "好哒推送数据日志");
  28. string content = EncryptHelper.Encrypt1(obj, AesSecret);
  29. function.WriteLog("加密数据:" + content, "好哒推送数据日志");
  30. obj = new SortedList<string, string>();
  31. obj.Add("type", "好哒商户交易信息");
  32. obj.Add("notice_id", Guid.NewGuid().ToString());
  33. obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
  34. obj.Add("content", content);
  35. string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
  36. PushDataEncrypt = requestJson;
  37. function.WriteLog("请求参数:" + PushDataEncrypt, "好哒推送数据日志");
  38. function.WriteLog("请求地址:" + NoticeUrl.Replace("{path}", path), "好哒推送数据日志");
  39. string result = function.PostWebRequest(NoticeUrl.Replace("{path}", path), requestJson, "application/json");
  40. function.WriteLog("返回报文:" + result + "\n\n", "好哒推送数据日志");
  41. }
  42. catch(Exception ex)
  43. {
  44. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "\n\n", "好哒推送数据异常");
  45. }
  46. }
  47. }
  48. }