Beispiel #1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            System.Data.DataTable dataTable      = ArticleHelper.GetNoImgMsgIdArticleList();
            SiteSettings          masterSettings = SettingsManager.GetMasterSettings(false);
            string text = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret);

            text = JsonConvert.DeserializeObject <Token>(text).access_token;
            if (dataTable.Rows.Count > 0)
            {
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    string text2 = NewsApi.GetMedia_IDByPath(text, dataTable.Rows[i]["ImageUrl"].ToString());
                    text2 = NewsApi.GetJsonValue(text2, "media_id");
                    if (!string.IsNullOrEmpty(text2))
                    {
                        ArticleHelper.UpdateMedia_Id(0, Globals.ToNum(dataTable.Rows[i]["ArticleId"].ToString()), text2);
                    }
                }
            }
            dataTable = ArticleHelper.GetNoImgMsgIdArticleItemList();
            if (dataTable.Rows.Count > 0)
            {
                for (int j = 0; j < dataTable.Rows.Count; j++)
                {
                    string text3 = NewsApi.GetMedia_IDByPath(text, dataTable.Rows[j]["ImageUrl"].ToString());
                    text3 = NewsApi.GetJsonValue(text3, "media_id");
                    if (!string.IsNullOrEmpty(text3))
                    {
                        ArticleHelper.UpdateMedia_Id(1, Globals.ToNum(dataTable.Rows[j]["ID"].ToString()), text3);
                    }
                }
            }
            System.Web.HttpContext.Current.Response.Write("document.write('');");
            System.Web.HttpContext.Current.Response.End();
        }
Beispiel #2
0
        public string Send(string access_token, string openid)
        {
            string arg_10_0  = base.Request["type"];
            string arg_21_0  = base.Request["data"];
            string postData  = "{\"touser\":\"" + openid + "\",\"msgtype\":\"text\",\"text\": {\"content\":\"欢迎您的来访!\"}}";
            string msg       = NewsApi.KFSend(access_token, postData);
            string jsonValue = NewsApi.GetJsonValue(msg, "media_id");
            string text      = NewsApi.Send(access_token, NewsApi.CreateImageNewsJson(jsonValue));

            if (string.IsNullOrWhiteSpace(text))
            {
                return("{\"code\":0,\"msg\":\"type参数错误\"}");
            }
            string jsonValue2 = NewsApi.GetJsonValue(text, "errcode");
            string jsonValue3 = NewsApi.GetJsonValue(text, "errmsg");

            if (jsonValue2 == "0")
            {
                return("{\"code\":1,\"msg\":\"\"}");
            }
            return(string.Concat(new string[]
            {
                "{\"code\":0,\"msg\":\"errcode:",
                jsonValue2,
                ", errmsg:",
                jsonValue3,
                "\"}"
            }));
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable    noImgMsgIdArticleList = ArticleHelper.GetNoImgMsgIdArticleList();
            SiteSettings masterSettings        = SettingsManager.GetMasterSettings(false);
            string       str = JsonConvert.DeserializeObject <Token>(TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret)).access_token;

            if (noImgMsgIdArticleList.Rows.Count > 0)
            {
                for (int i = 0; i < noImgMsgIdArticleList.Rows.Count; i++)
                {
                    string jsonValue = NewsApi.GetJsonValue(NewsApi.GetMedia_IDByPath(str, noImgMsgIdArticleList.Rows[i]["ImageUrl"].ToString()), "media_id");
                    if (!string.IsNullOrEmpty(jsonValue))
                    {
                        ArticleHelper.UpdateMedia_Id(0, Globals.ToNum(noImgMsgIdArticleList.Rows[i]["ArticleId"].ToString()), jsonValue);
                    }
                }
            }
            noImgMsgIdArticleList = ArticleHelper.GetNoImgMsgIdArticleItemList();
            if (noImgMsgIdArticleList.Rows.Count > 0)
            {
                for (int j = 0; j < noImgMsgIdArticleList.Rows.Count; j++)
                {
                    string str3 = NewsApi.GetJsonValue(NewsApi.GetMedia_IDByPath(str, noImgMsgIdArticleList.Rows[j]["ImageUrl"].ToString()), "media_id");
                    if (!string.IsNullOrEmpty(str3))
                    {
                        ArticleHelper.UpdateMedia_Id(1, Globals.ToNum(noImgMsgIdArticleList.Rows[j]["ID"].ToString()), str3);
                    }
                }
            }
            HttpContext.Current.Response.Write("document.write('');");
            HttpContext.Current.Response.End();
        }
Beispiel #4
0
        public string Send(string access_token, string openid)
        {
            string text1     = base.Request["type"];
            string text2     = base.Request["data"];
            string postData  = "{\"touser\":\"" + openid + "\",\"msgtype\":\"text\",\"text\": {\"content\":\"欢迎您的来访!\"}}";
            string str2      = null;
            string jsonValue = NewsApi.GetJsonValue(NewsApi.KFSend(access_token, postData), "media_id");

            str2 = NewsApi.Send(access_token, NewsApi.CreateImageNewsJson(jsonValue));
            StreamWriter writer = File.AppendText(base.Server.MapPath("error.txt"));

            writer.WriteLine(str2);
            writer.WriteLine(DateTime.Now);
            writer.Flush();
            writer.Close();
            if (string.IsNullOrWhiteSpace(str2))
            {
                return("{\"code\":0,\"msg\":\"type参数错误\"}");
            }
            string str5 = NewsApi.GetJsonValue(str2, "errcode");
            string str6 = NewsApi.GetJsonValue(str2, "errmsg");

            if (str5 == "0")
            {
                return("{\"code\":1,\"msg\":\"\"}");
            }
            return("{\"code\":0,\"msg\":\"errcode:" + str5 + ", errmsg:" + str6 + "\"}");
        }
