Commit cb7c006f authored by liuxinjun's avatar liuxinjun

1.004版本

parent e37fcb24
......@@ -38,6 +38,7 @@ var sdk = {
//游戏数据存储/获取
set: "/game/set",
get: "/game/get",
time: "/game/time",
ConfigData: {
"config1": {},
......@@ -75,6 +76,12 @@ var sdk = {
init(args, callback){
var self = this;
if(!self.ip1)
{
console.error("请调用WechatLogin!");
wx.showToast({title: '请先登录',icon:'loading',duration: 8});
return;
}
if(args.debug){
this.debug = args.debug;
}
......@@ -161,9 +168,69 @@ var sdk = {
}
},
/**
* @apiGroup C
* @apiName WeChatLogin
* @api {微信登录} 微信登录 WeChatLogin(登录)
*
* @apiSuccessExample {json} 示例:
* // 2.登录页:获取用户信息
* //.调用sdk登录
* sdk.WeChatLogin((d)=>{
* console.log("用户信息:", d)
* // 登录成功:返回用户信息;
* // 登录失败:返回false
* });
*
*/
WeChatLogin(callback){
//根据sdk_conf初始化api
this.init_api();
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var userinfo = this.getUser();
var wxauth = this.getItem("wxauth"); //记录微信是否授权
if(userinfo&&wxauth){
console.log("直接进入游戏");
//用户信息获取到并且授权了
callback(userinfo)
}else if(userinfo&&!wxauth)
{
//用户信息存在但是没有授权,就应该去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权1");
callback(d);
});
}else if(!userinfo&&wxauth)
{
//用户信息没有但是有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权2");
callback(d);
});
}
else{
//没有用户信息,也没有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxLogin((d) => {
console.log("登陆");
this.WxAuthLogin((d) => {
console.log("授权3");
callback(d);
});
});
}
}
},
//.根据配置初始化api
initApi(type){
init_api(type){
if(sdk_conf.env==='prod')
{
this.ip1 = sdk_conf.env_apis.prod.ip1;
......@@ -483,7 +550,7 @@ var sdk = {
},
/**
* @apiGroup B
* @apiName setAld
* @apiName setAldEvent
* @api {阿拉丁埋点} 统计埋点(使用前请到阿拉丁注册游戏,并配置sdk/ald-game-conf.js) setAld(阿拉丁埋点)
* @apiParam {String} type 描述用户的动作名称,不超过255个字符,不支持数字,英文,中文,"-"、"_"、"+",以外的字符格式
* @apiParam {String} key 动作的参数,不超过255个字符,不支持数字,英文,中文,"-"、"_"、"+",以外的字符格式
......@@ -492,9 +559,9 @@ var sdk = {
* @apiSuccessExample {json} 示例:
* //使用前,在开发者设置中添加 request合法域名https://glog.aldwx.com
* //统计类型(点击), 统计位置(开始游戏按钮), 统计参数(点了1次)
* sdk.setAld("click", "playButton", "1")
* sdk.setAldEvent("click", "playButton", "1")
*/
setAld(type, key, value){
setAldEvent(type, key, value){
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
// wx.aldSendEvent('事件名称',{'参数key' : '参数value'})、
wx.aldSendEvent(type, { key : value })
......@@ -1169,71 +1236,7 @@ var sdk = {
}
},
/**
* @apiGroup C
* @apiName WeChatLogin
* @api {微信登录} 微信登录 WeChatLogin(登录)
*
* @apiSuccessExample {json} 示例:
* // 2.登录页:获取用户信息
* var user = sdk.getUser();
* if(user){
* console.log("用户信息:", user)
* }else{
* //.调用sdk登录
* sdk.WeChatLogin((d)=>{
* console.log("用户信息:", d)
* // 登录成功:返回用户信息;
* // 登录失败:返回false
* });
* }
*
*/
WeChatLogin(callback){
//根据sdk_conf初始化api
this.initApi();
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var userinfo = this.getUser();
var wxauth = this.getItem("wxauth"); //记录微信是否授权
if(userinfo&&wxauth){
console.log("直接进入游戏");
//用户信息获取到并且授权了
callback(userinfo)
}else if(userinfo&&!wxauth)
{
//用户信息存在但是没有授权,就应该去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权1");
callback(d);
});
}else if(!userinfo&&wxauth)
{
//用户信息没有但是有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxAuthLogin((d) => {
console.log("授权2");
callback(d);
});
}
else{
//没有用户信息,也没有授权,就应该去登陆并且去授权后调用服务端member/update用户信息
this.WxLogin((d) => {
console.log("登陆");
this.WxAuthLogin((d) => {
console.log("授权3");
callback(d);
});
});
}
}
},
/**
......@@ -1560,8 +1563,8 @@ var sdk = {
/**
* @apiGroup C
* @apiName setItem
* @api {set} 数据存储 setItem(存)
* @apiName setLocalCache
* @api {set} 数据存储 setLocalCache(存)
* @apiParam {String} key 键
* @apiParam {String} value 值
* @apiParam {String} expireTime 过期时间单位(秒)
......@@ -1580,10 +1583,9 @@ var sdk = {
},
/**
* @apiGroup C
* @apiName getItem
* @api {数据存储} 数据存储 getItem(取)
* @apiName getLocalCache
* @api {数据存储} 数据存储 getLocalCache(取)
* @apiParam {String} key 键
* @apiParam {String} value 值
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.getLocalCache("nick")
......@@ -1620,7 +1622,303 @@ var sdk = {
return -1;
}
},
/**
* @apiGroup C
* @apiName getConfig3ByType
* @api {数据存储} 数据存储 getConfig3ByType(取)
* @apiParam {String} type 键
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.getConfig3ByType("send_pic")
*/
getConfig3ByButtonKey(buttonKey){
var c3 = this.getConfig3();
if(c3.length>0)
{
for(var i=0;i<c3.length;i++)
{
var c = c3[i];
if(c.type===buttonKey)
{
return c;
}
}
return null;
}else{
return null;
}
},
/**
* @apiGroup C
* @apiName getLocalCache
* @api {数据存储} 数据存储 getLocalCache(取)
* @apiParam {String} key 键
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.getLocalCache("nick")
*/
getLocalCache(key){
var nowTime = new Date().getTime();
console.log("getLocalCache nowTime",nowTime);
var localData = cc.sys.localStorage.getItem(key);
console.log("getLocalCache "+key+" 本地获取值:"+localData);
if(localData)
{
var data = JSON.parse(localData);
var expireTime = data.expireTime;
if(nowTime>=expireTime)
{
cc.sys.localStorage.removeItem(key);
console.log("getLocalCache dataKey : "+key+" is expire");
return 0;
}else
{
var data = data.data;
console.log("getLocalCache dataKey : "+key+" is "+data);
return data;
}
}else
{
//本地不存在数据,应该去远程服务器拿数据
return -1;
}
},
/**
* @apiGroup C
* @apiName getServerTime
* @api {数据存储} 数据获取 getServerTime (取)
* @apiSuccessExample {json} 示例:
* sdk.getServerTime((d)=>{
if(d.c==1){
console.log("获取返回",d.nowTime);
}
});
*/
getServerTime(callbackFunction){
this.Post(this.ip2 + this.time, { }, function (d) {
callbackFunction(d);
});
},
/**
* @apiGroup C
* @apiName formatTime
* @api 数据获取 formatTime (取)
* @apiParam {Date} time 时间
* @apiParam {String} type 类型 date or time
* @apiParam {String} split 分隔符 / - : 空
* @apiSuccessExample {json} 示例:
* var time = this.formatTime(new Date(),"date",""); 20180920
* var time = this.formatTime(new Date(),"time",""); 20180920122324
*/
formatTime(time,type,split)
{
var mat={};
mat.M=time.getMonth()+1;//月份记得加1
mat.H=time.getHours();
mat.s=time.getSeconds();
mat.m=time.getMinutes();
mat.Y=time.getFullYear();
mat.D=time.getDate();
mat.d=time.getDay();//星期几
mat.d=this.formatZero(mat.d);
mat.H=this.formatZero(mat.H);
mat.M=this.formatZero(mat.M);
mat.D=this.formatZero(mat.D);
mat.s=this.formatZero(mat.s);
mat.m=this.formatZero(mat.m);
if(type=="date")
{
if(split.indexOf(":")>-1)
{
    mat.Y=mat.Y.toString().substr(2,2);
    return mat.Y+"/"+mat.M+"/"+mat.D
}else if(split.indexOf("/")>-1){
return mat.Y+"/"+mat.M+"/"+mat.D
}else if(split.indexOf("-")>-1){
return mat.Y+"-"+mat.M+"-"+mat.D
}else if(split.indexOf("-")>-1){
return mat.Y+"-"+mat.M+"-"+mat.D
}else
{
return mat.Y+mat.M+mat.D
}
}else
{
if(split.indexOf(":")>-1)
{
mat.Y=mat.Y.toString().substr(2,2);
return mat.Y+"/"+mat.M+"/"+mat.D+" "+mat.H+":"+mat.m+":"+mat.s;
}else if(split.indexOf("/")>-1){
return mat.Y+"/"+mat.M+"/"+mat.D+" "+mat.H+"/"+mat.m+"/"+mat.s;
}else if(split.indexOf("-")>-1){
return mat.Y+"-"+mat.M+"-"+mat.D+" "+mat.H+"-"+mat.m+"-"+mat.s;
}else if(split.indexOf("-")>-1){
return mat.Y+"-"+mat.M+"-"+mat.D+" "+mat.H+"-"+mat.m+"-"+mat.s;
}else
{
return mat.Y+mat.M+mat.D+mat.H+mat.m+mat.s;
}
}
},
formatZero(str){
str=str.toString();
if(str.length<2){
str='0'+ str;
}
return str;
},
/**
* @apiGroup C
* @apiName setEvent
* @api {数据存储} 数据存储 setEvent(存) 将事件信息发送到乐玩服务器记录
* @apiParam {String} eventName 事件名称
* @apiParam {String} eventId 事件ID 通常谢按钮的英文或者中文名字
* @apiParam {JSON} params 参数相关
* @apiSuccessExample {json} 示例:
* sdk.setEvent("click","level11",{'key1':'val'},null)
*/
setEvent(eventName,eventId,params,callbackFunction){
var data = {};
data.uid=this.getUser().uid;
data.game= sdk_conf.game;
data.version=sdk_conf.version;
data.event_id = eventId;
data.event_name =eventName;
data.event_params = JSON.stringify(params);
this.Post(this.ip3 + this.Logcommon, { log_type: "EventLog", data: JSON.stringify(data) }, function (d) {
callbackFunction(d);
});
},
/**
* @apiGroup C
* @apiName setOnClickListener
* @api 对控件设置监听事件 setOnClickListener
* @apiParam {String} buttonKey 按钮编码
* @apiParam {this} 调用场景的this指针
* @apiParam {node}} 控件需要的对象
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.setOnClickListener("send_pic")
*/
setOnClickListener(buttonKey,sceneThis,control)
{
var config = this.getConfig3ByButtonKey(buttonKey);
var dl =config.date_list;
switch(buttonKey)
{
case "send_pic": //换公众号图片
if(dl.length)
{
for(var i in dl)
{
//this.onShowSprite(sData[i],date);
var nowTime =new Date().getTime();
if(nowTime >=dl[i].s_time && nowTime <=dl[i].e_time)
{
if(data.image_url)
{
//创建
sdk.createImage(control,dl[i].image_url);
}
}
}
}
break;
case "open_micro_game_left":
//跳转小程序
if(dl.length)
{
for(var i in dl)
{
this.navigateToMiniProgram(dl[i],function(res){
console.log("小程序跳转成功",res);
}.bind(sceneThis),function(){
console.log("小程序跳转失败");
}.bind(thsceneThisis),function(){
console.log("开始小程序跳转");
}.bind(sceneThis));
}
}
break;
case "open_micro_game_right":
//跳转小游戏
if(dl.length)
{
for(var i in dl)
{
//this.onJumpProgramGame(sData[i],date);
this.navigateToMiniProgram(dl[i],function(res){
console.log("小程序跳转成功",res);
}.bind(sceneThis),function(){
console.log("小程序跳转失败");
}.bind(sceneThis),function(){
console.log("开始小程序跳转");
}.bind(sceneThis));
}
}
break;
}
},
/**
* @apiGroup C
* @apiName navigateToMiniProgram
* @api 跳转到小程序或者小游戏注意有时间限定 navigateToMiniProgram
* @apiParam {String} data json包含app_id,path,extraData
* @apiParam {fucntion} success 成功返回
* @apiParam {fucntion} fail 失败返回
* @apiParam {fucntion} complete 完成返回
*
* @apiSuccessExample {json} 示例:
* var nick = sdk.setOnClickListener("send_pic")
*/
navigateToMiniProgram(data,success,fail,complete)
{
var nowTime =new Date().getTime();
if(nowTime >=data.s_time && nowTime <=data.e_time)
{
wx.navigateToMiniProgram({
appId: data.app_id, //string 要打开的小程序appId
path: data.path, //string 打开的页面路径,如果为空则打开首页
extraData: data.extra, //object 需要传递给目标小程序的数据
success: success,
fail: fail,
complete: complete,
});
}
},
......
......@@ -2,9 +2,9 @@ var sdk_conf = {
//.开发调试环境:prod 或 test,env_apis配合使用,主要是将接口切换正式环境和测试环境,上线务必修改为:prod
env:'prod',
//.游戏唯一标识:由游戏技术修改
game: 'xxx',
game: 'zuiqiangchijiwang',
//.当前游戏版本:由游戏技术修改
version: '1.005',
version: '1.006',
//.banner广告单元id
bannerAdUnitId: '',
//.video广告单元id
......@@ -13,7 +13,7 @@ var sdk_conf = {
//.开发平台:由sdk维护者确定,weixin 或 toutiao,接入游戏的技术不需要修改
dev_platform: 'weixin',
//.乐玩sdk的版本号:由sdk维护者确定,接入游戏的技术不需要修改
llewan_sdk_version:'1.003',
llewan_sdk_version:'1.004',
//.接口加密key,切勿修改
md5_key: '$5dfjr$%dsadsfdsii',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment