321 lines
6.6 KiB
JavaScript
321 lines
6.6 KiB
JavaScript
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_CRAZY = {
|
|
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._platGameId = appId;
|
|
this.sdk = window.HORTOR_AGENT;
|
|
this.sdk.init(function (status) {
|
|
console.log('crazy game init with status: ' + status);
|
|
});
|
|
},
|
|
|
|
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;
|
|
}
|
|
}
|
|
this.sdk.config({
|
|
gameId: this._platGameId,
|
|
share: {
|
|
timeline: {
|
|
title: this._exshareinfo.title,
|
|
imgUrl: this._exshareinfo.imgurl,
|
|
success: function (data) {
|
|
console.log(data);
|
|
},
|
|
cancel: function (data) {
|
|
console.log(data);
|
|
}
|
|
},
|
|
friend: {
|
|
title: this._exshareinfo.title,
|
|
desc: this._exshareinfo.title,
|
|
imgUrl: this._exshareinfo.imgurl,
|
|
success: function (data) {
|
|
console.log(data);
|
|
},
|
|
cancel: function (data) {
|
|
console.log(data);
|
|
}
|
|
},
|
|
shareCustomParam:{//配置⾃自定义参数
|
|
// cp_fromid: this._owner.accountID,//⾃自定义参数key必须以cp_开始
|
|
// cp_fromname: this._owner.nickName,
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
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;
|
|
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() {
|
|
|
|
},
|
|
|
|
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);
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = PLAT_CRAZY;
|