Beispiel #5
0
        public string Send(string access_token, string openid)
        {
            string text1     = base.Request["type"];
            string text2     = base.Request["data"];
            string postData  = "{\"touser\":\"" + openid + "\",\"msgtype\":\"text\",\"text\": {\"content\":\"欢迎您的来访!\"}}";
            string msg       = null;
            string jsonValue = NewsApi.GetJsonValue(NewsApi.KFSend(access_token, postData), "media_id");

            msg = NewsApi.Send(access_token, NewsApi.CreateImageNewsJson(jsonValue));
            if (string.IsNullOrWhiteSpace(msg))
            {
                return("{\"code\":0,\"msg\":\"type参数错误\"}");
            }
            string str5 = NewsApi.GetJsonValue(msg, "errcode");
            string str6 = NewsApi.GetJsonValue(msg, "errmsg");

            if (str5 == "0")
            {
                return("{\"code\":1,\"msg\":\"\"}");
            }
            return("{\"code\":0,\"msg\":\"errcode:" + str5 + ", errmsg:" + str6 + "\"}");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string str2;

            if (base.IsPostBack)
            {
                return;
            }
            if (!(this.type == "getarticleinfo"))
            {
                if (!(this.type == "postdata"))
                {
                    if (this.sendID > 0)
                    {
                        this.hdfSendID.Value = this.sendID.ToString();
                        SendAllInfo sendAllInfo = WeiXinHelper.GetSendAllInfo(this.sendID);
                        if (sendAllInfo != null)
                        {
                            MessageType messageType = sendAllInfo.MessageType;
                            this.hdfMessageType.Value = ((int)sendAllInfo.MessageType).ToString();
                            int articleID = sendAllInfo.ArticleID;
                            this.hdfArticleID.Value = articleID.ToString();
                            this.txtTitle.Text      = sendAllInfo.Title;
                            switch (messageType)
                            {
                            case MessageType.Text:
                                this.fkContent.Text = sendAllInfo.Content;
                                break;

                            case MessageType.News:
                                if (articleID <= 0)
                                {
                                    this.hdfIsOldArticle.Value = "1";
                                    NewsReplyInfo reply = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo;
                                    if (((reply != null) && (reply.NewsMsg != null)) && (reply.NewsMsg.Count != 0))
                                    {
                                        this.htmlInfo = "<div class=\"mate-inner\"><h3 id=\"singelTitle\">" + reply.NewsMsg[0].Title + "</h3><span>" + reply.LastEditDate.ToString("M月d日") + "</span><div class=\"mate-img\"><img id=\"img1\" src=\"" + reply.NewsMsg[0].PicUrl + "\" class=\"img-responsive\"></div><div class=\"mate-info\" id=\"Lbmsgdesc\">" + reply.NewsMsg[0].Description + "</div><div class=\"red-all clearfix\"><strong class=\"fl\">查看全文</strong><em class=\"fr\">&gt;</em></div></div>";
                                    }
                                }
                                break;

                            case MessageType.List:
                                if (articleID <= 0)
                                {
                                    this.hdfIsOldArticle.Value = "1";
                                    NewsReplyInfo info6 = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo;
                                    if (info6 != null)
                                    {
                                        StringBuilder builder2 = new StringBuilder();
                                        if ((info6.NewsMsg != null) && (info6.NewsMsg.Count > 0))
                                        {
                                            int num15 = 0;
                                            foreach (NewsMsgInfo info7 in info6.NewsMsg)
                                            {
                                                num15++;
                                                if (num15 == 1)
                                                {
                                                    builder2.Append("<div class=\"mate-inner top\">                 <div class=\"mate-img\" >                     <img id=\"img1\" src=\"" + info7.PicUrl + "\" class=\"img-responsive\">                     <div class=\"title\" id=\"title1\">" + info7.Title + "</div>                 </div>             </div>");
                                                }
                                                else
                                                {
                                                    builder2.Append("             <div class=\"mate-inner\">                 <div class=\"child-mate\">                     <div class=\"child-mate-title clearfix\">                         <div class=\"title\">" + info7.Title + "</div>                         <div class=\"img\">                             <img src=\"" + info7.PicUrl + "\" class=\"img-responsive\">                         </div>                     </div>                 </div>             </div>");
                                                }
                                            }
                                            this.htmlInfo = builder2.ToString();
                                        }
                                    }
                                }
                                break;
                            }
                        }
                        else
                        {
                            base.Response.Redirect("sendalllist.aspx");
                            base.Response.End();
                        }
                    }
                    else if (this.LocalArticleID > 0)
                    {
                        ArticleInfo articleInfo = ArticleHelper.GetArticleInfo(this.LocalArticleID);
                        if (articleInfo != null)
                        {
                            this.hdfArticleID.Value   = this.LocalArticleID.ToString();
                            this.hdfMessageType.Value = ((int)articleInfo.ArticleType).ToString();
                        }
                    }
                    if (string.IsNullOrEmpty(this.htmlInfo))
                    {
                        this.htmlInfo = "<div class=\"exit-shop-info\">内容区</div>";
                    }
                    this.litInfo.Text = this.htmlInfo;
                    return;
                }
                base.Response.ContentType = "application/json";
                str2        = "{\"type\":\"1\",\"tips\":\"操作成功\"}";
                this.sendID = Globals.RequestFormNum("sendid");
                int    num2         = Globals.RequestFormNum("sendtype");
                int    msgType      = Globals.RequestFormNum("msgtype");
                int    num4         = Globals.RequestFormNum("articleid");
                string title        = Globals.RequestFormStr("title");
                string content      = Globals.RequestFormStr("content");
                int    isoldarticle = Globals.RequestFormNum("isoldarticle");
                string str5         = this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, true);
                if (!string.IsNullOrEmpty(str5))
                {
                    str2 = "{\"type\":\"0\",\"tips\":\"" + str5 + "\"}";
                }
                else
                {
                    MessageType  type           = (MessageType)msgType;
                    string       str6           = string.Empty;
                    SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                    string       str7           = JsonConvert.DeserializeObject <Token>(TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret)).access_token;
                    switch (type)
                    {
                    case MessageType.News:
                    case MessageType.List:
                    {
                        bool        flag  = true;
                        ArticleInfo info3 = ArticleHelper.GetArticleInfo(num4);
                        if (info3.MediaId.Length < 1)
                        {
                            string jsonValue = NewsApi.GetJsonValue(NewsApi.GetMedia_IDByPath(str7, info3.ImageUrl), "media_id");
                            if (string.IsNullOrEmpty(jsonValue))
                            {
                                flag = false;
                                str2 = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(NewsApi.GetJsonValue(jsonValue, "errcode")) + "111111\"}";
                            }
                            else
                            {
                                ArticleHelper.UpdateMedia_Id(0, info3.ArticleId, jsonValue);
                            }
                        }
                        if (type == MessageType.List)
                        {
                            foreach (ArticleItemsInfo info4 in info3.ItemsInfo)
                            {
                                if ((info4.MediaId == null) || (info4.MediaId.Length < 1))
                                {
                                    string msg     = NewsApi.GetMedia_IDByPath(str7, info4.ImageUrl);
                                    string mediaid = NewsApi.GetJsonValue(msg, "media_id");
                                    if (mediaid.Length == 0)
                                    {
                                        this.errcode = NewsApi.GetJsonValue(msg, "errcode");
                                        msg          = "";
                                        flag         = false;
                                        str2         = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "\"}";
                                        break;
                                    }
                                    ArticleHelper.UpdateMedia_Id(1, info4.Id, mediaid);
                                }
                            }
                        }
                        if (flag)
                        {
                            string articlesJsonStr = this.GetArticlesJsonStr(info3);
                            string str12           = NewsApi.UploadNews(str7, articlesJsonStr);
                            this.sendID = Globals.ToNum(this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, false));
                            string str13 = NewsApi.GetJsonValue(str12, "media_id");
                            if (str13.Length > 0)
                            {
                                if (num2 == 1)
                                {
                                    str6 = NewsApi.SendAll(str7, NewsApi.CreateImageNewsJson(str13));
                                    if (!string.IsNullOrWhiteSpace(str6))
                                    {
                                        string str14 = NewsApi.GetJsonValue(str6, "msg_id");
                                        if (!string.IsNullOrEmpty(str14))
                                        {
                                            WeiXinHelper.UpdateMsgId(this.sendID, str14, 0, 0, 0, "");
                                        }
                                        else
                                        {
                                            this.errcode = NewsApi.GetJsonValue(str6, "errcode");
                                            string errorCodeMsg = NewsApi.GetErrorCodeMsg(this.errcode);
                                            WeiXinHelper.UpdateMsgId(this.sendID, str14, 2, 0, 0, errorCodeMsg);
                                            str2 = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg + "!!\"}";
                                        }
                                    }
                                    else
                                    {
                                        str2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}";
                                    }
                                }
                                else
                                {
                                    DataTable rencentOpenID  = WeiXinHelper.GetRencentOpenID(100);
                                    int       count          = rencentOpenID.Rows.Count;
                                    int       sendcount      = 0;
                                    string    returnjsondata = string.Empty;
                                    for (int i = 0; i < rencentOpenID.Rows.Count; i++)
                                    {
                                        string str17 = NewsApi.KFSend(str7, this.GetKFSendImageJson(rencentOpenID.Rows[i][0].ToString(), info3));
                                        this.errcode = NewsApi.GetJsonValue(str17, "errcode");
                                        if (this.errcode == "0")
                                        {
                                            sendcount++;
                                        }
                                        else
                                        {
                                            returnjsondata = NewsApi.GetErrorCodeMsg(this.errcode);
                                        }
                                    }
                                    int sendstate = (sendcount > 0) ? 1 : 2;
                                    WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate, sendcount, count, returnjsondata);
                                }
                            }
                            else
                            {
                                this.errcode = NewsApi.GetJsonValue(str12, "errcode");
                                str2         = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "!\"}";
                            }
                        }
                        goto Label_091D;
                    }
                    }
                    this.sendID = Globals.ToNum(this.SavePostData(msgType, num4, title, content, isoldarticle, this.sendID, false));
                    if (num2 == 1)
                    {
                        str6 = NewsApi.SendAll(str7, this.CreateTxtNewsJson(content));
                        if (!string.IsNullOrWhiteSpace(str6))
                        {
                            string msgid = NewsApi.GetJsonValue(str6, "msg_id");
                            if (msgid.Length == 0)
                            {
                                this.errcode = NewsApi.GetJsonValue(str6, "errcode");
                                string str19 = NewsApi.GetErrorCodeMsg(this.errcode);
                                WeiXinHelper.UpdateMsgId(this.sendID, msgid, 2, 0, 0, str19);
                                str2 = "{\"type\":\"2\",\"tips\":\"" + str19 + "\"}";
                            }
                            else
                            {
                                WeiXinHelper.UpdateMsgId(this.sendID, msgid, 0, 0, 0, "");
                            }
                        }
                        else
                        {
                            str2 = "{\"type\":\"2\",\"tips\":\"type参数错误\"}";
                        }
                    }
                    else
                    {
                        DataTable table2     = WeiXinHelper.GetRencentOpenID(100);
                        int       totalcount = table2.Rows.Count;
                        int       num11      = 0;
                        string    str20      = string.Empty;
                        for (int j = 0; j < table2.Rows.Count; j++)
                        {
                            string str21 = NewsApi.KFSend(str7, NewsApi.CreateKFTxtNewsJson(table2.Rows[j][0].ToString(), this.String2Json(this.FormatSendContent(content))));
                            this.errcode = NewsApi.GetJsonValue(str21, "errcode");
                            if (this.errcode == "0")
                            {
                                num11++;
                            }
                            else
                            {
                                str20 = NewsApi.GetErrorCodeMsg(this.errcode);
                            }
                        }
                        int num13 = (num11 > 0) ? 1 : 2;
                        WeiXinHelper.UpdateMsgId(this.sendID, "", num13, num11, totalcount, str20);
                        if (num11 == 0)
                        {
                            str2 = "{\"type\":\"0\",\"tips\":\"发送失败\"}";
                        }
                    }
                }
                goto Label_091D;
            }
            base.Response.ContentType = "application/json";
            string s         = "{\"type\":\"0\",\"tips\":\"操作失败\"}";
            int    articleid = Globals.RequestFormNum("articleid");

            if (articleid > 0)
            {
                ArticleInfo info = ArticleHelper.GetArticleInfo(articleid);
                if (info != null)
                {
                    StringBuilder builder = new StringBuilder();
                    switch (info.ArticleType)
                    {
                    case ArticleType.News:
                        s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"memo\":\"", this.String2Json(info.Memo), "\"}" });
                        goto Label_030E;

                    case ArticleType.List:
                        foreach (ArticleItemsInfo info2 in info.ItemsInfo)
                        {
                            builder.Append("{\"title\":\"" + this.String2Json(info2.Title) + "\",\"imgurl\":\"" + this.String2Json(info2.ImageUrl) + "\"},");
                        }
                        s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"items\":[", builder.ToString().Trim(new char[] { ',' }), "]}" });
                        goto Label_030E;
                    }
                    s = string.Concat(new object[] { "{\"type\":\"1\",\"articletype\":", (int)info.ArticleType, ",\"title\":\"", this.String2Json(info.Title), "\",\"date\":\"", this.String2Json(info.PubTime.ToString("M月d日")), "\",\"imgurl\":\"", this.String2Json(info.ImageUrl), "\",\"memo\":\"", this.String2Json(info.Content), "\"}" });
                }
            }
