diff --git a/jcfw/jcfw.js b/jcfw/jcfw.js index f4d4446..edf1e9b 100644 --- a/jcfw/jcfw.js +++ b/jcfw/jcfw.js @@ -96,7 +96,9 @@ var JCFW = { IQIYI: 7011, GAMEDOG: 7012, // 游戏狗 XIAOQI: 7013, // 小7手游 - QUNHEI: 7014 // 群黑 + QUNHEI: 7014, // 群黑 + SD: 7028, // 盛大 + NATIVE_XIAOMI: 7103, //小米Native }, __getUrl(isoffical, key, env) { diff --git a/jcfw/platform/plat.js b/jcfw/platform/plat.js index 8b29550..1bfbcee 100644 --- a/jcfw/platform/plat.js +++ b/jcfw/platform/plat.js @@ -1,9 +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_QUICK = { + +/** + * 小米Native with 白鹭 + * */ +var Plat_egret = { SHARE_FAIL: 25, SHARE_TIME: 3000, shareCount: {}, @@ -55,10 +54,6 @@ var PLAT_QUICK = { init(owner, channelid, appId) { this._owner = owner; this._ptid = channelid; - this._platGameId = appId; // productKey - this.sdk = window['QuickSDK']; - this._productCode = getParameter('productCode'); - this._platChannel = getParameter('channelCode'); this.platUid = ''; this.platUserName = ''; }, @@ -161,6 +156,7 @@ var PLAT_QUICK = { * none: 不显示图标,此时 title 文本最多可显示两行 * */ PTShowToast(str, icon) { + egret.ExternalInterface.call("showToast", str); }, PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) { @@ -169,62 +165,25 @@ var PLAT_QUICK = { PTLogin(info, successcb, failcb) { var self = this; - if (info.productCode) { - this._productCode = info.productCode; - } - this.sdk.init(this._productCode,this._platGameId,true,function(){ - console.log("quick sdk init success"); - self.sdk.logout(function() { - console.log('QuickSDK logout'); - if (self.platUid) { - self.reloadGame(); - } - }); - self.sdk.setLogoutNotification(function(logoutObject){ - console.log('QuickSDK:玩家点击注销帐号'); - if (self.platUid) { - self.reloadGame(); - } - }) - self.sdk.login(function(callbackData){ - if(callbackData.status){ - console.log('QuickSDK登录成功: uid=>' + JSON.stringify(callbackData.data)); - /** - * callbackData.data 结构: - * uid 渠道uid - * username 渠道username - * token token 游戏服务器需通过v2/checkUserInfo接口(参见服务器接口文档)验证token和UID的正确性 - * isLogin 是否游客,登录后此值为true - * channelId 渠道ID - * message status为false时,此字段为Failed表示登录失败,为cancel表示玩家取消登录 - * */ - let data = callbackData.data; - if (self.platUid && self.platUid !== data.uid) { - self.reloadGame(); - } - self.platUid = data.uid; - self.platUserName = data.username; - let loginData = { - openid: data.uid, - token: data.token, - polySdkSubchannel: self._platChannel, - successcb, - failcb - }; - if (info) { - loginData.polySdkChannel = info.channelId; - } - if (data.channelId) { - loginData.polySdkSubchannel = data.channelId; - } - self._owner.login.login(loginData); - }else{ - console.log('QuickSDK登录失败:' + callbackData.message); - failcb && failcb(callbackData.message); - } - }); - }) - + egret.ExternalInterface.addCallback("sendUidToJS", function (message) { + console.log('login message from native: ' + message); + let obj = JSON.parse(message); + let loginData = { + successcb, + failcb + }; + Object.assign(loginData, obj); + self._owner.login.login(loginData); + }); + egret.ExternalInterface.addCallback("loginOut", function (message) { + console.log('login out from native: ' + message); + this.reloadGame(); + }); + egret.ExternalInterface.addCallback("loginCancel", function (message) { + console.log('login cancel from native: ' + message); + failcb && failcb(-1, 0, 'user cancel'); + }); + egret.ExternalInterface.call("getUid", ""); }, PTSetClipboardData: function (content, successcb, failcb) { @@ -261,11 +220,11 @@ var PLAT_QUICK = { }, PTVibrateShort(successcb, failcb) { - + egret.ExternalInterface.call("vibrate", "0"); }, PTVibrateLong(successcb, failcb) { - + egret.ExternalInterface.call("vibrate", "1"); }, /** @@ -326,23 +285,46 @@ var PLAT_QUICK = { * 上报角色信息 * */ reportRoleInfo(data) { - Object.assign(data, { - uid: this.platUid, - username: this.platUserName, - }) return new Promise((resolve, reject) => { - this.sdk.uploadGameRoleInfo(JSON.stringify(data), function (res) { - console.log('[quick] report role info: ', JSON.stringify(res)); - resolve(res); - }) + let dataStr = JSON.stringify(data); + egret.ExternalInterface.call("reportRoleInfo", dataStr); + resolve(); }); }, /** * 重新加载游戏 */ reloadGame() { - if (location.reload) location.reload(true); + window.location.reload(); + }, + /** + * + * { + * orderId: '', + * productCode: '', + * count: 1 + * } + */ + pay(data) { + let str = JSON.stringify(data); + return new Promise((resolve, reject) => { + egret.ExternalInterface.addCallback("payResult", function (message) { + console.log('message from native: ' + message); + try { + let data = JSON.parse(message); + if (data.errcode) { + reject && reject(data) + } else { + resolve && resolve(data); + } + } catch (err) { + reject && reject({errcode: 101, errmsg: '解析支付结果出错'}) + } + }); + egret.ExternalInterface.call("pay", str); + }); + } }; -module.exports = PLAT_QUICK; +module.exports = Plat_egret; diff --git a/jcfw/platform/plat_7028.js b/jcfw/platform/plat_7028.js new file mode 100644 index 0000000..5136463 --- /dev/null +++ b/jcfw/platform/plat_7028.js @@ -0,0 +1,304 @@ +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 TOKEN_KEY = 'jc_7028_token_key'; +var PLAT_QUICK = { + SHARE_FAIL: 25, + SHARE_TIME: 3000, + shareCount: {}, + + getLaunchInfo() { + return null; + }, + + getSystemInfo() { + return null; + }, + + /** example: + * + * @param {object} btninfo : + * { + * width: 100, + * height: 100, + * name: logo.png + * } + * @param {function} cb + */ + getUserInfo(btninfo, cb) { + + }, + + destoryAuth() { + + }, + + setUserInfo(dstinfo, ptinfo) { + dstinfo.nickname = ptinfo.nickName; + dstinfo.country = ptinfo.country; + dstinfo.province = ptinfo.province; + dstinfo.city = ptinfo.city; + dstinfo.avatar_url = ptinfo.avatarUrl; + dstinfo.sex = ptinfo.gender; + }, + + 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) { + this._owner = owner; + this._ptid = channelid; + this.platUid = ''; + this.platUserName = ''; + }, + + bindController(ctrl) { + this._man = ctrl; + }, + + 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; + } + let title = atitle; + if (!title && this._exshareinfo) { + title = this._exshareinfo.title; + } + this.PTShare(title, img, sp); + this._checkShareRes(st, stype, sp, uuid, successcb, failcb); + }, + + captureShare(rc, title, stype, param, successcb, failcb, exinfo) { + var st = (new Date()).getTime(); + let sp = this._owner.makeShareParam(stype, param, exinfo); + 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) { + + }, + + PTShare(content, imgurl, param, successcb, failcb) { + successcb && successcb(); + }, + + PTShareCapture(content, rc, param, successcb, failcb) { + successcb && successcb(); + }, + + PTOpenKF(cb, info) { + + }, + + PTCreateGameClubButton(nleft, ntop, nwidth) { + + }, + /** + * @param {string} str 显示的文字 + * @param {icon} icon 图标类型 默认'none'; + * success: 显示成功图标 + * loading: 显示加载图标 + * none: 不显示图标,此时 title 文本最多可显示两行 + * */ + PTShowToast(str, icon) { + }, + + PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) { + + }, + + PTLogin(info, successcb, failcb) { + let token = getParameter('play_token'); + let tokenLoc = this.getLocalStorage(TOKEN_KEY); + if (!token && tokenLoc) { + token = tokenLoc; + } else if (token) { + this.setLocalStorage(TOKEN_KEY, token); + history.replaceState(window.history.state, "title", 'index.html') + } + var self = this; + let loginData = { + token: token, + successcb, + failcb + }; + self._owner.login.login(loginData); + + }, + + PTSetClipboardData: function (content, successcb, failcb) { + + }, + + PTGetClipboardData: function (successcb, failcb) { + + }, + + PTPreviewImage(imgurl, successcb, failcb) { + + }, + + //广告相关 + PTInitADService() { + + }, + + PTCreateBannerAD(adid, st) { + return null; + }, + + PTCreateVideoAD(adid) { + return null; + }, + + PTCreateInsertAD(adid) { + return null; + }, + + PTSetVideoADCallback(adobj, adowner, cb) { + + }, + + PTVibrateShort(successcb, failcb) { + + }, + + PTVibrateLong(successcb, failcb) { + + }, + + /** + * @return {null} + */ + PTOpenDataContext() { + return null; + }, + + PTPostOpenMsg(msg) { + + }, + + // 排行榜相关 + saveRankData(nscore, nmoney, stitle) { + + }, + + showRankData() { + + }, + + hideRankData() { + + }, + + prevRankPage() { + + }, + + nextRankPage() { + + }, + + PTADWatch(adid, successcb, failcb) { + }, + + setLocalStorage(key, value) { + if (window.localStorage) { + localStorage.setItem(key, value); + } + }, + + getLocalStorage(key) { + if (window.localStorage) { + return localStorage.getItem(key); + } else { + return null; + } + }, + + removeStorage(key) { + if (window.localStorage) { + localStorage.removeItem(key); + } + }, + /** + * 上报角色信息 + * */ + reportRoleInfo(data) { + Object.assign(data, { + uid: this.platUid, + username: this.platUserName, + }) + return new Promise((resolve, reject) => { + this.sdk.uploadGameRoleInfo(JSON.stringify(data), function (res) { + console.log('[sd] report role info: ', JSON.stringify(res)); + resolve(res); + }) + }); + }, + /** + * 重新加载游戏 + */ + reloadGame() { + if (location.reload) location.reload(true); + } +}; + +module.exports = PLAT_QUICK; diff --git a/jcfw/platform/plat_native_egret.js b/jcfw/platform/plat_native_egret.js new file mode 100644 index 0000000..1bfbcee --- /dev/null +++ b/jcfw/platform/plat_native_egret.js @@ -0,0 +1,330 @@ + +/** + * 小米Native with 白鹭 + * */ +var Plat_egret = { + SHARE_FAIL: 25, + SHARE_TIME: 3000, + shareCount: {}, + + getLaunchInfo() { + return null; + }, + + getSystemInfo() { + return null; + }, + + /** example: + * + * @param {object} btninfo : + * { + * width: 100, + * height: 100, + * name: logo.png + * } + * @param {function} cb + */ + getUserInfo(btninfo, cb) { + + }, + + destoryAuth() { + + }, + + setUserInfo(dstinfo, ptinfo) { + dstinfo.nickname = ptinfo.nickName; + dstinfo.country = ptinfo.country; + dstinfo.province = ptinfo.province; + dstinfo.city = ptinfo.city; + dstinfo.avatar_url = ptinfo.avatarUrl; + dstinfo.sex = ptinfo.gender; + }, + + 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) { + this._owner = owner; + this._ptid = channelid; + this.platUid = ''; + this.platUserName = ''; + }, + + bindController(ctrl) { + this._man = ctrl; + }, + + 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; + } + let title = atitle; + if (!title && this._exshareinfo) { + title = this._exshareinfo.title; + } + this.PTShare(title, img, sp); + this._checkShareRes(st, stype, sp, uuid, successcb, failcb); + }, + + captureShare(rc, title, stype, param, successcb, failcb, exinfo) { + var st = (new Date()).getTime(); + let sp = this._owner.makeShareParam(stype, param, exinfo); + 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) { + + }, + + PTShare(content, imgurl, param, successcb, failcb) { + successcb && successcb(); + }, + + PTShareCapture(content, rc, param, successcb, failcb) { + successcb && successcb(); + }, + + PTOpenKF(cb, info) { + + }, + + PTCreateGameClubButton(nleft, ntop, nwidth) { + + }, + /** + * @param {string} str 显示的文字 + * @param {icon} icon 图标类型 默认'none'; + * success: 显示成功图标 + * loading: 显示加载图标 + * none: 不显示图标,此时 title 文本最多可显示两行 + * */ + PTShowToast(str, icon) { + egret.ExternalInterface.call("showToast", str); + }, + + PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) { + + }, + + PTLogin(info, successcb, failcb) { + var self = this; + egret.ExternalInterface.addCallback("sendUidToJS", function (message) { + console.log('login message from native: ' + message); + let obj = JSON.parse(message); + let loginData = { + successcb, + failcb + }; + Object.assign(loginData, obj); + self._owner.login.login(loginData); + }); + egret.ExternalInterface.addCallback("loginOut", function (message) { + console.log('login out from native: ' + message); + this.reloadGame(); + }); + egret.ExternalInterface.addCallback("loginCancel", function (message) { + console.log('login cancel from native: ' + message); + failcb && failcb(-1, 0, 'user cancel'); + }); + egret.ExternalInterface.call("getUid", ""); + }, + + PTSetClipboardData: function (content, successcb, failcb) { + + }, + + PTGetClipboardData: function (successcb, failcb) { + + }, + + PTPreviewImage(imgurl, successcb, failcb) { + + }, + + //广告相关 + PTInitADService() { + + }, + + PTCreateBannerAD(adid, st) { + return null; + }, + + PTCreateVideoAD(adid) { + return null; + }, + + PTCreateInsertAD(adid) { + return null; + }, + + PTSetVideoADCallback(adobj, adowner, cb) { + + }, + + PTVibrateShort(successcb, failcb) { + egret.ExternalInterface.call("vibrate", "0"); + }, + + PTVibrateLong(successcb, failcb) { + egret.ExternalInterface.call("vibrate", "1"); + }, + + /** + * @return {null} + */ + PTOpenDataContext() { + return null; + }, + + PTPostOpenMsg(msg) { + + }, + + // 排行榜相关 + saveRankData(nscore, nmoney, stitle) { + + }, + + showRankData() { + + }, + + hideRankData() { + + }, + + prevRankPage() { + + }, + + nextRankPage() { + + }, + + PTADWatch(adid, successcb, failcb) { + }, + + setLocalStorage(key, value) { + if (window.localStorage) { + localStorage.setItem(key, value); + } + }, + + getLocalStorage(key) { + if (window.localStorage) { + return localStorage.getItem(key); + } else { + return null; + } + }, + + removeStorage(key) { + if (window.localStorage) { + localStorage.removeItem(key); + } + }, + /** + * 上报角色信息 + * */ + reportRoleInfo(data) { + return new Promise((resolve, reject) => { + let dataStr = JSON.stringify(data); + egret.ExternalInterface.call("reportRoleInfo", dataStr); + resolve(); + }); + }, + /** + * 重新加载游戏 + */ + reloadGame() { + window.location.reload(); + }, + /** + * + * { + * orderId: '', + * productCode: '', + * count: 1 + * } + */ + pay(data) { + let str = JSON.stringify(data); + return new Promise((resolve, reject) => { + egret.ExternalInterface.addCallback("payResult", function (message) { + console.log('message from native: ' + message); + try { + let data = JSON.parse(message); + if (data.errcode) { + reject && reject(data) + } else { + resolve && resolve(data); + } + } catch (err) { + reject && reject({errcode: 101, errmsg: '解析支付结果出错'}) + } + }); + egret.ExternalInterface.call("pay", str); + }); + + } +}; + +module.exports = Plat_egret; diff --git a/jcfw/platform/plat_quick.js b/jcfw/platform/plat_quick.js index 8b29550..1d275b7 100644 --- a/jcfw/platform/plat_quick.js +++ b/jcfw/platform/plat_quick.js @@ -174,12 +174,13 @@ var PLAT_QUICK = { } this.sdk.init(this._productCode,this._platGameId,true,function(){ console.log("quick sdk init success"); - self.sdk.logout(function() { - console.log('QuickSDK logout'); + self.sdk.setSwitchAccountNotification(function(logoutObject) { + console.log('QuickSDK change account'); if (self.platUid) { self.reloadGame(); } }); + self.sdk.setLogoutNotification(function(logoutObject){ console.log('QuickSDK:玩家点击注销帐号'); if (self.platUid) {