Browse Source

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

tang biao 5 years ago
parent
commit
e641ce9671
4 changed files with 113 additions and 7 deletions
  1. 102 4
      assets/scripts/net/Api.js
  2. 9 1
      assets/scripts/rank/GameRank.js
  3. 1 1
      assets/scripts/utils/Global.js
  4. 1 1
      settings/builder.json

+ 102 - 4
assets/scripts/net/Api.js

@@ -77,7 +77,9 @@ class Api {
             }
         }
 
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            Api.ttGet(requestBody);
+        } else if (CC_WECHATGAME) {
             Api.wxGet(requestBody);
         } else if (CC_QQPLAY) {
             Api.qqGet(requestBody);
@@ -91,7 +93,11 @@ class Api {
      * @param {*} requestBody 
      */
     static httpPost(requestBody) {
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            requestBody.url = Api.requestUrl(requestBody.url);
+            requestBody.data = Api.baseParam(requestBody.data);
+            return Api.ttPost(requestBody);
+        } else if (CC_WECHATGAME) {
             requestBody.url = Api.requestUrl(requestBody.url);
             requestBody.data = Api.baseParam(requestBody.data);
             return Api.wxPost(requestBody);
@@ -164,6 +170,43 @@ class Api {
         });
     }
 
+    //头条
+    static ttGet(requestBody) {
+        let onSuccess = requestBody.success;
+        let onFail = requestBody.fail;
+        let onComplete = requestBody.complete;
+        tt.request({
+            url: requestBody.url,
+            data: requestBody.data,
+            method: requestBody.method === undefined ? 'GET' : 'POST',
+            header: requestBody.header === undefined ? {} : requestBody.header,
+            success: (res) => {
+                //直接处理登录失效的逻辑
+                if (res.data.code === ResponseStateCode.LOGIN_INVALIDATE) {
+                    GameGlobal.needLogin = true;
+                    cc.director.loadScene('login');
+                    return;
+                }
+
+                if (res.data.code === ResponseStateCode.OK) {
+                    if (onSuccess != undefined) {
+                        onSuccess(res.data.data);
+                    }
+                } else {
+                    if (onFail != undefined) {
+                        onFail(res.data.code, res.data.msg);
+                    }
+                }
+            },
+            fail: (res) => {
+                console.log('wxGet fail: ' + res);
+                if (onFail != undefined) {
+                    onFail(-1, res.errMsg);
+                }
+            },
+            complete: onComplete,
+        });
+    }
 
     static wxPost(requestBody) {
         requestBody.header = {
@@ -173,6 +216,14 @@ class Api {
         Api.wxGet(requestBody);
     }
 
+    static ttPost(requestBody) {
+        requestBody.header = {
+            "Content-Type": "application/x-www-form-urlencoded"
+        };
+        requestBody.method = 'POST';
+        Api.ttGet(requestBody);
+    }
+
    static qqGet(requestBody) {
         requestBody.header = {
             'Referer': 'https://hudong.qq.com',
@@ -310,7 +361,9 @@ class Api {
     static httpGetPromise(url, data) {
         url = Api.requestUrl(url);
         data = Api.baseParam(data);
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            return Api.ttGetP(url, data);
+        }else if (CC_WECHATGAME) {
             return Api.wxGetP(url, data);
         } else if (CC_QQPLAY) {
             return Api.qqGetP(url, data);
@@ -326,7 +379,9 @@ class Api {
     static httpPostPromise(url, data) {
         url = Api.requestUrl(url);
         data = Api.baseParam(data);
-        if (CC_WECHATGAME) {
+        if (window.tt != undefined) {
+            return Api.ttPostP(url, data);
+        } if (CC_WECHATGAME) {
             return Api.wxPostP(url, data);
         } else if (CC_QQPLAY) {
             return Api.qqPostP(url, data);
@@ -377,7 +432,50 @@ class Api {
         });
     }
 
+    //头条
+    static ttGetP(url, data) {
+        return Api.ttRequestPromise(url, data, 'GET');
+    }
+
+    static ttPostP(url, data) {
+        let header = {
+            "Content-Type": "application/x-www-form-urlencoded"
+        };
+        return Api.ttRequestPromise(url, data, 'POST', header);
+    }
+
+    static ttRequestPromise(url, data, method, header) {
+        return new Promise((resolve, reject) => {
+            tt.request({
+                url: url,
+                data: data,
+                method: method,
+                headers: header === undefined ? {} : header,
+                success: (res) => {
+                //直接处理登录失效的逻辑
+                if (res.data.code === ResponseStateCode.LOGIN_INVALIDATE) {
+                    GameGlobal.needLogin = true;
+                    cc.director.loadScene('login');
+                    reject(res.data);
+                }
+            if (res.data.code === ResponseStateCode.OK) {
+                resolve(res.data);
+            } else {
+                reject(res.data);
+            }
+        },
+            fail: (res) => {
+                reject({
+                    code: -1,
+                    msg: '头条登录接口调用失败'
+                });
+            },
+            complete: {},
+            });
+        });
+    }
 
+    //QQ
     static qqGetP(url, data) {
         url = Api.urlEncode(url, data);
         return Api.qqRequestPromise(url, '', 'GET');

+ 9 - 1
assets/scripts/rank/GameRank.js

@@ -88,6 +88,9 @@ cc.Class({
 
     init(index = 0) {
         this.tabIndex = index;
+        if (window.tt != undefined) {
+            this.tabIndex = 1;
+        }
         this._initTab();
     },
 
@@ -96,7 +99,7 @@ cc.Class({
     },
 
     onDestroy() {
-        if (window.wx != undefined) {
+        if (CC_WECHATGAME && window.tt == undefined) {
             window.wx.postMessage({
                 messageType: 4
             });
@@ -116,6 +119,11 @@ cc.Class({
         for(let i = 0; i < this.rankTab.length; i++) {
             this.rankTab[i] = this.rankTab[i].getComponent('GameTab');
             this.rankTab[i].init();
+            if (window.tt != undefined) {
+                if (i == 0 || i == 2) {
+                    this.rankTab[i].node.active = false;
+                }
+            }
         }
         this.handleTab(null, this.tabIndex);
     },

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

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

+ 1 - 1
settings/builder.json

@@ -37,7 +37,7 @@
   "title": "taptapstar",
   "webOrientation": "auto",
   "wechatgame": {
-    "REMOTE_SERVER_ROOT": "https://pub.dwstatic.com/wxgame/taptapstar_test",
+    "REMOTE_SERVER_ROOT": "https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test",
     "appid": "tt672c1191f806d2a2",
     "isSubdomain": false,
     "orientation": "portrait",