public override Reply Handle(string tag, ClickRequest msg) { var ctx = "报歉,目前还不能处理您的请求。"; switch (msg.EventKey.ToUpper()) { case "HELP": ctx = HelpText; break; } var reply = new Reply() { Content = ctx, CreateTime = DateTime.Now.ToUnixTimestamp(), FromUserName = msg.ToUserName, MsgId = DateTime.Now.Ticks, MsgType = "text", ToUserName = msg.FromUserName }; return reply; }
/// <summary> /// 处理回复, 如果不使用 aes 加密, 则不加密 /// </summary> /// <param name="client"></param> /// <param name="msg"></param> /// <param name="nonce"></param> /// <param name="useAes"></param> /// <returns></returns> public static string Encrypt(this ApiClient client, Reply msg, string nonce, bool useAes) { if (msg == null) throw new ArgumentNullException("msg"); var ctx = ""; var ser = new XmlSerializer(typeof(Reply)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); using (var msm = new MemoryStream()) { ser.Serialize(msm, msg, ns); ctx = Encoding.UTF8.GetString(msm.GetBuffer()); } if (useAes) { ctx = Cryptography.AESEncrypt(ctx, client.Config.AesKey, client.Config.AppID); var ticks = DateTime.Now.ToUnixTimestamp(); var signature = Cryptography.Signature(client.Config.Token, nonce, ctx, ticks.ToString()).ToLower(); return string.Format(Fmt, ctx, signature, ticks, nonce); } else return ctx; }