增加uc和魅族小游戏
This commit is contained in:
parent
cc6a73f20a
commit
23273b729f
@ -1,18 +1,20 @@
|
||||
|
||||
/**
|
||||
* 小米Native with 白鹭
|
||||
* */
|
||||
var Plat_egret = {
|
||||
* https://gamedoc.quickapp.cn
|
||||
* https://shimo.im/docs/enni3mhvNyo5fZOm/read
|
||||
* 魅族小游戏使用该文件
|
||||
*/
|
||||
var Plat_meizu = {
|
||||
SHARE_FAIL: 25,
|
||||
SHARE_TIME: 3000,
|
||||
shareCount: {},
|
||||
webRequest: true, // 强制使用XMLHttpRequest
|
||||
|
||||
getLaunchInfo() {
|
||||
return null;
|
||||
},
|
||||
|
||||
getSystemInfo() {
|
||||
return null;
|
||||
return qg.getSystemInfoSync();
|
||||
},
|
||||
|
||||
/** example:
|
||||
@ -26,11 +28,37 @@ var Plat_egret = {
|
||||
* @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(a, 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) {
|
||||
@ -51,11 +79,9 @@ var Plat_egret = {
|
||||
}
|
||||
},
|
||||
|
||||
init(owner, channelid, appId) {
|
||||
init(owner, channelid) {
|
||||
this._owner = owner;
|
||||
this._ptid = channelid;
|
||||
this.platUid = '';
|
||||
this.platUserName = '';
|
||||
},
|
||||
|
||||
bindController(ctrl) {
|
||||
@ -134,7 +160,17 @@ var Plat_egret = {
|
||||
},
|
||||
|
||||
PTShare(content, imgurl, param, successcb, failcb) {
|
||||
successcb && successcb();
|
||||
qg.share({
|
||||
success: function () {
|
||||
successcb && successcb();
|
||||
},
|
||||
fail: function (erromsg, errocode) {
|
||||
failcb && failcb();
|
||||
},
|
||||
cancel: function() {
|
||||
failcb && failcb();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
PTShareCapture(content, rc, param, successcb, failcb) {
|
||||
@ -143,6 +179,7 @@ var Plat_egret = {
|
||||
|
||||
PTOpenKF(cb, info) {
|
||||
|
||||
|
||||
},
|
||||
|
||||
PTCreateGameClubButton(nleft, ntop, nwidth) {
|
||||
@ -156,46 +193,56 @@ var Plat_egret = {
|
||||
* none: 不显示图标,此时 title 文本最多可显示两行
|
||||
* */
|
||||
PTShowToast(str, icon) {
|
||||
egret.ExternalInterface.call("showToast", str);
|
||||
qg.showToast({
|
||||
message: 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);
|
||||
qg.login({
|
||||
success: function (res) {
|
||||
self._owner.login.login({
|
||||
token: res.token,
|
||||
successcb: function (obj) {
|
||||
successcb && successcb(obj);
|
||||
}, failcb
|
||||
});
|
||||
},
|
||||
fail: function (res) {
|
||||
console.log('[quick app]login fail!');
|
||||
failcb && failcb(0, res ? res.errcode : -1, res ? res.errMsg : '');
|
||||
}
|
||||
});
|
||||
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) {
|
||||
|
||||
qg.setClipboardData({
|
||||
data: content,
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
PTGetClipboardData: function (successcb, failcb) {
|
||||
|
||||
qg.getClipboardData({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
})
|
||||
},
|
||||
|
||||
PTPreviewImage(imgurl, successcb, failcb) {
|
||||
|
||||
qg.previewImage({
|
||||
urls: [imgurl],
|
||||
current: imgurl,
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
//广告相关
|
||||
@ -204,27 +251,65 @@ var Plat_egret = {
|
||||
},
|
||||
|
||||
PTCreateBannerAD(adid, st) {
|
||||
if (qg.createBannerAd) {
|
||||
let data = {
|
||||
adUnitId: adid,
|
||||
style: st
|
||||
};
|
||||
return qg.createBannerAd(data);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
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) {
|
||||
egret.ExternalInterface.call("vibrate", "0");
|
||||
qg.vibrateShort({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
PTVibrateLong(successcb, failcb) {
|
||||
egret.ExternalInterface.call("vibrate", "1");
|
||||
qg.vibrateLong({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -260,6 +345,34 @@ var Plat_egret = {
|
||||
},
|
||||
|
||||
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) {
|
||||
@ -280,51 +393,7 @@ var Plat_egret = {
|
||||
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;
|
||||
module.exports = Plat_meizu;
|
||||
|
399
jcfw/platform/plat_meizu.js
Normal file
399
jcfw/platform/plat_meizu.js
Normal file
@ -0,0 +1,399 @@
|
||||
/**
|
||||
* https://gamedoc.quickapp.cn
|
||||
* https://shimo.im/docs/enni3mhvNyo5fZOm/read
|
||||
* 魅族小游戏使用该文件
|
||||
*/
|
||||
var Plat_meizu = {
|
||||
SHARE_FAIL: 25,
|
||||
SHARE_TIME: 3000,
|
||||
shareCount: {},
|
||||
webRequest: true, // 强制使用XMLHttpRequest
|
||||
|
||||
getLaunchInfo() {
|
||||
return null;
|
||||
},
|
||||
|
||||
getSystemInfo() {
|
||||
return qg.getSystemInfoSync();
|
||||
},
|
||||
|
||||
/** example:
|
||||
*
|
||||
* @param {object} btninfo :
|
||||
* {
|
||||
* width: 100,
|
||||
* height: 100,
|
||||
* name: logo.png
|
||||
* }
|
||||
* @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(a, 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) {
|
||||
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) {
|
||||
this._owner = owner;
|
||||
this._ptid = channelid;
|
||||
},
|
||||
|
||||
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) {
|
||||
qg.share({
|
||||
success: function () {
|
||||
successcb && successcb();
|
||||
},
|
||||
fail: function (erromsg, errocode) {
|
||||
failcb && failcb();
|
||||
},
|
||||
cancel: function() {
|
||||
failcb && failcb();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
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) {
|
||||
qg.showToast({
|
||||
message: str,
|
||||
});
|
||||
},
|
||||
|
||||
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.token,
|
||||
successcb: function (obj) {
|
||||
successcb && successcb(obj);
|
||||
}, failcb
|
||||
});
|
||||
},
|
||||
fail: function (res) {
|
||||
console.log('[quick app]login fail!');
|
||||
failcb && failcb(0, res ? res.errcode : -1, res ? res.errMsg : '');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
PTSetClipboardData: function (content, successcb, failcb) {
|
||||
qg.setClipboardData({
|
||||
data: content,
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
PTGetClipboardData: function (successcb, failcb) {
|
||||
qg.getClipboardData({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
})
|
||||
},
|
||||
|
||||
PTPreviewImage(imgurl, successcb, failcb) {
|
||||
qg.previewImage({
|
||||
urls: [imgurl],
|
||||
current: imgurl,
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
//广告相关
|
||||
PTInitADService() {
|
||||
|
||||
},
|
||||
|
||||
PTCreateBannerAD(adid, st) {
|
||||
if (qg.createBannerAd) {
|
||||
let data = {
|
||||
adUnitId: adid,
|
||||
style: st
|
||||
};
|
||||
return qg.createBannerAd(data);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
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) {
|
||||
qg.vibrateShort({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
PTVibrateLong(successcb, failcb) {
|
||||
qg.vibrateLong({
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {null}
|
||||
*/
|
||||
PTOpenDataContext() {
|
||||
return null;
|
||||
},
|
||||
|
||||
PTPostOpenMsg(msg) {
|
||||
|
||||
},
|
||||
|
||||
// 排行榜相关
|
||||
saveRankData(nscore, nmoney, stitle) {
|
||||
|
||||
},
|
||||
|
||||
showRankData() {
|
||||
|
||||
},
|
||||
|
||||
hideRankData() {
|
||||
|
||||
},
|
||||
|
||||
prevRankPage() {
|
||||
|
||||
},
|
||||
|
||||
nextRankPage() {
|
||||
|
||||
},
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Plat_meizu;
|
@ -1,6 +1,6 @@
|
||||
|
||||
/**
|
||||
* 小米Native with 白鹭
|
||||
* Android Native with 白鹭
|
||||
* */
|
||||
var Plat_egret = {
|
||||
SHARE_FAIL: 25,
|
||||
@ -177,7 +177,11 @@ var Plat_egret = {
|
||||
});
|
||||
egret.ExternalInterface.addCallback("loginOut", function (message) {
|
||||
console.log('login out from native: ' + message);
|
||||
this.reloadGame();
|
||||
self.reloadGame();
|
||||
});
|
||||
egret.ExternalInterface.addCallback("changeAccount", function (message) {
|
||||
console.log('change account from native: ' + message);
|
||||
self.reloadGame();
|
||||
});
|
||||
egret.ExternalInterface.addCallback("loginCancel", function (message) {
|
||||
console.log('login cancel from native: ' + message);
|
||||
|
479
jcfw/platform/plat_ucmini.js
Normal file
479
jcfw/platform/plat_ucmini.js
Normal file
@ -0,0 +1,479 @@
|
||||
/**
|
||||
* uc小游戏
|
||||
* https://minigame.uc.cn/api/login
|
||||
*/
|
||||
window.qg = window.uc;
|
||||
var PLAT_UC = {
|
||||
SHARE_FAIL: 25,
|
||||
SHARE_TIME: 3000,
|
||||
shareCount: {},
|
||||
|
||||
getLaunchInfo() {
|
||||
return null;
|
||||
},
|
||||
|
||||
getSystemInfo() {
|
||||
let systemInfo = uc.getSystemInfoSync();
|
||||
if (typeof systemInfo === 'string') {
|
||||
try {
|
||||
systemInfo = JSON.parse(systemInfo);
|
||||
} catch (e) { }
|
||||
}
|
||||
return systemInfo;
|
||||
},
|
||||
|
||||
/** example:
|
||||
*
|
||||
* @param {object} btninfo :
|
||||
* {
|
||||
* width: 100,
|
||||
* height: 100,
|
||||
* name: logo.png
|
||||
* }
|
||||
* @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('[uc.getUserInfo]');
|
||||
uc.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) {
|
||||
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) {
|
||||
this._owner = owner;
|
||||
this._ptid = channelid;
|
||||
// this.loadInfo();
|
||||
|
||||
// uc.showShareMenu({
|
||||
// withShareTicket: true
|
||||
// });
|
||||
// uc.updateShareMenu({
|
||||
// withShareTicket: true
|
||||
// });
|
||||
// let self = this;
|
||||
// let _onShow = function (res) {
|
||||
// console.log('[uc.onShow]', res.query);
|
||||
// self._owner.gameShow(res);
|
||||
// self._man && self._man.onPlatShow && self._man.onPlatShow(res);
|
||||
// if (self._jumpnow) {
|
||||
// self._jumpnow = false;
|
||||
// self._jumpobj.result = 2;
|
||||
// self._jumpobj.finishTime = new Date().getTime();
|
||||
// self._owner.event.emit(self._owner.event.Events.GOTO_APP_RESULT, self._jumpobj);
|
||||
// self._jumpobj = null;
|
||||
// }
|
||||
// };
|
||||
// try {
|
||||
// uc.offShow(_onShow);
|
||||
// } catch (err) {
|
||||
//
|
||||
// }
|
||||
// uc.onShow(_onShow);
|
||||
// let _onHide = function () {
|
||||
// console.log('[uc.onHide]');
|
||||
// self._owner.gameHide();
|
||||
// self._man && self._man.onPlatHide && self._man.onPlatHide();
|
||||
// };
|
||||
// try {
|
||||
// uc.offHide(_onHide);
|
||||
// } catch (err) {
|
||||
//
|
||||
// }
|
||||
// uc.onHide(_onHide);
|
||||
//
|
||||
// uc.onAudioInterruptionBegin((res) => {
|
||||
// console.log('uc.onAudioInterruptionBegin');
|
||||
// self._owner.event.emit(self._owner.event.Events.AUDIO_INTERRUPT_BEGIN, res);
|
||||
// });
|
||||
//
|
||||
// uc.onAudioInterruptionEnd((res) => {
|
||||
// console.log('uc.onAudioInterruptionEnd');
|
||||
// self._owner.event.emit(self._owner.event.Events.AUDIO_INTERRUPT_END, res);
|
||||
// });
|
||||
},
|
||||
|
||||
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) {
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// uc.showShareMenu({
|
||||
// withShareTicket: true,
|
||||
// success: function (data) {
|
||||
// console.log(data);
|
||||
// },
|
||||
// fail: function (data) {
|
||||
// console.log(data);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// uc.updateShareMenu({
|
||||
// withShareTicket: true,
|
||||
// success: function (data) {
|
||||
// console.log(data);
|
||||
// },
|
||||
// fail: function (data) {
|
||||
// console.log(data);
|
||||
// }
|
||||
// });
|
||||
// if (uc.aldOnShareAppMessage) {
|
||||
// uc.aldOnShareAppMessage(() => {
|
||||
// return {
|
||||
// title: this._exshareinfo.title,
|
||||
// imageUrl: this._exshareinfo.imgurl,
|
||||
// query: 'fromid=' + this._owner.accountID + '&fromname=' + this._owner.nickName
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// uc.onShareAppMessage(() => {
|
||||
// return {
|
||||
// title: this._exshareinfo.title,
|
||||
// imageUrl: this._exshareinfo.imgurl,
|
||||
// query: 'fromid=' + this._owner.accountID + '&fromname=' + this._owner.nickName
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
},
|
||||
|
||||
PTShare(content, imgurl, param, successcb, failcb) {
|
||||
uc.shareAppMessage({
|
||||
query: param,
|
||||
success: successcb,
|
||||
fail: failcb
|
||||
});
|
||||
},
|
||||
|
||||
PTShareCapture(content, rc, param, successcb, failcb) {
|
||||
failcb && failcb();
|
||||
},
|
||||
|
||||
PTOpenKF(cb, info) {
|
||||
|
||||
},
|
||||
|
||||
PTCreateGameClubButton(nleft, ntop, nwidth) {
|
||||
|
||||
},
|
||||
/**
|
||||
* @param {string} str 显示的文字
|
||||
* @param {icon} icon 在uc上此参数无效
|
||||
* */
|
||||
PTShowToast(str, icon) {
|
||||
uc.showToast({content: str});
|
||||
},
|
||||
|
||||
PTGotoApp(appid, apppath, exobj, cb, qdid, env, acontent) {
|
||||
|
||||
|
||||
},
|
||||
|
||||
PTLogin(info, successcb, failcb) {
|
||||
var self = this;
|
||||
uc.login({
|
||||
success: function (res) {
|
||||
console.log('[uc]login success!' + res.code);
|
||||
self._owner.login.login({token: res.code, successcb, failcb});
|
||||
},
|
||||
fail: function (res) {
|
||||
console.log('[uc]login fail!');
|
||||
failcb && failcb(0, res ? res.errcode : -1, res ? res.errmsg : '');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
PTSetClipboardData: function (content, successcb, failcb) {
|
||||
// uc.setClipboardData({
|
||||
// data: content,
|
||||
// successcb,
|
||||
// failcb
|
||||
// });
|
||||
},
|
||||
|
||||
PTGetClipboardData: function (successcb, failcb) {
|
||||
// uc.getClipboardData({
|
||||
// success: function (res) {
|
||||
// successcb && successcb(res.data);
|
||||
// },
|
||||
// failcb
|
||||
// });
|
||||
|
||||
},
|
||||
|
||||
PTPreviewImage(imgurl, successcb, failcb) {
|
||||
// uc.previewImage({
|
||||
// urls: [imgurl],
|
||||
// successcb,
|
||||
// failcb
|
||||
// })
|
||||
},
|
||||
|
||||
//广告相关
|
||||
PTInitADService() {
|
||||
|
||||
},
|
||||
|
||||
PTCreateBannerAD(adid, st) {
|
||||
if (uc.createBannerAd) {
|
||||
return uc.createBannerAd(st);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
PTCreateVideoAD(adid) {
|
||||
if (uc.createRewardVideoAd) {
|
||||
return uc.createRewardVideoAd();
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
PTCreateInsertAD(adid) {
|
||||
if (uc.createInterstitialAd) {
|
||||
return uc.createInterstitialAd();
|
||||
}
|
||||
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) {
|
||||
failcb && failcb();
|
||||
},
|
||||
|
||||
PTVibrateLong(successcb, failcb) {
|
||||
failcb && failcb();
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {null}
|
||||
*/
|
||||
PTOpenDataContext() {
|
||||
if (uc && uc.getOpenDataContext) {
|
||||
return uc.getOpenDataContext();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
PTPostOpenMsg(msg) {
|
||||
const openDataContext = this.PTOpenDataContext();
|
||||
openDataContext && openDataContext.postMessage(msg);
|
||||
},
|
||||
|
||||
// 排行榜相关
|
||||
saveRankData(nscore, nmoney, stitle) {
|
||||
|
||||
},
|
||||
|
||||
showRankData() {
|
||||
|
||||
},
|
||||
|
||||
hideRankData() {
|
||||
|
||||
},
|
||||
|
||||
prevRankPage() {
|
||||
|
||||
},
|
||||
|
||||
nextRankPage() {
|
||||
|
||||
},
|
||||
|
||||
PTADWatch(adid, successcb, failcb) {
|
||||
let videoAd = uc.createRewardVideoAd();
|
||||
|
||||
videoAd.load()
|
||||
.then(function () {
|
||||
videoAd.show();
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err.errMsg);
|
||||
});
|
||||
|
||||
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);
|
||||
},
|
||||
|
||||
setLocalStorage(key, value) {
|
||||
if (typeof localStorage != 'undefined') {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
},
|
||||
|
||||
getLocalStorage(key) {
|
||||
if (typeof localStorage != 'undefined') {
|
||||
return localStorage.getItem(key);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
removeStorage(key) {
|
||||
if (typeof localStorage != 'undefined') {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = PLAT_UC;
|
Loading…
x
Reference in New Issue
Block a user