Label_030E:
            base.Response.Write(s);
            base.Response.End();
            return;

Label_091D:
            base.Response.Write(str2);
            base.Response.End();
        }
Beispiel #7
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!base.IsPostBack)
            {
                if (this.type == "getarticleinfo")
                {
                    base.Response.ContentType = "application/json";
                    string s   = "{\"type\":\"0\",\"tips\":\"操作失败\"}";
                    int    num = Globals.RequestFormNum("articleid");
                    if (num > 0)
                    {
                        ArticleInfo articleInfo3 = ArticleHelper.GetArticleInfo(num);
                        if (articleInfo3 != null)
                        {
                            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                            switch (articleInfo3.ArticleType)
                            {
                            case ArticleType.News:
                                s = string.Concat(new object[]
                                {
                                    "{\"type\":\"1\",\"articletype\":",
                                    (int)articleInfo3.ArticleType,
                                    ",\"title\":\"",
                                    this.String2Json(articleInfo3.Title),
                                    "\",\"date\":\"",
                                    this.String2Json(articleInfo3.PubTime.ToString("M月d日")),
                                    "\",\"imgurl\":\"",
                                    this.String2Json(articleInfo3.ImageUrl),
                                    "\",\"memo\":\"",
                                    this.String2Json(articleInfo3.Memo),
                                    "\"}"
                                });
                                goto IL_30E;

                            case ArticleType.List:
                            {
                                System.Collections.Generic.IList <ArticleItemsInfo> itemsInfo = articleInfo3.ItemsInfo;
                                foreach (ArticleItemsInfo current in itemsInfo)
                                {
                                    stringBuilder.Append(string.Concat(new string[]
                                        {
                                            "{\"title\":\"",
                                            this.String2Json(current.Title),
                                            "\",\"imgurl\":\"",
                                            this.String2Json(current.ImageUrl),
                                            "\"},"
                                        }));
                                }
                                s = string.Concat(new object[]
                                    {
                                        "{\"type\":\"1\",\"articletype\":",
                                        (int)articleInfo3.ArticleType,
                                        ",\"title\":\"",
                                        this.String2Json(articleInfo3.Title),
                                        "\",\"date\":\"",
                                        this.String2Json(articleInfo3.PubTime.ToString("M月d日")),
                                        "\",\"imgurl\":\"",
                                        this.String2Json(articleInfo3.ImageUrl),
                                        "\",\"items\":[",
                                        stringBuilder.ToString().Trim(new char[]
                                        {
                                            ','
                                        }),
                                        "]}"
                                    });
                                goto IL_30E;
                            }
                            }
                            s = string.Concat(new object[]
                            {
                                "{\"type\":\"1\",\"articletype\":",
                                (int)articleInfo3.ArticleType,
                                ",\"title\":\"",
                                this.String2Json(articleInfo3.Title),
                                "\",\"date\":\"",
                                this.String2Json(articleInfo3.PubTime.ToString("M月d日")),
                                "\",\"imgurl\":\"",
                                this.String2Json(articleInfo3.ImageUrl),
                                "\",\"memo\":\"",
                                this.String2Json(articleInfo3.Content),
                                "\"}"
                            });
                        }
                    }
IL_30E:
                    base.Response.Write(s);
                    base.Response.End();
                    return;
                }
                if (this.type == "postdata")
                {
                    base.Response.ContentType = "application/json";
                    string ReturnResult = "{\"type\":\"1\",\"tips\":\"操作成功\"}";
                    this.sendID = Globals.RequestFormNum("sendid");
                    int    num2         = Globals.RequestFormNum("sendtype");
                    int    num3         = Globals.RequestFormNum("msgtype");
                    int    articleid    = Globals.RequestFormNum("articleid");
                    string title        = Globals.RequestFormStr("title");
                    string content      = Globals.RequestFormStr("content");
                    int    isoldarticle = Globals.RequestFormNum("isoldarticle");
                    string text         = this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, true);
                    if (string.IsNullOrEmpty(text))
                    {
                        MessageType  messageType    = (MessageType)num3;
                        string       text2          = string.Empty;
                        SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                        string       access_token   = TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret);
                        access_token = JsonConvert.DeserializeObject <Token>(access_token).access_token;
                        switch (messageType)
                        {
                        case MessageType.News:
                        case MessageType.List:
                        {
                            bool        flag        = true;
                            ArticleInfo articleInfo = ArticleHelper.GetArticleInfo(articleid);
                            if (articleInfo.MediaId.Length < 1)
                            {
                                string text3 = NewsApi.GetMedia_IDByPath(access_token, articleInfo.ImageUrl);
                                text3 = NewsApi.GetJsonValue(text3, "media_id");
                                if (!string.IsNullOrEmpty(text3))
                                {
                                    ArticleHelper.UpdateMedia_Id(0, articleInfo.ArticleId, text3);
                                }
                                else
                                {
                                    flag         = false;
                                    ReturnResult = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(NewsApi.GetJsonValue(text3, "errcode")) + "111111\"}";
                                }
                            }
                            if (messageType == MessageType.List)
                            {
                                foreach (ArticleItemsInfo current2 in articleInfo.ItemsInfo)
                                {
                                    if (current2.MediaId == null || current2.MediaId.Length < 1)
                                    {
                                        string media_IDByPath = NewsApi.GetMedia_IDByPath(access_token, current2.ImageUrl);
                                        string jsonValue      = NewsApi.GetJsonValue(media_IDByPath, "media_id");
                                        if (jsonValue.Length == 0)
                                        {
                                            this.errcode = NewsApi.GetJsonValue(media_IDByPath, "errcode");
                                            flag         = false;
                                            ReturnResult = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "\"}";
                                            break;
                                        }
                                        ArticleHelper.UpdateMedia_Id(1, current2.Id, jsonValue);
                                    }
                                }
                            }
                            if (!flag)
                            {
                                goto IL_91B;
                            }
                            string articlesJsonStr = this.GetArticlesJsonStr(articleInfo);
                            string msg             = NewsApi.UploadNews(access_token, articlesJsonStr);
                            this.sendID = Globals.ToNum(this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, false));
                            string jsonValue2 = NewsApi.GetJsonValue(msg, "media_id");
                            if (jsonValue2.Length <= 0)
                            {
                                this.errcode = NewsApi.GetJsonValue(msg, "errcode");
                                ReturnResult = "{\"type\":\"2\",\"tips\":\"" + NewsApi.GetErrorCodeMsg(this.errcode) + "!\"}";
                                goto IL_91B;
                            }
                            if (num2 != 1)
                            {
                                System.Data.DataTable dt = WeiXinHelper.GetRencentOpenID(0);
                                int    icount            = dt.Rows.Count;
                                int    sendcount         = 0;
                                string retjson           = string.Empty;
                                Task.Factory.StartNew(delegate
                                    {
                                        try
                                        {
                                            for (int i = 0; i < dt.Rows.Count; i++)
                                            {
                                                string msg2  = NewsApi.KFSend(access_token, this.GetKFSendImageJson(dt.Rows[i][0].ToString(), articleInfo));
                                                this.errcode = NewsApi.GetJsonValue(msg2, "errcode");
                                                if (this.errcode == "0")
                                                {
                                                    sendcount++;
                                                }
                                                else
                                                {
                                                    retjson = NewsApi.GetErrorCodeMsg(this.errcode);
                                                }
                                            }
                                            int sendstate = (sendcount > 0) ? 1 : 2;
                                            WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate, sendcount, icount, retjson);
                                        }
                                        catch (System.Exception ex)
                                        {
                                            Globals.Debuglog(ex.ToString(), "_DebuglogSendAllEdit.txt");
                                        }
                                    });
                                goto IL_91B;
                            }
                            text2 = NewsApi.SendAll(access_token, NewsApi.CreateImageNewsJson(jsonValue2));
                            if (string.IsNullOrWhiteSpace(text2))
                            {
                                ReturnResult = "{\"type\":\"2\",\"tips\":\"type参数错误\"}";
                                goto IL_91B;
                            }
                            string jsonValue3 = NewsApi.GetJsonValue(text2, "msg_id");
                            if (!string.IsNullOrEmpty(jsonValue3))
                            {
                                WeiXinHelper.UpdateMsgId(this.sendID, jsonValue3, 0, 0, 0, "");
                                goto IL_91B;
                            }
                            this.errcode = NewsApi.GetJsonValue(text2, "errcode");
                            string errorCodeMsg = NewsApi.GetErrorCodeMsg(this.errcode);
                            WeiXinHelper.UpdateMsgId(this.sendID, jsonValue3, 2, 0, 0, errorCodeMsg);
                            ReturnResult = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg + "!!\"}";
                            goto IL_91B;
                        }
                        }
                        this.sendID = Globals.ToNum(this.SavePostData(num3, articleid, title, content, isoldarticle, this.sendID, false));
                        if (num2 == 1)
                        {
                            text2 = NewsApi.SendAll(access_token, this.CreateTxtNewsJson(content));
                            if (!string.IsNullOrWhiteSpace(text2))
                            {
                                string jsonValue4 = NewsApi.GetJsonValue(text2, "msg_id");
                                if (jsonValue4.Length == 0)
                                {
                                    this.errcode = NewsApi.GetJsonValue(text2, "errcode");
                                    string errorCodeMsg2 = NewsApi.GetErrorCodeMsg(this.errcode);
                                    WeiXinHelper.UpdateMsgId(this.sendID, jsonValue4, 2, 0, 0, errorCodeMsg2);
                                    ReturnResult = "{\"type\":\"2\",\"tips\":\"" + errorCodeMsg2 + "\"}";
                                }
                                else
                                {
                                    WeiXinHelper.UpdateMsgId(this.sendID, jsonValue4, 0, 0, 0, "");
                                }
                            }
                            else
                            {
                                ReturnResult = "{\"type\":\"2\",\"tips\":\"type参数错误\"}";
                            }
                        }
                        else
                        {
                            System.Data.DataTable dt = WeiXinHelper.GetRencentOpenID(0);
                            int    icount            = dt.Rows.Count;
                            int    sendcount         = 0;
                            string retjson           = string.Empty;
                            Task.Factory.StartNew(delegate
                            {
                                try
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        string msg2  = NewsApi.KFSend(access_token, NewsApi.CreateKFTxtNewsJson(dt.Rows[i][0].ToString(), this.String2Json(this.FormatSendContent(content))));
                                        this.errcode = NewsApi.GetJsonValue(msg2, "errcode");
                                        if (this.errcode == "0")
                                        {
                                            sendcount++;
                                        }
                                        else
                                        {
                                            retjson = NewsApi.GetErrorCodeMsg(this.errcode);
                                        }
                                    }
                                    int sendstate = (sendcount > 0) ? 1 : 2;
                                    WeiXinHelper.UpdateMsgId(this.sendID, "", sendstate, sendcount, icount, retjson);
                                    if (sendcount == 0)
                                    {
                                        ReturnResult = "{\"type\":\"0\",\"tips\":\"发送失败\"}";
                                    }
                                }
                                catch (System.Exception ex)
                                {
                                    Globals.Debuglog(ex.ToString(), "_DebuglogSendAllEdit.txt");
                                }
                            });
                        }
                    }
                    else
                    {
                        ReturnResult = "{\"type\":\"0\",\"tips\":\"" + text + "\"}";
                    }
