Пример #1
0
        public string SendToUIDMessage(string msgtype, string displayname, string summary, string image, string url, string Content, string ArticleId)
        {
            string json = "{\"IsAuthorized\":\"0\"}";

            if (!this.sinaweibo.IsAuthorized)
            {
                return(json);
            }
            json = this.sinaweibo.HttpGet("https://m.api.weibo.com/2/messages/subscribers/get.json").Content.ReadAsStringAsync().Result;
            JObject obj2 = JObject.Parse(json);
            string  str  = "{\"touser\": [";
            string  str3 = Content;

            if (obj2["data"] == null)
            {
                return(json);
            }
            JObject obj3 = JObject.Parse(obj2["data"].ToString());

            if (obj3["uids"] == null)
            {
                return("{\"result\":false\"}");
            }
            foreach (string str4 in (IEnumerable <JToken>)obj3["uids"])
            {
                str = str + "\"" + str4 + "\",";
            }
            str = str.Substring(0, str.Length - 1);
            string str5 = "\"text\": {\"content\": \"" + str3 + "\"}";

            if (msgtype == "articles")
            {
                if (string.IsNullOrEmpty(summary))
                {
                    summary = displayname;
                }
                string str6 = "{\"display_name\": \"" + displayname + "\",\"summary\":\"" + summary + "\",\"image\":\"" + image + "\",\"url\":\"" + url + "\"},";
                IList <ArticleItemsInfo> articleItems = ArticleHelper.GetArticleItems(int.Parse(ArticleId));
                if (articleItems.Count > 0)
                {
                    string title = "";
                    foreach (ArticleItemsInfo info in articleItems)
                    {
                        if (string.IsNullOrEmpty(info.Content))
                        {
                            title = info.Title;
                        }
                        else
                        {
                            title = info.Content;
                        }
                        string str8 = str6;
                        str6 = str8 + "{\"display_name\": \"" + info.Title + "\",\"summary\":\"" + title + "\",\"image\":\"http://" + Globals.DomainName + info.ImageUrl + "\",\"url\":\"" + info.Url + "\"},";
                    }
                }
                str6 = str6.Substring(0, str6.Length - 1);
                str5 = "\"articles\": [" + str6 + "]";
            }
            string str9 = str;

            str = str9 + "]," + str5 + ",\"msgtype\": \"" + msgtype + "\"}";
            return(this.SendMsg(HttpUtility.UrlDecode(str), "https://m.api.weibo.com/2/messages/sendall.json?access_token=" + this.sinaweibo.AccessToken));
        }
Пример #2
0
        public string SendToUIDMessage(string msgtype, string displayname, string summary, string image, string url, string Content, string ArticleId)
        {
            string text = "{\"IsAuthorized\":\"0\"}";

            if (this.sinaweibo.IsAuthorized)
            {
                HttpResponseMessage httpResponseMessage = this.sinaweibo.HttpGet("https://m.api.weibo.com/2/messages/subscribers/get.json", new
                {
                });
                text = httpResponseMessage.Content.ReadAsStringAsync().Result;
                JObject jObject = JObject.Parse(text);
                string  text2   = "{\"touser\": [";
                if (jObject["data"] != null)
                {
                    JObject jObject2 = JObject.Parse(jObject["data"].ToString());
                    if (jObject2["uids"] != null)
                    {
                        using (IEnumerator <JToken> enumerator = ((IEnumerable <JToken>)jObject2["uids"]).GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                string str = (string)enumerator.Current;
                                text2 = text2 + "\"" + str + "\",";
                            }
                        }
                        text2 = text2.Substring(0, text2.Length - 1);
                        string text3 = "\"text\": {\"content\": \"" + Content + "\"}";
                        string text6;
                        if (msgtype == "articles")
                        {
                            if (string.IsNullOrEmpty(summary))
                            {
                                summary = displayname;
                            }
                            string text4 = string.Concat(new string[]
                            {
                                "{\"display_name\": \"",
                                displayname,
                                "\",\"summary\":\"",
                                summary,
                                "\",\"image\":\"",
                                image,
                                "\",\"url\":\"",
                                url,
                                "\"},"
                            });
                            IList <ArticleItemsInfo> articleItems = ArticleHelper.GetArticleItems(int.Parse(ArticleId));
                            if (articleItems.Count > 0)
                            {
                                foreach (ArticleItemsInfo current in articleItems)
                                {
                                    string text5;
                                    if (string.IsNullOrEmpty(current.Content))
                                    {
                                        text5 = current.Title;
                                    }
                                    else
                                    {
                                        text5 = current.Content;
                                    }
                                    text6 = text4;
                                    text4 = string.Concat(new string[]
                                    {
                                        text6,
                                        "{\"display_name\": \"",
                                        current.Title,
                                        "\",\"summary\":\"",
                                        text5,
                                        "\",\"image\":\"http://",
                                        Globals.DomainName,
                                        current.ImageUrl,
                                        "\",\"url\":\"",
                                        current.Url,
                                        "\"},"
                                    });
                                }
                            }
                            text4 = text4.Substring(0, text4.Length - 1);
                            text3 = "\"articles\": [" + text4 + "]";
                        }
                        text6 = text2;
                        text2 = string.Concat(new string[]
                        {
                            text6,
                            "],",
                            text3,
                            ",\"msgtype\": \"",
                            msgtype,
                            "\"}"
                        });
                        text = this.SendMsg(HttpUtility.UrlDecode(text2), "https://m.api.weibo.com/2/messages/sendall.json?access_token=" + this.sinaweibo.AccessToken);
                    }
                    else
                    {
                        text = "{\"result\":false\"}";
                    }
                }
            }
            return(text);
        }