public ActionResult TencentCallback(string code, string state, string openid, string openkey)
 {
     AccessGrant result;
     JsonValue value2;
     if (string.IsNullOrWhiteSpace(code) || !this.CheckSessionState(state))
     {
         return this.Redirect("/");
     }
     IOAuth2ServiceProvider<Maticsoft.OAuth.Tencent.Weibo.IWeibo> provider = new Maticsoft.OAuth.Tencent.Weibo.WeiboServiceProvider(this.TencentAppId, this.TencentSercet);
     try
     {
         result = provider.OAuthOperations.ExchangeForAccessAsync(code, this.RedirectTencentUrl, null).Result;
     }
     catch (AggregateException exception)
     {
         if (base.Session["OAuth2CallbackTry"] == null)
         {
             base.Session["OAuth2CallbackTry"] = 3;
         }
         int num = Globals.SafeInt(base.Session["OAuth2CallbackTry"].ToString(), -1);
         HttpResponseException innerException = exception.InnerExceptions[0].InnerException as HttpResponseException;
         if (innerException != null)
         {
             LogHelp.AddErrorLog(innerException.GetResponseBodyAsString(), innerException.StackTrace, "OAuth2 TencentCallback HttpResponseException Try:" + num);
         }
         if (num > 0)
         {
             base.Session["OAuth2CallbackTry"] = --num;
             return base.RedirectToAction("Tencent", "Social", new { area = Maticsoft.Components.MvcApplication.GetCurrentAreaRoute(base.ControllerContext).ToString() });
         }
         base.Session.Remove("OAuth2CallbackTry");
         return this.Redirect("/");
     }
     base.Session.Remove("OAuth2CallbackTry");
     result = new AccessGrant(result, new string[] { openid, openkey, Globals.ClientIP });
     Maticsoft.OAuth.Tencent.Weibo.IWeibo api = provider.GetApi(result);
     try
     {
         value2 = api.GetUserProfileAsync().Result;
     }
     catch (Exception exception3)
     {
         LogHelp.AddErrorLog(exception3.Message, exception3.StackTrace, "OAuth2 TencentCallback GetUserProfileAsync Exception");
         return this.Redirect("/");
     }
     if (value2 == null)
     {
         string loginfo = "GetUserProfileAsync: userInfoJson IS NULL";
         LogHelp.AddErrorLog(loginfo, loginfo, "OAuth2 TencentCallback");
         return this.Redirect("/");
     }
     string userIdOAuth = result.ExtraData[0] + "|" + result.ExtraData[1];
     string nickNameOAuth = value2.GetValue("data").GetValue<string>("name");
     return this.CallbackUserInfo(MediaType.Tencent, result, userIdOAuth, nickNameOAuth, null);
 }
