Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
Aidea
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
sa_aidea
Aidea
Commits
d0efb5f6
Commit
d0efb5f6
authored
Aug 19, 2021
by
马超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(微问诊): 添加获取微问诊token的接口
parent
b95d5824
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
242 additions
and
1 deletion
+242
-1
TokenService.java
...in/java/com/cftech/prescription/service/TokenService.java
+21
-0
TokenServiceImpl.java
...om/cftech/prescription/service/impl/TokenServiceImpl.java
+39
-0
CdfortisTokenUtil.java
...java/com/cftech/prescription/utils/CdfortisTokenUtil.java
+127
-0
CdfortisTokenController.java
.../com/cftech/prescription/web/CdfortisTokenController.java
+32
-0
prescription.http
.../prescription-module/src/main/test/http/prescription.http
+3
-0
token.http
...modules/prescription-module/src/main/test/http/token.http
+3
-0
common-test.properties
cftech-common-web/src/main/resources/common-test.properties
+9
-0
common.properties
cftech-common-web/src/main/resources/common.properties
+8
-1
No files found.
aidea-modules/prescription-module/src/main/java/com/cftech/prescription/service/TokenService.java
0 → 100644
View file @
d0efb5f6
package
com
.
cftech
.
prescription
.
service
;
import
com.alibaba.fastjson.JSONObject
;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
public
interface
TokenService
{
/**
* 获取微问诊token
*
* @return
*/
JSONObject
getTokenResult
();
}
aidea-modules/prescription-module/src/main/java/com/cftech/prescription/service/impl/TokenServiceImpl.java
0 → 100644
View file @
d0efb5f6
package
com
.
cftech
.
prescription
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cftech.prescription.service.TokenService
;
import
com.cftech.prescription.utils.CdfortisTokenUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
@Slf4j
@Service
public
class
TokenServiceImpl
implements
TokenService
{
@Autowired
CdfortisTokenUtil
cdfortisTokenUtil
;
@Override
public
JSONObject
getTokenResult
()
{
JSONObject
rtnJson
=
new
JSONObject
();
try
{
String
token
=
cdfortisTokenUtil
.
getToken
();
rtnJson
.
put
(
"errorNo"
,
"0"
);
rtnJson
.
put
(
"token"
,
token
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
rtnJson
.
put
(
"errorNo"
,
"1"
);
rtnJson
.
put
(
"errorMsg"
,
e
.
getMessage
());
rtnJson
.
put
(
"errorEnMsg"
,
e
.
getMessage
());
}
return
rtnJson
;
}
}
aidea-modules/prescription-module/src/main/java/com/cftech/prescription/utils/CdfortisTokenUtil.java
0 → 100644
View file @
d0efb5f6
package
com
.
cftech
.
prescription
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cftech.core.util.OKHttpUtils
;
import
com.cftech.core.util.SystemConfig
;
import
com.qcloud.cos.utils.Md5Utils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
/**
* 获取微问诊token Service
*
* @author :machao
* @date :Created in 2021/08/19 15:30
*/
@Slf4j
@Component
public
class
CdfortisTokenUtil
{
/**
* 获取token的Url
*/
private
static
String
tokenUrl
=
SystemConfig
.
p
.
getProperty
(
"cdfortis.token_url"
);
/**
* appkey
*/
private
static
String
appid
=
SystemConfig
.
p
.
getProperty
(
"cdfortis.appid"
);
/**
* appSecrt
*/
private
static
String
appSecret
=
SystemConfig
.
p
.
getProperty
(
"cdfortis.secret"
);
/**
* flag
*/
private
static
String
flag
=
SystemConfig
.
p
.
getProperty
(
"cdfortis.flag"
);
/**
* redis存储key
*/
private
static
String
CDFORTIS_TOKEN_KEY
=
"cdfortis_token"
+
":"
+
appid
;
/**
* 成功的返回值
*/
private
static
String
RESULT_SUCC_CODE
=
"C00010000"
;
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
private
RedisTemplate
<
String
,
String
>
getConfig
()
{
StringRedisSerializer
stringSerializer
=
new
StringRedisSerializer
();
redisTemplate
.
setKeySerializer
(
stringSerializer
);
redisTemplate
.
setHashKeySerializer
(
stringSerializer
);
redisTemplate
.
setHashValueSerializer
(
stringSerializer
);
return
redisTemplate
;
}
/**
* 获取token
*
* @return
*/
public
String
getToken
()
throws
Exception
{
// 检查redis中是否存在
if
(
getConfig
().
hasKey
(
CDFORTIS_TOKEN_KEY
))
{
return
redisTemplate
.
opsForValue
().
get
(
CDFORTIS_TOKEN_KEY
);
}
long
timestamp
=
System
.
currentTimeMillis
();
// 获取签名
String
sign
=
sign
(
appid
,
appSecret
,
flag
,
timestamp
);
// 获取tokenUrl
String
url
=
tokenUrl
.
replace
(
"{appid}"
,
appid
).
replace
(
"{flag}"
,
flag
)
.
replace
(
"{timestamp}"
,
timestamp
+
""
).
replace
(
"{sign}"
,
sign
);
log
.
debug
(
"微问诊token请求地址:{}"
,
url
);
try
{
// 解析结果
String
retStr
=
OKHttpUtils
.
getJSON
(
url
);
log
.
debug
(
"微问诊token请求结果:{}"
,
retStr
);
JSONObject
retObj
=
JSON
.
parseObject
(
retStr
);
JSONObject
returnCode
=
retObj
.
getJSONObject
(
"returnCode"
);
if
(!
RESULT_SUCC_CODE
.
equals
(
returnCode
.
getString
(
"key"
)))
{
log
.
error
(
returnCode
.
toJSONString
());
throw
new
Exception
(
returnCode
.
getString
(
"content"
));
}
JSONObject
data
=
retObj
.
getJSONObject
(
"data"
);
String
token
=
data
.
getString
(
"token"
);
Long
expire
=
data
.
getLongValue
(
"expire"
);
//存到redis
redisTemplate
.
opsForValue
().
set
(
CDFORTIS_TOKEN_KEY
,
token
,
expire
,
TimeUnit
.
SECONDS
);
return
token
;
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
Exception
(
e
.
getMessage
());
}
}
/**
* 获取签名
*
* @param appId
* @param secret
* @param flag
* @param timestamp
* @return
*/
private
String
sign
(
String
appId
,
String
secret
,
String
flag
,
long
timestamp
)
{
String
signStr
=
String
.
format
(
"appid=%s&flag=%s&secret=%s×tamp=%s"
,
appId
,
flag
,
secret
,
timestamp
);
String
sign
=
Md5Utils
.
md5Hex
(
signStr
.
getBytes
());
return
sign
;
}
}
aidea-modules/prescription-module/src/main/java/com/cftech/prescription/web/CdfortisTokenController.java
0 → 100644
View file @
d0efb5f6
package
com
.
cftech
.
prescription
.
web
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cftech.prescription.service.TokenService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 获取微问诊token
*
* @author :machao
* @date :Created in 2021/08/19 9:30
*/
@Slf4j
@RestController
@CrossOrigin
@RequestMapping
(
"/mobile/auth/cdfortis"
)
public
class
CdfortisTokenController
{
@Autowired
TokenService
tokenService
;
@GetMapping
(
"get/token"
)
public
JSONObject
getToken
()
{
return
tokenService
.
getTokenResult
();
}
}
aidea-modules/prescription-module/src/main/test/http/prescription.http
0 → 100644
View file @
d0efb5f6
GET http://localhost:8080/aidea/a/prescription/list
###
\ No newline at end of file
aidea-modules/prescription-module/src/main/test/http/token.http
0 → 100644
View file @
d0efb5f6
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/token
###
\ No newline at end of file
cftech-common-web/src/main/resources/common-test.properties
View file @
d0efb5f6
...
...
@@ -142,3 +142,12 @@ map.ads_resolve=https://apis.map.qq.com/ws/geocoder/v1/?address=${address}
map.key
=
OPIBZ-VYIW2-CK7UO-CM4WN-ELY2K-EUFYP
#\u7B7E\u540D\u5BC6\u94A5
map.secret_key
=
W1je0RfMuDsfxCy73M0b3iEfZRF5cAcU
#\u5fae\u95ee\u8bca\u914d\u7f6e\u53c2\u6570
#\u83b7\u53d6\u0074\u006f\u006b\u0065\u006e\u5730\u5740
#cdfortis.token_url=https://171.cdfortis.com/api/verify/token?appid={appid}&flag={flag}×tamp={timestamp}&sign={sign}
cdfortis.token_url
=
https://api.cdfortis.com/api/verify/token?appid={appid}&flag={flag}×tamp={timestamp}&sign={sign}
cdfortis.appid
=
74523ca670a6ceab8095a7476805c649
cdfortis.secret
=
c2cf8d3e9a6c715a8046541bf397ccc6
cdfortis.flag
=
aidea888
\ No newline at end of file
cftech-common-web/src/main/resources/common.properties
View file @
d0efb5f6
...
...
@@ -143,3 +143,10 @@ map.ads_resolve=https://apis.map.qq.com/ws/geocoder/v1/?address=${address}
map.key
=
OPIBZ-VYIW2-CK7UO-CM4WN-ELY2K-EUFYP
#\u7B7E\u540D\u5BC6\u94A5
map.secret_key
=
W1je0RfMuDsfxCy73M0b3iEfZRF5cAcU
#\u5fae\u95ee\u8bca\u914d\u7f6e\u53c2\u6570
#\u83b7\u53d6\u0074\u006f\u006b\u0065\u006e\u5730\u5740
cdfortis.token_url
=
https://api.cdfortis.com/api/verify/token?appid={appid}&flag={flag}×tamp={timestamp}&sign={sign}
cdfortis.appid
=
wxc587e8869baec269
cdfortis.secret
=
ad5b018eb390c9f8c1532c56f4767cc0
cdfortis.flag
=
aidea888
\ No newline at end of file
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