瀏覽代碼

修改登录和分享

smallqiang 5 年之前
父節點
當前提交
801be8a5f8

+ 4 - 4
assets/resources/prefabs/precedence/game_rank.prefab

@@ -666,7 +666,7 @@
     "asset": {
       "__uuid__": "cf09f681-edab-4bbb-9e85-11c0abe6fc35"
     },
-    "fileId": "f8Dg2+P69BnqifxMi5F0+y",
+    "fileId": "e28IJXMJFIJJ027cZhaPwH",
     "sync": false
   },
   {
@@ -1310,7 +1310,7 @@
     "asset": {
       "__uuid__": "cf09f681-edab-4bbb-9e85-11c0abe6fc35"
     },
-    "fileId": "2fnjupwFdNroKdkUW3Ss5a",
+    "fileId": "3foHP7CChA4qUdXasX3Q89",
     "sync": false
   },
   {
@@ -1717,7 +1717,7 @@
     "asset": {
       "__uuid__": "cf09f681-edab-4bbb-9e85-11c0abe6fc35"
     },
-    "fileId": "d2NMtKjblNqKuqqDY6gKuY",
+    "fileId": "89yIwt5xJP6I0cC+RzgQ5M",
     "sync": false
   },
   {
@@ -2124,7 +2124,7 @@
     "asset": {
       "__uuid__": "cf09f681-edab-4bbb-9e85-11c0abe6fc35"
     },
-    "fileId": "d8bAz6Y0FORrGo7hhTHPWE",
+    "fileId": "eexeL21GhHgKc6IKoaVNXT",
     "sync": false
   },
   {

+ 6 - 3
assets/resources/prefabs/precedence/invite_mission.prefab

@@ -1191,12 +1191,12 @@
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
-      "x": 0.5,
+      "x": 0,
       "y": 0.5
     },
     "_position": {
       "__type__": "cc.Vec3",
-      "x": -35.99999999999997,
+      "x": -300,
       "y": 137,
       "z": 0
     },
@@ -1257,7 +1257,7 @@
     "alignMode": 1,
     "_target": null,
     "_alignFlags": 9,
-    "_left": 63.33500000000001,
+    "_left": 50,
     "_right": 0,
     "_top": 402,
     "_bottom": 0,
@@ -2202,6 +2202,9 @@
     "shareButtonNode": {
       "__id__": 9
     },
