357 lines
7.3 KiB
JavaScript
357 lines
7.3 KiB
JavaScript
var PLAT_IWEI = {
|
||
SHARE_FAIL: 25,
|
||
SHARE_TIME: 3000,
|
||
shareCount: {},
|
||
|
||
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(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;
|
||
},
|
||
|
||
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) {
|
||
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 : '');
|
||
}
|
||
});
|
||
},
|
||
|
||
PTSetClipboardData: function (content, successcb, failcb) {
|
||
|
||
},
|
||
|
||
PTGetClipboardData: function (successcb, failcb) {
|
||
|
||
},
|
||
|
||
PTPreviewImage(imgurl, successcb, failcb) {
|
||
|
||
},
|
||
|
||
//广告相关
|
||
PTInitADService() {
|
||
|
||
},
|
||
|
||
PTCreateBannerAD(adid, st) {
|
||
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) {
|
||
|
||
},
|
||
|
||
PTVibrateLong(successcb, 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_IWEI;
|