123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- Namespace.register("U.MD.U.OT"); //用户登录的命名空间
- //推送的广告词
- U.MD.U.OT.advertisingLanguage = "最新科技:云操作系统,您也来加入吧!点击进入哦!";
- //#region 加载外联登录
- /**
- * 异步加载qq登录的js
- *
- * @param {array} 加载按钮样式(参考qq登录api)
- */
- U.MD.U.OT.qqLoadJs = function (bottonstyle) {
- //加载第三方登录的js
- U.UF.DL.asynLoadJs({
- "data-appid": "100584402",
- "charset": "utf-8",
- "src": "http://qzonestyle.gtimg.cn/qzone/openapi/qc-1.0.1.js"
- },
- function () {
- U.MD.U.OT.asynQqLoadJs(bottonstyle); //腾讯登录加载
- });
- }
- /**
- * qq登录加载异步js成功处理
- *
- * @param {array} 加载按钮样式(参考qq登录api)
- */
- U.MD.U.OT.asynQqLoadJs = function (bottonstyle) {
- //调用加载qq登录按钮加载函数
- QC.Login(bottonstyle, function (qquserinfo) {
- U.MD.U.OT.qqLoginCallBack(qquserinfo);
- });
- //由于qq登录按钮加载后会出现a标签,所以点击会出现错位于是会这里把a标签的href修改成"javascript:void(0)"
- $("a", $("#" + bottonstyle["btnId"])[0]).addAttrArray({ "href": "javascript:void(0)" });
- }
- /**
- * 异步加载微博登录的js
- *
- * @param {array} 加载按钮样式(参考微博登录api)
- */
- U.MD.U.OT.weiboLoadJs = function (bottonstyle) {
- //异步加载使用,微博登录加载
- U.UF.DL.asynLoadJs({
- "charset": "utf-8",
- "src": "http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=1242324937", //&i=" + Guid.newGuid()
- "charset": "utf-8",
- "type": "text/javascript"
- },
- function () {
- //微博按钮加载处理
- WB2.anyWhere(function (wb) {
- wb.widget.connectButton(bottonstyle); //加载按钮
- $("a", $("#" + bottonstyle["id"])[0]).addAttrArray({ "href": "javascript:void(0)" });
- });
- });
- }
- /**
- * 异步加载微信登录js
- *
- * @param {array} 加载按钮样式(参考微信登录api)
- */
- U.MD.U.OT.weixinLoadJs = function (bottonstyle) {
- //异步加载微信登录
- U.UF.DL.asynLoadJs({
- "charset": "utf-8",
- "src": "http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js",
- "charset": "utf-8",
- "type": "text/javascript"
- },
- function () {
- //初始化微信
- new WxLogin({
- id: bottonstyle.ID || "",
- appid: "wxae62986df7490c49",
- scope: "snsapi_login",
- redirect_uri: "",
- state: bottonstyle.state || Guid.newGuid(),
- style: bottonstyle.style || "",
- href: bottonstyle.href || ""
- });
- });
- }
- /**
- * 注销第三方登录
- *
- */
- U.MD.U.OT.logout = function () {
- try {
- //退出微博登陆
- if (WB2 && WB2.checkLogin()) {
- WB2.logout();
- }
- } catch (e) { }
- try {
- //退出qq登陆
- if (QC && QC.Login.check()) {
- QC.Login.signOut();
- }
- } catch (e) { }
- }
- //#endregion
- //#region 腾讯登录
- /**
- * 腾讯登录回调
- *
- */
- U.MD.U.OT.qqLoginCallBack = function () {
- //如果用户已经通过qq登录的处理
- if (QC.Login.check()) {
- //获取用户登录openid
- QC.Login.getMe(function (openid, token) {
- var _qquserinfo = {}; //最终得到的qq信息
- _qquserinfo.accessToken = token; //token
- _qquserinfo.openID = openid; //openid
- //获取用户信息
- QC.api("get_user_info", {}).success(function (userinfo) {
- userinfo = userinfo.data; //qq用户信息回调
- //获取用户基本信息
- _qquserinfo.UserNickName = userinfo.nickname; //用户基本信息
- _qquserinfo.gender = userinfo == "男" ? 1 : 0; //用户的性别
- _qquserinfo.province = userinfo.province;
- _qquserinfo.city = userinfo.city;
- _qquserinfo.Birthday = U.UF.D.toTimeStamp(_qquserinfo.year + "/01/01");
- //腾讯微博基本信息
- QC.api("get_info", {}).success(function (weibouserinfo) {
- weibouserinfo = weibouserinfo.data.data;
- var _location = weibouserinfo.location.split(' ');
- //发送一条雨云科技的消息
- QC.api("add_pic_t", {
- "content": U.MD.U.OT.advertisingLanguage,
- "pic": "/img/qqew.jpg"
- });
- //关注我们的腾讯微博
- QC.api("add_idol", {
- "name": "雨云科技"
- });
- //登录用户信息
- _qquserinfo.nickname = weibouserinfo.nick;
- _qquserinfo.gender = weibouserinfo.sex;
- _qquserinfo.openID = openidp;
- _qquserinfo.accessToken = token;
- _qquserinfo.province = _location[1];
- _qquserinfo.city = _location[2];
- _qquserinfo.description = weibouserinfo.introduction;
- _qquserinfo.UserEmail = weibouserinfo.email;
- _qquserinfo.Birthday = U.UF.D.toTimeStamp(weibouserinfo.birth_year + "-" + weibouserinfo.birth_month + "-" + weibouserinfo.birth_day, "-");
- //获取信息成功后在1473中注册登录
- U.MD.U.OT.thirdPartyLogin(_qquserinfo);
- }).error(function () {
- //如果微博没有信息,则直接用注册qq用户的信息
- U.MD.U.OT.thirdPartyLogin(_qquserinfo);
- });
- }).error(function () { U.alert("获取用户信息失败"); })
- });
- }
- }
- //#endregion
- //#region 微博登录
- /**
- * 微博登录成功或者失败后的回调函数
- *
- */
- U.MD.U.OT.weiboLoginCallBack = function (userinfo) {
- U.MD.U.OT.thirdPartyLogin(userinfo); //1473登录
- WB2.anyWhere(function (WB2) { //调用
- WB2.parseCMD("/statuses/update.json",
- //利用微博登录授权后设置用户发送一条微博消息
- function (message) { },
- {
- "status": U.MD.U.OT.advertisingLanguage
- });
- //让用户关注云端
- WB2.parseCMD("/friendships/create.json",
- function (message) { },
- { "screen_name": "1473云端" });
- });
- }
- /**
- * 微博关注按钮,传入参数为需要关注的id。
- *
- */
- U.MD.U.OT.addWeiboFollowBottom = function (id) {
- //初始化得到微博功能
- WB2.anyWhere(function (weibo) {
- //设置按钮
- weibo.widget.followButton({
- "nick_name": "1473云端", //设置腾讯微博关注按钮
- "id": id,
- "show_head": false,
- "show_name": false,
- "show_cancel": false
- });
- });
- }
- //#endregion
- //#region 微信登录处理
- //2ed68d9671db0ee8ba114f69567502b6
- /**
- * 判断外链用户是否存在
- *
- * @param {array} 登录值参数
- * @param {array} 回调函数
- */
- U.MD.U.OT.weixin = function () {
- //防止二维码缓存。
- U.MD.U.OT.wxData = { "id": Guid.newGuid() };
- window.open("https://open.weixin.qq.com/connect/qrconnect?appid=wxae62986df7490c49&redirect_uri=" + window.encodeURI("/WxDomain.htm") + "&response_type=code&scope=snsapi_login&state=" + U.MD.U.OT.wxData.id);
- }
- /**
- * 微信注册异步回调区域
- *
- */
- U.MD.U.OT.asynWeixin = function (str) {
- var _co = U.UF.C.queryString("code", str), //获取code值
- _state = U.UF.C.queryString("state", str); //回调状态
- if (_state == U.MD.U.OT.wxData.id && _state != null) { //判断状态吗是否匹配
- U.A.Request("http://zhifu.1473.cn/weixin/login.php?code=" + _co, [], function (r) {
- if (r.value.openid) {
- U.MD.U.OT.thirdPartyLogin(r.value); //登录
- }
- else {
- U.alert("微信扫描登录失败");
- }
- });
- }
- }
- //#endregion
- //#region 外链登录成功使用
- /**
- * 判断外链用户是否存在
- *
- * @param {array} 登录值参数
- */
- U.MD.U.OT.thirdPartyLogin = function (userinfo) {
- var _openid = userinfo.openID || userinfo.id || userinfo.openid; //userinfo.openID代表QQ的openid userinfo.id代表微博的openid userinfo.openid代表微信的openid
- U.A.Request(US.USER, ["ThirdPartyLogin", _openid],
- U.MD.U.OT.asynThirdPartyLogin, [null, userinfo]); //通过微博或者qq的openid 获取是否在1473上注册的用户
- }
- /**
- * 微博或者qq云端登录异步
- *
- * @param {array} 登录值参数
- * @param {array} 回调函数
- */
- U.MD.U.OT.asynThirdPartyLogin = function (r) {
- //用户存在直接登录
- if (typeof r.value == "object") {
- U.MD.U.L.asynLoginAjax(r); //直接登录
- }
- //用户不存在填写资料
- else {
- U.MD.U.R.isregister[0] = U.MD.U.R.isregister[1] = false; //设置信息不成功
- window.parent.U.MD.U.OT.perfectUserInfo(r.context[1], r.value); //填写登录信息
- }
- }
- //#endregion
- //#region 外链登录
- //U.MD.U.OT.perfectUserInfoInit = function (userinfo, username) {
- // var i,
- // _password = U.UF.Math.getRandom(1000000), //生成一个数据密码
- // _el = $("#U_MD_U_OT_B"), //获取第三方登录填写资料的框
- // _childs = _el.find("div"); //获取子元素
- // U.MD.U.R.isregister[0] = U.MD.U.R.isregister[1] = false; //设置注册的信息默认为false
- // //用户名的处理
- // while (username.toString().length < 6) {
- // username = "0" + username;
- // }
- // _childs[4].innerHTML = "账号:<span>" + username + "</span>"; //用户的账号
- // _childs[5].innerHTML = "密码:" + _password; //用户的密码
- // //取消按钮的设置
- // _childs[_childs.length - 1].onclick = function () {
- // U.MD.U.OT.userRegister(userinfo, false, _form, username, _password);
- // }
- // //确定按钮的处理
- // _childs[_childs.length - 1].onclick = function () {
- // U.MD.U.OT.userRegister(userinfo, true, _form);
- // }
- //}
- /**
- * 把用户填写的账号密码写入数据库
- *
- * @param {array} 登录值参数
- * @param {array} 回调函数
- */
- U.MD.U.OT.userRegister = function (userinfo, b, form, username, password) {
- var _openid, //第三方平台的openid
- _el = $("#U_MD_U_OT_B"),
- _inputs = _el.find("input");
- //点击确定密码自己设置
- if (b) {
- username = _inputs[0].value; //用户名
- password = _inputs[1].value; //密码
- }
- //判断用户注册的信息是否通过
- if (U.MD.U.R.isregister[0] && U.MD.U.R.isregister[1]) {
- _openid = userinfo.openID || userinfo.id || userinfo.openid; //获取用户的唯一识别id
- //调用ajax进行注册处理
- U.A.Request(US.USER, ["UserRegister", username, password, "", US.city.userAllLocation || "", _openid],
- U.MD.U.OT.asynUserRegister, [_el[0], userinfo, form]); //注册中
- }
- else {
- U.alert("注册的信息有问题,请修改。");
- }
- }
- /**
- * 外链登录成功 同时修改个人信息
- *
- * @param {object} 注册用户的信息
- */
- U.MD.U.OT.asynUserRegister = function (r) {
- var _userinfo, //登录用户信息
- _context = r.context,
- _outeruserinfo = _context[1],
- _form = _context[2];
- //QQ,微博方式注册进来
- if (U.MD.U.R.asynRegister(r, true)) {
- _userinfo = US.userInfo;
- //用户在第三方的资料设置在1473总
- _userinfo.Country = "中国";
- _userinfo.Province = _USE.province || "";
- _userinfo.UserEmail = _USE.UserEmail || "";
- _userinfo.Birthday = U.UF.D.getYearMonthDay(_USE.Birthday, "String");
- _userinfo.City = _USE.city || "";
- _userinfo.UserAddress = _USE.location || "";
- _userinfo.UserNickName = _USE.screen_name || _USE.nickname || "";
- _userinfo.UserRemarks = _USE.description || "";
- _userinfo.UserIndividualitysignature = _USE.description || "";
- _userinfo.UserThumbnailImageHead = _USE.avatar_large || _USE.avatar_hd || _USE.figureurl_qq_2 || _USE.figureurl_qq_1 || "";
- _userinfo.UserSex = (_USE.gender == "m" | _USE.gender == 1) ? 1 : 0;
- //基本资料同步到服务器中
- U.A.Request(US.USER, ["UpdateUserBasicInfo", _userinfo.UserId, "", _userinfo.UserNickName, "", "", _userinfo.UserIndividualitysignature, _userinfo.UserEmail, "", _userinfo.UserSex, _userinfo.Country, _userinfo.Province, _userinfo.City, _userinfo.Birthday], function () { }); //修改用户登录资料
- //用户头像信息更新到服务器中
- U.A.Request(US.USER, ["UpdateUserHeadPortrait", US.userInfo.userid, _userinfo.UserThumbnailImageHead, _userinfo.UserThumbnailImageHead], function () { });
- //关闭窗体
- _form.close();
- }
- else {
- //注册成功提醒
- U.alert("注册失败。请重新尝试");
- }
- }
- //#endregion
|