Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
wangming
/
kzy-wx
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ead63904
authored
Apr 23, 2020
by
魏文甫
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wei_master' into '105'
update See merge request
!49
2 parents
9e0ec080
1432cbfc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
4 deletions
src/main/java/com/server/utils/ParamStrMap.java
src/main/java/com/server/web/controller/BaseController.java
src/main/java/com/server/utils/ParamStrMap.java
0 → 100644
View file @
ead6390
package
com
.
server
.
utils
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by dell on 2018/2/28.
*/
public
class
ParamStrMap
{
private
Map
<
String
,
String
>
data
=
new
HashMap
();
private
ParamStrMap
()
{
}
public
static
ParamStrMap
create
()
{
return
new
ParamStrMap
();
}
public
static
ParamStrMap
create
(
String
key
,
String
value
)
{
return
create
().
put
(
key
,
value
);
}
public
ParamStrMap
put
(
String
key
,
String
value
)
{
this
.
data
.
put
(
key
,
value
);
return
this
;
}
public
Map
<
String
,
String
>
getData
()
{
return
this
.
data
;
}
}
src/main/java/com/server/web/controller/BaseController.java
View file @
ead6390
package
com
.
server
.
web
.
controller
;
package
com
.
server
.
web
.
controller
;
import
com.server.utils.ParamStrMap
;
import
com.server.utils.weixin.HttpURLUtil
;
import
com.server.utils.weixin.WeixinBaseUtil
;
import
com.server.utils.weixin.WeixinBaseUtil
;
import
com.server.utils.weixin.bean.AccessTokenBean
;
import
com.server.utils.weixin.bean.AccessTokenBean
;
import
com.server.web.common.mapper.TKzyUserMapper
;
import
com.server.web.common.mapper.TKzyUserMapper
;
...
@@ -32,6 +34,8 @@ public class BaseController {
...
@@ -32,6 +34,8 @@ public class BaseController {
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
public
final
static
String
WX_USER_SESSION_KEY
=
"weixin_user_session_key"
;
public
final
static
String
WX_USER_SESSION_KEY
=
"weixin_user_session_key"
;
//获取微信accesstockenurl
public
static
final
String
AccessTokenURL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
;
/**
/**
* 获取appaccessToken
* 获取appaccessToken
...
@@ -50,10 +54,15 @@ public class BaseController {
...
@@ -50,10 +54,15 @@ public class BaseController {
}
}
if
(
redisAccessToken
){
if
(
redisAccessToken
){
String
url
=
WeixinBaseUtil
.
ACCESS_TOKEN_URL
+
"&appid="
+
appId
+
"&secret="
+
appSecret
;
// String url = WeixinBaseUtil.ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret;
RestTemplate
restTemplate
=
new
RestTemplate
();
// RestTemplate restTemplate = new RestTemplate();
json
=
restTemplate
.
getForObject
(
url
,
String
.
class
);
// json = restTemplate.getForObject(url, String.class);
redisTemplate
.
opsForValue
().
set
(
"wx_accessToken_"
+
appId
,
json
,
60
*
60
,
TimeUnit
.
SECONDS
);
// redisTemplate.opsForValue().set("wx_accessToken_"+appId,json,60*60, TimeUnit.SECONDS);
final
Map
queryParas
=
ParamStrMap
.
create
(
"appid"
,
appId
).
put
(
"secret"
,
appSecret
).
getData
();
json
=
HttpURLUtil
.
get
(
AccessTokenURL
,
queryParas
);
redisTemplate
.
opsForValue
().
set
(
"wx_accessToken_"
+
appId
,
json
,
60
*
5
,
TimeUnit
.
SECONDS
);
}
}
AccessTokenBean
accessTokenBean
=
new
AccessTokenBean
(
json
);
AccessTokenBean
accessTokenBean
=
new
AccessTokenBean
(
json
);
return
accessTokenBean
.
getAccessToken
();
return
accessTokenBean
.
getAccessToken
();
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment