Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sb_h5
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
data_server
sb_h5
Commits
91e07e02
Commit
91e07e02
authored
Apr 23, 2019
by
高诸锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
d850fc68
Pipeline
#6344
passed with stage
in 18 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
63 deletions
+62
-63
partner.js
app/controller/partner.js
+1
-1
partner.js
app/service/partner.js
+61
-62
No files found.
app/controller/partner.js
View file @
91e07e02
...
...
@@ -33,7 +33,7 @@ class PartnerController extends Controller {
const
{
ctx
,
service
}
=
this
;
const
{
appKey
}
=
ctx
.
params
;
const
ret
=
await
service
.
partner
.
fetchTheme
(
appKey
);
if
(
ret
&&
ret
.
id
===
appKey
)
{
if
(
ret
&&
ret
.
appKey
===
appKey
)
{
ctx
.
success
(
ret
);
return
;
}
...
...
app/service/partner.js
View file @
91e07e02
...
...
@@ -12,29 +12,83 @@ class PartnerService extends Service {
async
fetchTheme
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchTheme
,
host
,
redisThemePrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
cache
.
get
(
redisThemePrefix
+
appKey
);
const
data
=
await
this
.
app
.
redis
.
get
(
redisThemePrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
JSON
.
stringify
(
data
)
,
err
);
await
this
.
app
.
cache
.
del
(
redisThemePrefix
+
appKey
);
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisThemePrefix
+
appKey
);
}
}
}
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchTheme
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
timeout
:
[
30000
,
30000
],
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
,
subject
:
'
ss
'
,
subject
:
'
hf
'
,
},
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
cache
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
7200
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
}
return
ret
.
data
[
0
];
}
async
fetchInfo
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchInfo
,
host
,
redisInfoPrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisInfoPrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchInfo'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisInfoPrefix
+
appKey
);
}
}
}
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchInfo
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
30000
,
30000
],
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
,
},
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisInfoPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
}
return
ret
.
data
[
0
];
}
async
fetchAgreements
(
id
)
{
const
{
ctx
,
partnerAPI
:
{
fetchAgreements
,
host
,
redisAgreementsPrefix
}
}
=
this
;
const
data
=
await
this
.
app
.
redis
.
get
(
redisAgreementsPrefix
+
id
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchAgreements'
,
redisAgreementsPrefix
+
id
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
redis
.
del
(
redisAgreementsPrefix
+
id
);
}
}
const
url
=
`
${
host
+
fetchAgreements
}
/
${
id
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
30000
,
30000
],
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchAgreements
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
id
)
{
await
this
.
app
.
redis
.
set
(
redisAgreementsPrefix
+
id
,
JSON
.
stringify
(
ret
.
data
),
'EX'
,
300
);
}
return
ret
.
data
;
}
...
...
@@ -80,61 +134,6 @@ class PartnerService extends Service {
}
}
}
async
fetchAgreements
(
id
)
{
const
{
ctx
,
partnerAPI
:
{
fetchAgreements
,
host
,
redisAgreementsPrefix
}
}
=
this
;
const
data
=
await
this
.
app
.
cache
.
get
(
redisAgreementsPrefix
+
id
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchAgreements'
,
redisAgreementsPrefix
+
id
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
cache
.
del
(
redisAgreementsPrefix
+
id
);
}
}
const
url
=
`
${
host
+
fetchAgreements
}
/
${
id
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchAgreements
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
id
)
{
await
this
.
app
.
cache
.
set
(
redisAgreementsPrefix
+
id
,
JSON
.
stringify
(
ret
.
data
),
300
);
}
return
ret
.
data
;
}
// 获取合作方appKey开通的服务
async
fetchInfo
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchInfo
,
host
,
redisInfoPrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisInfoPrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchInfo'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisInfoPrefix
+
appKey
);
}
}
}
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchInfo
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
,
},
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisInfoPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
}
return
ret
.
data
[
0
];
}
}
module
.
exports
=
PartnerService
;
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