|
@@ -9,6 +9,7 @@ class WeChat {
|
|
|
this.wxWidth = 0;//微信小程序可用屏幕宽度
|
|
|
this.wxHeight = 0;//微信小程序可用屏幕高度
|
|
|
this.js_code = null;
|
|
|
+ this.anonymousCode = null;
|
|
|
this.shareArray = WeChat.shareObjcts;
|
|
|
}
|
|
|
|
|
@@ -18,16 +19,30 @@ class WeChat {
|
|
|
* @param {Function} cb 回调方法
|
|
|
*/
|
|
|
checkLogin(cb) {
|
|
|
- CC_WECHATGAME && wx.checkSession({
|
|
|
- success() {
|
|
|
- //session_key 未失效
|
|
|
- cb && cb(true)
|
|
|
- },
|
|
|
- fail() {
|
|
|
- //session_key 已失效
|
|
|
- cb && cb(false)
|
|
|
- }
|
|
|
- })
|
|
|
+
|
|
|
+ if (window.tt != undefined) {
|
|
|
+ tt.checkSession({
|
|
|
+ success() {
|
|
|
+ //session_key 未失效
|
|
|
+ cb && cb(true)
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ //session_key 已失效
|
|
|
+ cb && cb(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if (CC_WECHATGAME) {
|
|
|
+ wx.checkSession({
|
|
|
+ success() {
|
|
|
+ //session_key 未失效
|
|
|
+ cb && cb(true)
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ //session_key 已失效
|
|
|
+ cb && cb(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -53,7 +68,7 @@ class WeChat {
|
|
|
login(cb) {
|
|
|
|
|
|
this.cb = cb || function () { }
|
|
|
- if (!CC_WECHATGAME) {
|
|
|
+ if (!CC_WECHATGAME || window.tt == undefined) {
|
|
|
GameGlobal.user = {
|
|
|
uid: 1,
|
|
|
token: 'lucifer_test_token',
|
|
@@ -65,11 +80,23 @@ class WeChat {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.isSupportInfoBtn = wx.createUserInfoButton ? true : false;
|
|
|
+ if (window.tt != undefined) {
|
|
|
+ var self = this;
|
|
|
+ tt.login({
|
|
|
+ success (res) {
|
|
|
+ self.js_code = res.code;
|
|
|
+ self.anonymousCode = res.anonymousCode;
|
|
|
+ self._getUserInfo();
|
|
|
+ },
|
|
|
+ fail (res) {
|
|
|
+ console.log(`login调用失败`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (CC_WECHATGAME) {
|
|
|
+ this.isSupportInfoBtn = wx.createUserInfoButton ? true : false;
|
|
|
|
|
|
- wx.login({
|
|
|
- success: ({ code }) => {
|
|
|
- // console.log(code);
|
|
|
+ wx.login({
|
|
|
+ success: ({ code }) => {
|
|
|
this.js_code = code;
|
|
|
//如果支持用户信息按钮
|
|
|
if (this.isSupportInfoBtn) {
|
|
@@ -89,27 +116,45 @@ class WeChat {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- wx.getSystemInfo({
|
|
|
- success: (res) => {
|
|
|
- GameGlobal.os = res.platform == "android" ? 2 : 1;
|
|
|
- this.wxWidth = res.windowWidth;
|
|
|
- this.wxHeight = res.windowHeight;
|
|
|
- }
|
|
|
- });
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: (res) => {
|
|
|
+ GameGlobal.os = res.platform == "android" ? 2 : 1;
|
|
|
+ this.wxWidth = res.windowWidth;
|
|
|
+ this.wxHeight = res.windowHeight;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_getUserInfo() {
|
|
|
- wx.getUserInfo({
|
|
|
- withCredentials: true,
|
|
|
- success: (res) => {
|
|
|
- this._login(res);
|
|
|
- }
|
|
|
- })
|
|
|
+ if (window.tt != undefined) {
|
|
|
+ var self = this;
|
|
|
+ tt.getUserInfo({
|
|
|
+ withCredentials: true,
|
|
|
+ success (res) {
|
|
|
+ console.log(`getUserInfo调用成功${res.userInfo}`);
|
|
|
+ self._login(res);
|
|
|
+ },
|
|
|
+ fail (res) {
|
|
|
+ console.log(`getUserInfo调用失败`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (CC_WECHATGAME) {
|
|
|
+ wx.getUserInfo({
|
|
|
+ withCredentials: true,
|
|
|
+ success: (res) => {
|
|
|
+ this._login(res);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_login(res) {
|
|
|
- // let loginApi = new LoginApi();
|
|
|
- LoginApi.login(this.js_code, res, this.cb);
|
|
|
+ if (window.tt != undefined) {
|
|
|
+ LoginApi.ttLogin(this.js_code, this.anonymousCode, res, this.cb);
|
|
|
+ } else if (CC_WECHATGAME) {
|
|
|
+ LoginApi.login(this.js_code, res, this.cb);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|