예제 #1
0
        protected virtual void ProcessRequestInfoWeixin(WebParameter p, GoData d)
        {
            //微信相关信息
            p.ExtentionObj.weixin                     = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            p.ExtentionObj.weixin.signature           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "signature"]);
            p.ExtentionObj.weixin.timestamp           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "timestamp"]);
            p.ExtentionObj.weixin.nonce               = ComFunc.nvl(p[DomainKey.QUERY_STRING, "nonce"]);
            p.ExtentionObj.weixin.token               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_token"]);
            p.ExtentionObj.weixin.encrypt_type        = ComFunc.nvl(p[DomainKey.QUERY_STRING, "encrypt_type"]);
            p.ExtentionObj.weixin.encrypt_key         = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_encry_key"]);
            p.ExtentionObj.weixin.appid               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appid"]);
            p.ExtentionObj.weixin.appsecret           = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appsecret"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_path = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Path"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_pass = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Pass"]);

            p.SetValue("logkey", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            string content = string.Empty;

            if (CurrentContext.Request.Method.ToLower() == "post")
            {
                content = p.RequestContent;

                //如果内容为aes加密
                if (p.ExtentionObj.weixin.encrypt_type == "aes")
                {
                    WXBizMsgCrypt wxcpt  = new WXBizMsgCrypt(p.ExtentionObj.weixin.token, p.ExtentionObj.weixin.encrypt_key, p.ExtentionObj.weixin.appid);
                    string        msg    = "";
                    var           result = wxcpt.DecryptMsg(p.ExtentionObj.weixin.signature, p.ExtentionObj.weixin.timestamp, p.ExtentionObj.weixin.nonce, content, ref msg);
                    content = msg;
                }
                var contentobj = FrameDLRObject.IsXmlThen(content, null, FrameDLRFlags.SensitiveCase);

                if (contentobj != null)
                {
                    var root = (FrameDLRObject)contentobj.GetValue("xml");
                    foreach (var item in root.Items)
                    {
                        if (item.Key == "CreateTime")
                        {
                            p[DomainKey.POST_DATA, item.Key] = new DateTime(1970, 1, 1).AddSeconds(IntStd.IsNotIntThen(item.Value));
                        }
                        else
                        {
                            p[DomainKey.POST_DATA, item.Key] = item.Value;
                        }

                        if (item.Value is FrameDLRObject)
                        {
                            foreach (var sub in ((FrameDLRObject)item.Value).Items)
                            {
                                if (sub.Key == "CreateTime")
                                {
                                    p[DomainKey.POST_DATA, sub.Key] = new DateTime(1970, 1, 1).AddSeconds(IntStd.IsNotIntThen(sub.Value));
                                }
                                else
                                {
                                    p[DomainKey.POST_DATA, sub.Key] = sub.Value;
                                }
                            }
                        }
                    }
                }
                //微信推送过来的xml对象
                p.ExtentionObj.weixin.RecieveXMLObject = contentobj;
                //事件触发时的action处理
                if (ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]) == "event")
                {
                    p.Action = "event_" + ComFunc.nvl(p[DomainKey.POST_DATA, "Event"]);
                }
                else
                {
                    //普通消息处理,action为消息类型
                    p.Action = "msg_" + ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]);
                }
            }
            else
            {
                //action为api_valid的时候为微信服务器的验证请求
                p.Action = "api_valid";
            }
        }