565 lines
13 KiB
JavaScript
565 lines
13 KiB
JavaScript
// Learn cc.Class:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
|
|
// Learn Attribute:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
|
|
|
|
//var httpclient = require("httpclient");
|
|
//var urlbuilder = require("urlbuilder");
|
|
var httpclient = require('httpclient');
|
|
var urlbuilder = require('urlbuilder');
|
|
const BaseNet = require('../../BaseNet');
|
|
|
|
module.exports = {
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
// start () {},
|
|
|
|
// update (dt) {},
|
|
|
|
init(channelid, gameid, isoffical, owner) {
|
|
this.owner = owner;
|
|
this.gameid = gameid;
|
|
this.channelid = channelid;
|
|
this.urlbd = new urlbuilder(BaseNet.getNormalApiUrl('service'));
|
|
console.log(
|
|
'[jcshare]init:' + gameid + '|' + channelid + '|' + isoffical
|
|
);
|
|
},
|
|
|
|
setAccountID(accountid, sessionid) {
|
|
this.accountid = accountid;
|
|
this.sessionid = sessionid;
|
|
},
|
|
|
|
setNickName(nickname) {
|
|
this.nickname = nickname;
|
|
},
|
|
|
|
setFromAppID(appid) {
|
|
this.fromid = appid;
|
|
},
|
|
|
|
setLocalUUID(uuid) {
|
|
this.localid = uuid;
|
|
},
|
|
|
|
setSystemInfo(info) {},
|
|
|
|
acceptInvite(actionid, inviterid, successcb, failcb) {
|
|
if (!actionid) {
|
|
return;
|
|
}
|
|
let sid = inviterid ? inviterid : '';
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Fission')
|
|
.addKV('a', 'accept')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('business_no', actionid)
|
|
.addKV('inviter_id', sid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0 || obj.errcode == 1 || obj.errcode == 2) {
|
|
console.log('[acceptInvite]success!' + JSON.stringify(obj));
|
|
successcb && successcb();
|
|
} else {
|
|
console.log(
|
|
'[acceptInvite]failed!' + obj.errcode + ':' + obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log('[acceptInvite]failed!' + errcode + ':' + errmsg);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryShareStat(actionid, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Fission')
|
|
.addKV('a', 'getChild')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('business_no', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryShareStat]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj.nodes);
|
|
} else {
|
|
console.log(
|
|
'[queryShareStat]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log('[queryShareStat]failed!' + errcode + ':' + errmsg);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
acceptDailyInvite(
|
|
inviterid,
|
|
activity_param,
|
|
nickname,
|
|
avataurl,
|
|
sex,
|
|
custom_data,
|
|
successcb,
|
|
failcb
|
|
) {
|
|
let sid = inviterid ? inviterid : '';
|
|
custom_data = custom_data ? custom_data : '';
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'DailyMission')
|
|
.addKV('a', 'acceptInvite')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('nickname', nickname)
|
|
.addKV('avatar_url', avataurl)
|
|
.addKV('sex', sex)
|
|
.addKV('inviter_id', sid)
|
|
.addKV('activity_param', activity_param)
|
|
.addKV('custom_data', custom_data);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0 || obj.errcode == 1 || obj.errcode == 2) {
|
|
console.log(
|
|
'[acceptDailyInvite]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb();
|
|
} else {
|
|
console.log(
|
|
'[acceptDailyInvite]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[acceptDailyInvite]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryDailyShareStat(actionid, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'DailyMission')
|
|
.addKV('a', 'getInviteeNum')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('activity_param', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryDailyShareStat]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj);
|
|
} else {
|
|
console.log(
|
|
'[queryDailyShareStat]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[queryDailyShareStat]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryDailyShareDetail(actionid, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'DailyMission')
|
|
.addKV('a', 'getInviteeList')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('activity_param', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryDailyShareDetail]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj.invitee_list);
|
|
} else {
|
|
console.log(
|
|
'[queryDailyShareDetail]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[queryDailyShareDetail]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryShareDetail(actionid, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Fission')
|
|
.addKV('a', 'getFriendsDetail')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('business_no', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryShareDetail]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj.nodes);
|
|
} else {
|
|
console.log(
|
|
'[queryShareDetail]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[queryShareDetail]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryActionCode(score, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Exchange')
|
|
.addKV('a', 'reportScore')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('score', score);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryActionCode]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj.exchange_code);
|
|
} else {
|
|
console.log(
|
|
'[queryActionCode]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[queryActionCode]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
useActionCode(actioncode, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Exchange')
|
|
.addKV('a', 'getPrizeInfo')
|
|
.addKV('exchange_code', actioncode);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[useActionCode]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj.exchange_code);
|
|
} else {
|
|
console.log(
|
|
'[useActionCode]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log('[useActionCode]failed!' + errcode + ':' + errmsg);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
acceptRelayInvite(actionid, inviterid, successcb, failcb) {
|
|
let sid = inviterid ? inviterid : '';
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Relay')
|
|
.addKV('a', 'acceptInvite')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('inviter_id', sid)
|
|
.addKV('activity_param', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0 || obj.errcode == 1) {
|
|
console.log(
|
|
'[acceptRelayInvite]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb();
|
|
} else {
|
|
console.log(
|
|
'[acceptRelayInvite]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[acceptRelayInvite]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
queryRelayShareStat(actionid, successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Relay')
|
|
.addKV('a', 'getInviteeNum')
|
|
.addKV('session_id', this.sessionid)
|
|
.addKV('account_id', this.accountid)
|
|
.addKV('activity_param', actionid);
|
|
|
|
httpclient.httpGet(
|
|
this.urlbd.baseurl,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log(
|
|
'[queryRelayShareStat]success!' + JSON.stringify(obj)
|
|
);
|
|
successcb && successcb(obj);
|
|
} else {
|
|
console.log(
|
|
'[queryRelayShareStat]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[queryRelayShareStat]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
|
|
shareNormal(
|
|
content,
|
|
imgurl,
|
|
sharetype,
|
|
shareparam,
|
|
extrainfo,
|
|
successcb,
|
|
failcb
|
|
) {
|
|
let uuid = this.owner ? this.owner.makeUUID() : '';
|
|
let qstr =
|
|
'inviter_id=' +
|
|
this.accountid +
|
|
'&activity_param=' +
|
|
shareparam +
|
|
'&localuuid=' +
|
|
uuid +
|
|
'&sharetype=' +
|
|
sharetype;
|
|
if (extrainfo) {
|
|
qstr += '&';
|
|
qstr += extrainfo;
|
|
}
|
|
|
|
switch (this.channelid) {
|
|
case 6001:
|
|
{
|
|
wx.shareAppMessage({
|
|
title: content,
|
|
imageUrl: imgurl,
|
|
query: qstr,
|
|
});
|
|
this.owner &&
|
|
this.owner.gamelog.logShare(
|
|
sharetype,
|
|
uuid,
|
|
shareparam
|
|
);
|
|
successcb && successcb();
|
|
}
|
|
break;
|
|
case 6002:
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
},
|
|
|
|
shareCapture(
|
|
content,
|
|
rc,
|
|
sharetype,
|
|
shareparam,
|
|
extrainfo,
|
|
successcb,
|
|
failcb
|
|
) {
|
|
let uuid = this.owner ? this.owner.makeUUID() : '';
|
|
let qstr =
|
|
'inviter_id=' +
|
|
this.accountid +
|
|
'&activity_param=' +
|
|
shareparam +
|
|
'&localuuid=' +
|
|
uuid +
|
|
'&sharetype=' +
|
|
sharetype;
|
|
if (extrainfo) {
|
|
qstr += '&';
|
|
qstr += extrainfo;
|
|
}
|
|
switch (this.channelid) {
|
|
case 6001:
|
|
{
|
|
wx.shareAppMessage({
|
|
title: content,
|
|
imageUrl: imgurl,
|
|
query: qstr,
|
|
});
|
|
this.owner &&
|
|
this.owner.gamelog.logShare(
|
|
sharetype,
|
|
uuid,
|
|
shareparam
|
|
);
|
|
successcb && successcb();
|
|
}
|
|
break;
|
|
case 6002:
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
},
|
|
|
|
getRecommendGames(successcb, failcb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV('c', 'Voodoo')
|
|
.addKV('a', 'getRecommendGames')
|
|
.addKV('gameid', this.gameid)
|
|
.addKV('channel', this.channelid);
|
|
var url = this.urlbd.baseurl;
|
|
|
|
httpclient.httpGet(
|
|
url,
|
|
function (restext) {
|
|
var obj = JSON.parse(restext);
|
|
if (obj.errcode == 0) {
|
|
console.log('[getRecommendGames]success!');
|
|
successcb && successcb(obj);
|
|
} else {
|
|
console.log(
|
|
'[getRecommendGames]failed!' +
|
|
obj.errcode +
|
|
':' +
|
|
obj.errmsg
|
|
);
|
|
failcb && failcb(0, obj.errcode, obj.errmsg);
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
console.log(
|
|
'[getRecommendGames]failed!' + errcode + ':' + errmsg
|
|
);
|
|
failcb && failcb(errcode, 0, errmsg);
|
|
}
|
|
);
|
|
},
|
|
};
|