From fabe8249bc9003c4f8fd40a2f064ce46b0ef58e7 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 2 Apr 2020 14:28:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=96=AF=E7=8B=82=E6=B8=B8?= =?UTF-8?q?=E4=B9=90=E5=9C=BA=E5=92=8C=E7=88=B1=E5=BE=AE=E6=B8=B8=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jcfw/platform/plat.js | 232 +++++++++++++++++++------------- jcfw/platform/plat_crazygame.js | 2 + jcfw/platform/plat_iwei.js | 143 ++++++-------------- 3 files changed, 180 insertions(+), 197 deletions(-) diff --git a/jcfw/platform/plat.js b/jcfw/platform/plat.js index d2bbddd..2475f08 100644 --- a/jcfw/platform/plat.js +++ b/jcfw/platform/plat.js @@ -1,28 +1,37 @@ -var PLAT_HUAWEI = { +var getParameter = function(t) { + var e = window.location.search, + i = new RegExp(t + "=([^&?]*)", "ig"); + return e.match(i) ? e.match(i)[0].substr(t.length + 1) : null +} +var PLAT_IWEI = { SHARE_FAIL: 25, SHARE_TIME: 3000, - appid: '', shareCount: {}, - getSystemInfoAsync(successcb, failcb) { - hbs.getSystemInfo({ - success : function (res) { - console.log("getSystemInfo success res = " + res.brand); - successcb && successcb(res); - }, - fail:function(){ - console.log("getSystemInfo fail"); - failcb && failcb(); - } - }); + getLaunchInfo() { + return null; }, + getSystemInfo() { + return null; + }, + /** example: + * + * @param {object} btninfo : + * { + * width: 100, + * height: 100, + * name: logo.png + * } + * @param {function} cb + */ getUserInfo(btninfo, cb) { - cb && cb(null, -1000); + }, destoryAuth() { + }, setUserInfo(dstinfo, ptinfo) { @@ -35,13 +44,28 @@ var PLAT_HUAWEI = { }, setTokenInfo(dstinfo, tokeninfo) { - + if (tokeninfo && tokeninfo.rawData) { + dstinfo.rawData = tokeninfo.rawData; + dstinfo.signature = tokeninfo.signature; + dstinfo.encryptedData = tokeninfo.encryptedData; + dstinfo.iv = tokeninfo.iv; + } }, - init(owner, channelid, appid) { + init(owner, channelid, appId) { this._owner = owner; this._ptid = channelid; - this.appid = appid; + this._platGameId = appId; + this.sdk = window['AWY_SDK']; + var isSubscribe = getParameter('is_subscribe') || '0'; + this.isSubscribe = parseInt(isSubscribe); + var isChid = getParameter('chid') || '0'; + this.isChid = parseInt(isChid); + this.sdk.config(this._platGameId, function () { + console.log('iwei game init'); + }, function () { + + }); }, bindController(ctrl) { @@ -49,7 +73,9 @@ var PLAT_HUAWEI = { }, commonShare(aimg, atitle, stype, param, successcb, failcb, exinfo) { + var st = (new Date()).getTime(); let sp = this._owner.makeShareParam(stype, param, exinfo); + let uuid = this._owner.currUUID(); let img = aimg; if (!img && this._exshareinfo) { img = this._exshareinfo.imgurl; @@ -58,7 +84,8 @@ var PLAT_HUAWEI = { if (!title && this._exshareinfo) { title = this._exshareinfo.title; } - this.PTShare(title, img, sp, successcb, failcb); + this.PTShare(title, img, sp); + this._checkShareRes(st, stype, sp, uuid, successcb, failcb); }, captureShare(rc, title, stype, param, successcb, failcb, exinfo) { @@ -67,30 +94,72 @@ var PLAT_HUAWEI = { let uuid = this._owner.currUUID(); this.PTShareCapture(title, rc, sp); + this._checkShareRes(st, stype, sp, uuid, successcb, failcb); + }, + + _checkShareRes(starttime, sharetype, param, tokenid, successcb, failcb) { + if (!this._man) { + try { + failcb && failcb(-100, param, tokenid); + } catch (err) { + + } + return; + } + this._man.scheduleOnce(() => { + let dt = (new Date()).getTime() - starttime; + console.log(dt); + + if (this.shareCount[sharetype] == undefined) { + this.shareCount[sharetype] = false; + } + if (this.shareCount[sharetype] == false && Math.random() * 100 > this.SHARE_FAIL) { + this.shareCount[sharetype] = true; + try { + failcb && failcb(-1, param, tokenid, dt); + } catch (err) { + + } + return; + } + + if (dt > this.SHARE_TIME) { + try { + successcb && successcb(param, tokenid, dt); + } catch (err) { + + } + } else { + try { + failcb && failcb(-2, param, tokenid, dt); + } catch (err) { + + } + } + }, 0.5); }, PTInitShare(normalinfo) { - + if (!normalinfo) { + return; + } + if (!this._exshareinfo) { + this._exshareinfo = normalinfo; + } else { + if (normalinfo.title && this._exshareinfo.title != normalinfo.title) { + this._exshareinfo.title = normalinfo.title; + } + if (normalinfo.imgurl && this._exshareinfo.imgurl != normalinfo.imgurl) { + this._exshareinfo.imgurl = normalinfo.imgurl; + } + } + this.sdk.shareTitle(this._exshareinfo.title); + this.sdk.shareDesc(this._exshareinfo.title); + this.sdk.shareIcon(this._exshareinfo.imgurl); }, PTShare(content, imgurl, param, successcb, failcb) { - hbs.systemShare({ - type: 'text/html', - data: content, - success:function(){ - successcb && successcb(); - }, - fail:function(erromsg, errorcode){ - console.log('share fail --- ' + errorcode + ':' + erromsg) - failcb && failcb(-3, param); - }, - cancel:function(data){ - console.log("share cancel:" + data) - failcb && failcb(-3, param); - }, - complete:function(){console.log('share complete')} - }); - + successcb && successcb(); }, PTShareCapture(content, rc, param, successcb, failcb) { @@ -98,10 +167,11 @@ var PLAT_HUAWEI = { }, PTOpenKF(cb, info) { + }, PTCreateGameClubButton(nleft, ntop, nwidth) { - return null; + }, /** * @param {string} str 显示的文字 @@ -111,10 +181,6 @@ var PLAT_HUAWEI = { * none: 不显示图标,此时 title 文本最多可显示两行 * */ PTShowToast(str, icon) { - hbs.showToast({ - title: str, - icon: 'none' - }); }, PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) { @@ -123,20 +189,28 @@ var PLAT_HUAWEI = { PTLogin(info, successcb, failcb) { var self = this; - hbs.gameLogin({ - forceLogin: 1, - appid: this.appid, - success: function (res) { - console.log('[hbs]hbs login success'); - self._owner.login.login({token: res.playerId, successcb, failcb}); - }, - fail: function (res) { - console.log('[hbs]login fail!', res); - failcb && failcb(0, res ? res.errcode : -1, res ? res.data : ''); - } + var token = getParameter('token'); + if (!token) { + return failcb && failcb(0, -1, '未找到有效的token'); + } + self._owner.login.login({ + token: token, + successcb, failcb }); }, + PTSetClipboardData: function (content, successcb, failcb) { + + }, + + PTGetClipboardData: function (successcb, failcb) { + + }, + + PTPreviewImage(imgurl, successcb, failcb) { + + }, + //广告相关 PTInitADService() { @@ -159,25 +233,11 @@ var PLAT_HUAWEI = { }, PTVibrateShort(successcb, failcb) { - hbs.vibrateShort({ - success: () => { - successcb && successcb(); - }, - fail: () => { - failcb && failcb(); - } - }) + }, PTVibrateLong(successcb, failcb) { - hbs.vibrateLong({ - success: () => { - successcb && successcb(); - }, - fail: () => { - failcb && failcb(); - } - }) + }, /** @@ -188,53 +248,31 @@ var PLAT_HUAWEI = { }, PTPostOpenMsg(msg) { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage(msg); + }, // 排行榜相关 saveRankData(nscore, nmoney, stitle) { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage({ - type: 'save_data', - score: nscore, - money: nmoney, - title: stitle - }); + }, showRankData() { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage({ - type: 'friends_all' - }); + }, hideRankData() { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage({ - type: 'friends_all_hide' - }); + }, prevRankPage() { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage({ - type: 'pagechange', - prev: 1 - }); + }, nextRankPage() { - const openDataContext = this.PTOpenDataContext(); - openDataContext && openDataContext.postMessage({ - type: 'pagechange', - next: 1 - }); + }, PTADWatch(adid, successcb, failcb) { - failcb && failcb(adid, {}, true, adid); }, setLocalStorage(key, value) { @@ -258,4 +296,4 @@ var PLAT_HUAWEI = { } }; -module.exports = PLAT_HUAWEI; +module.exports = PLAT_IWEI; diff --git a/jcfw/platform/plat_crazygame.js b/jcfw/platform/plat_crazygame.js index 4dc82a5..9296931 100644 --- a/jcfw/platform/plat_crazygame.js +++ b/jcfw/platform/plat_crazygame.js @@ -57,6 +57,8 @@ var PLAT_CRAZY = { this._ptid = channelid; this._platGameId = appId; this.sdk = window.HORTOR_AGENT; + var isSubscribe = getParameter('is_subscribe') || '0'; + this.isSubscribe = parseInt(isSubscribe); this.sdk.init(function (status) { console.log('crazy game init with status: ' + status); }); diff --git a/jcfw/platform/plat_iwei.js b/jcfw/platform/plat_iwei.js index c911572..2475f08 100644 --- a/jcfw/platform/plat_iwei.js +++ b/jcfw/platform/plat_iwei.js @@ -1,3 +1,8 @@ +var getParameter = function(t) { + var e = window.location.search, + i = new RegExp(t + "=([^&?]*)", "ig"); + return e.match(i) ? e.match(i)[0].substr(t.length + 1) : null +} var PLAT_IWEI = { SHARE_FAIL: 25, SHARE_TIME: 3000, @@ -8,7 +13,7 @@ var PLAT_IWEI = { }, getSystemInfo() { - return qg.getSystemInfoSync(); + return null; }, /** example: @@ -22,37 +27,11 @@ var PLAT_IWEI = { * @param {function} cb */ getUserInfo(btninfo, cb) { - this._usercb = cb; - let _flag = 0; - - if (btninfo && btninfo.flag) { - _flag = btninfo.flag; - } - - let self = this; - let getInfo = function () { - console.log('[xm.getUserInfo]'); - qg.getUserInfo({ - success: function (res) { - res.flag = _flag; - self._usercb && self._usercb(res, 1); - }, - fail: function (res) { - res.flag = _flag; - console.log(res); - self._usercb && self._usercb(res, -1, null, _flag); - } - }) - } - getInfo(); }, destoryAuth() { - if (this.btnAuthorize) { - this.btnAuthorize.destroy && this.btnAuthorize.destroy(); - this.btnAuthorize = null; - } + }, setUserInfo(dstinfo, ptinfo) { @@ -73,9 +52,20 @@ var PLAT_IWEI = { } }, - init(owner, channelid) { + init(owner, channelid, appId) { this._owner = owner; this._ptid = channelid; + this._platGameId = appId; + this.sdk = window['AWY_SDK']; + var isSubscribe = getParameter('is_subscribe') || '0'; + this.isSubscribe = parseInt(isSubscribe); + var isChid = getParameter('chid') || '0'; + this.isChid = parseInt(isChid); + this.sdk.config(this._platGameId, function () { + console.log('iwei game init'); + }, function () { + + }); }, bindController(ctrl) { @@ -150,7 +140,22 @@ var PLAT_IWEI = { }, PTInitShare(normalinfo) { - + if (!normalinfo) { + return; + } + if (!this._exshareinfo) { + this._exshareinfo = normalinfo; + } else { + if (normalinfo.title && this._exshareinfo.title != normalinfo.title) { + this._exshareinfo.title = normalinfo.title; + } + if (normalinfo.imgurl && this._exshareinfo.imgurl != normalinfo.imgurl) { + this._exshareinfo.imgurl = normalinfo.imgurl; + } + } + this.sdk.shareTitle(this._exshareinfo.title); + this.sdk.shareDesc(this._exshareinfo.title); + this.sdk.shareIcon(this._exshareinfo.imgurl); }, PTShare(content, imgurl, param, successcb, failcb) { @@ -163,7 +168,6 @@ var PLAT_IWEI = { PTOpenKF(cb, info) { - }, PTCreateGameClubButton(nleft, ntop, nwidth) { @@ -181,25 +185,17 @@ var PLAT_IWEI = { PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) { - }, PTLogin(info, successcb, failcb) { var self = this; - qg.login({ - success: function (res) { - self._owner.login.login({ - token: res.data.appAccountId, - successcb: function (obj) { - obj.clientSession = res.data.session; - successcb && successcb(obj); - }, failcb - }); - }, - fail: function (res) { - console.log('[xm]login fail!'); - failcb && failcb(0, res ? res.errcode : -1, res ? res.errMsg : ''); - } + var token = getParameter('token'); + if (!token) { + return failcb && failcb(0, -1, '未找到有效的token'); + } + self._owner.login.login({ + token: token, + successcb, failcb }); }, @@ -225,40 +221,15 @@ var PLAT_IWEI = { }, PTCreateVideoAD(adid) { - if (qg.createRewardedVideoAd) { - let data = { - adUnitId: adid - }; - return qg.createRewardedVideoAd(data); - } return null; }, PTCreateInsertAD(adid) { - if (qg.createInterstitialAd) { - let data = { - adUnitId: adid - }; - return qg.createInterstitialAd(data); - } return null; }, PTSetVideoADCallback(adobj, adowner, cb) { - let closeCb = function (res) { - console.log('[ad]onClose:' + JSON.stringify(res)); - // 用户点击了【关闭广告】按钮 - // 小于 2.1.0 的基础库版本,res 是一个 undefined - if (res && res.isEnded || res === undefined) { - // 正常播放结束,可以下发游戏奖励 - cb && cb(res.isEnded, adowner, res); - } else { - // 播放中途退出,不下发游戏奖励 - cb && cb(false, adowner, res); - } - // ad.offClose && ad.offClose(closeCb); - }; - adobj.onClose && adobj.onClose(closeCb); + }, PTVibrateShort(successcb, failcb) { @@ -302,34 +273,6 @@ var PLAT_IWEI = { }, PTADWatch(adid, successcb, failcb) { - let videoAd = qg.createRewardedVideoAd({ - adUnitId: adid - }); - - videoAd.onLoad = function () { - videoAd.offLoad(this); - videoAd.show(); - } - var errorCb = function (res) { - console.log('[videoad]onerror:' + JSON.stringify(res)); - failcb && failcb(adid, res, true, adid); - videoAd.offError(this); - } - videoAd.onError(errorCb); - - var getFun = function (res) { - if (res.isEnded) { - try { - successcb && successcb(adid, res, adid); - } catch (e) { - - } - cb = null; - } - videoAd.offClose(this); - } - videoAd.onClose(getFun); - videoAd.load(); }, setLocalStorage(key, value) {