Commit b544f450 authored by liuxinjun's avatar liuxinjun

增加保存到服务端默认处理

parent cbf8d11c
......@@ -1377,17 +1377,25 @@ var sdk = {
* @apiParam {String} dataKey 键
* @apiParam {String} dataType 数据类型
* @apiParam {String} data 需要保存的数据
* @apiParam {String} expireTime 过期时间
* @apiParam {String} expireTime 过期时间 单位(秒),0:默认一天;-1:永不失效(10年);
* sdk.setToServer("testKey","TestData","{'key':'test'}",4);
*
*/
setToServer: function(dataKey,dataType,data,expireTime){
var self = this;
if(expireTime==-1)
{
expireTime=10*365*24*60*60;
}else if(expireTime==0)
{
expireTime=24*60*60;
}
dataKey = sdk_conf.game+":"+dataType+":"+dataKey;
self.setLocalCache(dataKey,JSON.stringify(data),expireTime);
console.log(dataKey+" setLocalCache "+JSON.stringify(data));
console.log("setToServer "+dataKey + " value "+JSON.stringify(data));
this.Get(this.ip2 + this.set, { key: dataKey,data: JSON.stringify(data),data_type:dataType,expireTime:String(expireTime)}, function (d) {
console.log("setToServer 返回",JSON.stringify(d));
console.log("setToServer 服务端返回",JSON.stringify(d));
if(d.c==0)
{
console.error("设置失败,请联系服务端技术查看问题!");
......@@ -1413,16 +1421,18 @@ var sdk = {
getFromServer: function(dataKey,dataType,data,callbackFunction){
var self = this;
dataKey = sdk_conf.game+":"+dataType+":"+dataKey;
var cacheData = this.getLocalCache(dataKey)
console.log(dataKey+" 本地获取值:"+cacheData);
console.log("getFromServer "+dataKey+" 本地获取值:"+cacheData);
if(cacheData==-1)
{
//去远程服务器拿数据
this.Get(this.ip2 + this.get, { key: dataKey,data_type:dataType,data: JSON.stringify(data)}, function (d) {
console.log(dataKey+" 本地不存在,去服务器获取值:"+JSON.stringify(d));
callbackFunction(d);
console.log("getFromServer "+dataKey+" 本地不存在,去服务器获取值:"+JSON.stringify(d));
callbackFunction(d.d);
});
}else if(cacheData==0)
{
......@@ -1432,8 +1442,8 @@ var sdk = {
//去远程服务器拿数据
this.Get(this.ip2 + this.get, { key: dataKey,data_type:dataType,data: JSON.stringify(data)}, function (d) {
console.log(dataKey+" 本地已经过期,去服务器获取值:"+JSON.stringify(d));
callbackFunction(d);
console.log("getFromServer "+dataKey+" 本地已经过期,去服务器获取值:"+JSON.stringify(d));
callbackFunction(d.d);
});
}else
......@@ -1450,7 +1460,7 @@ var sdk = {
* @api {set} 数据存储 setItem(存)
* @apiParam {String} key 键
* @apiParam {String} value 值
* @apiParam {String} expireTime 过期时间
* @apiParam {String} expireTime 过期时间单位(秒)
*
* @apiSuccessExample {json} 示例:
* sdk.setLocalCache("nick","hello")
......@@ -1480,6 +1490,7 @@ var sdk = {
console.log("getLocalCache nowTime",nowTime);
var localData = cc.sys.localStorage.getItem(key);
console.log("getLocalCache "+key+" 本地获取值:"+localData);
if(localData)
......@@ -1489,13 +1500,13 @@ var sdk = {
if(nowTime>=expireTime)
{
cc.sys.localStorage.removeItem(key);
console.log("本地 dataKey : "+key+" is expire");
console.log("getLocalCache dataKey : "+key+" is expire");
return 0;
}else
{
var data = JSON.stringify(data.data);
console.log("本地 dataKey : "+key+" is "+data);
console.log("getLocalCache dataKey : "+key+" is "+data);
return data;
}
......
......@@ -10,14 +10,10 @@ var sdk_conf = {
//.video广告单元id
videoAdUnitId: '',
//.开发平台:由sdk维护者确定,weixin 或 toutiao,接入游戏的技术不需要修改
dev_platform: 'weixin',
//.乐玩sdk的版本号:由sdk维护者确定,接入游戏的技术不需要修改
llewan_sdk_version:'1.003',
llewan_sdk_version:'1.001',
//.接口加密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