PushHelper.cs 2.1 KB

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