Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
llewan-weixin-sdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
llewan
llewan-weixin-sdk
Commits
b544f450
Commit
b544f450
authored
Sep 25, 2018
by
liuxinjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加保存到服务端默认处理
parent
cbf8d11c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
17 deletions
+24
-17
sdk.js
assets/llewan-weixin-sdk/sdk.js
+23
-12
sdk_conf.js
assets/llewan-weixin-sdk/sdk_conf.js
+1
-5
No files found.
assets/llewan-weixin-sdk/sdk.js
View file @
b544f450
...
@@ -1377,17 +1377,25 @@ var sdk = {
...
@@ -1377,17 +1377,25 @@ var sdk = {
* @apiParam {String} dataKey 键
* @apiParam {String} dataKey 键
* @apiParam {String} dataType 数据类型
* @apiParam {String} dataType 数据类型
* @apiParam {String} data 需要保存的数据
* @apiParam {String} data 需要保存的数据
* @apiParam {String} expireTime 过期时间
* @apiParam {String} expireTime 过期时间
单位(秒),0:默认一天;-1:永不失效(10年);
* sdk.setToServer("testKey","TestData","{'key':'test'}",4);
* sdk.setToServer("testKey","TestData","{'key':'test'}",4);
*
*
*/
*/
setToServer
:
function
(
dataKey
,
dataType
,
data
,
expireTime
){
setToServer
:
function
(
dataKey
,
dataType
,
data
,
expireTime
){
var
self
=
this
;
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
);
self
.
setLocalCache
(
dataKey
,
JSON
.
stringify
(
data
),
expireTime
);
console
.
log
(
dataKey
+
" setLocalCach
e "
+
JSON
.
stringify
(
data
));
console
.
log
(
"setToServer "
+
dataKey
+
" valu
e "
+
JSON
.
stringify
(
data
));
this
.
Get
(
this
.
ip2
+
this
.
set
,
{
key
:
dataKey
,
data
:
JSON
.
stringify
(
data
),
data_type
:
dataType
,
expireTime
:
String
(
expireTime
)},
function
(
d
)
{
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
)
if
(
d
.
c
==
0
)
{
{
console
.
error
(
"设置失败,请联系服务端技术查看问题!"
);
console
.
error
(
"设置失败,请联系服务端技术查看问题!"
);
...
@@ -1413,16 +1421,18 @@ var sdk = {
...
@@ -1413,16 +1421,18 @@ var sdk = {
getFromServer
:
function
(
dataKey
,
dataType
,
data
,
callbackFunction
){
getFromServer
:
function
(
dataKey
,
dataType
,
data
,
callbackFunction
){
var
self
=
this
;
var
self
=
this
;
dataKey
=
sdk_conf
.
game
+
":"
+
dataType
+
":"
+
dataKey
;
var
cacheData
=
this
.
getLocalCache
(
dataKey
)
var
cacheData
=
this
.
getLocalCache
(
dataKey
)
console
.
log
(
dataKey
+
" 本地获取值:"
+
cacheData
);
console
.
log
(
"getFromServer "
+
dataKey
+
" 本地获取值:"
+
cacheData
);
if
(
cacheData
==-
1
)
if
(
cacheData
==-
1
)
{
{
//去远程服务器拿数据
//去远程服务器拿数据
this
.
Get
(
this
.
ip2
+
this
.
get
,
{
key
:
dataKey
,
data_type
:
dataType
,
data
:
JSON
.
stringify
(
data
)},
function
(
d
)
{
this
.
Get
(
this
.
ip2
+
this
.
get
,
{
key
:
dataKey
,
data_type
:
dataType
,
data
:
JSON
.
stringify
(
data
)},
function
(
d
)
{
console
.
log
(
dataKey
+
" 本地不存在,去服务器获取值:"
+
JSON
.
stringify
(
d
));
console
.
log
(
"getFromServer "
+
dataKey
+
" 本地不存在,去服务器获取值:"
+
JSON
.
stringify
(
d
));
callbackFunction
(
d
);
callbackFunction
(
d
.
d
);
});
});
}
else
if
(
cacheData
==
0
)
}
else
if
(
cacheData
==
0
)
{
{
...
@@ -1432,8 +1442,8 @@ var sdk = {
...
@@ -1432,8 +1442,8 @@ var sdk = {
//去远程服务器拿数据
//去远程服务器拿数据
this
.
Get
(
this
.
ip2
+
this
.
get
,
{
key
:
dataKey
,
data_type
:
dataType
,
data
:
JSON
.
stringify
(
data
)},
function
(
d
)
{
this
.
Get
(
this
.
ip2
+
this
.
get
,
{
key
:
dataKey
,
data_type
:
dataType
,
data
:
JSON
.
stringify
(
data
)},
function
(
d
)
{
console
.
log
(
dataKey
+
" 本地已经过期,去服务器获取值:"
+
JSON
.
stringify
(
d
));
console
.
log
(
"getFromServer "
+
dataKey
+
" 本地已经过期,去服务器获取值:"
+
JSON
.
stringify
(
d
));
callbackFunction
(
d
);
callbackFunction
(
d
.
d
);
});
});
}
else
}
else
...
@@ -1450,7 +1460,7 @@ var sdk = {
...
@@ -1450,7 +1460,7 @@ var sdk = {
* @api {set} 数据存储 setItem(存)
* @api {set} 数据存储 setItem(存)
* @apiParam {String} key 键
* @apiParam {String} key 键
* @apiParam {String} value 值
* @apiParam {String} value 值
* @apiParam {String} expireTime 过期时间
* @apiParam {String} expireTime 过期时间
单位(秒)
*
*
* @apiSuccessExample {json} 示例:
* @apiSuccessExample {json} 示例:
* sdk.setLocalCache("nick","hello")
* sdk.setLocalCache("nick","hello")
...
@@ -1480,7 +1490,8 @@ var sdk = {
...
@@ -1480,7 +1490,8 @@ var sdk = {
console
.
log
(
"getLocalCache nowTime"
,
nowTime
);
console
.
log
(
"getLocalCache nowTime"
,
nowTime
);
var
localData
=
cc
.
sys
.
localStorage
.
getItem
(
key
);
var
localData
=
cc
.
sys
.
localStorage
.
getItem
(
key
);
console
.
log
(
"getLocalCache "
+
key
+
" 本地获取值:"
+
localData
);
if
(
localData
)
if
(
localData
)
{
{
...
@@ -1489,13 +1500,13 @@ var sdk = {
...
@@ -1489,13 +1500,13 @@ var sdk = {
if
(
nowTime
>=
expireTime
)
if
(
nowTime
>=
expireTime
)
{
{
cc
.
sys
.
localStorage
.
removeItem
(
key
);
cc
.
sys
.
localStorage
.
removeItem
(
key
);
console
.
log
(
"
本地
dataKey : "
+
key
+
" is expire"
);
console
.
log
(
"
getLocalCache
dataKey : "
+
key
+
" is expire"
);
return
0
;
return
0
;
}
else
}
else
{
{
var
data
=
JSON
.
stringify
(
data
.
data
);
var
data
=
JSON
.
stringify
(
data
.
data
);
console
.
log
(
"
本地
dataKey : "
+
key
+
" is "
+
data
);
console
.
log
(
"
getLocalCache
dataKey : "
+
key
+
" is "
+
data
);
return
data
;
return
data
;
}
}
...
...
assets/llewan-weixin-sdk/sdk_conf.js
View file @
b544f450
...
@@ -10,14 +10,10 @@ var sdk_conf = {
...
@@ -10,14 +10,10 @@ var sdk_conf = {
//.video广告单元id
//.video广告单元id
videoAdUnitId
:
''
,
videoAdUnitId
:
''
,
//.开发平台:由sdk维护者确定,weixin 或 toutiao,接入游戏的技术不需要修改
//.开发平台:由sdk维护者确定,weixin 或 toutiao,接入游戏的技术不需要修改
dev_platform
:
'weixin'
,
dev_platform
:
'weixin'
,
//.乐玩sdk的版本号:由sdk维护者确定,接入游戏的技术不需要修改
//.乐玩sdk的版本号:由sdk维护者确定,接入游戏的技术不需要修改
llewan_sdk_version
:
'1.00
3
'
,
llewan_sdk_version
:
'1.00
1
'
,
//.接口加密key,切勿修改
//.接口加密key,切勿修改
md5_key
:
'$5dfjr$%dsadsfdsii'
,
md5_key
:
'$5dfjr$%dsadsfdsii'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment