AliyunPushHelper.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 AliyunPushHelper
  12. {
  13. public readonly static AliyunPushHelper Instance = new AliyunPushHelper();
  14. private AliyunPushHelper()
  15. {
  16. }
  17. public void Start()//启动
  18. {
  19. Thread thread = new Thread(threadStart);
  20. thread.IsBackground = true;
  21. thread.Start();
  22. }
  23. private void threadStart()
  24. {
  25. while (true)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("AliyunPushQueue");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. try
  31. {
  32. DoSomeThing(content);
  33. }
  34. catch (Exception ex)
  35. {
  36. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "SLS日志异常");
  37. }
  38. }
  39. else
  40. {
  41. Thread.Sleep(5000);
  42. }
  43. }
  44. }
  45. //要执行的方法
  46. public void DoSomeThing(string content)
  47. {
  48. JsonData data = JsonMapper.ToObject(content);
  49. string Account = data["Account"].ToString();
  50. if(Account == "14781419364")
  51. {
  52. return;
  53. }
  54. string Device = data["Device"].ToString();
  55. string Title = data["Title"].ToString();
  56. string Body = data["Body"].ToString();
  57. if(Device == "IOS")
  58. {
  59. AliyunPush.PushForIos(Account, Title, Body);
  60. }
  61. else
  62. {
  63. AliyunPush.Push(Account, Title, Body);
  64. }
  65. }
  66. }
  67. }