/// <summary> /// 获取QQ Connect 授权页面地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string GetConnectLoginPageUrl(int userId) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); List <DiscuzOAuthParameter> paramList = new List <DiscuzOAuthParameter>(); paramList.Add(new DiscuzOAuthParameter("client_ip", DNTRequest.GetIP())); paramList.Add(new DiscuzOAuthParameter("type", userId > 0 ? "loginbind" : "login")); DiscuzOAuth oauth = new DiscuzOAuth(); string queryStr = ""; string requestTokenUrl = oauth.GetOAuthUrl(REQUEST_TOKEN_URL, "POST", config.Connectappid, config.Connectappkey, "", "", "", oauthCallback, paramList, out queryStr); string response = Utils.GetHttpWebResponse(requestTokenUrl, queryStr); try { ConnectResponse <OAuthTokenInfo> tokenInfo = JavaScriptConvert.DeserializeObject <ConnectResponse <OAuthTokenInfo> >(response); Utils.WriteCookie("connect", "token", tokenInfo.Result.Token); Utils.WriteCookie("connect", "secret", tokenInfo.Result.Secret); string authorizeUrl = oauth.GetOAuthUrl(AUTHORIZE_URL, "GET", config.Connectappid, config.Connectappkey, tokenInfo.Result.Token, tokenInfo.Result.Secret, "", oauthCallback, new List <DiscuzOAuthParameter>(), out queryStr); return(authorizeUrl + "?" + queryStr); } catch { return("?Failed to get tmptoken"); } }
protected void Page_Load(object sender, EventArgs e) { if (!DiscuzCloud.GetCloudServiceEnableStatus("connect")) { ResponseScript("<script>alert('站点 " + (config.Cloudenabled == 1 ? "QQ 登录服务" : "云平台") + "未开启');window.location.href='" + (config.Cloudenabled == 1 ? " global_cloudindex.aspx" : "global_cloudset.aspx") + "';</script>"); } if (DNTRequest.GetInt("save", 0) > 0) { config.Allowconnectregister = DNTRequest.GetInt("enablereg", 0); config.Allowuseqzavater = DNTRequest.GetInt("enablecatchqzavatar", 0); int bindCount = DNTRequest.GetInt("maxbindcount", -1); if (bindCount < 0) { ResponseScript("<script>alert('允许QQ号注册数量填写错误');window.location.href='global_connectset.aspx';</script>"); return; } config.Maxuserbindcount = bindCount; DiscuzCloudConfigs.SaveConfig(config); DiscuzCloudConfigs.ResetConfig(); ResponseScript("<script>alert('操作成功');window.location.href='global_connectset.aspx';</script>"); } uploadLogoUrl = DiscuzCloud.GetCloudUploadLogoIFrame(userid); }
/// <summary> /// 解除用户QQ绑定 /// </summary> /// <param name="openId"></param> /// <returns></returns> public static int UnbindUserConnectInfo(string openId) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); UserConnectInfo userConnectInfo = DiscuzCloud.GetUserConnectInfo(openId); if (userConnectInfo == null) { return(-1); } List <DiscuzOAuthParameter> paramList = new List <DiscuzOAuthParameter>(); paramList.Add(new DiscuzOAuthParameter("client_ip", DNTRequest.GetIP())); DiscuzOAuth oauth = new DiscuzOAuth(); string queryStr = ""; string unbindUrl = oauth.GetOAuthUrl(UNBIND_URL, "POST", config.Connectappid, config.Connectappkey, userConnectInfo.Token, userConnectInfo.Secret, "", "", paramList, out queryStr); string response = Utils.GetHttpWebResponse(unbindUrl, queryStr); DeleteUserConnectInfo(openId); Utils.WriteCookie("bindconnect", ""); return(1); }
public override bool Run(CommandParameter commandParam, ref string result) { try { QQConnectAuthInfo authInfo = JavaScriptConvert.DeserializeObject <List <QQConnectAuthInfo> >(commandParam.CloudParams)[0]; if (authInfo != null) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); config.Connectappid = authInfo.AppId; config.Connectappkey = authInfo.AppKey; DiscuzCloudConfigs.SaveConfig(config); DiscuzCloudConfigs.ResetConfig(); result = CloudUtils.GetCloudResponse <bool>(true); } else { result = CloudUtils.GetCloudResponse <bool>(false); } } catch { result = CloudUtils.GetCloudResponse <bool>(false); } return(true); }
/// <summary> /// 获取云平台通知已绑定用户的接口地址 /// </summary> /// <param name="connectInfo"></param> /// <param name="userName"></param> /// <param name="birthday"></param> /// <param name="gender"></param> /// <param name="email"></param> /// <param name="isPublicEmail"></param> /// <param name="isUsedQQAvatar"></param> /// <param name="type"></param> /// <returns></returns> public static string GetBindUserNotifyUrl(UserConnectInfo connectInfo, string userName, string birthday, int gender, string email, int isPublicEmail, int isUsedQQAvatar, string type) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); List <DiscuzOAuthParameter> paramList = new List <DiscuzOAuthParameter>(); paramList.Add(new DiscuzOAuthParameter("s_id", string.Empty)); paramList.Add(new DiscuzOAuthParameter("openid", connectInfo.OpenId)); paramList.Add(new DiscuzOAuthParameter("oauth_consumer_key", config.Connectappid)); paramList.Add(new DiscuzOAuthParameter("u_id", connectInfo.Uid.ToString())); paramList.Add(new DiscuzOAuthParameter("username", userName)); paramList.Add(new DiscuzOAuthParameter("birthday", birthday)); string sex = "unknown"; sex = gender == 1 ? "male" : sex; sex = gender == 2 ? "female" : sex; paramList.Add(new DiscuzOAuthParameter("sex", sex)); paramList.Add(new DiscuzOAuthParameter("email", email)); paramList.Add(new DiscuzOAuthParameter("is_public_email", isPublicEmail.ToString())); paramList.Add(new DiscuzOAuthParameter("is_use_qq_avatar", isUsedQQAvatar.ToString())); paramList.Add(new DiscuzOAuthParameter("statreferer", "forum")); paramList.Add(new DiscuzOAuthParameter("avatar_input", "234")); paramList.Add(new DiscuzOAuthParameter("avatar_agent", "23432")); paramList.Add(new DiscuzOAuthParameter("type", type)); paramList.Add(new DiscuzOAuthParameter("site_ucenter_id", config.Sitekey)); string queryString = ""; string sig = GenerateNotifySignature(paramList, config.Connectappid + "|" + config.Connectappkey, out queryString); return(CONNECT_URL + "notify/user/bind?" + queryString + "sig=" + sig); }
/// <summary> /// 获取云平台方法签名 /// </summary> /// <param name="method"></param> /// <param name="timeStamp"></param> /// <param name="mParams"></param> /// <returns></returns> private static string GetCloudMethodSignature(string method, string timeStamp, DiscuzCloudMethodParameter mParams) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); return(Utils.MD5(string.Format("format={0}&method={1}&sId={2}{3}|{4}|{5}", FORMAT, method, config.Cloudsiteid, mParams.GetPostData(), config.Cloudsitekey, timeStamp))); }
/// <summary> /// 从云平台调用指定方法并返回指定类型(T)信息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="method"></param> /// <param name="mParams"></param> /// <returns></returns> private static BaseCloudResponse <T> GetCloudResponse <T>(string method, DiscuzCloudMethodParameter mParams) { string timeStamp = mParams.Find("sTimestamp"); timeStamp = string.IsNullOrEmpty(timeStamp) ? Utils.ConvertToUnixTimestamp(DateTime.Now).ToString() : timeStamp; string postData = string.Format("format={0}&method={1}&sId={2}&sig={3}&ts={4}{5}" , FORMAT, method, DiscuzCloudConfigs.GetConfig().Cloudsiteid, GetCloudMethodSignature(method, timeStamp, mParams), timeStamp, mParams.GetPostData()); string response = Utils.GetHttpWebResponse(CLOUD_URL, postData); try { return(JavaScriptConvert.DeserializeObject <BaseCloudResponse <T> >(response)); } catch { BaseCloudResponse <string> err = JavaScriptConvert.DeserializeObject <BaseCloudResponse <string> >(response); BaseCloudResponse <T> errObj = new BaseCloudResponse <T>(); errObj.ErrCode = err.ErrCode; errObj.ErrMessage = err.ErrMessage; return(errObj); } }
//public static string ResumeSite() //{ // DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(); // mParams.Add("sUrl", Utils.GetRootUrl(BaseConfigs.GetForumPath)); // mParams.Add("sCharset", CHARSET); // mParams.Add("sProductType", productType); // mParams.Add("sProductVersion", productVersion); // BaseCloudResponse<RegisterCloud> resumeCloudResult = GetCloudResponse<RegisterCloud>("site.resume", mParams); // if (resumeCloudResult.ErrCode == 0 && // (resumeCloudResult.Result.CloudSiteId != config.Cloudsiteid || resumeCloudResult.Result.CloudSiteKey != config.Cloudsitekey)) // { // config.Cloudsiteid = resumeCloudResult.Result.CloudSiteId; // config.Cloudsitekey = resumeCloudResult.Result.CloudSiteKey; // GeneralConfigs.SaveConfig(config); // GeneralConfigs.ResetConfig(); // } // return resumeCloudResult.ErrMessage; //} /// <summary> /// 同步站点信息,包括站点名称和站点地址 /// </summary> /// <returns></returns> public static string SyncSite() { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(); mParams.Add("sId", config.Cloudsiteid); mParams.Add("sName", GeneralConfigs.GetConfig().Forumtitle); mParams.Add("sSiteKey", config.Sitekey); mParams.Add("sCharset", "utf-8"); mParams.Add("sTimeZone", "8"); mParams.Add("sLanguage", "zh_CN"); mParams.Add("sProductType", productType); mParams.Add("sProductVersion", productVersion); mParams.Add("sApiVersion", "0.4"); mParams.Add("sSiteUid", BaseConfigs.GetFounderUid > 0 ? BaseConfigs.GetFounderUid.ToString() : "1"); mParams.Add("sProductRelease", PRODUCT_RELEASE); mParams.Add("sTimestamp", Utils.ConvertToUnixTimestamp(DateTime.Now).ToString()); #if DEBUG mParams.Add("sUrl", "http://247.mydev.com/~cailong/"); mParams.Add("sUCenterUrl", "http://247.mydev.com/~cailong/"); #else mParams.Add("sUrl", Utils.GetRootUrl(BaseConfigs.GetForumPath)); mParams.Add("sUCenterUrl", Utils.GetRootUrl(BaseConfigs.GetForumPath)); #endif BaseCloudResponse <bool> syncSiteResult = GetCloudResponse <bool>("site.sync", mParams); return(syncSiteResult.ErrMessage); }
public override bool Run(CommandParameter commandParam, ref string result) { string[] actionList = { "connect", "qqgroup" }; string action = ""; foreach (string act in actionList) { if (commandParam.CloudParams.IndexOf(string.Format("\"{0}\"", act)) != -1) { action = act; break; } } int enable = commandParam.CloudParams.IndexOf(string.Format("\"{0}\"", "normal")) != -1 ? 1 : 0; DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); bool changed = false; switch (action) { case "connect": config.Connectenabled = enable; changed = true; break; } if (changed) { DiscuzCloudConfigs.SaveConfig(config); DiscuzCloudConfigs.ResetConfig(); } result = CloudUtils.GetCloudResponse <bool>(true); return(true); }
/// <summary> /// 获取云平台后台服务管理列表Iframe地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string GetCloudAppListIFrame(int userId) { DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(false); mParams.Add("refer", Utils.GetRootUrl(BaseConfigs.GetForumPath)); mParams.Add("s_id", DiscuzCloudConfigs.GetConfig().Cloudsiteid); mParams.Add("s_site_uid", userId.ToString()); return(GetCloudCpUrl("cloud/appList/", mParams)); }
/// <summary> /// 返回指定用户是否绑定了QQ互联 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static bool IsBindConnect(int userId) { if (DiscuzCloudConfigs.GetConfig().Connectenabled == 0 || userId < 1) { return(false); } return(GetUserConnectInfo(userId) != null); }
/// <summary> /// 获取云平台绑定QQ号的页面地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string GetCloudBindUrl(int userId) { DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(false); mParams.Add("s_id", DiscuzCloudConfigs.GetConfig().Cloudsiteid); mParams.Add("s_site_uid", userId.ToString()); return(GetCloudCpUrl("bind/index", mParams)); }
public static string GetCloudTestResponse(string method, DiscuzCloudMethodParameter mParams) { string timeStamp = mParams.Find("sTimestamp"); timeStamp = string.IsNullOrEmpty(timeStamp) ? Utils.ConvertToUnixTimestamp(DateTime.Now).ToString() : timeStamp; string postData = string.Format("format={0}&method={1}&sId={2}&sig={3}&ts={4}{5}" , FORMAT, method, DiscuzCloudConfigs.GetConfig().Cloudsiteid, GetCloudMethodSignature(method, timeStamp, mParams), timeStamp, mParams.GetPostData()); return(Utils.GetHttpWebResponse(CLOUD_URL, postData)); }
/// <summary> /// 获取云平台上传站点logo的页面地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static string GetCloudUploadLogoIFrame(int userId) { DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(false); mParams.Add("s_id", DiscuzCloudConfigs.GetConfig().Cloudsiteid); mParams.Add("s_site_uid", userId.ToString()); mParams.Add("link_url", "admin/global/global_connectset.aspx"); mParams.Add("self_url", "admin/global/global_connectset.aspx?upload=1"); return(GetCloudCpUrl("connect/service", mParams)); }
public override bool Run(CommandParameter commandParam, ref string result) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); config.Cloudenabled = 1; DiscuzCloudConfigs.SaveConfig(config); DiscuzCloudConfigs.ResetConfig(); result = CloudUtils.GetCloudResponse <bool>(Utils.UrlDecode(commandParam.CloudParams) == "[]"); return(true); }
/// <summary> /// 更换站点KEY /// </summary> /// <returns></returns> public static string ResetSiteKey() { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); DiscuzCloudMethodParameter mParams = new DiscuzCloudMethodParameter(); mParams.Add("sId", config.Cloudsiteid); BaseCloudResponse <RegisterCloud> resetCloudResult = GetCloudResponse <RegisterCloud>("site.resetKey", mParams); if (resetCloudResult.ErrCode == 0) { config.Cloudsitekey = resetCloudResult.Result.CloudSiteKey; DiscuzCloudConfigs.SaveConfig(config); DiscuzCloudConfigs.ResetConfig(); } return(resetCloudResult.ErrMessage); }
/// <summary> /// 发送删除已发送feed的请求到云平台接口 /// </summary> /// <param name="feedInfo"></param> /// <param name="ip"></param> /// <returns></returns> public static bool DeletePushedFeedInDiscuzCloud(TopicPushFeedInfo feedInfo, string ip) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); List <DiscuzOAuthParameter> parmlist = new List <DiscuzOAuthParameter>(); parmlist.Add(new DiscuzOAuthParameter("client_ip", ip)); parmlist.Add(new DiscuzOAuthParameter("thread_id", feedInfo.TopicId.ToString())); DiscuzOAuth oAuth = new DiscuzOAuth(); string queryStr = ""; string deleteFeedUrl = oAuth.GetOAuthUrl(API_CONNECT_URL + "connect/feed/remove", "POST", config.Connectappid, config.Connectappkey, feedInfo.AuthorToken, feedInfo.AuthorSecret, "", "", parmlist, out queryStr); Utils.GetHttpWebResponse(deleteFeedUrl, queryStr); return(true); }
/// <summary> /// 获取指定云平台服务的开启状态,true为开启 /// </summary> /// <param name="serviceName">服务名称(connect,connect_reg)</param> /// <returns></returns> public static bool GetCloudServiceEnableStatus(string serviceName) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); if (config.Cloudenabled == 0) { return(false); } switch (serviceName) { case "connect": return(config.Connectenabled == 1); case "connect_reg": return(config.Allowconnectregister == 1); default: return(false); } }
/// <summary> /// 检查云平台Callback的签名,用来防范伪造请求 /// </summary> /// <param name="sig"></param> /// <returns></returns> private bool CheckCallbackSignature(string sig) { StringBuilder sb = new StringBuilder(); List <DiscuzOAuthParameter> parms = new List <DiscuzOAuthParameter>(); foreach (string key in HttpContext.Current.Request.QueryString.AllKeys) { if (key.Substring(0, 4) == "con_" && key != "con_sig") { parms.Add(new DiscuzOAuthParameter(key, DNTRequest.GetString(key))); } } parms.Sort(new ParameterComparer()); foreach (DiscuzOAuthParameter parm in parms) { if (!string.IsNullOrEmpty(parm.Value)) { sb.AppendFormat("{0}={1}&", parm.Name, parm.Value); } } sb.Append(DiscuzCloudConfigs.GetConfig().Connectappkey); return(sig == Utils.MD5(sb.ToString())); }
/// <summary> /// 获取当前Oauth用户的accessTokenInfo /// </summary> /// <returns></returns> public static OAuthAccessTokenInfo GetConnectAccessTokenInfo() { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); List <DiscuzOAuthParameter> paramList = new List <DiscuzOAuthParameter>(); paramList.Add(new DiscuzOAuthParameter("client_ip", DNTRequest.GetIP())); DiscuzOAuth oauth = new DiscuzOAuth(); string queryStr = ""; string accessTokenUrl = oauth.GetOAuthUrl(ACCESS_TOKEN_URL, "POST", config.Connectappid, config.Connectappkey, Utils.GetCookie("connect", "token"), Utils.GetCookie("connect", "secret"), DNTRequest.GetString("con_oauth_verifier"), "", paramList, out queryStr); string response = Utils.GetHttpWebResponse(accessTokenUrl, queryStr); try { ConnectResponse <OAuthAccessTokenInfo> accessTokenInfo = JavaScriptConvert.DeserializeObject <ConnectResponse <OAuthAccessTokenInfo> >(response); return(accessTokenInfo.Result); } catch { return(null); } }
protected override void ShowPage() { if (!DiscuzCloud.GetCloudServiceEnableStatus("connect")) { AddErrLine("QQ登录功能已关闭"); return; } switch (action) { case "access": if (!CheckCallbackSignature(DNTRequest.GetString("con_sig"))) { AddErrLine("非法请求"); return; } OAuthAccessTokenInfo tokenInfo = DiscuzCloud.GetConnectAccessTokenInfo(); if (tokenInfo == null) { AddErrLine("QQ登录过程中出现异常,请尝试再次登录"); return; } userconnectinfo = DiscuzCloud.GetUserConnectInfo(tokenInfo.Openid); if (userconnectinfo == null) { userconnectinfo = new UserConnectInfo(); userconnectinfo.OpenId = tokenInfo.Openid; userconnectinfo.Token = tokenInfo.Token; userconnectinfo.Secret = tokenInfo.Secret; userconnectinfo.AllowVisitQQUserInfo = DNTRequest.GetInt("con_is_user_info", 0); userconnectinfo.AllowPushFeed = DNTRequest.GetInt("con_is_feed", 0) == 1 ? 3 : 0; userconnectinfo.CallbackInfo = usedusernames + "&" + birthday + "&" + gender + "&" + email; DiscuzCloud.CreateUserConnectInfo(userconnectinfo); } else if (userconnectinfo.Uid > 0) { if (userid > 0) { SetBackLink("index.aspx"); AddErrLine(userconnectinfo.Uid != userid ? "该QQ已经绑定了其他帐号" : "该QQ用户已登录"); return; } ShortUserInfo userInfo = Users.GetShortUserInfo(userconnectinfo.Uid); string redirectUrl = ""; //如果userInfo==null,可能是管理员后台删除了这个帐号,则用户的ConnnectInfo也需要被解绑重置 if (userInfo == null) { DiscuzCloud.UnbindUserConnectInfo(userconnectinfo.OpenId); redirectUrl = HttpContext.Current.Request.RawUrl; } else { redirectUrl = forumpath + "index.aspx"; //如果云端的token和Secret发生改变,则更新本地保存的token和Secret if (tokenInfo.Token != userconnectinfo.Token || tokenInfo.Secret != userconnectinfo.Secret) { userconnectinfo.Token = tokenInfo.Token; userconnectinfo.Secret = tokenInfo.Secret; DiscuzCloud.UpdateUserConnectInfo(userconnectinfo); } LoginUser(userInfo); } HttpContext.Current.Response.Redirect(redirectUrl); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { string[] callbackInfo = userconnectinfo.CallbackInfo.Split('&'); if (callbackInfo.Length == 4) { usedusernames = string.IsNullOrEmpty(usedusernames) ? callbackInfo[0] : usedusernames; birthday = string.IsNullOrEmpty(birthday) ? callbackInfo[1] : birthday; gender = gender == 0 ? Utils.StrToInt(callbackInfo[2], 0) : gender; email = string.IsNullOrEmpty(email) ? callbackInfo[3] : email; } } UserBindConnectLog userBindLog = DiscuzCloud.GetUserConnectBindLog(userconnectinfo.OpenId); isbindoverflow = userBindLog != null && cloudconfig.Maxuserbindcount > 0 && userBindLog.BindCount >= cloudconfig.Maxuserbindcount; allowreg = config.Regstatus != 0 && cloudconfig.Allowconnectregister == 1 && !isbindoverflow; connectswitch = allowreg && userid < 0 ? 1 : 2; #region convert used username list byte[] bt = Convert.FromBase64String(usedusernames); usedusernames = System.Text.Encoding.Default.GetString(bt); #endregion avatarurl = string.Format("http://avatar.connect.discuz.qq.com/{0}/{1}", DiscuzCloudConfigs.GetConfig().Connectappid, userconnectinfo.OpenId); openid = userconnectinfo.OpenId; break; case "bind": if (ispost) { if (DNTRequest.GetString("bind_type") == "new") { RegisterAndBind(); } else { if (userid < 0) { BindForumExistedUser(); } else { BindLoginedUser(); } } } break; case "unbind": if (userid < 1) { AddErrLine("未登录用户无法进行该操作"); return; } userconnectinfo = DiscuzCloud.GetUserConnectInfo(userid); if (userconnectinfo == null) { AddErrLine("您并没有绑定过QQ,不需要执行该操作"); return; } if (ispost) { if (userconnectinfo.IsSetPassword == 0) { string passwd = DNTRequest.GetString("newpasswd"); if (string.IsNullOrEmpty(passwd)) { AddErrLine("您必须为帐号设置新密码才能解除绑定"); return; } if (passwd.Length < 6) { AddErrLine("密码不得少于6个字符"); return; } if (passwd != DNTRequest.GetString("confirmpasswd")) { AddErrLine("两次输入的新密码不一致"); return; } UserInfo userInfo = Users.GetUserInfo(userid); userInfo.Password = passwd; Users.ResetPassword(userInfo); //同步其他应用密码 Sync.UpdatePassword(userInfo.Username, userInfo.Password, ""); if (!Utils.StrIsNullOrEmpty(DNTRequest.GetString("changesecques"))) { Users.UpdateUserSecques(userid, DNTRequest.GetInt("question", 0), DNTRequest.GetString("answer")); } ForumUtils.WriteCookie("password", ForumUtils.SetCookiePassword(userInfo.Password, config.Passwordkey)); OnlineUsers.UpdatePassword(olid, userInfo.Password); } DiscuzCloud.UnbindUserConnectInfo(userconnectinfo.OpenId); UserBindConnectLog bindLog = DiscuzCloud.GetUserConnectBindLog(userconnectinfo.OpenId); if (bindLog != null) { bindLog.Type = 2; DiscuzCloud.UpdateUserConnectBindLog(bindLog); } AddMsgLine("解绑成功"); string reurl = Utils.UrlDecode(ForumUtils.GetReUrl()); SetUrl(reurl.IndexOf("register.aspx") < 0 ? reurl : forumpath + "index.aspx"); SetMetaRefresh(); } break; default: if (isbindconnect) { AddErrLine("用户已登录"); return; } HttpContext.Current.Response.Redirect(DiscuzCloud.GetConnectLoginPageUrl(userid)); HttpContext.Current.ApplicationInstance.CompleteRequest(); break; } }
private bool SaveUserAvatar(UserConnectInfo userConnectInfo) { string formatUid = Avatars.FormatUid(userConnectInfo.Uid.ToString()); string avatarFileName = string.Format("{0}avatars/upload/{1}/{2}/{3}/{4}_avatar_", BaseConfigs.GetForumPath, formatUid.Substring(0, 3), formatUid.Substring(3, 2), formatUid.Substring(5, 2), formatUid.Substring(7, 2)); avatarFileName = Utils.GetMapPath(avatarFileName); string url = string.Format("http://avatar.connect.discuz.qq.com/{0}/{1}", DiscuzCloudConfigs.GetConfig().Connectappid, userConnectInfo.OpenId); if (!Directory.Exists(avatarFileName)) { Utils.CreateDir(avatarFileName); } if (!Thumbnail.MakeRemoteThumbnailImage(url, avatarFileName + "large.jpg", 200, 200)) { return(false); } Image tmpImage = Image.FromFile(avatarFileName + "large.jpg"); if (tmpImage.Width * 0.8 <= 130) { Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg", (int)(tmpImage.Width * 0.8), (int)(tmpImage.Height * 0.8)); Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg", (int)(tmpImage.Width * 0.6), (int)(tmpImage.Height * 0.6)); } else { Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "medium.jpg", (int)(tmpImage.Width * 0.5), (int)(tmpImage.Height * 0.5)); Thumbnail.MakeThumbnailImage(avatarFileName + "large.jpg", avatarFileName + "small.jpg", (int)(tmpImage.Width * 0.3), (int)(tmpImage.Height * 0.3)); } try { tmpImage.Dispose(); } catch { } //当支持FTP上传头像时,使用FTP上传远程头像 if (FTPs.GetForumAvatarInfo.Allowupload == 1) { FTPs ftps = new FTPs(); string ftpAvatarFileName = string.Format("/avatars/upload/{0}/{1}/{2}/", formatUid.Substring(0, 3), formatUid.Substring(3, 2), formatUid.Substring(5, 2)); ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "large.jpg", FTPs.FTPUploadEnum.ForumAvatar); ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "medium.jpg", FTPs.FTPUploadEnum.ForumAvatar); ftps.UpLoadFile(ftpAvatarFileName, avatarFileName + "small.jpg", FTPs.FTPUploadEnum.ForumAvatar); } return(true); }
/// <summary> /// 获取云平台后台调用签名(产品后台iframe链接和跳转链接的附带签名) /// </summary> /// <param name="mParams"></param> /// <param name="timeStamp"></param> /// <returns></returns> private static string GetCloudIframeSignature(DiscuzCloudMethodParameter mParams, string timeStamp) { return(Utils.MD5(string.Format("{0}|{1}|{2}", mParams.GetPostData().TrimStart('&'), DiscuzCloudConfigs.GetConfig().Cloudsitekey, timeStamp))); }
private bool CheckSignature(string sign, string className, string method, string myParams) { return(sign == Utils.MD5(string.Format("{0}|{1}|{2}|{3}", className, method, myParams, DiscuzCloudConfigs.GetConfig().Cloudsitekey))); }
/// <summary> /// 发送feed请求到云平台 /// </summary> /// <param name="topic"></param> /// <param name="post"></param> /// <param name="attachments"></param> /// <param name="connectInfo"></param> /// <returns></returns> public static bool PushFeedToDiscuzCloud(TopicInfo topic, PostInfo post, AttachmentInfo[] attachments, UserConnectInfo connectInfo, string ip, string rootUrl) { DiscuzCloudConfigInfo config = DiscuzCloudConfigs.GetConfig(); List <DiscuzOAuthParameter> parmlist = new List <DiscuzOAuthParameter>(); parmlist.Add(new DiscuzOAuthParameter("client_ip", ip)); parmlist.Add(new DiscuzOAuthParameter("thread_id", topic.Tid.ToString())); parmlist.Add(new DiscuzOAuthParameter("author_id", topic.Posterid.ToString())); parmlist.Add(new DiscuzOAuthParameter("author", topic.Poster)); parmlist.Add(new DiscuzOAuthParameter("forum_id", topic.Fid.ToString())); parmlist.Add(new DiscuzOAuthParameter("p_id", post.Pid.ToString())); parmlist.Add(new DiscuzOAuthParameter("subject", topic.Title)); #region 构造postparmsinfo GeneralConfigInfo generalConfig = GeneralConfigs.GetConfig(); PostpramsInfo postpramsInfo = new PostpramsInfo(); postpramsInfo.Sdetail = post.Message; postpramsInfo.Smiliesinfo = Smilies.GetSmiliesListWithInfo(); postpramsInfo.Bbcodemode = generalConfig.Bbcodemode; postpramsInfo.Parseurloff = post.Parseurloff; postpramsInfo.Bbcodeoff = post.Bbcodeoff; postpramsInfo.Signature = 0; postpramsInfo.Allowhtml = post.Htmlon; postpramsInfo.Pid = post.Pid; postpramsInfo.Showimages = 1 - post.Smileyoff; postpramsInfo.Smileyoff = post.Smileyoff; postpramsInfo.Smiliesmax = generalConfig.Smiliesmax; //判断是否为回复可见帖, hide=0为不解析[hide]标签, hide>0解析为回复可见字样, hide=-1解析为以下内容回复可见字样显示真实内容 //将逻辑判断放入取列表的循环中处理,此处只做是否为回复人的判断,主题作者也该可见 postpramsInfo.Hide = 0; #endregion parmlist.Add(new DiscuzOAuthParameter("html_content", UBB.UBBToHTML(postpramsInfo))); parmlist.Add(new DiscuzOAuthParameter("bbcode_content", post.Message)); parmlist.Add(new DiscuzOAuthParameter("read_permission", "0")); parmlist.Add(new DiscuzOAuthParameter("u_id", topic.Posterid.ToString())); parmlist.Add(new DiscuzOAuthParameter("f_type", connectInfo.AllowPushFeed.ToString())); StringBuilder attachUrlList = new StringBuilder(); int attachCount = 0; if (attachments != null) { foreach (AttachmentInfo info in attachments) { if (attachCount < 3 && info.Filetype.IndexOf("image") > -1 && info.Attachprice <= 0) { attachUrlList.AppendFormat("|{0}upload/{1}", rootUrl, info.Filename.Replace("\\", "/")); attachCount++; } } } parmlist.Add(new DiscuzOAuthParameter("attach_images", attachUrlList.ToString().TrimStart('|'))); DiscuzOAuth oAuth = new DiscuzOAuth(); string queryStr = ""; string feedUrl = oAuth.GetOAuthUrl(API_CONNECT_URL + "connect/feed/new", "POST", config.Connectappid, config.Connectappkey, connectInfo.Token, connectInfo.Secret, "", "", parmlist, out queryStr); Utils.GetHttpWebResponse(feedUrl, queryStr); return(true); }