先看一下效果php
1.ucenter for net :https://github.com/dozer47528/UCenter-API-For-DotNet or http://pan.baidu.com/s/1i3znQV7html
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 文件 linux
建立ashx文件的时候必定要注意命名空间,生成的跟如今项目的不同但编译经过,个人由于这个调试了很长时间才发现这个地方错了git
接着配置webconfig 文件,添加以下配置(配置根据本身的状况而定)github
<!--客户端版本--> <add key="UC_CLIENT_VERSION" value="1.6.0"/> <!--发行时间--> <add key="UC_CLIENT_RELEASE" value="20141101"/> <!--API 开关(value类型:True False 默认值:True)--> <!--是否容许删除用户--> <add key="API_DELETEUSER" value="True"/> <!--是否容许重命名用户--> <add key="API_RENAMEUSER" value="True"/> <!--是否容许获得标签--> <add key="API_GETTAG" value="True"/> <!--是否容许同步登陆--> <add key="API_SYNLOGIN" value="True"/> <!--是否容许同步登出--> <add key="API_SYNLOGOUT" value="True"/> <!--是否容许更改密码--> <add key="API_UPDATEPW" value="True"/> <!--是否容许更新关键字--> <add key="API_UPDATEBADWORDS" value="True"/> <!--是否容许更新域名解析缓存--> <add key="API_UPDATEHOSTS" value="True"/> <!--是否容许更新应用列表--> <add key="API_UPDATEAPPS" value="True"/> <!--是否容许更新客户端缓存--> <add key="API_UPDATECLIENT" value="True"/> <!--是否容许更新用户积分--> <add key="API_UPDATECREDIT" value="True"/> <!--是否容许向UCenter提供积分设置--> <add key="API_GETCREDITSETTINGS" value="True"/> <!--是否容许获取用户的某项积分--> <add key="API_GETCREDIT" value="True"/> <!--是否容许更新应用积分设置--> <add key="API_UPDATECREDITSETTINGS" value="True"/> <!--API 开关结束--> <!--返回值设置--> <!--返回成功(默认:1)--> <add key="API_RETURN_SUCCEED" value="1"/> <!--返回失败(默认:-1)--> <add key="API_RETURN_FAILED" value="-1"/> <!--返回禁用(默认:-2)--> <add key="API_RETURN_FORBIDDEN" value="-2"/> <!--返回值设置结束--> <!--[必填]通讯密钥--> <add key="UC_KEY" value="20150612"/> <!--[必填]UCenter地址--> <add key="UC_API" value="http://XXX/uc_server"/> <!--[必填]默认编码--> <add key="UC_CHARSET" value="utf-8"/> <!--[非必填]UCenter IP--> <add key="UC_IP" value=""/> <!--[必填]应用ID--> <add key="UC_APPID" value="2"/>
UC_KEY,UC_API,UC_APPID 其中这3个必填,必定要改为本身添加的net网站的配置,我这里以下图配置

接下来就期待通讯成功了,若是不成功,那就检查discuz里 config_ucenter.php 跟本身网站的webconfig的配置
Discuz!Board 通常会通讯成功的,由于我在安装discuz的时候也一块儿安装了ucenter除非你对网站搬家了,之后说搬家后的问题
接下来就是同步登录了:
这里是个人代码

其实就是调用了一下 IUcClient类的方法,而后经过usersynlogin来拿到远程登录的js代码,我这里不知道为何,用 Response.Write() 来输出到前端,但我这里返回到了xmlHttpResponse里面,html里面拿不到
因此我这里用webhttprequest进行了一部处理,原理就是返回的js里面有个src,你直接在浏览器访问一下就把要登录的cookie下来了,但要注意cookie的域名要设置二级域名共享,退出的话也是一样的处理
再说一下注册:注册这里我关闭了验证码,去掉了邮箱必填(度娘能够告诉你怎么关闭)
下面也直接调用 client.UserRegister(username, Password, string.Format("{0:ddhhmmss}", DateTime.Now) + "@suiji.com", 0, "");
及时你去掉了邮箱必填也要给一个默认邮箱,这里我随机生成了一个邮箱
还有一点要注意,即便你开启了当即激活
也须要登录一下让discuz自动激活你的用户
下面再说一下搬家的注意事项(我这里从winserver 搬到了linux上):
1:配置里的url cookie的域名 这些都要更改
2.在用ftp修改的时候必定不要使用notepad,这样会产生编码问题,致使通讯失败
3.data source template 等这几个文件夹及文件的777权限(当你出问题是不妨检查一下文件权限)

文章写的不是很详细,你们多多见谅
感谢:
UCenter API For .Net 在 CodePlex 上发布啦!公司里的php,linux同事