Example #2
0
        public void SendWeiBo(int userId, string mediaIDs, string content, string url, string imageUrl = new string())
        {
            string strWhere = " userid=" + userId;
            if (!string.IsNullOrWhiteSpace(mediaIDs))
            {
                strWhere = strWhere + " and MediaID in  (" + mediaIDs + ")";
            }
            List<Maticsoft.Model.Members.UserBind> modelList = this.GetModelList(strWhere);
            if ((modelList != null) && (modelList.Count != 0))
            {
                if (string.IsNullOrWhiteSpace(url))
                {
                    url = "http://" + Globals.DomainFullName;
                }
                foreach (Maticsoft.Model.Members.UserBind bind in modelList)
                {
                    switch (bind.MediaID)
                    {
                        case 3:
                        {
                            string clientId = ConfigSystem.GetValueByCache("Social_SinaAppId");
                            string str3 = ConfigSystem.GetValueByCache("Social_SinaSercet");
                            IOAuth2ServiceProvider<Maticsoft.OAuth.Sina.IWeibo> provider = new Maticsoft.OAuth.Sina.WeiboServiceProvider(clientId, str3);
                            Maticsoft.OAuth.Sina.IWeibo weibo = provider.GetApi(new AccessGrant(bind.TokenAccess, new string[] { bind.MediaUserID }));
                            try
                            {
                                if (string.IsNullOrWhiteSpace(imageUrl))
                                {
                                    weibo.UpdateStatusAsync(content + " " + url).Wait();
                                }
                                else
                                {
                                    string str4 = imageUrl;
                                    if (imageUrl.Contains("http://"))
                                    {
                                        System.Net.WebClient client = new System.Net.WebClient();
                                        string str5 = "/Upload/Temp/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                                        if (!Directory.Exists(HttpContext.Current.Server.MapPath(str5)))
                                        {
                                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(str5));
                                        }
                                        str4 = str5 + this.CreateIDCode() + ".jpg";
                                        client.DownloadFile(imageUrl, HttpContext.Current.Server.MapPath(str4));
                                    }
                                    weibo.UploadStatusAsync(content + url, new FileInfo(HttpContext.Current.Server.MapPath(str4))).Wait();
                                }
                            }
                            catch (Exception exception)
                            {
                                Maticsoft.Model.SysManage.ErrorLog model = new Maticsoft.Model.SysManage.ErrorLog {
                                    Loginfo = exception.Message,
                                    OPTime = DateTime.Now,
                                    StackTrace = exception.StackTrace,
                                    Url = ""
                                };
                                Maticsoft.BLL.SysManage.ErrorLog.Add(model);
                            }
                            continue;
                        }
                        case 4:
                            break;

                        case 13:
                        {
                            string str6 = ConfigSystem.GetValueByCache("Social_QQAppId");
                            string str7 = ConfigSystem.GetValueByCache("Social_QQSercet");
                            IOAuth2ServiceProvider<IQConnect> provider2 = new QConnectServiceProvider(str6, str7);
                            IQConnect connect = provider2.GetApi(new AccessGrant(bind.TokenAccess, new string[] { bind.MediaUserID }));
                            try
                            {
                                if (string.IsNullOrWhiteSpace(imageUrl))
                                {
                                    connect.UpdateStatusAsync(content + url).Wait();
                                }
                                else
                                {
                                    string str8 = imageUrl;
                                    if (imageUrl.Contains("http://"))
                                    {
                                        System.Net.WebClient client2 = new System.Net.WebClient();
                                        string str9 = "/Upload/Temp/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                                        if (!Directory.Exists(HttpContext.Current.Server.MapPath(str9)))
                                        {
                                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(str9));
                                        }
                                        str8 = str9 + this.CreateIDCode() + ".jpg";
                                        client2.DownloadFile(imageUrl, HttpContext.Current.Server.MapPath(str8));
                                    }
                                    connect.UploadStatusAsync(content + url, new FileInfo(HttpContext.Current.Server.MapPath(str8))).Wait();
                                }
                            }
                            catch (Exception exception2)
                            {
                                Maticsoft.Model.SysManage.ErrorLog log2 = new Maticsoft.Model.SysManage.ErrorLog {
                                    Loginfo = exception2.Message,
                                    OPTime = DateTime.Now,
                                    StackTrace = exception2.StackTrace,
                                    Url = ""
                                };
                                Maticsoft.BLL.SysManage.ErrorLog.Add(log2);
                            }
                            continue;
                        }
                        default:
                        {
                            continue;
                        }
                    }
                    string valueByCache = ConfigSystem.GetValueByCache("Social_TencentAppId");
                    string clientSecret = ConfigSystem.GetValueByCache("Social_TencentSercet");
                    IOAuth2ServiceProvider<Maticsoft.OAuth.Tencent.Weibo.IWeibo> provider3 = new Maticsoft.OAuth.Tencent.Weibo.WeiboServiceProvider(valueByCache, clientSecret);
                    string[] strArray = bind.MediaUserID.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (strArray.Length < 2)
                    {
                        throw new ArgumentNullException(" OpenIdKeys is NULL !");
                    }
                    Maticsoft.OAuth.Tencent.Weibo.IWeibo api = provider3.GetApi(new AccessGrant(bind.TokenAccess, new string[] { strArray[0], strArray[1], Globals.ClientIP }));
                    if (string.IsNullOrWhiteSpace(imageUrl))
                    {
                        api.UpdateStatusAsync(content + url).Wait();
                        continue;
                    }
                    string path = imageUrl;
                    if (imageUrl.Contains("http://"))
                    {
                        System.Net.WebClient client3 = new System.Net.WebClient();
                        string str13 = "/Upload/Temp/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                        if (!Directory.Exists(HttpContext.Current.Server.MapPath(str13)))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(str13));
                        }
                        path = str13 + this.CreateIDCode() + ".jpg";
                        client3.DownloadFile(imageUrl, HttpContext.Current.Server.MapPath(path));
                    }
                    api.UploadStatusAsync(content + url, new FileInfo(HttpContext.Current.Server.MapPath(path))).Wait();
                }
            }
        }
 public ActionResult Tencent()
 {
     if (string.IsNullOrWhiteSpace(this.TencentAppId))
     {
         return base.Content("该网站尚未启用腾讯微博登录");
     }
     IOAuth2ServiceProvider<Maticsoft.OAuth.Tencent.Weibo.IWeibo> provider = new Maticsoft.OAuth.Tencent.Weibo.WeiboServiceProvider(this.TencentAppId, this.TencentSercet);
     OAuth2Parameters parameters2 = new OAuth2Parameters {
         RedirectUrl = this.RedirectTencentUrl,
         State = this.STATE
     };
     OAuth2Parameters parameters = parameters2;
     base.Session["OAuth2CallbackState"] = this.STATE;
     return this.Redirect(provider.OAuthOperations.BuildAuthorizeUrl(GrantType.AuthorizationCode, parameters));
 }