星空网 > 软件开发 > ASP.net

netMVC 搭建Ucenter 同步登陆退出discuz

先看一下效果

netMVC 搭建Ucenter 同步登陆退出discuz

首先准备材料:

1.ucenter for net :https://github.com/dozer47528/UCenter-API-For-DotNet or http://pan.baidu.com/s/1i3znQV7

2.uc.ashx  下面是具体代码

using DS.Web.UCenter;using DS.Web.UCenter.Api;using DS.Web.UCenter.Client;using log4net;using pc_manishi.Controllers;using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace pc_manishi.API{  /// <summary>  /// Summary description for uc  /// </summary>  public class uc : UcApiBase  {    HttpResponse Response = HttpContext.Current.Response;    HttpRequest Request = HttpContext.Current.Request;    private static readonly ILog logger = LogManager.GetLogger(typeof(AddressController));    public override ApiReturn DeleteUser(IEnumerable<int> ids)    {      throw new NotImplementedException();    }    public override ApiReturn RenameUser(int uid, string oldUserName, string newUserName)    {      throw new NotImplementedException();    }    public override UcTagReturns GetTag(string tagName)    {      throw new NotImplementedException();    }    //登陆    public override ApiReturn SynLogin(int uid)    {      try      {        IUcClient client = new UcClient();        UcUserInfo user = client.UserInfo(uid);        if (user.Success)        {          //LoggerCore.Debug(user.Uid + "--" + user.UserName);          HttpContext.Current.Session["uid"] = user.Uid;          HttpContext.Current.Session["username"] = user.UserName;          HttpContext.Current.Session["email"] = user.Mail;          return ApiReturn.Success;        }        return ApiReturn.Failed;      }      catch (Exception ex)      {        logger.Error("远程登录错误", ex);        return ApiReturn.Failed;      }      //throw new NotImplementedException();    }    //登出    public override ApiReturn SynLogout()    {      try      {        logger.Error("论坛正在登出操作");        //HttpContext.Current.Session.Abandon();      }      catch (Exception ex)      {        logger.Error("远程退出错误", ex);      }      return ApiReturn.Success;     //throw new NotImplementedException();    }    public override ApiReturn UpdatePw(string userName, string passWord)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateBadWords(UcBadWords badWords)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateHosts(UcHosts hosts)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateApps(UcApps apps)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateClient(UcClientSetting client)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateCredit(int uid, int credit, int amount)    {      throw new NotImplementedException();    }    public override UcCreditSettingReturns GetCreditSettings()    {      throw new NotImplementedException();    }    public override ApiReturn GetCredit(int uid, int credit)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateCreditSettings(UcCreditSettings creditSettings)    {      throw new NotImplementedException();    }  }}

下面我们开始:

  首先在自己的mvc项目里面简历api 文件夹,把创建uc.ashx 文件 netMVC 搭建Ucenter 同步登陆退出discuz

UC_KEY,UC_API,UC_APPID 其中这3个必填,一定要改成自己添加的net网站的配置,我这里如下图配置
netMVC 搭建Ucenter 同步登陆退出discuz

接下来就期待通信成功了,如果不成功,那就检查discuz里 config_ucenter.php 跟自己网站的webconfig的配置
Discuz!Board 一般会通信成功的,因为我在安装discuz的时候也一起安装了ucenter除非你对网站搬家了,以后说搬家后的问题

接下来就是同步登陆了:
这里是我的代码
netMVC 搭建Ucenter 同步登陆退出discuz
其实就是调用了一下 IUcClient类的方法,然后通过usersynlogin来拿到远程登陆的js代码,我这里不知道为什么,用  Response.Write() 来输出到前端,但我这里返回到了所以我这里用webhttprequest进行了一部处理,原理就是返回的js里面有个src,你直接在浏览器访问一下就把要登陆的cookie下来了,但要注意cookie的域名要设置二级域名共享,退出的话也是同样的处理

再说一下注册:注册这里我关闭了验证码,去掉了邮箱必填(度娘可以告诉你怎么关闭)
下面也直接调用 client.UserRegister(username, Password, string.Format("{0:ddhhmmss}", DateTime.Now) + "@suiji.com", 0, "");
及时你去掉了邮箱必填也要给一个默认邮箱,这里我随机生成了一个邮箱


还有一点要注意,即使你开启了立即激活netMVC 搭建Ucenter 同步登陆退出discuz
也需要登陆一下让discuz自动激活你的用户

下面再说一下搬家的注意事项(我这里从winserver 搬到了linux上):
1:配置里的url cookie的域名 这些都要更改
2.在用ftp修改的时候一定不要使用notepad,这样会产生编码问题,导致通信失败
3.data source template 等这几个文件夹及文件的777权限(当你出问题是不妨检查一下文件权限)
netMVC 搭建Ucenter 同步登陆退出discuz
net
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

PRINTWAY.IO:https://www.ikjzd.com/w/1573203823057870849
普罗空运:https://www.ikjzd.com/w/1573203827386736642
申请流程:https://www.ikjzd.com/w/1573203828724719618
ProdSG(产品安全法):https://www.ikjzd.com/w/1573203829622300674
Product Hunt:https://www.ikjzd.com/w/1573203838807826433
Product Reviews:https://www.ikjzd.com/w/1573203839650537473
三亚有哪些酒店值得入住?:https://www.vstour.cn/a/366173.html
零售晚报:丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836649.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流