Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Config.Instance.IsInitialized)
            {
                Config.Instance.Load();
            }

            if (WxNormalHandler.IsVerifyingSignature())
            {
                //首次接入校验Signature
                WxNormalHandler.VerifySignature();
            }
            else
            {
                byte[] bReq = Request.BinaryRead(Request.TotalBytes);
                if (bReq.Length > 0)
                {
                    string sReq = Encoding.UTF8.GetString(bReq);
                    if (sReq.Length > 0)
                    {
                        if (WxNormalHandler.IsRcvTecentMsg(ref sReq))
                        {
                            //收到消息
                            WxMsgHandler hMsg = new WxMsgHandler();
                            if (hMsg.Parse(sReq))
                            {
                                if (hMsg.MsgType == WxMsgType.Text)
                                {
                                    hMsg.TextMsg2Db(hMsg.FromUser, hMsg.MsgId, hMsg.MsgType, hMsg.Content);

                                    //响应消息处理
                                    TextMsgResponse(Config.Instance.Wx.Response, ref hMsg);
                                }
                                else
                                {
                                    Response.Write("success");
                                }
                            }
                            else
                            {
                                Response.Write("success");
                            }
                        }
                        else if (WxNormalHandler.IsRcvTecentEvent(ref sReq))
                        {
                            //收到事件
                            WxEventHandler hEvt = new WxEventHandler();
                            if (hEvt.Parse(sReq))
                            {
                                if (hEvt.Event == WxEventType.Subscribe)
                                {
                                    //关注,执行数据库注册操作
                                    if (hEvt.Subscribe(hEvt.FromUser))
                                    {
                                        string _Welcome = Config.Instance.Wx.Welcome;
                                        _Welcome = _Welcome.Replace("{{$date}}", zDate.Format(DateTime.Now, DateFormatStyle.Style(true, false, false, true)));
                                        _Welcome = _Welcome.Replace("{{$name}}", Config.Instance.Wx.Name);

                                        SubscribeResponse(_Welcome, ref hEvt);
                                    }
                                }
                                else if (hEvt.Event == WxEventType.Unsubscribe)
                                {
                                    //取消关注
                                    hEvt.Unsubscribe(hEvt.FromUser);
                                }
                            }
                        }
                    }
                }

                //其他情况直接返回
                Response.Write("");
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            JObject res = new JObject();

            string sMode = Request.QueryString["mode"];

            if (sMode == null)
            {
                sMode = "";
            }
            else
            {
                sMode = sMode.Trim();
            }

            if (!WxUserWrapper.VerifyUserStatus())
            {
                _DoError(ref res, -10001001, "Please sign in first!", sMode);
            }
            else
            {
                if (Request.Files.Count > 0)
                {
                    string sPath = "";

                    try
                    {
                        string sExt  = zUrl.Type(Request.Files[0].FileName);
                        string sName = zDate.Format(DateTime.Now, DateFormatStyle.Style(true, true, true, true, "", "", "", ""));
                        sName += zString.RadonString(4, RandomStrDictionary.AZ09);
                        sName += "." + sExt;

                        sPath = Server.MapPath("/UploadFiles/" + sName);
                        Request.Files[0].SaveAs(sPath);

                        string url = "/UploadFiles/" + sName;

                        if (IsDroparea(sMode))
                        {
                            res.Add("path", "/UploadFiles/");
                            res.Add("filename", sName);
                        }
                        else
                        {
                            res.Add("error", 0);
                            res.Add("url", url);
                        }
                    }
                    catch (Exception ex)
                    {
                        zLogger.Instance.DebugLog(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, sPath + "\r\n" + ex.ToString(), ex.StackTrace);

                        _DoError(ref res, -10001002, "Failed to upload the files!", sMode);
                    }
                }
                else
                {
                    _DoError(ref res, -10001003, "The http body is empty!", sMode);
                }
            }

            Response.Write(res.ToString());
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormatDefinition" /> class.
 /// </summary>
 /// <param name="Format">Format.</param>
 /// <param name="Sample">Sample.</param>
 /// <param name="IsDefault">IsDefault (default to false).</param>
 /// <param name="DateStyle">DateStyle.</param>
 /// <param name="TimeStyle">TimeStyle.</param>
 public FormatDefinition(string Format = default(string), string Sample = default(string), bool?IsDefault = false, DateFormatStyle DateStyle = default(DateFormatStyle), DateFormatStyle TimeStyle = default(DateFormatStyle))
 {
     this.Format = Format;
     this.Sample = Sample;
     // use default value if no "IsDefault" provided
     if (IsDefault == null)
     {
         this.IsDefault = false;
     }
     else
     {
         this.IsDefault = IsDefault;
     }
     this.DateStyle = DateStyle;
     this.TimeStyle = TimeStyle;
 }
Esempio n. 4
0
 /// <summary>
 /// 获取当前时间
 /// </summary>
 /// <returns></returns>
 public string Now( )
 {
     return(zDate.Format(DateTime.Now, DateFormatStyle.Style(true, true, true, true)));
 }