OrderPushHelper.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Threading;
  3. using System.Linq;
  4. using System.Data;
  5. using Library;
  6. using MySystem.Models;
  7. using LitJson;
  8. using System.Collections.Generic;
  9. using System.Security.Cryptography;
  10. namespace MySystem
  11. {
  12. public class OrderPushHelper
  13. {
  14. public readonly static OrderPushHelper Instance = new OrderPushHelper();
  15. private OrderPushHelper()
  16. {
  17. }
  18. string reqUrl = "https://lcx.93a.cn:18080/mikl/wechat/payResult";
  19. public void Start()//启动
  20. {
  21. Thread thread = new Thread(listen);
  22. thread.IsBackground = true;
  23. thread.Start();
  24. }
  25. public void listen()
  26. {
  27. while (true)
  28. {
  29. string content = RedisDbconn.Instance.RPop<string>("OrderPushQueue");
  30. if (!string.IsNullOrEmpty(content))
  31. {
  32. try
  33. {
  34. doSomething(content);
  35. Thread.Sleep(10);
  36. }
  37. catch (Exception ex)
  38. {
  39. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商户订单信息推送异常");
  40. }
  41. }
  42. else
  43. {
  44. Thread.Sleep(1000);
  45. }
  46. }
  47. }
  48. public void doSomething(string content)
  49. {
  50. JsonData jsonObj = JsonMapper.ToObject(content);
  51. SortedList<string, string> data = new SortedList<string, string>();
  52. data.Add("order_no", jsonObj["order_no"].ToString()); //订单号
  53. data.Add("order_status", jsonObj["order_status"].ToString()); //订单状态
  54. data.Add("order_time", jsonObj["order_time"].ToString()); //变动时间
  55. post(data);
  56. }
  57. private string post(SortedList<string, string> data)
  58. {
  59. string req = Newtonsoft.Json.JsonConvert.SerializeObject(data);
  60. function.WriteLog("请求地址:" + reqUrl, "商户订单信息推送日志");
  61. function.WriteLog("请求参数:" + req, "商户订单信息推送日志");
  62. string result = function.PostWebRequest(reqUrl, req, "application/json");
  63. function.WriteLog("响应数据:" + result, "商户订单信息推送日志");
  64. return result;
  65. }
  66. }
  67. }