AliyunPushHelper.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. string Device = data["Device"].ToString();
  51. string Title = data["Title"].ToString();
  52. string Body = data["Body"].ToString();
  53. if(Device == "IOS")
  54. {
  55. AliyunPush.PushForIos(Account, Title, Body);
  56. }
  57. else
  58. {
  59. AliyunPush.Push(Account, Title, Body);
  60. }
  61. }
  62. }
  63. }