SendMsgObj.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using Ragdoll;
  3. using Newtonsoft.Json;
  4. using UnityEngine;
  5. namespace HttpApi
  6. {
  7. public class SendMsgObj : AbsMsgObj
  8. {
  9. private static readonly TimeSpan Utc5Span = TimeSpan.FromHours(5);
  10. private static Int64 _msgNum = 0;
  11. private struct EncryptMsg
  12. {
  13. public string api;
  14. public string session;
  15. public int sendToPlayer;
  16. public int msgType;
  17. public string msgContent;
  18. public string check;
  19. public string time;
  20. public string extra;
  21. }
  22. [JsonProperty] public readonly int sendTo;
  23. [JsonProperty] public readonly int msgType;
  24. [JsonProperty] public readonly string msgContent;
  25. [JsonProperty] public string check = "";
  26. [JsonProperty] public string time;
  27. [JsonProperty] public string extra = "";
  28. public SendMsgObj(string session, int sendTo, int msgType, string msgContent) : base(session)
  29. {
  30. this.sendTo = sendTo;
  31. this.msgType = msgType;
  32. this.msgContent = msgContent;
  33. }
  34. protected override string GetApi()
  35. {
  36. return "send";
  37. }
  38. public override string ToJson()
  39. {
  40. var now = DateTime.Now.ToUniversalTime();
  41. var nowUtc5 = now.Add(Utc5Span);
  42. var timeStr = nowUtc5.ToString("yyyy-MM-dd hh:mm:ss " + _msgNum++);
  43. if (_msgNum >= Int64.MaxValue - 1)
  44. {
  45. _msgNum = 0;
  46. }
  47. time = timeStr;
  48. var encryptMsg = new EncryptMsg
  49. {
  50. api = api,
  51. session = session,
  52. sendToPlayer = sendTo,
  53. msgType = msgType,
  54. msgContent = msgContent,
  55. check = check,
  56. time = time,
  57. extra = extra
  58. };
  59. var jsonStr = JsonConvert.SerializeObject(encryptMsg);
  60. Debug.Log("json str is " + jsonStr);
  61. check = EnUtil.AesAndSha256(jsonStr);
  62. return JsonConvert.SerializeObject(this);
  63. }
  64. }
  65. }