コード例 #1
0
        public void TestMessageProcesser()
        {
            JMessage msg = new JMessage
            {
                SenderId  = GetSendUser().Id.ToInt(),
                Channel   = SendChannel.Email,
                SendToIds = new int[] { GetSendToUser().Id.ToInt() },
                Title     = "消息发送测试",
                Content   = "<strong>消息发送测试内容</strong>",
            };
            MessageProcesser processer = new MessageProcesser(new MessageRouter());

            processer.Process(msg);
            Assert.IsTrue(msg.Id > 0);
        }
コード例 #2
0
ファイル: EventTest.cs プロジェクト: jackjet870/YuChang
        public void TemplateSendJobFinishEvent()
        {
            var xml = @"
<xml><ToUserName><![CDATA[gh_26fac8adcd13]]></ToUserName>
<FromUserName><![CDATA[o1Ux1uP_0TDyXNvZjrKwOyn0Aprs]]></FromUserName>
<CreateTime>1418619744</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
<MsgID>201843808</MsgID>
<Status><![CDATA[success]]></Status>
</xml>
";
            // Message.FromXml(xml);
            var msg = Message.FromXml(xml) as TemplateSendJobFinishEvent;

            Assert.IsNotNull(msg);
            Assert.AreEqual(EventType.TemplateSendJobFinish, msg.Event);

            var p = new MessageProcesser();

            p.Process(xml);
        }
コード例 #3
0
ファイル: HttpHandler.cs プロジェクト: xiaopohou/YuChang
        public void Process(HttpRequest request, HttpResponse response)
        {
            if (request == null)
            {
                throw Error.ArugmentNull("request");
            }

            if (response == null)
            {
                throw Error.ArugmentNull("response");
            }

            try
            {
                Trace.WriteLine(DateTime.Now);
                if (!CheckSignature(request))
                {
                    response.Write("Invalid request." + Environment.NewLine);
                    Trace.WriteLine("CheckSignature fail");

                    return;
                }

                var httpMethod = request.HttpMethod.ToLower();
                if (httpMethod == "get")
                {
                    if (request.QueryString["echostr"] != null)
                    {
                        response.Write(request.QueryString["echostr"]);
                    }

                    return;
                }

                //处理 post
                Stream s = request.InputStream;
                byte[] b = new byte[s.Length];
                s.Read(b, 0, (int)s.Length);
                var postStr = Encoding.UTF8.GetString(b);

                if (string.IsNullOrEmpty(postStr))
                {
                    Trace.WriteLine("Post string is null or empty.");
                    return;
                }

                Trace.WriteLine("Post Message:");
                Trace.WriteLine(postStr);

                var reply = processer.Process(postStr);
                var xml   = reply.ToXml();

                response.ContentEncoding = Encoding.UTF8;
                response.Write(xml);

                Trace.WriteLine("Reply Message:");
                Trace.WriteLine(xml);
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc.Source);
                Trace.WriteLine(exc.StackTrace);
                throw exc;
            }
            finally
            {
                Trace.Flush();
                Trace.Close();
            }
        }