1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using Ragdoll;
- using Newtonsoft.Json;
- using UnityEngine;
- namespace HttpApi
- {
- public class SendMsgObj : AbsMsgObj
- {
- private static readonly TimeSpan Utc5Span = TimeSpan.FromHours(5);
- private static Int64 _msgNum = 0;
-
- private struct EncryptMsg
- {
- public string api;
- public string session;
- public int sendToPlayer;
- public int msgType;
- public string msgContent;
- public string check;
- public string time;
- public string extra;
- }
- [JsonProperty] public readonly int sendTo;
- [JsonProperty] public readonly int msgType;
- [JsonProperty] public readonly string msgContent;
- [JsonProperty] public string check = "";
- [JsonProperty] public string time;
- [JsonProperty] public string extra = "";
- public SendMsgObj(string session, int sendTo, int msgType, string msgContent) : base(session)
- {
- this.sendTo = sendTo;
- this.msgType = msgType;
- this.msgContent = msgContent;
- }
- protected override string GetApi()
- {
- return "send";
- }
- public override string ToJson()
- {
- var now = DateTime.Now.ToUniversalTime();
- var nowUtc5 = now.Add(Utc5Span);
- var timeStr = nowUtc5.ToString("yyyy-MM-dd hh:mm:ss " + _msgNum++);
- if (_msgNum >= Int64.MaxValue - 1)
- {
- _msgNum = 0;
- }
- time = timeStr;
- var encryptMsg = new EncryptMsg
- {
- api = api,
- session = session,
- sendToPlayer = sendTo,
- msgType = msgType,
- msgContent = msgContent,
- check = check,
- time = time,
- extra = extra
- };
- var jsonStr = JsonConvert.SerializeObject(encryptMsg);
- Debug.Log("json str is " + jsonStr);
- check = EnUtil.AesAndSha256(jsonStr);
- return JsonConvert.SerializeObject(this);
- }
- }
- }
|