IL_91B:
                    base.Response.Write(ReturnResult);
                    base.Response.End();
                    return;
                }
                if (this.sendID > 0)
                {
                    this.hdfSendID.Value = this.sendID.ToString();
                    SendAllInfo sendAllInfo = WeiXinHelper.GetSendAllInfo(this.sendID);
                    if (sendAllInfo != null)
                    {
                        MessageType messageType2 = sendAllInfo.MessageType;
                        this.hdfMessageType.Value = ((int)sendAllInfo.MessageType).ToString();
                        int articleID = sendAllInfo.ArticleID;
                        this.hdfArticleID.Value = articleID.ToString();
                        this.txtTitle.Text      = sendAllInfo.Title;
                        switch (messageType2)
                        {
                        case MessageType.Text:
                            this.fkContent.Text = sendAllInfo.Content;
                            break;

                        case MessageType.News:
                            if (articleID <= 0)
                            {
                                this.hdfIsOldArticle.Value = "1";
                                NewsReplyInfo newsReplyInfo = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo;
                                if (newsReplyInfo != null && newsReplyInfo.NewsMsg != null && newsReplyInfo.NewsMsg.Count != 0)
                                {
                                    this.htmlInfo = string.Concat(new string[]
                                    {
                                        "<div class=\"mate-inner\"><h3 id=\"singelTitle\">",
                                        newsReplyInfo.NewsMsg[0].Title,
                                        "</h3><span>",
                                        newsReplyInfo.LastEditDate.ToString("M月d日"),
                                        "</span><div class=\"mate-img\"><img id=\"img1\" src=\"",
                                        newsReplyInfo.NewsMsg[0].PicUrl,
                                        "\" class=\"img-responsive\"></div><div class=\"mate-info\" id=\"Lbmsgdesc\">",
                                        newsReplyInfo.NewsMsg[0].Description,
                                        "</div><div class=\"red-all clearfix\"><strong class=\"fl\">查看全文</strong><em class=\"fr\">&gt;</em></div></div>"
                                    });
                                }
                            }
                            break;

                        case MessageType.List:
                            if (articleID <= 0)
                            {
                                this.hdfIsOldArticle.Value = "1";
                                NewsReplyInfo newsReplyInfo2 = ReplyHelper.GetReply(this.sendID) as NewsReplyInfo;
                                if (newsReplyInfo2 != null)
                                {
                                    System.Text.StringBuilder stringBuilder2 = new System.Text.StringBuilder();
                                    if (newsReplyInfo2.NewsMsg != null && newsReplyInfo2.NewsMsg.Count > 0)
                                    {
                                        int num4 = 0;
                                        foreach (NewsMsgInfo current3 in newsReplyInfo2.NewsMsg)
                                        {
                                            num4++;
                                            if (num4 == 1)
                                            {
                                                stringBuilder2.Append(string.Concat(new string[]
                                                {
                                                    "<div class=\"mate-inner top\">                 <div class=\"mate-img\" >                     <img id=\"img1\" src=\"",
                                                    current3.PicUrl,
                                                    "\" class=\"img-responsive\">                     <div class=\"title\" id=\"title1\">",
                                                    current3.Title,
                                                    "</div>                 </div>             </div>"
                                                }));
                                            }
                                            else
                                            {
                                                stringBuilder2.Append(string.Concat(new string[]
                                                {
                                                    "             <div class=\"mate-inner\">                 <div class=\"child-mate\">                     <div class=\"child-mate-title clearfix\">                         <div class=\"title\">",
                                                    current3.Title,
                                                    "</div>                         <div class=\"img\">                             <img src=\"",
                                                    current3.PicUrl,
                                                    "\" class=\"img-responsive\">                         </div>                     </div>                 </div>             </div>"
                                                }));
                                            }
                                        }
                                        this.htmlInfo = stringBuilder2.ToString();
                                    }
                                }
                            }
                            break;
                        }
                    }
                    else
                    {
                        base.Response.Redirect("sendalllist.aspx");
                        base.Response.End();
                    }
                }
                else if (this.LocalArticleID > 0)
                {
                    ArticleInfo articleInfo2 = ArticleHelper.GetArticleInfo(this.LocalArticleID);
                    if (articleInfo2 != null)
                    {
                        this.hdfArticleID.Value   = this.LocalArticleID.ToString();
                        this.hdfMessageType.Value = ((int)articleInfo2.ArticleType).ToString();
                    }
                }
                if (string.IsNullOrEmpty(this.htmlInfo))
                {
                    this.htmlInfo = "<div class=\"exit-shop-info\">内容区</div>";
                }
                this.litInfo.Text = this.htmlInfo;
            }
        }
