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 SinaCallback(string code) { AccessGrant result; JsonValue value2; IOAuth2ServiceProvider<Maticsoft.OAuth.Sina.IWeibo> provider = new Maticsoft.OAuth.Sina.WeiboServiceProvider(this.SinaAppId, this.SinaSercet); if (string.IsNullOrWhiteSpace(code)) { return this.Redirect("/"); } try { result = provider.OAuthOperations.ExchangeForAccessAsync(code, this.RedirectSinaUrl, 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 SinaCallback HttpResponseException Try:" + num); } if (num > 0) { base.Session["OAuth2CallbackTry"] = --num; return base.RedirectToAction("Sina", "Social", new { area = Maticsoft.Components.MvcApplication.GetCurrentAreaRoute(base.ControllerContext).ToString() }); } base.Session.Remove("OAuth2CallbackTry"); return this.Redirect("/"); } Maticsoft.OAuth.Sina.IWeibo api = provider.GetApi(result); try { value2 = api.GetUserProfileAsync().Result; } catch (Exception exception3) { LogHelp.AddErrorLog(exception3.Message, exception3.StackTrace, "OAuth2 SinaCallback GetUserProfileAsync Exception"); return this.Redirect("/"); } if (value2 == null) { string loginfo = "GetUserProfileAsync: userInfoJson IS NULL"; LogHelp.AddErrorLog(loginfo, loginfo, "OAuth2 SinaCallback"); return this.Redirect("/"); } long num2 = value2.GetValue<long>("id"); string nickNameOAuth = value2.GetValue<string>("name"); return this.CallbackUserInfo(MediaType.Sina, result, num2.ToString(), nickNameOAuth, null); }
public void SendWeiBo(string bindIds, string content, string url, string imageUrl = new string()) { string strWhere = ""; if (!string.IsNullOrWhiteSpace(bindIds)) { strWhere = strWhere + " BindId in (" + bindIds + ")"; } 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) { string str6; switch (bind.MediaID) { case 3: { string clientId = ConfigSystem.GetValueByCache("Social_SinaAppId"); string clientSecret = ConfigSystem.GetValueByCache("Social_SinaSercet"); IOAuth2ServiceProvider<Maticsoft.OAuth.Sina.IWeibo> provider = new Maticsoft.OAuth.Sina.WeiboServiceProvider(clientId, clientSecret); 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 path = 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)); } path = str5 + this.CreateIDCode() + ".jpg"; client.DownloadFile(imageUrl, HttpContext.Current.Server.MapPath(path)); } weibo.UploadStatusAsync(content + url, new FileInfo(HttpContext.Current.Server.MapPath(path))).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); } break; } case 13: goto Label_0201; } continue; Label_0201: str6 = ConfigSystem.GetValueByCache("Social_QQAppId"); string valueByCache = ConfigSystem.GetValueByCache("Social_QQSercet"); IOAuth2ServiceProvider<IQConnect> provider2 = new QConnectServiceProvider(str6, valueByCache); IQConnect api = provider2.GetApi(new AccessGrant(bind.TokenAccess, new string[] { bind.MediaUserID })); try { if (string.IsNullOrWhiteSpace(imageUrl)) { api.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)); } api.UploadStatusAsync(content + url, new FileInfo(HttpContext.Current.Server.MapPath(str8))).Wait(); } continue; } 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; } } } }
public ActionResult Sina() { if (string.IsNullOrWhiteSpace(this.SinaAppId)) { return base.Content("该网站尚未启用新浪微博登录"); } IOAuth2ServiceProvider<Maticsoft.OAuth.Sina.IWeibo> provider = new Maticsoft.OAuth.Sina.WeiboServiceProvider(this.SinaAppId, this.SinaSercet); OAuth2Parameters parameters2 = new OAuth2Parameters { RedirectUrl = this.RedirectSinaUrl, State = this.STATE }; OAuth2Parameters parameters = parameters2; return this.Redirect(provider.OAuthOperations.BuildAuthorizeUrl(GrantType.AuthorizationCode, parameters)); }