Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            wid = context.Session[DTKeys.SESSION_WEB_ID] as string;
            if (string.IsNullOrEmpty(wid))
            {
                return;
            }
            HttpRequest request = context.Request;

            this.app_secret = SettingsManager.GetMasterSettings(false, wid).App_Secret;
            string signature = request["signature"];
            string nonce     = request["nonce"];
            string timestamp = request["timestamp"];
            string s         = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (this.ValidateSHA(signature, nonce, timestamp))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    StringBuilder builder = new StringBuilder();
                    string        str5    = "";
                    byte[]        buffer  = new byte[request.InputStream.Length];
                    request.InputStream.Read(buffer, 0, buffer.Length);
                    string str6 = Encoding.UTF8.GetString(buffer);
                    str6 = HttpContext.Current.Server.UrlDecode(str6);
                    builder.Append(str6);
                    StreamWriter writer = File.AppendText(context.Server.MapPath("wberror.txt"));
                    writer.WriteLine(str6);
                    writer.WriteLine(DateTime.Now);
                    writer.Flush();
                    writer.Close();
                    string  senderId   = "";
                    string  receiverId = "";
                    int     messageId  = 0;
                    JObject obj2       = JObject.Parse(str6);
                    if ((((obj2["type"] != null) && (obj2["type"].ToString() == MessageType.text.ToString())) || ((obj2["type"] != null) && (obj2["type"].ToString() == MessageType.image.ToString()))) || ((obj2["type"] != null) && (obj2["type"].ToString() == MessageType.voice.ToString())))
                    {
                        MessageInfo messageInfo = new MessageInfo {
                            Created_at  = DateTime.Now.ToString(),
                            Receiver_id = obj2["receiver_id"].ToString(),
                            Sender_id   = obj2["sender_id"].ToString(),
                            Text        = obj2["text"].ToString(),
                            Type        = obj2["type"].ToString(),
                            Status      = 0
                        };
                        if (obj2["data"] != null)
                        {
                            JObject obj3 = JObject.Parse(obj2["data"].ToString());
                            if (obj3["tovfid"] != null)
                            {
                                messageInfo.Tovfid = obj3["tovfid"].ToString();
                            }
                            if (obj3["vfid"] != null)
                            {
                                messageInfo.Vfid = obj3["vfid"].ToString();
                            }
                        }
                        messageInfo.Access_Token = SettingsManager.GetMasterSettings(false, wid).Access_Token;
                        messageId = WeiboHelper.SaveMessage(messageInfo);
                    }
                    if (((obj2["type"] != null) && (obj2["type"].ToString() == MessageType.text.ToString())) && SettingsManager.GetMasterSettings(false, wid).CustomReply)
                    {
                        senderId   = obj2["receiver_id"].ToString();
                        receiverId = obj2["sender_id"].ToString();
                        DataView defaultView = WeiboHelper.GetReplyAll(1).DefaultView;
                        if (defaultView.Count > 0)
                        {
                            defaultView.RowFilter = "Keys='" + obj2["text"].ToString() + "'";
                            if (defaultView.Count > 0)
                            {
                                int num2 = new Random().Next(0, defaultView.Count);
                                if (defaultView[num2]["ReceiverType"].ToString() == "text")
                                {
                                    str5 = generateReplyMsg(textMsg(defaultView[num2]["Content"].ToString(), messageId), "text", senderId, receiverId);
                                }
                                else
                                {
                                    str5 = generateReplyMsg(articleMsg(defaultView[num2]["Display_name"].ToString(), defaultView[num2]["Summary"].ToString(), defaultView[num2]["Image"].ToString(), defaultView[num2]["Url"].ToString(), defaultView[num2]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                                }
                            }
                            else
                            {
                                defaultView.RowFilter = "Keys like '%" + obj2["text"].ToString() + "%'";
                                if (defaultView.Count > 0)
                                {
                                    int num3 = new Random().Next(0, defaultView.Count);
                                    if (defaultView[num3]["ReceiverType"].ToString() == "text")
                                    {
                                        str5 = generateReplyMsg(textMsg(defaultView[num3]["Content"].ToString(), messageId), "text", senderId, receiverId);
                                    }
                                    else
                                    {
                                        str5 = generateReplyMsg(articleMsg(defaultView[num3]["Display_name"].ToString(), defaultView[num3]["Summary"].ToString(), defaultView[num3]["Image"].ToString(), defaultView[num3]["Url"].ToString(), defaultView[num3]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                                    }
                                }
                            }
                        }
                    }
                    if (((obj2["type"] != null) && (obj2["type"].ToString() == "event")) && (SettingsManager.GetMasterSettings(false, wid).SubscribeReply&& (JObject.Parse(obj2["data"].ToString())["subtype"].ToString().Trim() == "subscribe")))
                    {
                        senderId   = obj2["receiver_id"].ToString();
                        receiverId = obj2["sender_id"].ToString();
                        DataView view2 = WeiboHelper.GetWeibo_Reply(2).DefaultView;
                        if (view2.Count > 0)
                        {
                            int num4 = new Random().Next(0, view2.Count);
                            if (view2[num4]["ReceiverType"].ToString() == "text")
                            {
                                str5 = generateReplyMsg(textMsg(view2[num4]["Content"].ToString(), messageId), "text", senderId, receiverId);
                            }
                            else
                            {
                                str5 = generateReplyMsg(articleMsg(view2[num4]["Display_name"].ToString(), view2[num4]["Summary"].ToString(), view2[num4]["Image"].ToString(), view2[num4]["Url"].ToString(), view2[num4]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                            }
                        }
                    }
                    if (((obj2["type"] != null) && (obj2["type"].ToString() == "mention")) && SettingsManager.GetMasterSettings(false, wid).ByRemind)
                    {
                        JObject.Parse(obj2["data"].ToString());
                        senderId   = obj2["receiver_id"].ToString();
                        receiverId = obj2["sender_id"].ToString();
                        DataView view3 = WeiboHelper.GetWeibo_Reply(3).DefaultView;
                        if (view3.Count > 0)
                        {
                            int num5 = new Random().Next(0, view3.Count);
                            if (view3[num5]["ReceiverType"].ToString() == "text")
                            {
                                str5 = generateReplyMsg(textMsg(view3[num5]["Content"].ToString(), messageId), "text", senderId, receiverId);
                            }
                            else
                            {
                                str5 = generateReplyMsg(articleMsg(view3[num5]["Display_name"].ToString(), view3[num5]["Summary"].ToString(), view3[num5]["Image"].ToString(), view3[num5]["Url"].ToString(), view3[num5]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                            }
                        }
                    }
                    context.Response.Write(str5);
                    StreamWriter writer2 = File.AppendText(context.Server.MapPath("wberror.txt"));
                    writer2.WriteLine(str5);
                    writer2.WriteLine(DateTime.Now);
                    writer2.Flush();
                    writer2.Close();
                }
                catch (Exception exception)
                {
                    StreamWriter writer3 = File.AppendText(context.Server.MapPath("wberror.txt"));
                    writer3.WriteLine(exception.Message);
                    writer3.WriteLine(exception.StackTrace);
                    writer3.WriteLine(DateTime.Now);
                    writer3.Flush();
                    writer3.Close();
                }
            }
        }
Exemple #2
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            System.Web.HttpRequest request = context.Request;
            this.app_secret = SettingsManager.GetMasterSettings(false).App_Secret;
            string signature = request["signature"];
            string nonce     = request["nonce"];
            string timestamp = request["timestamp"];
            string s         = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                bool flag = this.ValidateSHA(signature, nonce, timestamp);
                if (flag)
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
                return;
            }
            try
            {
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                string s2    = "";
                byte[] array = new byte[request.InputStream.Length];
                request.InputStream.Read(array, 0, array.Length);
                string text = System.Text.Encoding.UTF8.GetString(array);
                text = System.Web.HttpContext.Current.Server.UrlDecode(text);
                stringBuilder.Append(text);
                int     messageId = 0;
                JObject jObject   = JObject.Parse(text);
                if ((jObject["type"] != null && jObject["type"].ToString() == wb.MessageType.text.ToString()) || (jObject["type"] != null && jObject["type"].ToString() == wb.MessageType.image.ToString()) || (jObject["type"] != null && jObject["type"].ToString() == wb.MessageType.voice.ToString()))
                {
                    MessageInfo messageInfo = new MessageInfo();
                    messageInfo.Created_at  = System.DateTime.Now.ToString();
                    messageInfo.Receiver_id = jObject["receiver_id"].ToString();
                    messageInfo.Sender_id   = jObject["sender_id"].ToString();
                    messageInfo.Text        = jObject["text"].ToString();
                    messageInfo.Type        = jObject["type"].ToString();
                    messageInfo.Status      = 0;
                    if (jObject["data"] != null)
                    {
                        JObject jObject2 = JObject.Parse(jObject["data"].ToString());
                        if (jObject2["tovfid"] != null)
                        {
                            messageInfo.Tovfid = jObject2["tovfid"].ToString();
                        }
                        if (jObject2["vfid"] != null)
                        {
                            messageInfo.Vfid = jObject2["vfid"].ToString();
                        }
                    }
                    messageInfo.Access_Token = SettingsManager.GetMasterSettings(false).Access_Token;
                    messageId = WeiboHelper.SaveMessage(messageInfo);
                }
                if (jObject["type"] != null && jObject["type"].ToString() == wb.MessageType.text.ToString())
                {
                    SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                    if (masterSettings.CustomReply)
                    {
                        string senderId   = jObject["receiver_id"].ToString();
                        string receiverId = jObject["sender_id"].ToString();
                        System.Data.DataView defaultView = WeiboHelper.GetReplyAll(1).DefaultView;
                        if (defaultView.Count > 0)
                        {
                            defaultView.RowFilter = "Keys='" + jObject["text"].ToString() + "'";
                            if (defaultView.Count > 0)
                            {
                                System.Random random      = new System.Random();
                                int           recordIndex = random.Next(0, defaultView.Count);
                                if (defaultView[recordIndex]["ReceiverType"].ToString() == "text")
                                {
                                    s2 = wb.generateReplyMsg(wb.textMsg(defaultView[recordIndex]["Content"].ToString(), messageId), "text", senderId, receiverId);
                                }
                                else
                                {
                                    s2 = wb.generateReplyMsg(wb.articleMsg(defaultView[recordIndex]["Display_name"].ToString(), defaultView[recordIndex]["Summary"].ToString(), defaultView[recordIndex]["Image"].ToString(), defaultView[recordIndex]["Url"].ToString(), defaultView[recordIndex]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                                }
                            }
                            else
                            {
                                defaultView.RowFilter = "Keys like '%" + jObject["text"].ToString() + "%'";
                                if (defaultView.Count > 0)
                                {
                                    System.Random random2      = new System.Random();
                                    int           recordIndex2 = random2.Next(0, defaultView.Count);
                                    if (defaultView[recordIndex2]["ReceiverType"].ToString() == "text")
                                    {
                                        s2 = wb.generateReplyMsg(wb.textMsg(defaultView[recordIndex2]["Content"].ToString(), messageId), "text", senderId, receiverId);
                                    }
                                    else
                                    {
                                        s2 = wb.generateReplyMsg(wb.articleMsg(defaultView[recordIndex2]["Display_name"].ToString(), defaultView[recordIndex2]["Summary"].ToString(), defaultView[recordIndex2]["Image"].ToString(), defaultView[recordIndex2]["Url"].ToString(), defaultView[recordIndex2]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                                    }
                                }
                            }
                        }
                    }
                }
                if (jObject["type"] != null && jObject["type"].ToString() == "event")
                {
                    SiteSettings masterSettings2 = SettingsManager.GetMasterSettings(false);
                    JObject      jObject3        = JObject.Parse(jObject["data"].ToString());
                    if (!(jObject3["subtype"].ToString().Trim() == "click") && masterSettings2.SubscribeReply && jObject3["subtype"].ToString().Trim() == "subscribe")
                    {
                        string senderId   = jObject["receiver_id"].ToString();
                        string receiverId = jObject["sender_id"].ToString();
                        System.Data.DataView defaultView2 = WeiboHelper.GetWeibo_Reply(2).DefaultView;
                        if (defaultView2.Count > 0)
                        {
                            System.Random random3      = new System.Random();
                            int           recordIndex3 = random3.Next(0, defaultView2.Count);
                            if (defaultView2[recordIndex3]["ReceiverType"].ToString() == "text")
                            {
                                s2 = wb.generateReplyMsg(wb.textMsg(defaultView2[recordIndex3]["Content"].ToString(), messageId), "text", senderId, receiverId);
                            }
                            else
                            {
                                s2 = wb.generateReplyMsg(wb.articleMsg(defaultView2[recordIndex3]["Display_name"].ToString(), defaultView2[recordIndex3]["Summary"].ToString(), defaultView2[recordIndex3]["Image"].ToString(), defaultView2[recordIndex3]["Url"].ToString(), defaultView2[recordIndex3]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                            }
                        }
                    }
                }
                if (jObject["type"] != null && jObject["type"].ToString() == "mention")
                {
                    SiteSettings masterSettings3 = SettingsManager.GetMasterSettings(false);
                    if (masterSettings3.ByRemind)
                    {
                        JObject.Parse(jObject["data"].ToString());
                        string senderId   = jObject["receiver_id"].ToString();
                        string receiverId = jObject["sender_id"].ToString();
                        System.Data.DataView defaultView3 = WeiboHelper.GetWeibo_Reply(3).DefaultView;
                        if (defaultView3.Count > 0)
                        {
                            System.Random random4      = new System.Random();
                            int           recordIndex4 = random4.Next(0, defaultView3.Count);
                            if (defaultView3[recordIndex4]["ReceiverType"].ToString() == "text")
                            {
                                s2 = wb.generateReplyMsg(wb.textMsg(defaultView3[recordIndex4]["Content"].ToString(), messageId), "text", senderId, receiverId);
                            }
                            else
                            {
                                s2 = wb.generateReplyMsg(wb.articleMsg(defaultView3[recordIndex4]["Display_name"].ToString(), defaultView3[recordIndex4]["Summary"].ToString(), defaultView3[recordIndex4]["Image"].ToString(), defaultView3[recordIndex4]["Url"].ToString(), defaultView3[recordIndex4]["ArticleId"].ToString(), messageId), "articles", senderId, receiverId);
                            }
                        }
                    }
                }
                context.Response.Write(s2);
            }
            catch (System.Exception ex)
            {
                Globals.Debuglog(ex.Message, "_DebugLogWB.txt");
            }
        }