コード例 #1
0
        /// <summary>
        /// 提交分享
        /// </summary>
        /// <param name="task"></param>
        public void PostShare(Beauty.App.BeautyService.WebTask task)
        {
            //http://www.meilishuo.com/aj/twitter/fetch
            try
            {
                int count = 0;

                Beauty.App.BeautyService.WebShare share = client.GetShare(task.Taskid.ToString());
                if (share != null)
                {
                    Beauty.App.BeautyService.WebBady bady = client.GetBady(share.Bady.ID.ToString());
                    string url  = System.Web.HttpUtility.UrlEncode(bady.Link);
                    string html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/twitter/fetch", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", "url=" + url, true, user.Cookie, null, Encoding.UTF8, null, true);
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    PostBadyResult       obj        = serializer.Deserialize <PostBadyResult>(html);
                    //{"error_code":0,"data":{"gInfo":{"title":"\u7c73\u897f\u679c \u7ae5\u88c5\u513f\u7ae5\u76ae\u8863\u5916\u5957\u7537\u7ae5\u79cb\u88c52013\u65b0\u6b3e\u5939\u514b\u886b\u4f11\u95f2\u5916\u5957\u6f6eSM7A7","goods_url":"http:\/\/detail.tmall.com\/item.htm?id=27015308049","image":"http:\/\/img01.taobaocdn.com\/bao\/uploaded\/i1\/14275026844061217\/T1DcimFcxgXXXXXXXX_!!0-item_pic.jpg","domain":"tmall.com","price":158,"goodsID":64628518}}}
                    //string errorcode = html.Substring(html.IndexOf(":") + 1, html.IndexOf(",") - html.IndexOf(":") - 1);
                    if (obj.data == null)
                    {
                        //提交错误时,3次重复提交
                        count++;
                        while (count < 3)
                        {
                            html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/twitter/fetch", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", bady.Link, true, user.Cookie, null, Encoding.UTF8, null, true);

                            obj = serializer.Deserialize <PostBadyResult>(html);

                            if (obj.error_code == 0)
                            {
                                break;
                            }
                            count++;
                        }
                    }

                    if (obj.error_code != 0)
                    {
                        return;
                    }

                    Beauty.App.BeautyService.WebGroup group = null;

                    ///如果分组编号为空,立马获取该用户的分组
                    if (string.IsNullOrEmpty(task.Type))
                    {
                        ///update group

                        html = HttpHelper.GetHtml("http://www.meilishuo.com/aj/magazine/user_groups", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", null, "", true, user.Cookie, null, Encoding.GetEncoding("gb2312"), null, true);

                        List <UserGroup> objs = serializer.Deserialize <List <UserGroup> >(html);
                        if (objs != null && objs.Count > 0)
                        {
                            foreach (UserGroup usergroup in objs)
                            {
                                if (usergroup.name.Contains(share.Keyword))
                                {
                                    group = new BeautyService.WebGroup {
                                        Name = usergroup.name, ID = usergroup.group_id
                                    };
                                }
                                client.BeginUpdateGroup(user.Username, usergroup.group_id, usergroup.name, null, null);
                            }

                            if (group == null && objs.Count > 0)
                            {
                                group = new BeautyService.WebGroup {
                                    Name = objs[0].name, ID = objs[0].group_id
                                };
                            }
                        }
                    }
                    else
                    {
                        group = client.GetGroup(task.Type);
                    }

                    //创建新分组
                    if (!string.IsNullOrEmpty(task.NewType))
                    {
                        string groupid = CreateGroup(task.NewType);
                        if (groupid != null)
                        {
                            client.BeginUpdateGroup(user.Username, groupid, task.NewType, null, null);
                            group = new BeautyService.WebGroup {
                                Name = task.NewType, ID = groupid
                            };
                        }
                    }

                    //分组不为空才能提交
                    if (group != null)
                    {
                        if (obj.data != null)
                        {
                            string postdata = "type=7&goodsID=" + obj.data.gInfo.goodsID + "&group_id=" + task.Type + "&name=" + group.Name + "&tContent=" + task.Comment + "&goods_pic_url=" + obj.data.gInfo.image + "&syncToQzone=false&syncToWeibo=false";
                            //string goodid = html.Substring(html.LastIndexOf(":") + 1, html.IndexOf("}") - html.LastIndexOf(":") - 1);
                            //{"code":0,"data":{"twitter_id":1739748392,"group_id":42454433}}
                            html = HttpHelper.GetHtml("http://www.meilishuo.com/aw/twitter/create", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", "application/json, text/javascript, */*; q=0.01", "application/x-www-form-urlencoded; charset=UTF-8", postdata, true, user.Cookie, null, Encoding.UTF8, null, true);

                            PostShareResult resultobject = serializer.Deserialize <PostShareResult>(html);
                            if (resultobject.code == 0)
                            {
                                writelog("完成分享任务");
                                client.BeginCompleteShareTask(task.ID.ToString(), task.Taskid.ToString(), bady.ID.ToString(), obj.data.gInfo.goodsID.ToString(), resultobject.data.twitter_id.ToString(), resultobject.data.group_id.ToString(), null, null);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMsg = "An application error occurred. Please contact the adminstrator " +
                                  "with the following information:/n/n";
                errorMsg += ex.Message + "/n/nStack Trace:/n" + ex.StackTrace + "//" + ex.Source;
                client.BeginLog(errorMsg, null, null);
            }
        }