From 24fbe18a4aecd36ee68d25052f7a771ff9ce4ceb Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 21 Mar 2019 10:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=96=84console.log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.config.json | 2 +- src/app.wpy | 9 + src/common/global.js | 2 +- src/jcfw/SDKManage.js | 15 +- src/jcfw/jcfw.js | 1279 ++++++++++++++++++----------------- src/jcfw/service/jcshare.js | 1046 ++++++++++++++-------------- src/mixins/base.js | 12 +- src/pages/index.wpy | 20 +- src/pages/login.wpy | 7 +- 9 files changed, 1218 insertions(+), 1174 deletions(-) diff --git a/project.config.json b/project.config.json index 1f72e8f..f443360 100644 --- a/project.config.json +++ b/project.config.json @@ -1,7 +1,7 @@ { "description": "A WePY project", "setting": { - "urlCheck": true, + "urlCheck": false, "es6": false, "postcss": false, "minified": false, diff --git a/src/app.wpy b/src/app.wpy index b1481d4..e76cb8a 100644 --- a/src/app.wpy +++ b/src/app.wpy @@ -22,6 +22,8 @@ import wepy from 'wepy' import 'wepy-async-function' import jcEvent from './common/jc-event'; import http from './utils/http'; +import log, { hookConsoleLog } from './utils/logger'; +import g from './common/global'; let sdkManage = require('./jcfw/SDKManage'); export default class extends wepy.app { @@ -54,6 +56,7 @@ export default class extends wepy.app { super(); this.use('requestfix'); this.use('promisify'); + (g.env === 'test') && hookConsoleLog(); sdkManage.init(); sdkManage.Login(() => { let account = wepy.getStorageSync('account'); @@ -201,5 +204,11 @@ export default class extends wepy.app { getShareCount(cb) { sdkManage.getAchievInviteeNum(cb); } + getShareDetail(cb) { + sdkManage.queryAchievementShareDetail(cb); + } + updateUserInfo(allInfo, cb) { + sdkManage.updateUser(allInfo, cb); + } } diff --git a/src/common/global.js b/src/common/global.js index 5d175d7..186523b 100644 --- a/src/common/global.js +++ b/src/common/global.js @@ -1,4 +1,4 @@ -const env = 'product'; //product, test +const env = 'test'; //product, test export default { env: env, apiBase: env === 'test'? 'https://ghost-test.kingsome.cn' : 'https://ghost.kingsome.cn', diff --git a/src/jcfw/SDKManage.js b/src/jcfw/SDKManage.js index a4b3e9d..c4bb510 100755 --- a/src/jcfw/SDKManage.js +++ b/src/jcfw/SDKManage.js @@ -189,8 +189,19 @@ var SDKManage = function() { ]; this.doLogin(); }; - - + this.queryAchievementShareDetail = function(cb) { + var callback = function(res) { + console.log('playerData.invitee_detail'); + console.log(res); + if (cb) { + cb(res); + } + }; + jcshare.queryAchievementShareDetail([1001], callback, function() {}); + }; + this.updateUser = function(allInfo, cb) { + jcfw.updateUser(allInfo, cb) + } }; diff --git a/src/jcfw/jcfw.js b/src/jcfw/jcfw.js index b9a1f88..8b2694d 100755 --- a/src/jcfw/jcfw.js +++ b/src/jcfw/jcfw.js @@ -1,639 +1,640 @@ -var jccloud = require('./service/jccloud'); -var jcgamelog = require( './service/jcgamelog'); -var jclogin = require( './service/jclogin'); -var jcshare = require( './service/jcshare'); -var jcAD = require('./service/jcAD'); -var jcStat = require('./service/jcstat'); -var jcNotify = require('./service/jcnotify'); -var storage = require('./common/storage'); - -const notification = require('./common/notification'); - -const _GAME_LOCALUUID = 'jc_game_localuuid'; - -const _GAME_INFO_HANDLER_BINDING = 'jc_gameinfo_handler_binding'; -const _GAME_INFO_HANDLER_UNBINDING = 'jc_gameinfo_handler_unbinding'; - -const JC_CLOUD_URL = 'cloud'; -const JC_GAMELOG_URL = 'gamelog'; -const JC_LOGIN_URL= 'login'; -const JC_NOTIFY_URL= 'notify'; -const JC_SVC_URL= 'service'; -const JC_STAT_URL= 'stat'; -const JC_GAMELIST_URL= 'service'; - -var JCFW = { - cloud: jccloud, - gamelog: jcgamelog, - login: jclogin, - share: jcshare, - ad: jcAD, - stat: jcStat, - notify: jcNotify, - - - localUUID: '', - - systemInfo: null, - lauchInfo: null, - shareInfo: {}, - _handlers: [], - - _inited: false, - - __getUrl(isoffical, key){ - let pre = key; - if(!isoffical){ - pre += '-test'; - } - let str = 'https://' + pre + '.kingsome.cn/webapp/index.php'; - - // let str = 'https://www.xmjl123.cn/' + pre + '/webapp/index.php'; - return str; - }, - - // 初始化 - /** - * - * @param {number} channelid : 频道ID - * @param {number} gameid :游戏ID - * @param {boolean} isoffical :上线版本还是测试版本 - * @param {object} response :回调对象(可不填),如果填的话,可实现以下一个或多个函数: - * .onLogin(logininfo) - * .onLoginFail(net_err, logic_err, errmsg) - * .onUpdateUser(userinfo) - * .onUpdateUserFail(net_err, logic_err, errmsg) - * .onShare(***) - * .onShareFail(***) - */ - init(channelid, gameid, isoffical, response, env){ - if(this._inited){ - if(this.rsp != response){ - this.rsp = response; - } - return; - } - - this.rsp = response; - - this.channelID = parseInt(channelid); - this.gameID = parseInt(gameid); - - this.isOffical = isoffical; - - this._fixChannelID(); - - this._checkListener(); - - this.gamelog.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_GAMELOG_URL)); - this.cloud.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_CLOUD_URL)); - this.login.init(this.channelID, this.gameID, isoffical, this, env, this.__getUrl(isoffical, JC_LOGIN_URL)); - this.share.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_SVC_URL)); - this.ad.init(this.channelID, this.gameID, isoffical, this); - this.stat.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_STAT_URL)); - this.notify.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_NOTIFY_URL)); - - - this._loadLocalID(); - this._loadLaunchInfo(); - this._loadSystemInfo(); - //this._loadConfig(); - - this._handleInit(this.channelID, this.gameID, isoffical); - - this._inited = true; - }, - - /** - * 登陆函数 - * @param {object} successcb :成功回调(初始化时设置了回调对象的话,此处可不填) - * @param {object} failcb :失败回调(初始化时设置了回调对象的话,此处可不填) - * @param {string} ex_param :额外参数(预留字段,某些平台可能会使用此字段) - */ - loginUser(successcb, failcb, ex_param){ - //console.log('loginUser'); - if(this._logining){ - return 1; - } - this.logining = true; - this.login.loginPT((res) =>{ - this._logining = false; - this.logined = true; - this.setAccountID(res.account_id, res.session_id, res); - this.setNickName(res.nickname); - this.setServerTime(res.server_time); - this.gamelog.logLoginSuccess(res, this.login.login_costtime); - this.gamelog.logShareInvite(this.shareInfo.inviter, this.shareInfo.type, this.shareInfo.id, this.shareInfo.param); - this.gamelog.logSystemInfo(this.systemInfo); - if(this.shareInfo && this.shareInfo.id && this.shareInfo.id != ''){ - this.share.acceptDailyInvite(this.shareInfo.param,this.shareInfo.id,()=>{}, ()=>{}); - } - this.rsp && this.rsp.onLogin && this.rsp.onLogin(res); - successcb && successcb(res); - if(this.cacheuser){ - this.updateUser(this.cacheuser.info, this.cacheuser.success, this.cacheuser.fail); - } - }, (neterr, logicerr, errmsg) => { - this._logining = false; - this.gamelog.logLoginFailed(neterr, logicerr, errmsg); - this.rsp && this.rsp.onLoginFail && this.rsp.onLoginFail(neterr, logicerr, errmsg); - failcb && failcb(neterr, logicerr, errmsg); - }, ex_param); - return 0; - }, - - loginUserByToken(token, successcb, failcb){ - //console.log('loginUserByToken:' + token); - return this.loginUser(successcb, failcb, token); - }, - - // 激活 - /** - * - * @param {object} allinfo :包含用户信息的对象: 注意:allinfo.userInfo为用户实际信息 - * @param {object} successcb :成功回调(初始化时设置了回调对象的话,此处可不填) - * @param {object} failcb :失败回调(初始化时设置了回调对象的话,此处可不填) - */ - updateUser(allinfo, successcb, failcb){ - //console.log('updateUser'); - if(!this.logined){ - if(!this.cacheuser){ - this.cacheuser = {}; - } - this.cacheuser.info = allinfo; - this.cacheuser.success = successcb; - this.cacheuser.fail = failcb; - return; - }else{ - this.cacheuser = null; - } - let userinfo = allinfo && allinfo.userInfo; - if(!userinfo){ - this.gamelog.logAuthFail(); - this.setUserInfo(null); - }else{ - this.gamelog.logAuthSuccess(userinfo); - this.setUserInfo(userinfo); - } - - if(!allinfo || !userinfo){ - this.rsp && this.rsp.onUpdateUserFail && this.rsp.onUpdateUserFail(0, -10000, 'info is NULL'); - failcb && failcb(0, -10000, 'info is NULL'); - return 0; - } - - if(this._userupdating){ - return 1; - } - this._userupdating = true; - this.login.updatePTInfo(userinfo, allinfo, (obj) => { - this._userupdating = false; - this.rsp && this.rsp.onUpdateUser && this.rsp.onUpdateUser(obj); - successcb && successcb(obj); - }, (neterr, logicerr, errmsg) => { - this._userupdating = false; - this.rsp && this.rsp.onUpdateUserFail && this.rsp.onUpdateUserFail(neterr, logicerr, errmsg); - failcb && failcb(neterr, logicerr, errmsg); - }); - return 0; - }, - - initGlobalConfig(successcb, failcb){ - this.cloud.getServerConfig((cfg) => { - this.rsp && this.rsp.onServerConfig && this.rsp.onServerConfig(cfg); - successcb && successcb(cfg); - }, (neterr, logicerr, errmsg) =>{ - this.rsp && this.rsp.onServerConfigFail && this.rsp.onServerConfigFail(neterr, logicerr, errmsg); - failcb && failcb(neterr, logicerr, errmsg); - }); - }, - - // 普通分享 - shareNormal(content, imgurl, sharetype, shareparam, extrainfo){ - this.share.shareNormal(content, imgurl, sharetype, shareparam, extrainfo, () => { - this.rsp && this.rsp.onShare && this.rsp.onShare(content, imgurl, sharetype, shareparam, extrainfo); - }, () => { - this.rsp && this.rsp.onShareFail && this.rsp.onShareFail(content, imgurl, sharetype, shareparam, extrainfo); - }); - }, - - // 截图分享 - shareCapture(content, capture_rect, sharetype, shareparam, extrainfo){ - this.share.shareCapture(content, capture_rect, sharetype, shareparam, extrainfo, () => { - this.rsp && this.rsp.onShare && this.rsp.onShare(content, capture_rect, sharetype, shareparam, extrainfo); - }, () => { - this.rsp && this.rsp.onShareFail && this.rsp.onShareFail(content, capture_rect, sharetype, shareparam, extrainfo); - }); - }, - - // 生成唯一ID【无需关注此函数】 - makeUUID(){ - return this.gamelog.generateUUID(); - }, - // 根据OpenID生成账号ID【通常情况不使用此函数】 - makeAccountID(openid){ - return this.login.AccountID(openid); - }, - - // 添加监听处理器 - // handler是回调对象,按实际需要可实现以下一个或多个回调: - // .onJCInit(channelid, gameid, isoffical){} - // .onJCAccountID(accountid, sessionid){} - // .onJCLocalUUID(localuuid){} - // .onJCUserInfo(userinfo){} - // .onJCLaunchInfo(lauchscene, lauchfromid, launchparam){} - // .onJCGameStart(startmode, extparam){} - // .onJCGameOver(score, bsuccess, extparam){} - addHandler(handler){ - this._checkListener(); - if(!handler){ - return false; - } - let obj = this._handlers.find(element => { - return element == handler; - }); - if(!obj){ - this._handlers.push(handler); - this._initHandler(handler); - } - return true; - }, - - // 删除监听处理器 - delHandler(handler){ - if(!handler || !this._handlers){ - return false; - } - let idx = this._handlers.findIndex((item) => { - return item == handler; - }); - if(idx < 0){ - return true; - } - this._handlers.splice(idx, 1); - return true; - }, - - // 重置本地ID【通常情况不使用此函数】 - resetLocalID(){ - this._cleanLocalID(); - this._loadLocalID(); - }, - - // 设置sdk回调 - setResponse(rsp){ - this.rsp = rsp; - }, - - // 获取服务器当前时间【登陆完成后才能调用】 - getServerNowTime(){ - let tm = new Date().getTime(); - return this.loginSrvTime + (tm - this.loginLocalTime) / 1000; - }, - - //游戏相关------------------------------------------------------- - // 游戏开始 - // startmode: 0:正常开始游戏 1:重新开始 2:再来一次 - gameStart(startmode, extparam){ - switch(startmode){ - case 0: - this.gamelog.logStartGame(extparam); - break; - case 1: - this.gamelog.logRestartGame(extparam); - break; - case 2: - this.gamelog.logTryAgain(extparam); - break; - } - this._handleGameStart(startmode, extparam); - }, - - // 游戏结束 - gameOver(score, bsuccess, extparam){ - this.gamelog.logGameover(extparam, score, bsuccess? 1: 0); - this._handleGameOver(score, bsuccess, extparam); - }, - - // 游戏显示 - gameShow(showinfo){ - this.gamelog.logShow(); - this._handleGameShow(showinfo); - }, - - // 游戏隐藏 - gameHide(){ - this.gamelog.logHide(); - this._handGameHide(); - }, - - // 使用道具 - gameUseItem(itemid, itemcount, reson, extparam){ - this.gamelog.logUseItem(itemid, itemcount, reson, extparam); - }, - - // 获得道具 - gameGetItem(itemid, itemcount, reson, extparam){ - this.gamelog.logProductItem(itemid, itemcount, reson, extparam); - }, - //----------------------------------------------------------------- - - // 以下函数无需手动调用 - - setAccountID(accountid, sessionid, exobj){ - this.accountID = accountid; - this.sessionID = sessionid; - this.accountobj = exobj; - if(exobj && exobj.wid){ - this.weakID = exobj.wid; - } - if(exobj && exobj.sid){ - this.strongID = exobj.sid; - } - if(exobj && exobj.ptid){ - this.ptID = exobj.ptID; - } - this.share.setAccountID(accountid, sessionid, exobj); - this.gamelog.setAccountID(accountid, sessionid, exobj); - this.login.setAccountID(accountid, sessionid, exobj); - this.cloud.setAccountID(accountid, sessionid, exobj); - this.ad.setAccountID(accountid, sessionid, exobj); - this.stat.setAccountID(accountid, sessionid, exobj); - this.notify.setAccountID(accountid, sessionid, exobj); - - - this._handleAccountID(accountid, sessionid, exobj); - // this.logined = this.accountID && this.accountID != ''; - }, - - setLocalUUID(uuid){ - this.localUUID = uuid; - this.gamelog.setLocalUUID(uuid); - this.cloud.setLocalUUID(uuid); - this.login.setLocalUUID(uuid); - this.share.setLocalUUID(uuid); - this.ad.setLocalUUID(uuid); - this.stat.setLocalUUID(uuid); - this.notify.setLocalUUID(uuid); - - - this._handleLocalID(uuid); - }, - - setNickName(nickname){ - if(nickname && nickname != '' && this.nickName != nickname){ - this.nickName = nickname; - this.gamelog.setNickName(nickname); - this.cloud.setNickName(nickname); - this.login.setNickName(nickname); - this.share.setNickName(nickname); - this.ad.setNickName(nickname); - this.stat.setNickName(nickname); - this.notify.setNickName(nickname); - - - this._handleNickName(nickname); - } - }, - - setFromAppID(appid, scene, paramobj){ - this.scene = scene; - if(appid){ - this.fromID = appid; - this.gamelog.setFromAppID(appid); - this.cloud.setFromAppID(appid); - this.login.setFromAppID(appid); - this.share.setFromAppID(appid); - this.ad.setFromAppID(appid); - this.stat.setFromAppID(appid); - this.notify.setFromAppID(appid); - - } - if(paramobj){ - this.lauchparam = paramobj; - } - this._handleLauchInfo(scene, appid, paramobj); - }, - - setSystemInfo(info){ - this.systemInfo = info; - this.gamelog.setSystemInfo(info); - this.cloud.setSystemInfo(info); - this.login.setSystemInfo(info); - this.share.setSystemInfo(info); - this.ad.setSystemInfo(info); - this.stat.setSystemInfo(info); - this.notify.setSystemInfo(info); - }, - - setUserInfo(info){ - if(!this._userInfo){ - this._userinfo = {}; - } - this.login.appendUserInfo(this._userinfo, info); - // this.userInfo = info; - if(this._userinfo.nickName){ - this.setNickName(this._userinfo.nickName); - } - this.share.setUserInfo(this._userinfo); - this._handleUserInfo(this._userinfo); - }, - - setServerTime(srvtime){ - if(!srvtime){ - return; - } - this.loginSrvTime = srvtime; - this.loginLocalTime = new Date().getTime(); - this.notify.setServerTime(srvtime, this.loginLocalTime); - this._handleServerTime(srvtime, this.loginLocalTime); - }, - - _loadLocalID(){ - let id = storage.get(_GAME_LOCALUUID); - let bneedsave = false; - if(!id){ - id = this.makeUUID(); - bneedsave = true; - } - this.setLocalUUID(id); - if(bneedsave){ - this._saveLocalID(); - } - }, - - _saveLocalID(){ - if(!storage.set(_GAME_LOCALUUID, this.localUUID)){ - setTimeout(this._saveLocalID.bind(this), 5000); - } - }, - - _cleanLocalID(){ - storage.remove(_GAME_LOCALUUID); - }, - - _loadLaunchInfo(){ - this.lauchInfo = wx.getLaunchOptionsSync(); - - this.gamelog.handlelaunch(this.lauchInfo, (sharetype, shareparam, shareid, inviterid, - fromid, fromscene, launchobj) => { - this.shareInfo.type = sharetype; - this.shareInfo.param = shareparam; - this.shareInfo.id = shareid; - this.shareInfo.inviter = inviterid; - - this.setFromAppID(fromid, fromscene, launchobj); - }); - }, - - _loadSystemInfo(){ - - let info = wx.getSystemInfoSync(); - this.gamelog.logLaunchSystemInfo(info); - - this.setSystemInfo(info); - - }, - - _loadConfig(){ - this.initGlobalConfig(); - }, - - _initHandler(obj){ - if(this.gameID && obj.onJCInit){ - obj.onJCInit(this.channelID, this.gameID, this.isOffical); - } - if(this.accountID && this.sessionID && obj.onJCAccountID){ - obj.onJCAccountID(this.accountID, this.sessionID, this.accountobj); - } - if(this.localUUID && obj.onJCLocalUUID){ - obj.onJCLocalUUID(this.localUUID); - } - if(this.nickName && obj.onJCNickName){ - obj.onJCNickName(this.nickName); - } - if(this._userinfo && obj.onJCUserInfo){ - obj.onJCUserInfo(this._userinfo); - } - if(this.fromID && obj.onJCLaunchInfo){ - obj.onJCLaunchInfo(this.scene, this.fromID, this.lauchparam); - } - }, - - _handleInit(channelid, gameid, isoffical){ - this._handlers.forEach(element => { - if(element.onJCInit){ - element.onJCInit(channelid, gameid, isoffical); - } - }); - }, - - _handleAccountID(accountid, sessionid, exobj){ - this._handlers.forEach(element => { - if(element.onJCAccountID){ - element.onJCAccountID(accountid, sessionid, exobj); - } - }); - }, - - _handleLocalID(localuuid){ - this._handlers.forEach(element => { - if(element.onJCLocalUUID){ - element.onJCLocalUUID(localuuid); - } - }); - }, - - _handleNickName(nickname){ - this._handlers.forEach(element => { - if(element.onJCNickName){ - element.onJCNickName(nickname); - } - }); - }, - - _handleUserInfo(userinfo){ - this._handlers.forEach(element => { - if(element.onJCUserInfo){ - element.onJCUserInfo(userinfo); - } - }); - }, - - _handleLauchInfo(lauchscene, lauchfromid, launchparam){ - this._handlers.forEach(element => { - if(element.onJCLaunchInfo){ - element.onJCLaunchInfo(lauchscene, lauchfromid, launchparam); - } - }); - }, - - _handleServerTime(servertime, localtime){ - this._handlers.forEach(element => { - if(element.onJCServerTime){ - element.onJCServerTime(servertime, localtime); - } - }); - }, - - _handleGameStart(startmode, extparam){ - this._handlers.forEach(element => { - if(element.onJCGameStart){ - element.onJCGameStart(startmode, extparam); - } - }); - }, - - _handleGameOver(score, bsuccess, extparam){ - this._handlers.forEach(element => { - if(element.onJCGameOver){ - element.onJCGameOver(score, bsuccess, extparam); - } - }); - }, - - _handleGameShow(showinfo){ - this._handlers.forEach(element => { - if(element.onJCGameShow){ - element.onJCGameShow(showinfo); - } - }); - }, - - _handGameHide(hideinfo){ - this._handlers.forEach(element => { - if(element.onJCGameHide){ - element.onJCGameHide(hideinfo); - } - }); - }, - - _handleNotifyMsgs(lst, notifyobj){ - this._handlers.forEach(element => { - if(element.onJCNotifyMsg){ - element.onJCNotifyMsg(lst, notifyobj); - } - }); - }, - - _checkListener(){ - if(!this._listenerID){ - this._listenerID = notification.on(_GAME_INFO_HANDLER_BINDING, (msgid, handler) => { - this.addHandler(handler); - }, this); - } - if(!this._unlistenerID){ - this._unlistenerID = notification.on(_GAME_INFO_HANDLER_UNBINDING, (msgid, handler) => { - this.delHandler(handler); - }, this); - } - }, - - _fixChannelID(){ - - } -}; - - - -module.exports = JCFW; \ No newline at end of file +var jccloud = require('./service/jccloud'); +var jcgamelog = require('./service/jcgamelog'); +var jclogin = require('./service/jclogin'); +var jcshare = require('./service/jcshare'); +var jcAD = require('./service/jcAD'); +var jcStat = require('./service/jcstat'); +var jcNotify = require('./service/jcnotify'); +var storage = require('./common/storage'); + +const notification = require('./common/notification'); + +const _GAME_LOCALUUID = 'jc_game_localuuid'; + +const _GAME_INFO_HANDLER_BINDING = 'jc_gameinfo_handler_binding'; +const _GAME_INFO_HANDLER_UNBINDING = 'jc_gameinfo_handler_unbinding'; + +const JC_CLOUD_URL = 'cloud'; +const JC_GAMELOG_URL = 'gamelog'; +const JC_LOGIN_URL = 'login'; +const JC_NOTIFY_URL = 'notify'; +const JC_SVC_URL = 'service'; +const JC_STAT_URL = 'stat'; +const JC_GAMELIST_URL = 'service'; + +var JCFW = { + cloud: jccloud, + gamelog: jcgamelog, + login: jclogin, + share: jcshare, + ad: jcAD, + stat: jcStat, + notify: jcNotify, + + + localUUID: '', + + systemInfo: null, + lauchInfo: null, + shareInfo: {}, + _handlers: [], + + _inited: false, + + __getUrl(isoffical, key) { + let pre = key; + if (!isoffical) { + pre += '-test'; + } + let str = 'https://' + pre + '.kingsome.cn/webapp/index.php'; + + // let str = 'https://www.xmjl123.cn/' + pre + '/webapp/index.php'; + return str; + }, + + // 初始化 + /** + * + * @param {number} channelid : 频道ID + * @param {number} gameid :游戏ID + * @param {boolean} isoffical :上线版本还是测试版本 + * @param {object} response :回调对象(可不填),如果填的话,可实现以下一个或多个函数: + * .onLogin(logininfo) + * .onLoginFail(net_err, logic_err, errmsg) + * .onUpdateUser(userinfo) + * .onUpdateUserFail(net_err, logic_err, errmsg) + * .onShare(***) + * .onShareFail(***) + */ + init(channelid, gameid, isoffical, response, env) { + if (this._inited) { + if (this.rsp != response) { + this.rsp = response; + } + return; + } + + this.rsp = response; + + this.channelID = parseInt(channelid); + this.gameID = parseInt(gameid); + + this.isOffical = isoffical; + + this._fixChannelID(); + + this._checkListener(); + + this.gamelog.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_GAMELOG_URL)); + this.cloud.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_CLOUD_URL)); + this.login.init(this.channelID, this.gameID, isoffical, this, env, this.__getUrl(isoffical, JC_LOGIN_URL)); + this.share.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_SVC_URL)); + this.ad.init(this.channelID, this.gameID, isoffical, this); + this.stat.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_STAT_URL)); + this.notify.init(this.channelID, this.gameID, isoffical, this, this.__getUrl(isoffical, JC_NOTIFY_URL)); + + + this._loadLocalID(); + this._loadLaunchInfo(); + this._loadSystemInfo(); + //this._loadConfig(); + + this._handleInit(this.channelID, this.gameID, isoffical); + + this._inited = true; + }, + + /** + * 登陆函数 + * @param {object} successcb :成功回调(初始化时设置了回调对象的话,此处可不填) + * @param {object} failcb :失败回调(初始化时设置了回调对象的话,此处可不填) + * @param {string} ex_param :额外参数(预留字段,某些平台可能会使用此字段) + */ + loginUser(successcb, failcb, ex_param) { + //console.log('loginUser'); + if (this._logining) { + return 1; + } + this.logining = true; + this.login.loginPT((res) => { + this._logining = false; + this.logined = true; + this.setAccountID(res.account_id, res.session_id, res); + this.setNickName(res.nickname); + this.setServerTime(res.server_time); + this.gamelog.logLoginSuccess(res, this.login.login_costtime); + this.gamelog.logShareInvite(this.shareInfo.inviter, this.shareInfo.type, this.shareInfo.id, this.shareInfo.param); + this.gamelog.logSystemInfo(this.systemInfo); + if (this.shareInfo && this.shareInfo.id && this.shareInfo.id != '') { + this.share.acceptDailyInvite(this.shareInfo.param, this.shareInfo.id, () => { + }, () => { + }); + } + this.rsp && this.rsp.onLogin && this.rsp.onLogin(res); + successcb && successcb(res); + if (this.cacheuser) { + this.updateUser(this.cacheuser.info, this.cacheuser.success, this.cacheuser.fail); + } + }, (neterr, logicerr, errmsg) => { + this._logining = false; + this.gamelog.logLoginFailed(neterr, logicerr, errmsg); + this.rsp && this.rsp.onLoginFail && this.rsp.onLoginFail(neterr, logicerr, errmsg); + failcb && failcb(neterr, logicerr, errmsg); + }, ex_param); + return 0; + }, + + loginUserByToken(token, successcb, failcb) { + //console.log('loginUserByToken:' + token); + return this.loginUser(successcb, failcb, token); + }, + + // 激活 + /** + * + * @param {object} allinfo :包含用户信息的对象: 注意:allinfo.userInfo为用户实际信息 + * @param {object} successcb :成功回调(初始化时设置了回调对象的话,此处可不填) + * @param {object} failcb :失败回调(初始化时设置了回调对象的话,此处可不填) + */ + updateUser(allinfo, successcb, failcb) { + //console.log('updateUser'); + if (!this.logined) { + if (!this.cacheuser) { + this.cacheuser = {}; + } + this.cacheuser.info = allinfo; + this.cacheuser.success = successcb; + this.cacheuser.fail = failcb; + return; + } else { + this.cacheuser = null; + } + let userinfo = allinfo && allinfo.userInfo; + if (!userinfo) { + this.gamelog.logAuthFail(); + this.setUserInfo(null); + } else { + this.gamelog.logAuthSuccess(userinfo); + this.setUserInfo(userinfo); + } + + if (!allinfo || !userinfo) { + this.rsp && this.rsp.onUpdateUserFail && this.rsp.onUpdateUserFail(0, -10000, 'info is NULL'); + failcb && failcb(0, -10000, 'info is NULL'); + return 0; + } + + if (this._userupdating) { + return 1; + } + this._userupdating = true; + this.login.updatePTInfo(userinfo, allinfo, (obj) => { + this._userupdating = false; + this.rsp && this.rsp.onUpdateUser && this.rsp.onUpdateUser(obj); + successcb && successcb(obj); + }, (neterr, logicerr, errmsg) => { + this._userupdating = false; + this.rsp && this.rsp.onUpdateUserFail && this.rsp.onUpdateUserFail(neterr, logicerr, errmsg); + failcb && failcb(neterr, logicerr, errmsg); + }); + return 0; + }, + + initGlobalConfig(successcb, failcb) { + this.cloud.getServerConfig((cfg) => { + this.rsp && this.rsp.onServerConfig && this.rsp.onServerConfig(cfg); + successcb && successcb(cfg); + }, (neterr, logicerr, errmsg) => { + this.rsp && this.rsp.onServerConfigFail && this.rsp.onServerConfigFail(neterr, logicerr, errmsg); + failcb && failcb(neterr, logicerr, errmsg); + }); + }, + + // 普通分享 + shareNormal(content, imgurl, sharetype, shareparam, extrainfo) { + this.share.shareNormal(content, imgurl, sharetype, shareparam, extrainfo, () => { + this.rsp && this.rsp.onShare && this.rsp.onShare(content, imgurl, sharetype, shareparam, extrainfo); + }, () => { + this.rsp && this.rsp.onShareFail && this.rsp.onShareFail(content, imgurl, sharetype, shareparam, extrainfo); + }); + }, + + // 截图分享 + shareCapture(content, capture_rect, sharetype, shareparam, extrainfo) { + this.share.shareCapture(content, capture_rect, sharetype, shareparam, extrainfo, () => { + this.rsp && this.rsp.onShare && this.rsp.onShare(content, capture_rect, sharetype, shareparam, extrainfo); + }, () => { + this.rsp && this.rsp.onShareFail && this.rsp.onShareFail(content, capture_rect, sharetype, shareparam, extrainfo); + }); + }, + + // 生成唯一ID【无需关注此函数】 + makeUUID() { + return this.gamelog.generateUUID(); + }, + // 根据OpenID生成账号ID【通常情况不使用此函数】 + makeAccountID(openid) { + return this.login.AccountID(openid); + }, + + // 添加监听处理器 + // handler是回调对象,按实际需要可实现以下一个或多个回调: + // .onJCInit(channelid, gameid, isoffical){} + // .onJCAccountID(accountid, sessionid){} + // .onJCLocalUUID(localuuid){} + // .onJCUserInfo(userinfo){} + // .onJCLaunchInfo(lauchscene, lauchfromid, launchparam){} + // .onJCGameStart(startmode, extparam){} + // .onJCGameOver(score, bsuccess, extparam){} + addHandler(handler) { + this._checkListener(); + if (!handler) { + return false; + } + let obj = this._handlers.find(element => { + return element == handler; + }); + if (!obj) { + this._handlers.push(handler); + this._initHandler(handler); + } + return true; + }, + + // 删除监听处理器 + delHandler(handler) { + if (!handler || !this._handlers) { + return false; + } + let idx = this._handlers.findIndex((item) => { + return item == handler; + }); + if (idx < 0) { + return true; + } + this._handlers.splice(idx, 1); + return true; + }, + + // 重置本地ID【通常情况不使用此函数】 + resetLocalID() { + this._cleanLocalID(); + this._loadLocalID(); + }, + + // 设置sdk回调 + setResponse(rsp) { + this.rsp = rsp; + }, + + // 获取服务器当前时间【登陆完成后才能调用】 + getServerNowTime() { + let tm = new Date().getTime(); + return this.loginSrvTime + (tm - this.loginLocalTime) / 1000; + }, + + //游戏相关------------------------------------------------------- + // 游戏开始 + // startmode: 0:正常开始游戏 1:重新开始 2:再来一次 + gameStart(startmode, extparam) { + switch (startmode) { + case 0: + this.gamelog.logStartGame(extparam); + break; + case 1: + this.gamelog.logRestartGame(extparam); + break; + case 2: + this.gamelog.logTryAgain(extparam); + break; + } + this._handleGameStart(startmode, extparam); + }, + + // 游戏结束 + gameOver(score, bsuccess, extparam) { + this.gamelog.logGameover(extparam, score, bsuccess ? 1 : 0); + this._handleGameOver(score, bsuccess, extparam); + }, + + // 游戏显示 + gameShow(showinfo) { + this.gamelog.logShow(); + this._handleGameShow(showinfo); + }, + + // 游戏隐藏 + gameHide() { + this.gamelog.logHide(); + this._handGameHide(); + }, + + // 使用道具 + gameUseItem(itemid, itemcount, reson, extparam) { + this.gamelog.logUseItem(itemid, itemcount, reson, extparam); + }, + + // 获得道具 + gameGetItem(itemid, itemcount, reson, extparam) { + this.gamelog.logProductItem(itemid, itemcount, reson, extparam); + }, + //----------------------------------------------------------------- + + // 以下函数无需手动调用 + + setAccountID(accountid, sessionid, exobj) { + this.accountID = accountid; + this.sessionID = sessionid; + this.accountobj = exobj; + if (exobj && exobj.wid) { + this.weakID = exobj.wid; + } + if (exobj && exobj.sid) { + this.strongID = exobj.sid; + } + if (exobj && exobj.ptid) { + this.ptID = exobj.ptID; + } + this.share.setAccountID(accountid, sessionid, exobj); + this.gamelog.setAccountID(accountid, sessionid, exobj); + this.login.setAccountID(accountid, sessionid, exobj); + this.cloud.setAccountID(accountid, sessionid, exobj); + this.ad.setAccountID(accountid, sessionid, exobj); + this.stat.setAccountID(accountid, sessionid, exobj); + this.notify.setAccountID(accountid, sessionid, exobj); + + + this._handleAccountID(accountid, sessionid, exobj); + // this.logined = this.accountID && this.accountID != ''; + }, + + setLocalUUID(uuid) { + this.localUUID = uuid; + this.gamelog.setLocalUUID(uuid); + this.cloud.setLocalUUID(uuid); + this.login.setLocalUUID(uuid); + this.share.setLocalUUID(uuid); + this.ad.setLocalUUID(uuid); + this.stat.setLocalUUID(uuid); + this.notify.setLocalUUID(uuid); + + + this._handleLocalID(uuid); + }, + + setNickName(nickname) { + if (nickname && nickname != '' && this.nickName != nickname) { + this.nickName = nickname; + this.gamelog.setNickName(nickname); + this.cloud.setNickName(nickname); + this.login.setNickName(nickname); + this.share.setNickName(nickname); + this.ad.setNickName(nickname); + this.stat.setNickName(nickname); + this.notify.setNickName(nickname); + + + this._handleNickName(nickname); + } + }, + + setFromAppID(appid, scene, paramobj) { + this.scene = scene; + if (appid) { + this.fromID = appid; + this.gamelog.setFromAppID(appid); + this.cloud.setFromAppID(appid); + this.login.setFromAppID(appid); + this.share.setFromAppID(appid); + this.ad.setFromAppID(appid); + this.stat.setFromAppID(appid); + this.notify.setFromAppID(appid); + + } + if (paramobj) { + this.lauchparam = paramobj; + } + this._handleLauchInfo(scene, appid, paramobj); + }, + + setSystemInfo(info) { + this.systemInfo = info; + this.gamelog.setSystemInfo(info); + this.cloud.setSystemInfo(info); + this.login.setSystemInfo(info); + this.share.setSystemInfo(info); + this.ad.setSystemInfo(info); + this.stat.setSystemInfo(info); + this.notify.setSystemInfo(info); + }, + + setUserInfo(info) { + if (!this._userInfo) { + this._userinfo = {}; + } + this.login.appendUserInfo(this._userinfo, info); + // this.userInfo = info; + if (this._userinfo.nickName) { + this.setNickName(this._userinfo.nickName); + } + this.share.setUserInfo(this._userinfo); + this._handleUserInfo(this._userinfo); + }, + + setServerTime(srvtime) { + if (!srvtime) { + return; + } + this.loginSrvTime = srvtime; + this.loginLocalTime = new Date().getTime(); + this.notify.setServerTime(srvtime, this.loginLocalTime); + this._handleServerTime(srvtime, this.loginLocalTime); + }, + + _loadLocalID() { + let id = storage.get(_GAME_LOCALUUID); + let bneedsave = false; + if (!id) { + id = this.makeUUID(); + bneedsave = true; + } + this.setLocalUUID(id); + if (bneedsave) { + this._saveLocalID(); + } + }, + + _saveLocalID() { + if (!storage.set(_GAME_LOCALUUID, this.localUUID)) { + setTimeout(this._saveLocalID.bind(this), 5000); + } + }, + + _cleanLocalID() { + storage.remove(_GAME_LOCALUUID); + }, + + _loadLaunchInfo() { + this.lauchInfo = wx.getLaunchOptionsSync(); + + this.gamelog.handlelaunch(this.lauchInfo, (sharetype, shareparam, shareid, inviterid, + fromid, fromscene, launchobj) => { + this.shareInfo.type = sharetype; + this.shareInfo.param = shareparam; + this.shareInfo.id = shareid; + this.shareInfo.inviter = inviterid; + + this.setFromAppID(fromid, fromscene, launchobj); + }); + }, + + _loadSystemInfo() { + + let info = wx.getSystemInfoSync(); + this.gamelog.logLaunchSystemInfo(info); + + this.setSystemInfo(info); + + }, + + _loadConfig() { + this.initGlobalConfig(); + }, + + _initHandler(obj) { + if (this.gameID && obj.onJCInit) { + obj.onJCInit(this.channelID, this.gameID, this.isOffical); + } + if (this.accountID && this.sessionID && obj.onJCAccountID) { + obj.onJCAccountID(this.accountID, this.sessionID, this.accountobj); + } + if (this.localUUID && obj.onJCLocalUUID) { + obj.onJCLocalUUID(this.localUUID); + } + if (this.nickName && obj.onJCNickName) { + obj.onJCNickName(this.nickName); + } + if (this._userinfo && obj.onJCUserInfo) { + obj.onJCUserInfo(this._userinfo); + } + if (this.fromID && obj.onJCLaunchInfo) { + obj.onJCLaunchInfo(this.scene, this.fromID, this.lauchparam); + } + }, + + _handleInit(channelid, gameid, isoffical) { + this._handlers.forEach(element => { + if (element.onJCInit) { + element.onJCInit(channelid, gameid, isoffical); + } + }); + }, + + _handleAccountID(accountid, sessionid, exobj) { + this._handlers.forEach(element => { + if (element.onJCAccountID) { + element.onJCAccountID(accountid, sessionid, exobj); + } + }); + }, + + _handleLocalID(localuuid) { + this._handlers.forEach(element => { + if (element.onJCLocalUUID) { + element.onJCLocalUUID(localuuid); + } + }); + }, + + _handleNickName(nickname) { + this._handlers.forEach(element => { + if (element.onJCNickName) { + element.onJCNickName(nickname); + } + }); + }, + + _handleUserInfo(userinfo) { + this._handlers.forEach(element => { + if (element.onJCUserInfo) { + element.onJCUserInfo(userinfo); + } + }); + }, + + _handleLauchInfo(lauchscene, lauchfromid, launchparam) { + this._handlers.forEach(element => { + if (element.onJCLaunchInfo) { + element.onJCLaunchInfo(lauchscene, lauchfromid, launchparam); + } + }); + }, + + _handleServerTime(servertime, localtime) { + this._handlers.forEach(element => { + if (element.onJCServerTime) { + element.onJCServerTime(servertime, localtime); + } + }); + }, + + _handleGameStart(startmode, extparam) { + this._handlers.forEach(element => { + if (element.onJCGameStart) { + element.onJCGameStart(startmode, extparam); + } + }); + }, + + _handleGameOver(score, bsuccess, extparam) { + this._handlers.forEach(element => { + if (element.onJCGameOver) { + element.onJCGameOver(score, bsuccess, extparam); + } + }); + }, + + _handleGameShow(showinfo) { + this._handlers.forEach(element => { + if (element.onJCGameShow) { + element.onJCGameShow(showinfo); + } + }); + }, + + _handGameHide(hideinfo) { + this._handlers.forEach(element => { + if (element.onJCGameHide) { + element.onJCGameHide(hideinfo); + } + }); + }, + + _handleNotifyMsgs(lst, notifyobj) { + this._handlers.forEach(element => { + if (element.onJCNotifyMsg) { + element.onJCNotifyMsg(lst, notifyobj); + } + }); + }, + + _checkListener() { + if (!this._listenerID) { + this._listenerID = notification.on(_GAME_INFO_HANDLER_BINDING, (msgid, handler) => { + this.addHandler(handler); + }, this); + } + if (!this._unlistenerID) { + this._unlistenerID = notification.on(_GAME_INFO_HANDLER_UNBINDING, (msgid, handler) => { + this.delHandler(handler); + }, this); + } + }, + + _fixChannelID() { + + } +}; + + +module.exports = JCFW; diff --git a/src/jcfw/service/jcshare.js b/src/jcfw/service/jcshare.js index c224ac3..4821433 100755 --- a/src/jcfw/service/jcshare.js +++ b/src/jcfw/service/jcshare.js @@ -2,542 +2,546 @@ var httpclient = require('../common/httpclient'); var urlbuilder = require('../common/urlbuilder'); module.exports = { - // LIFE-CYCLE CALLBACKS: + // LIFE-CYCLE CALLBACKS: - // onLoad () {}, + // onLoad () {}, - // start () {}, + // start () {}, - // update (dt) {}, + // update (dt) {}, - init(channelid, gameid, isoffical, owner, url){ - this.owner = owner; - this.gameid = gameid; - this.channelid = channelid; - this.urlbd = new urlbuilder(url); - //console.log("[jcshare]init:"+gameid + "|" + channelid + "|" + isoffical); - }, + init(channelid, gameid, isoffical, owner, url) { + this.owner = owner; + this.gameid = gameid; + this.channelid = channelid; + this.urlbd = new urlbuilder(url); + //console.log("[jcshare]init:"+gameid + "|" + channelid + "|" + isoffical); + }, - setAccountID(accountid, sessionid){ - this.accountid = accountid; - this.sessionid = sessionid; - }, + setAccountID(accountid, sessionid) { + this.accountid = accountid; + this.sessionid = sessionid; + }, - setNickName(nickname){ - this.nickname = nickname; - }, + setNickName(nickname) { + this.nickname = nickname; + }, - setFromAppID(appid){ - this.fromid = appid; - }, + setFromAppID(appid) { + this.fromid = appid; + }, - setLocalUUID(uuid){ - this.localid = uuid; - }, + setLocalUUID(uuid) { + this.localid = uuid; + }, - setSystemInfo(info){ + setSystemInfo(info) { - }, - - setUserInfo(info){ - this.sex = info.sex; - this.avatar_url = info.avatar_url; - }, + }, - /** - * 接受邀请(分级时用,大部分时候不用此接口) - * @param {string} actionid 业务号 - * @param {string} inviterid 邀请方账号id - * @param {object} successcb 成功回调(以下该名称都是此功能) - * @param {object} failcb 失败回调(以下该名称都是此功能) - */ - acceptInvite(actionid, inviterid, successcb, failcb){ - if(!actionid){ - return; - } - let sid = inviterid? inviterid: ""; - this.urlbd.clear(); - this.urlbd.addKV('c', 'Fission') - .addKV('a', 'accept') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('business_no', actionid) - .addKV('inviter_id', sid) - .addKV('nickname', this.nickname) - .addKV('sex', this.sex) - .addKV('avatar_url', this.avatar_url) - ; + setUserInfo(info) { + this.sex = info.sex; + this.avatar_url = info.avatar_url; + }, - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0 || obj.errcode == 1 || obj.errcode == 2){ - //console.log('[acceptInvite]success!'+JSON.stringify(obj)); - successcb && successcb(); - }else{ - //console.log('[acceptInvite]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[acceptInvite]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); + /** + * 接受邀请(分级时用,大部分时候不用此接口) + * @param {string} actionid 业务号 + * @param {string} inviterid 邀请方账号id + * @param {object} successcb 成功回调(以下该名称都是此功能) + * @param {object} failcb 失败回调(以下该名称都是此功能) + */ + acceptInvite(actionid, inviterid, successcb, failcb) { + if (!actionid) { + return; + } + let sid = inviterid ? inviterid : ''; + this.urlbd.clear(); + this.urlbd.addKV('c', 'Fission') + .addKV('a', 'accept') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('business_no', actionid) + .addKV('inviter_id', sid) + .addKV('nickname', this.nickname) + .addKV('sex', this.sex) + .addKV('avatar_url', this.avatar_url) + ; + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0 || obj.errcode == 1 || obj.errcode == 2) { + //console.log('[acceptInvite]success!'+JSON.stringify(obj)); + successcb && successcb(); + } else { + //console.log('[acceptInvite]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[acceptInvite]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 查询子节点数据(分级时用,大部分时候不用此接口) + * @param {string} actionid 业务号 + * @param {object} successcb + * @param {object} failcb + */ + queryShareStat(actionid, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'Fission') + .addKV('a', 'getChild') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('business_no', actionid); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryShareStat]success!'+JSON.stringify(obj)); + successcb && successcb(obj.nodes); + } else { + //console.log('[queryShareStat]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryShareStat]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 查询接受邀请人的详细信息(分级时用,大部分时候不用此接口) + * @param {string} actionid 业务号 + * @param {object} successcb + * @param {object} failcb + */ + queryShareDetail(actionid, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'Fission') + .addKV('a', 'getFriendsDetail') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('business_no', actionid); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryShareDetail]success!'+JSON.stringify(obj)); + successcb && successcb(obj.nodes); + } else { + //console.log('[queryShareDetail]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryShareDetail]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 每日任务的接受邀请【使用jcfw的话无需主动调用】 + * @param {string} actionid 任务id + * @param {string} inviterid 邀请方账号id + * @param {object} successcb + * @param {object} failcb + */ + acceptDailyInvite(actionid, inviterid, successcb, failcb) { + let sid = inviterid ? inviterid : ''; + this.urlbd.clear(); + this.urlbd.addKV('c', 'DailyMission') + .addKV('a', 'acceptInvite') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('inviter_id', sid) + .addKV('activity_param', actionid) + .addKV('nickname', this.nickname) + .addKV('sex', this.sex) + .addKV('avatar_url', this.avatar_url) + ; + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0 || obj.errcode == 1) { + //console.log('[acceptDailyInvite]success!'+JSON.stringify(obj)); + successcb && successcb(); + } else { + //console.log('[acceptDailyInvite]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[acceptDailyInvite]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 每日任务的查询接受邀请的人数 + * @param {string} actionid 业务号 + * @param {object} successcb + * @param {object} failcb + */ + queryDailyShareStat(actionid, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'DailyMission') + .addKV('a', 'getInviteeNum') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('activity_param', actionid); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryDailyShareStat]success!'+JSON.stringify(obj)); + successcb && successcb(obj); + } else { + //console.log('[queryDailyShareStat]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryDailyShareStat]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 每日任务的查询接受邀请人的详细信息 + * @param {string} actionid 业务号 + * @param {object} successcb + * @param {object} failcb + */ + queryDailyShareDetail(actionid, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'DailyMission') + .addKV('a', 'getInviteeList') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('activity_param', actionid); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryDailyShareDetail]success!'+JSON.stringify(obj)); + successcb && successcb(obj.invitee_list); + } else { + //console.log('[queryDailyShareDetail]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryDailyShareDetail]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 上报游戏分数,获取兑换码 + * @param {string} score 分数 + * @param {object} successcb + * @param {object} failcb + */ + queryActionCode(score, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'Exchange') + .addKV('a', 'reportScore') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('score', score); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryActionCode]success!'+JSON.stringify(obj)); + successcb && successcb(obj.exchange_code); + } else { + //console.log('[queryActionCode]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryActionCode]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 接力活动的接受邀请 + * @param {string} actionid 任务id + * @param {string} inviterid 邀请方账号id + * @param {object} successcb + * @param {object} failcb + */ + acceptRelayInvite(actionid, inviterid, successcb, failcb) { + let sid = inviterid ? inviterid : ''; + this.urlbd.clear(); + this.urlbd.addKV('c', 'Relay') + .addKV('a', 'acceptInvite') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('inviter_id', sid) + .addKV('activity_param', actionid) + .addKV('nickname', this.nickname) + .addKV('sex', this.sex) + .addKV('avatar_url', this.avatar_url) + ; + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0 || obj.errcode == 1) { + //console.log('[acceptRelayInvite]success!'+JSON.stringify(obj)); + successcb && successcb(); + } else { + //console.log('[acceptRelayInvite]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[acceptRelayInvite]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 接力活动的查询接受邀请的人数 + * @param {string} actionid 业务号 + * @param {object} successcb + * @param {object} failcb + */ + queryRelayShareStat(actionid, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'Relay') + .addKV('a', 'getInviteeNum') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('activity_param', actionid); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryRelayShareStat]success!'+JSON.stringify(obj)); + successcb && successcb(obj); + } else { + //console.log('[queryRelayShareStat]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryRelayShareStat]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 成就的接受邀请 + * @param {Array} relationidlst 有关联的成就id列表,格式如下:[[1001,3], [1002,3], [1003,3]] + * @param {string} inviterid 邀请方账号id + * @param {object} successcb + * @param {object} failcb + */ + acceptAchivementInvite(relationidlst, inviterid, successcb, failcb) { + let sid = inviterid ? inviterid : ''; + this.urlbd.clear(); + this.urlbd.addKV('c', 'AchievementShare') + .addKV('a', 'acceptInvite') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('inviter_id', sid) + .addKV('relate_achivements', JSON.stringify(relationidlst)) + .addKV('nickname', this.nickname) + .addKV('sex', this.sex) + .addKV('avatar_url', this.avatar_url) + ; + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0 || obj.errcode == 1) { + //console.log('[acceptAchivementInvite]success!'+JSON.stringify(obj)); + successcb && successcb(); + } else { + //console.log('[acceptAchivementInvite]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[acceptAchivementInvite]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 成就的查询接受邀请的人数 + * @param {Array} actionidlst 成就id列表,格式如下:[1001,1002,1003] + * @param {object} successcb + * @param {object} failcb + */ + queryAchievementShareStat(actionidlst, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'AchievementShare') + .addKV('a', 'getInviteeNum') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('achievement_ids', actionidlst.join()); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[queryAchievementShareStat]success!'+JSON.stringify(obj)); + successcb && successcb(obj); + } else { + //console.log('[queryAchievementShareStat]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryAchievementShareStat]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 成就的查询接受邀请的详细信息 + * @param {Array} actionidlst 成就id列表,格式如下:[1001,1002,1003] + * @param {object} successcb + * @param {object} failcb + */ + queryAchievementShareDetail(actionidlst, successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'AchievementShare') + .addKV('a', 'getInviteeList') + .addKV('session_id', this.sessionid) + .addKV('account_id', this.accountid) + .addKV('achievement_ids', actionidlst.join()); + + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj && obj.errcode == 0) { + //console.log('[queryAchievementShareDetail]success!'+JSON.stringify(obj)); + successcb && successcb(obj.invitee_list); + } else { + //console.log('[queryAchievementShareDetail]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[queryAchievementShareDetail]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + }, + + /** + * 普通分享 + * @param {string} content 分享显示的标题 + * @param {string} imgurl 分享显示的图片 + * @param {int} sharetype 分享类型(每日活动/成就/接力) + * @param {string} shareparam 分享类型相关参数(活动id/成就id等) + * @param {string} extrainfo 分享额外参数(key/value格式的字符串:eg: 'inviter_name=***&inviter_sex=***' + * @param {object} successcb + * @param {object} failcb + */ + shareNormal(content, imgurl, sharetype, shareparam, extrainfo, successcb, failcb) { + let uuid = this.owner ? this.owner.makeUUID() : ''; + let qstr = 'inviter_id=' + this.accountid + '&activity_param=' + + shareparam + '&localuuid=' + uuid + '&sharetype=' + sharetype; + if (extrainfo) { + qstr += '&'; + qstr += extrainfo; + } + + switch (this.channelid) { + case 6001: { + wx.shareAppMessage({ + title: content, + imageUrl: imgurl, + query: qstr }); - }, + this.owner && this.owner.gamelog.logShare(sharetype, uuid, shareparam); + successcb && successcb(); + } + break; + case 6002: { - /** - * 查询子节点数据(分级时用,大部分时候不用此接口) - * @param {string} actionid 业务号 - * @param {object} successcb - * @param {object} failcb - */ - queryShareStat(actionid, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'Fission') - .addKV('a', 'getChild') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('business_no', actionid); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryShareStat]success!'+JSON.stringify(obj)); - successcb && successcb(obj.nodes); - }else{ - //console.log('[queryShareStat]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryShareStat]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 查询接受邀请人的详细信息(分级时用,大部分时候不用此接口) - * @param {string} actionid 业务号 - * @param {object} successcb - * @param {object} failcb - */ - queryShareDetail(actionid, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'Fission') - .addKV('a', 'getFriendsDetail') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('business_no', actionid); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryShareDetail]success!'+JSON.stringify(obj)); - successcb && successcb(obj.nodes); - }else{ - //console.log('[queryShareDetail]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryShareDetail]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 每日任务的接受邀请【使用jcfw的话无需主动调用】 - * @param {string} actionid 任务id - * @param {string} inviterid 邀请方账号id - * @param {object} successcb - * @param {object} failcb - */ - acceptDailyInvite(actionid, inviterid, successcb, failcb){ - let sid = inviterid? inviterid: ""; - this.urlbd.clear(); - this.urlbd.addKV('c', 'DailyMission') - .addKV('a', 'acceptInvite') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('inviter_id', sid) - .addKV('activity_param', actionid) - .addKV('nickname', this.nickname) - .addKV('sex', this.sex) - .addKV('avatar_url', this.avatar_url) - ; - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0 || obj.errcode == 1){ - //console.log('[acceptDailyInvite]success!'+JSON.stringify(obj)); - successcb && successcb(); - }else{ - //console.log('[acceptDailyInvite]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[acceptDailyInvite]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 每日任务的查询接受邀请的人数 - * @param {string} actionid 业务号 - * @param {object} successcb - * @param {object} failcb - */ - queryDailyShareStat(actionid, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'DailyMission') - .addKV('a', 'getInviteeNum') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('activity_param', actionid); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryDailyShareStat]success!'+JSON.stringify(obj)); - successcb && successcb(obj); - }else{ - //console.log('[queryDailyShareStat]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryDailyShareStat]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 每日任务的查询接受邀请人的详细信息 - * @param {string} actionid 业务号 - * @param {object} successcb - * @param {object} failcb - */ - queryDailyShareDetail(actionid, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'DailyMission') - .addKV('a', 'getInviteeList') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('activity_param', actionid); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryDailyShareDetail]success!'+JSON.stringify(obj)); - successcb && successcb(obj.invitee_list); - }else{ - //console.log('[queryDailyShareDetail]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryDailyShareDetail]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 上报游戏分数,获取兑换码 - * @param {string} score 分数 - * @param {object} successcb - * @param {object} failcb - */ - queryActionCode(score, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'Exchange') - .addKV('a', 'reportScore') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('score', score); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryActionCode]success!'+JSON.stringify(obj)); - successcb && successcb(obj.exchange_code); - }else{ - //console.log('[queryActionCode]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryActionCode]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 接力活动的接受邀请 - * @param {string} actionid 任务id - * @param {string} inviterid 邀请方账号id - * @param {object} successcb - * @param {object} failcb - */ - acceptRelayInvite(actionid, inviterid, successcb, failcb){ - let sid = inviterid? inviterid: ""; - this.urlbd.clear(); - this.urlbd.addKV('c', 'Relay') - .addKV('a', 'acceptInvite') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('inviter_id', sid) - .addKV('activity_param', actionid) - .addKV('nickname', this.nickname) - .addKV('sex', this.sex) - .addKV('avatar_url', this.avatar_url) - ; - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0 || obj.errcode == 1){ - //console.log('[acceptRelayInvite]success!'+JSON.stringify(obj)); - successcb && successcb(); - }else{ - //console.log('[acceptRelayInvite]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[acceptRelayInvite]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 接力活动的查询接受邀请的人数 - * @param {string} actionid 业务号 - * @param {object} successcb - * @param {object} failcb - */ - queryRelayShareStat(actionid, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'Relay') - .addKV('a', 'getInviteeNum') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('activity_param', actionid); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryRelayShareStat]success!'+JSON.stringify(obj)); - successcb && successcb(obj); - }else{ - //console.log('[queryRelayShareStat]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryRelayShareStat]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 成就的接受邀请 - * @param {Array} relationidlst 有关联的成就id列表,格式如下:[[1001,3], [1002,3], [1003,3]] - * @param {string} inviterid 邀请方账号id - * @param {object} successcb - * @param {object} failcb - */ - acceptAchivementInvite(relationidlst, inviterid, successcb, failcb){ - let sid = inviterid? inviterid: ""; - this.urlbd.clear(); - this.urlbd.addKV('c', 'AchievementShare') - .addKV('a', 'acceptInvite') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('inviter_id', sid) - .addKV('relate_achivements', JSON.stringify(relationidlst)) - .addKV('nickname', this.nickname) - .addKV('sex', this.sex) - .addKV('avatar_url', this.avatar_url) - ; - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0 || obj.errcode == 1){ - //console.log('[acceptAchivementInvite]success!'+JSON.stringify(obj)); - successcb && successcb(); - }else{ - //console.log('[acceptAchivementInvite]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[acceptAchivementInvite]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 成就的查询接受邀请的人数 - * @param {Array} actionidlst 成就id列表,格式如下:[1001,1002,1003] - * @param {object} successcb - * @param {object} failcb - */ - queryAchievementShareStat(actionidlst, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'AchievementShare') - .addKV('a', 'getInviteeNum') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('achievement_ids', actionidlst.join()); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[queryAchievementShareStat]success!'+JSON.stringify(obj)); - successcb && successcb(obj); - }else{ - //console.log('[queryAchievementShareStat]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryAchievementShareStat]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - - /** - * 成就的查询接受邀请的详细信息 - * @param {Array} actionidlst 成就id列表,格式如下:[1001,1002,1003] - * @param {object} successcb - * @param {object} failcb - */ - queryAchievementShareDetail(actionidlst, successcb, failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'AchievementShare') - .addKV('a', 'getInviteeList') - .addKV('session_id', this.sessionid) - .addKV('account_id', this.accountid) - .addKV('achievement_ids', actionidlst.join()); - - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj && obj.errcode == 0){ - //console.log('[queryAchievementShareDetail]success!'+JSON.stringify(obj)); - successcb && successcb(obj.invitee_list); - }else{ - //console.log('[queryAchievementShareDetail]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[queryAchievementShareDetail]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); - }); - }, - }; - - /** - * 普通分享 - * @param {string} content 分享显示的标题 - * @param {string} imgurl 分享显示的图片 - * @param {int} sharetype 分享类型(每日活动/成就/接力) - * @param {string} shareparam 分享类型相关参数(活动id/成就id等) - * @param {string} extrainfo 分享额外参数(key/value格式的字符串:eg: 'inviter_name=***&inviter_sex=***' - * @param {object} successcb - * @param {object} failcb - */ - shareNormal(content, imgurl, sharetype, shareparam, extrainfo, successcb, failcb){ - let uuid = this.owner? this.owner.makeUUID(): ''; - let qstr = "inviter_id="+ this.accountid + "&activity_param=" - + shareparam + '&localuuid=' + uuid + '&sharetype=' + sharetype; - if(extrainfo){ - qstr += '&'; - qstr += extrainfo; - } - - switch(this.channelid){ - case 6001:{ - wx.shareAppMessage({ - title: content, - imageUrl: imgurl, - query: qstr - }); - this.owner && this.owner.gamelog.logShare(sharetype, uuid, shareparam); - successcb && successcb(); - }break; - case 6002:{ - - }break; - } - }, + } + break; + } + } + , - shareCapture(content, rc, sharetype, shareparam, extrainfo, successcb, failcb){ - let uuid = this.owner? this.owner.makeUUID(): ''; - let qstr = "inviter_id="+ this.accountid + "&activity_param=" - + shareparam + '&localuuid=' + uuid + '&sharetype=' + sharetype; - if(extrainfo){ - qstr += '&'; - qstr += extrainfo; - } - switch(this.channelid){ - case 6001:{ - let surl = canvas.toTempFilePathSync({ - x: rc.x, - y: rc.y, - width: rc.width, - height: rc.height, - destWidth: 500, - destHeight: 400, - }); - - wx.shareAppMessage({ - title: content, - imageUrl: surl, - query: qstr - }); - this.owner && this.owner.gamelog.logShare(sharetype, uuid, shareparam); - successcb && successcb(); - }break; - case 6002:{ - - }break; - } - }, - - acceptAchievementInvite(inviter_id,achievement_id,relate_achivements){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'AchievementShare') - .addKV('a', 'acceptInvite') - .addKV('account_id', this.accountid) - .addKV('session_id', this.sessionid) - .addKV('inviter_id', inviter_id); - if(relate_achivements){ - this.urlbd.addKV('relate_achivements', relate_achivements); - } - else{ - this.urlbd.addKV('achievement_id', Number(achievement_id)); - } - //console.log(this.urlbd.baseurl); - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[acceptAchievementInvite]success!'+JSON.stringify(obj)); - }else{ - //console.log('[acceptAchievementInvite]failed!'+obj.errcode+":"+obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[acceptAchievementInvite]failed!'+errcode+":"+errmsg); - }); - }, - getAchievInviteeNum(successcb,failcb){ - this.urlbd.clear(); - this.urlbd.addKV('c', 'AchievementShare') - .addKV('a', 'getInviteeNum') - .addKV('account_id', this.accountid) - .addKV('session_id', this.sessionid) - // .addKV('achievement_ids', achievement_ids) - httpclient.httpGet(this.urlbd.baseurl, function(restext){ - var obj = JSON.parse(restext); - if(obj.errcode == 0){ - //console.log('[getAchievInviteeNum]success!'+JSON.stringify(obj)); - successcb && successcb(obj.invitee_nums); - }else{ - //console.log('[getAchievInviteeNum]failed!'+obj.errcode+":"+obj.errmsg); - failcb && failcb(0, obj.errcode, obj.errmsg); - } - }, function(errcode, errmsg){ - //console.log('[getAchievInviteeNum]failed!'+errcode+":"+errmsg); - failcb && failcb(errcode, 0, errmsg); + shareCapture(content, rc, sharetype, shareparam, extrainfo, successcb, failcb) { + let uuid = this.owner ? this.owner.makeUUID() : ''; + let qstr = 'inviter_id=' + this.accountid + '&activity_param=' + + shareparam + '&localuuid=' + uuid + '&sharetype=' + sharetype; + if (extrainfo) { + qstr += '&'; + qstr += extrainfo; + } + switch (this.channelid) { + case 6001: { + let surl = canvas.toTempFilePathSync({ + x: rc.x, + y: rc.y, + width: rc.width, + height: rc.height, + destWidth: 500, + destHeight: 400 }); - }, -}; + wx.shareAppMessage({ + title: content, + imageUrl: surl, + query: qstr + }); + this.owner && this.owner.gamelog.logShare(sharetype, uuid, shareparam); + successcb && successcb(); + } + break; + case 6002: { + + } + break; + } + }, + + acceptAchievementInvite(inviter_id, achievement_id, relate_achivements) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'AchievementShare') + .addKV('a', 'acceptInvite') + .addKV('account_id', this.accountid) + .addKV('session_id', this.sessionid) + .addKV('inviter_id', inviter_id); + if (relate_achivements) { + this.urlbd.addKV('relate_achivements', relate_achivements); + } else { + this.urlbd.addKV('achievement_id', Number(achievement_id)); + } + //console.log(this.urlbd.baseurl); + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[acceptAchievementInvite]success!'+JSON.stringify(obj)); + } else { + //console.log('[acceptAchievementInvite]failed!'+obj.errcode+":"+obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[acceptAchievementInvite]failed!'+errcode+":"+errmsg); + }); + }, + getAchievInviteeNum(successcb, failcb) { + this.urlbd.clear(); + this.urlbd.addKV('c', 'AchievementShare') + .addKV('a', 'getInviteeNum') + .addKV('account_id', this.accountid) + .addKV('session_id', this.sessionid); + // .addKV('achievement_ids', achievement_ids) + httpclient.httpGet(this.urlbd.baseurl, function(restext) { + var obj = JSON.parse(restext); + if (obj.errcode == 0) { + //console.log('[getAchievInviteeNum]success!'+JSON.stringify(obj)); + successcb && successcb(obj.invitee_nums); + } else { + //console.log('[getAchievInviteeNum]failed!'+obj.errcode+":"+obj.errmsg); + failcb && failcb(0, obj.errcode, obj.errmsg); + } + }, function(errcode, errmsg) { + //console.log('[getAchievInviteeNum]failed!'+errcode+":"+errmsg); + failcb && failcb(errcode, 0, errmsg); + }); + + } + +} diff --git a/src/mixins/base.js b/src/mixins/base.js index b4a9f30..1348b90 100644 --- a/src/mixins/base.js +++ b/src/mixins/base.js @@ -1,5 +1,4 @@ import wepy from 'wepy' - export default class baseMixin extends wepy.mixin { /** * [公共方法] @@ -170,4 +169,15 @@ export default class baseMixin extends wepy.mixin { console.log(info); return (info.platform && (/^ios/.test(info.platform.toLowerCase()) || /^devtools/.test(info.platform.toLowerCase()))); } + jcLog(t, e, n) { + try { + n = n || 'debug'; + e = e || n.toUpperCase(); + const i = 'error' === n ? 'background: #c4161e; color: #fff' : 'warning' === n ? 'background: #ff8c1c; color: #fff' : 'info' === n ? 'background: #ff0080; color: #fff' : 'background: #44a5ab; color: #fff', + r = console.log('%c %c %c ==JCLOGGER== %c %c %c ' + e + ' ', 'background: #9854d8', 'background: #6c2ca7', 'color: #fff; background: #450f78;', 'background: #6c2ca7', 'background: #9854d8', i, void 0 !== t ? t : ''); + return console.log.bind(console, r); + } catch (e) { + return console.log(e); + } + } } diff --git a/src/pages/index.wpy b/src/pages/index.wpy index 2c89b02..5f9adff 100644 --- a/src/pages/index.wpy +++ b/src/pages/index.wpy @@ -43,15 +43,15 @@ import wepy from 'wepy'; import Toast from 'wepy-com-toast'; import http from '../utils/http'; - import base from '../mixins/base'; - import tips from '../mixins/tips'; - import cfg from '../mixins/cfg'; import recordCell from '../components/game-cell'; import recentGame from '../components/recent-game'; import zanLoadmore from '../components/zan-loadmore'; import jcEvent from '../common/jc-event'; import image from '../common/images'; import global from '../common/global'; + import base from '../mixins/base'; + import tips from '../mixins/tips'; + import cfg from '../mixins/cfg'; export default class Index extends wepy.page { mixins = [base, tips, cfg]; @@ -104,7 +104,6 @@ }) } }; - onPullDownRefresh() { this.initPageParam(); this.getAllData(); @@ -123,6 +122,9 @@ async onLoad(options) { let self = this; + wepy.showShareMenu({ + withShareTicket: true + }); this.payVer = global.env === 'product' ? 'release' : 'develop'; if (!this.$parent.checkClientLogin()) { this.getAllData(); @@ -203,7 +205,9 @@ if (!cfg._getrewardtype) { wepy.hideShareMenu(); } else { - wepy.showShareMenu(); + wepy.showShareMenu({ + withShareTicket: true + }); } this.showAll = this.$showAll(); let userInfo = this.$parent.getUserInfo(); @@ -248,7 +252,7 @@ async getUserInfo() { try { let res = await http.post('/api/emulated/user_info', {type: 'all'}); - console.log(res); + this.debugLog(res); if (res.userInfo) { let user = res.userInfo; this.score = user.score; @@ -301,7 +305,7 @@ self.noData = (self.records.length === 0); self.$apply(); } else { - console.log('get game data error'); + this.debugLog('get game data error'); self.loading = false } } catch (error) { @@ -325,7 +329,7 @@ shareTicket: res.shareTickets[0] }) .then(res => { - console.log(res); + this.debugLog(res); }) .catch(err => { console.log(err) diff --git a/src/pages/login.wpy b/src/pages/login.wpy index 0508ded..6b8e246 100644 --- a/src/pages/login.wpy +++ b/src/pages/login.wpy @@ -18,11 +18,15 @@