Browse Source

Merge branch 'dev' of http://svn.ouj.com:3000/DWG/taptapstar into dev

tang biao 5 years ago
parent
commit
0eb2b3371f

+ 8 - 3
assets/scripts/game/Game.js

@@ -61,7 +61,10 @@ cc.Class({
         GameEvent.init();
         this._setEventListener();
         /// 初始化广告W6Lcux7ArPGCBpnWuAyEVK48PrrYX7xWBA
-        if (CC_WECHATGAME) {
+
+        if (window.tt != undefined) {
+
+        } else if (CC_WECHATGAME) {
             GameGlobal._adVideo = new ADVideo();
             GameGlobal._adVideo.wxCreateADVideo();
         }
@@ -69,7 +72,9 @@ cc.Class({
         this._initSocketMng();
         this._getInformation();
 
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+
+        } else if (CC_WECHATGAME) {
             GameGlobal.wechatScoreKey = GameGlobal.debug ? 'buildingLevel_test' : 'buildingLevel';
             window.wx.postMessage({
                 messageType: 5,
@@ -377,7 +382,7 @@ cc.Class({
         this.sliderNode.getComponent('HomeSideCtrl').handelShowRedDot();
 
         //是否已经领取过神秘礼物
-        if (!GameGlobal.appletAward && CC_WECHATGAME) {
+        if (!GameGlobal.appletAward && CC_WECHATGAME && window.tt == undefined) {
             this.luckyBagButton.node.active = true;
             var offset = 0;
             if (this.winSize.height >= this.XHeight) {

+ 6 - 2
assets/scripts/login/LoginCtrl.js

@@ -25,7 +25,9 @@ cc.Class({
     },
 
     onLoad() {
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+
+        } else if (CC_WECHATGAME) {
             window.wx.postMessage({ //初始化的时候关闭子域刷新
                 messageType: 8,
             });
@@ -412,7 +414,9 @@ cc.Class({
 
     /// 更新全局channel
     _updateChannel() {
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            GameGlobal.channel = 'toutiao';
+        }else if (CC_WECHATGAME) {
             GameGlobal.channel = 'weixin';
         } else if (CC_QQPLAY) {
             GameGlobal.channel = 'qq';

+ 37 - 0
assets/scripts/net/LoginApi.js

@@ -71,6 +71,43 @@ class LoginApi {
         });
     }
 
+    //头条登录
+    static ttLogin(js_code, anonymousCode, ttRes, cb, fail) {
+
+        let url = "/auth/newsLoginByGame.do" ;
+
+        let data = {
+            nick: ttRes.userInfo.nickName,
+            head: ttRes.userInfo.avatarUrl.replace('132', '96'),
+            gender: ttRes.userInfo.gender,
+            code: js_code,
+            anonymousCode: anonymousCode
+        }
+
+        Api.httpGet({
+            url: url,
+            data: data,
+            success: (response) => {
+            console.log('login response: ' + JSON.stringify(response));
+            var user = response.user;
+            GameGlobal.user = {
+                token: response.token,
+                uid: user.id,
+                openId: user.openId,
+                nick: ttRes.userInfo.nickName,
+                avatarUrl: ttRes.userInfo.avatarUrl,
+                gender: ttRes.userInfo.gender,
+            };
+        cc.sys.localStorage.setItem('GlobalUser', GameGlobal.user);
+        cb();
+    },
+        fail: (errCode, errMsg) => {
+            console.log('login error code: ' + errCode, 'login error msg: ' + errMsg);
+            cb(true);
+        },
+    });
+    }
+
     static getUserInfoPromise() {
         let data = {
             targetUid: GameGlobal.user.uid

+ 75 - 30
assets/scripts/net/WeChat.js

@@ -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);
+        }
     }
 
     /**

+ 1 - 1
assets/scripts/utils/Global.js

@@ -11,7 +11,7 @@ window.GameGlobal = {
 
     debug: true,
 
-    ver: 122, //游戏版本号发版时需要核对
+    ver: 100, //游戏版本号发版时需要核对
     
     isCheck: false,
 

+ 1 - 1
settings/builder.json

@@ -38,7 +38,7 @@
   "webOrientation": "auto",
   "wechatgame": {
     "REMOTE_SERVER_ROOT": "https://pub.dwstatic.com/wxgame/taptapstar_test",
-    "appid": "wx36581990a2e76fba",
+    "appid": "tt672c1191f806d2a2",
     "isSubdomain": false,
     "orientation": "portrait",
     "subContext": ""