Beispiel #8
0
        public override AbstractResponse OnEvent_ClickRequest(ClickEventRequest clickEventRequest)
        {
            string userOpenId = clickEventRequest.FromUserName;

            WeiXinHelper.UpdateRencentOpenID(userOpenId);
            AbstractResponse result;

            try
            {
                int menuId = System.Convert.ToInt32(clickEventRequest.EventKey);
                Hidistro.Entities.VShop.MenuInfo menu = VShopHelper.GetMenu(menuId);
                if (menu == null)
                {
                    result = null;
                }
                else
                {
                    if (menu.BindType == BindType.StoreCard)
                    {
                        try
                        {
                            SiteSettings siteSettings = SettingsManager.GetMasterSettings(false);
                            string       access_token = TokenApi.GetToken(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret);
                            access_token = JsonConvert.DeserializeObject <Token>(access_token).access_token;
                            MemberInfo member = MemberProcessor.GetOpenIdMember(userOpenId, "wx");
                            if (member == null)
                            {
                                this.CreatMember(userOpenId, 0, access_token);
                                member = MemberProcessor.GetOpenIdMember(userOpenId, "wx");
                            }
                            string           userHead        = member.UserHead;
                            string           storeLogo       = siteSettings.DistributorLogoPic;
                            string           webStart        = Globals.GetWebUrlStart();
                            string           imageUrl        = "/Storage/master/DistributorCards/MemberCard" + member.UserId + ".jpg";
                            string           mediaid         = string.Empty;
                            int              ReferralId      = 0;
                            string           storeName       = siteSettings.SiteName;
                            string           NotSuccessMsg   = string.Empty;
                            DistributorsInfo distributorInfo = DistributorsBrower.GetDistributorInfo(member.UserId);
                            if (distributorInfo != null)
                            {
                                ReferralId = member.UserId;
                                if (siteSettings.IsShowDistributorSelfStoreName)
                                {
                                    storeName = distributorInfo.StoreName;
                                    storeLogo = distributorInfo.Logo;
                                }
                                imageUrl = "/Storage/master/DistributorCards/StoreCard" + ReferralId + ".jpg";
                            }
                            else if (!siteSettings.IsShowSiteStoreCard)
                            {
                                string content = "您还不是分销商,不能为您生成推广图片,立即<a href='" + webStart + "/Vshop/DistributorCenter.aspx'>申请分销商</a>";
                                if (!string.IsNullOrEmpty(siteSettings.ToRegistDistributorTips))
                                {
                                    content = System.Text.RegularExpressions.Regex.Replace(siteSettings.ToRegistDistributorTips, "{{申请分销商}}", "<a href='" + webStart + "/Vshop/DistributorCenter.aspx'>申请分销商</a>");
                                }
                                result = new TextResponse
                                {
                                    CreateTime   = System.DateTime.Now,
                                    ToUserName   = userOpenId,
                                    FromUserName = clickEventRequest.ToUserName,
                                    Content      = content
                                };
                                return(result);
                            }
                            string postData = string.Empty;
                            string creatingStoreCardTips = siteSettings.CreatingStoreCardTips;
                            if (!string.IsNullOrEmpty(creatingStoreCardTips))
                            {
                                postData = string.Concat(new string[]
                                {
                                    "{\"touser\":\"",
                                    userOpenId,
                                    "\",\"msgtype\":\"text\",\"text\":{\"content\":\"",
                                    Globals.String2Json(creatingStoreCardTips),
                                    "\"}}"
                                });
                                NewsApi.KFSend(access_token, postData);
                            }
                            string filePath = System.Web.HttpContext.Current.Request.MapPath(imageUrl);
                            Task.Factory.StartNew(delegate
                            {
                                try
                                {
                                    System.IO.File.Exists(filePath);
                                    string setJson = System.IO.File.ReadAllText(System.Web.HttpRuntime.AppDomainAppPath + "/Storage/Utility/StoreCardSet.js");
                                    string codeUrl = webStart + "/Follow.aspx?ReferralId=" + ReferralId.ToString();
                                    ScanInfos scanInfosByUserId = ScanHelp.GetScanInfosByUserId(ReferralId, 0, "WX");
                                    if (scanInfosByUserId == null)
                                    {
                                        ScanHelp.CreatNewScan(ReferralId, "WX", 0);
                                        scanInfosByUserId = ScanHelp.GetScanInfosByUserId(ReferralId, 0, "WX");
                                    }
                                    if (scanInfosByUserId != null && !string.IsNullOrEmpty(scanInfosByUserId.CodeUrl))
                                    {
                                        codeUrl = BarCodeApi.GetQRImageUrlByTicket(scanInfosByUserId.CodeUrl);
                                    }
                                    else
                                    {
                                        string token_Message = TokenApi.GetToken_Message(siteSettings.WeixinAppId, siteSettings.WeixinAppSecret);
                                        if (TokenApi.CheckIsRightToken(token_Message))
                                        {
                                            string text = BarCodeApi.CreateTicket(token_Message, scanInfosByUserId.Sceneid, "QR_LIMIT_SCENE", "2592000");
                                            if (!string.IsNullOrEmpty(text))
                                            {
                                                codeUrl = BarCodeApi.GetQRImageUrlByTicket(text);
                                                scanInfosByUserId.CodeUrl        = text;
                                                scanInfosByUserId.CreateTime     = System.DateTime.Now;
                                                scanInfosByUserId.LastActiveTime = System.DateTime.Now;
                                                ScanHelp.updateScanInfosCodeUrl(scanInfosByUserId);
                                            }
                                        }
                                    }
                                    StoreCardCreater storeCardCreater = new StoreCardCreater(setJson, userHead, storeLogo, codeUrl, member.UserName, storeName, ReferralId, member.UserId);
                                    if (storeCardCreater.ReadJson() && storeCardCreater.CreadCard(out NotSuccessMsg))
                                    {
                                        if (ReferralId > 0)
                                        {
                                            DistributorsBrower.UpdateStoreCard(ReferralId, NotSuccessMsg);
                                        }
                                        string media_IDByPath = NewsApi.GetMedia_IDByPath(access_token, webStart + imageUrl);
                                        mediaid = NewsApi.GetJsonValue(media_IDByPath, "media_id");
                                    }
                                    else
                                    {
                                        Globals.Debuglog(NotSuccessMsg, "_DebugCreateStoreCardlog.txt");
                                    }
                                    postData = string.Concat(new string[]
                                    {
                                        "{\"touser\":\"",
                                        userOpenId,
                                        "\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"",
                                        mediaid,
                                        "\"}}"
                                    });
                                    NewsApi.KFSend(access_token, postData);
                                }
                                catch (System.Exception ex3)
                                {
                                    postData = string.Concat(new string[]
                                    {
                                        "{\"touser\":\"",
                                        userOpenId,
                                        "\",\"msgtype\":\"text\",\"text\":{\"content\":\"生成图片失败,",
                                        Globals.String2Json(ex3.ToString()),
                                        "\"}}"
                                    });
                                    NewsApi.KFSend(access_token, postData);
                                }
                            });
                            result = null;
                            return(result);
                        }
                        catch (System.Exception ex)
                        {
                            result = new TextResponse
                            {
                                CreateTime   = System.DateTime.Now,
                                ToUserName   = userOpenId,
                                FromUserName = clickEventRequest.ToUserName,
                                Content      = "问题:" + ex.ToString()
                            };
                            return(result);
                        }
                    }
                    Hidistro.Entities.VShop.ReplyInfo reply = ReplyHelper.GetReply(menu.ReplyId);
                    if (reply == null)
                    {
                        result = null;
                    }
                    else
                    {
                        if (reply.MessageType != MessageType.Image)
                        {
                            AbstractResponse keyResponse = this.GetKeyResponse(reply.Keys, clickEventRequest);
                            if (keyResponse != null)
                            {
                                result = keyResponse;
                                return(result);
                            }
                        }
                        AbstractResponse response = this.GetResponse(reply, clickEventRequest.FromUserName);
                        if (response == null)
                        {
                            this.GotoManyCustomerService(clickEventRequest);
                        }
                        response.ToUserName   = clickEventRequest.FromUserName;
                        response.FromUserName = clickEventRequest.ToUserName;
                        result = response;
                    }
                }
            }
            catch (System.Exception ex2)
            {
                result = new TextResponse
                {
                    CreateTime   = System.DateTime.Now,
                    ToUserName   = clickEventRequest.FromUserName,
                    FromUserName = clickEventRequest.ToUserName,
                    Content      = "问题:" + ex2.ToString()
                };
            }
            return(result);
        }