+    "shareTipsLabel": {
+      "__id__": 34
+    },
     "_id": ""
   },
   {

+ 149 - 1
assets/scripts/common/Platform.js

@@ -9,7 +9,10 @@ const GameModule = require("../utils/GameModule");
 /// 处理
 class Platform {
     static initPlatform() {
-        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
+        
+        if (window.tt != undefined) {
+            this.handelTTLifeCyle();
+        }else if (CC_WECHATGAME) {
             this.handelWxLifeCyle();
         } else if (CC_QQPLAY) {
             this.handelQQLifeCycle();
@@ -71,6 +74,151 @@ class Platform {
         // })
     }
 
+    static handelTTLifeCyle() {
+        tt.onShow((query) => {
+            // if (typeof wx.getUpdateManager === 'function') {
+            //         const updateManager = wx.getUpdateManager();
+            //
+            //         updateManager.onCheckForUpdate(function (res) {
+            //         // 请求完新版本信息的回调
+            //         console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
+            //     })
+            //
+            //     updateManager.onUpdateReady(function () {
+            //         // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+            //         updateManager.applyUpdate();
+            //     })
+            //
+            //     updateManager.onUpdateFailed(function () {
+            //         // 新的版本下载失败
+            //     })
+            // }
+
+        //进入游戏的场景值
+        // console.log('scene ' + scene + '==============================game ===============================');
+        // if (scene == 1104) {
+        //     GameGlobal.isMineEnter = true;    //从我的小程序进入游戏
+        // } else {
+        //     GameGlobal.isMineEnter = false;    //从我的小程序进入游戏
+        // }
+        console.log('Global onShow' + JSON.stringify(query) + '======================================');
+            if (query != undefined && query != null) {
+                if (typeof query == "string") {
+                    query = JSON.parse(query);
+                }
+
+                GameGlobal.shareType = query.shareType;
+
+            // if (GameGlobal.shareType == ShareAction.SHOW_GROUP_RANK) {
+            //     if (shareTicket != undefined && shareTicket != null) {
+            //         GameGlobal.shareTicket = shareTicket;
+            //         GameEvent.fire(GameNotificationKey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜
+            //     } else {
+            //         GameGlobal.shareTicket = '';
+            //     }
+            // }
+
+                if (query.uid != undefined && GameGlobal.shareType == ShareAction.INVITE_FRIEND) {
+                    GameGlobal.shareUid = query.uid;
+                    GameEvent.fire(GameNotificationKey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友.....
+                }
+            }
+            //// 如果是从后台到前台
+            Platform.handelOnShow();
+        });
+
+        tt.onHide(() => {
+            console.log('Global onHide ===================================');
+            GameGlobal.isOnHide = true;
+            if (GameModule.userInfo) {
+                GameModule.userInfo.doReport();
+            }
+
+        // /// 关闭socket 如果socket是打开的状态 其它的状态就不管 打开之后直接重连 && Global._wxSocket.readyState == 'open'
+        // if (Global._wxSocket != undefined && Global._wxSocket != null ) {
+        //     Global._wxSocket.close();
+        // }
+            cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
+            HomeApi.exitGame();
+            if (GameModule.audioMng) {
+                GameModule.audioMng.stopAll();
+            }
+        });
+
+        tt.showShareMenu({
+            withShareTicket: true,
+            success: function (res) {
+
+            },
+            fail: function (res) {
+
+            },
+            complete: function (res) {
+
+            }
+        });
+
+        tt.onShareAppMessage(function () {
+            if (GameGlobal.isCheck) {
+
+                var uid = -1;
+                if (GameGlobal.user != undefined && GameGlobal.user.uid != undefined) {
+                    uid = GameGlobal.user.uid;
+                }
+
+                return {
+                    title: '猜猜他是谁?',
+                    imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_3.png',
+                    query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND,
+                    success: function (res) {
+                        console.log('onShareAppMessage 分享成功');
+                        // 分享成功上报
+                        SkillApi.report(2, (responseData) => {
+                            console.log('上报分享成功');
+                        },(error) => {
+
+                        });
+                    },
+                    fail: function (res) {
+                        // 转发失败
+                        console.log('onShareAppMessage 取消或分享失败');
+                    },
+                    complete: function () {
+
+                    }
+                }
+            } else {
+                let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10);
+                let shareObjct = WeChat.shareArray[randomIndex];
+                var uid = -1;
+                if (GameGlobal.user != undefined && GameGlobal.user.uid != undefined) {
+                    uid = GameGlobal.user.uid;
+                }
+
+                return {
+                    title: shareObjct.title,
+                    imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
+                    query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND,
+                    success: function (res) {
+                        console.log('onShareAppMessage 分享成功');
+                        // 分享成功上报
+                        SkillApi.report(2, (responseData) => {
+                            console.log('上报分享成功');
+                    },(error) => {
+
+                        });
+                    },
+                    fail: function (res) {
+                        // 转发失败
+                        console.log('onShareAppMessage 取消或分享失败');
+                    },
+                    complete: function () {
+                    },
+                };
+            }
+        });
+    }
+
     static handelWxLifeCyle() {
         wx.onShow(({scene, query, shareTicket }) => {
             if (typeof wx.getUpdateManager === 'function') {

+ 8 - 1
assets/scripts/invite/InviteMission.js

@@ -21,7 +21,8 @@ cc.Class({
 
         invitedItemArray: [InvitedItem],
 
-        shareButtonNode: cc.Node
+        shareButtonNode: cc.Node,
+        shareTipsLabel: cc.Label
     },
 
     // LIFE-CYCLE CALLBACKS:
@@ -44,6 +45,12 @@ cc.Class({
         GameEvent.on(GameNotificationKey.InviteGainAward, this, (model) => {
             this.gainActGift(model);
         });
+
+        if (window.tt != undefined) {
+            this.shareTipsLabel.string = "发送链接给你的好友,邀请TA来一起玩游戏吧~";
+        } else if (CC_QQPLAY) {
+            this.shareTipsLabel.string = "发送链接给你的QQ好友,邀请TA来一起玩游戏吧~";
+        }
     },
 
     start() {

+ 11 - 4
assets/scripts/login/LoginCtrl.js

@@ -194,7 +194,9 @@ cc.Class({
 
     //// 开始登录
     startLogin() {
-        if(CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            this._startWxLogin();
+        }else if(CC_WECHATGAME) {
             this._startWxLogin();
         } else if (CC_QQPLAY) {
             QQPlayer.qqLogin((isError) => {
@@ -283,7 +285,7 @@ cc.Class({
         if (GameGlobal.user == undefined || GameGlobal.user.uid == undefined) {
             if (CC_QQPLAY) {
                 this.startLogin();
-            } else if (CC_WECHATGAME) {
+            } else if (CC_WECHATGAME || window.tt != undefined) {
                 weChat.login((isError) => {
                     if (isError) {
                         this._getDataFail();
@@ -367,7 +369,12 @@ cc.Class({
         this.loginLabel.node.active = false;
         this.updateUINode.active = false;
         GameGlobal.commonAlert.showCommonErrorAlert('登录失败请重试');
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            if (this.restartButton) {
+                this.restartButton.node.active = true;
+                this.restartButton.interactable = true;
+            }
+        } else if (CC_WECHATGAME) {
             //检查登录态
             weChat.checkLogin(flag => {
                 if (flag) {
@@ -426,7 +433,7 @@ cc.Class({
     },
 
     _getUserInfo() {
-        if (CC_WECHATGAME) {
+        if (CC_WECHATGAME && window.tt == undefined) {
             this._getWXCode().then( (code) => {
                 wx.getUserInfo({
                     withCredentials: true,

+ 6 - 0
assets/scripts/loginReward/LoginRewardCtrl.js

@@ -48,6 +48,9 @@ cc.Class({
             if (this.reward == undefined) {
                 if (itemModel.rewardId > GameGlobal.userLoginReward.rewardCount) {
                     this.reward = itemModel;
+                    if (window.tt != undefined) {
+                        this.shareLabel.string = '分享领取双倍签到奖励';
+                    }
                 }
             }
         }
@@ -63,6 +66,9 @@ cc.Class({
 
             if (GameGlobal.userLoginReward.rewardCount >= 6 && !GameGlobal.userLoginReward.isLoginReward) {
                 this.shareLabel.string = '分享到群炫耀';
+                if (window.tt != undefined) {
+                    this.shareLabel.string = '分享炫耀';
+                }
                 this.reward = itemModel;
             }
         }

+ 3 - 3
assets/scripts/net/LoginApi.js

@@ -98,9 +98,9 @@ class LoginApi {
                 avatarUrl: ttRes.userInfo.avatarUrl,
                 gender: ttRes.userInfo.gender,
             };
-        cc.sys.localStorage.setItem('GlobalUser', GameGlobal.user);
-        cb();
-    },
+            cc.sys.localStorage.setItem('GlobalUser', GameGlobal.user);
+            cb();
+        },
         fail: (errCode, errMsg) => {
             console.log('login error code: ' + errCode, 'login error msg: ' + errMsg);
             cb(true);

+ 21 - 8
assets/scripts/net/WeChat.js

@@ -24,22 +24,22 @@ class WeChat {
             tt.checkSession({
                 success() {
                     //session_key 未失效
-                    cb && cb(true)
+                    cb && cb()
                 },
                 fail() {
                     //session_key 已失效
-                    cb && cb(false)
+                    cb && cb(true)
                 }
             })
         } else if (CC_WECHATGAME) {
             wx.checkSession({
                 success() {
                     //session_key 未失效
-                    cb && cb(true)
+                    cb && cb()
                 },
                 fail() {
                     //session_key 已失效
-                    cb && cb(false)
+                    cb && cb(true)
                 }
             })
         }
@@ -89,7 +89,7 @@ class WeChat {
                     self._getUserInfo();
                 },
                 fail (res) {
-                    console.log(`login调用失败`);
+                    self.cb && self.cb(true);
                 }
             });
         } else if (CC_WECHATGAME) {
@@ -132,11 +132,10 @@ class WeChat {
             tt.getUserInfo({
                 withCredentials: true,
                 success (res) {
-                    console.log(`getUserInfo调用成功${res.userInfo}`);
                     self._login(res);
                 },
                 fail (res) {
-                    console.log(`getUserInfo调用失败`);
+                    self.cb && self.cb(true);
                 }
             });
         } else if (CC_WECHATGAME) {
@@ -204,7 +203,21 @@ class WeChat {
         let randomIndex = parseInt(Math.random()*(WeChat.shareObjcts.length),10);
         let shareObjct = WeChat.shareObjcts[randomIndex];
 
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            tt.shareAppMessage({
+                title: shareObjct.title,
+                imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
+                query: 'uid=' + GameGlobal.user.uid + '&shareType=' + ShareAction.INVITE_FRIEND,
+                success: (res) => {
+                    console.log('分享成功');
+                    success && success();
+                },
+                fail: () => {
+                    console.log('分享失败或取消');
+                    fail && fail();
+                }
+            });
+        } else if (CC_WECHATGAME) {
             wx.shareAppMessage({
                 title: shareObjct.title,
                 imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,

+ 1 - 1
settings/builder.json

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