Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
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
pseer
gxpt_ht
Commits
e4c4d4a7
Commit
e4c4d4a7
authored
Feb 04, 2024
by
wuwenlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信小程序token过期验证bugfix
parent
03470bff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletions
+37
-1
WeChatConstants.java
.../src/main/java/share/common/constant/WeChatConstants.java
+1
-0
WechatNewServiceImpl.java
.../java/share/system/service/impl/WechatNewServiceImpl.java
+36
-1
No files found.
share-common/src/main/java/share/common/constant/WeChatConstants.java
View file @
e4c4d4a7
...
...
@@ -224,6 +224,7 @@ public class WeChatConstants {
// 微信部分
// --------------------------------------------------------------------------------------------------------
public
static
final
int
WECHAT_TOKEN_EXPIRED_CODE
=
40001
;
/** 获取accessToken的url */
public
static
final
String
WECHAT_ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}"
;
/** 开放平台获取accessToken的url */
...
...
share-system/src/main/java/share/system/service/impl/WechatNewServiceImpl.java
View file @
e4c4d4a7
...
...
@@ -106,7 +106,17 @@ public class WechatNewServiceImpl implements WechatNewService {
boolean
exists
=
redisUtil
.
exists
(
WeChatConstants
.
REDIS_WECAHT_MINI_ACCESS_TOKEN_KEY
);
if
(
exists
)
{
Object
accessToken
=
redisUtil
.
get
(
WeChatConstants
.
REDIS_WECAHT_MINI_ACCESS_TOKEN_KEY
);
return
accessToken
.
toString
();
try
{
int
code
=
sensitiveCheck
(
accessToken
.
toString
(),
"验证token是否过期"
);
if
(
code
==
WeChatConstants
.
WECHAT_TOKEN_EXPIRED_CODE
){
exists
=
false
;
}
}
catch
(
Exception
e
){
throw
new
BaseException
(
"验证token是否过期接口异常"
);
}
if
(
exists
)
{
return
accessToken
.
toString
();
}
}
String
appId
=
weChatConfig
.
getAppId
();
if
(
StrUtil
.
isBlank
(
appId
))
{
...
...
@@ -123,6 +133,24 @@ public class WechatNewServiceImpl implements WechatNewService {
return
accessTokenVo
.
getAccessToken
();
}
/**
* <a href="https://developers.weixin.qq.com/minigame/dev/wxcloudrun/src/guide/weixin/token.html">敏感词检测</a>
*
* @param token access_token
* @param content content
* @return errcode
*/
public
int
sensitiveCheck
(
String
token
,
String
content
)
throws
Exception
{
Map
<
String
,
String
>
paramMap
=
new
HashMap
<>(
1
);
paramMap
.
put
(
"content"
,
content
);
String
url
=
StrUtil
.
format
(
"https://api.weixin.qq.com/wxa/msg_sec_check?access_token={}"
,
token
);
String
result
=
restTemplateUtil
.
getData
(
url
,
paramMap
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
return
jsonObject
.
getInteger
(
"errcode"
);
}
/**
* 获取开放平台access_token
* 通过 code 获取
...
...
@@ -155,6 +183,10 @@ public class WechatNewServiceImpl implements WechatNewService {
return
JSONObject
.
parseObject
(
data
.
toJSONString
(),
WeChatOauthToken
.
class
);
}
/**
* 获取开放平台用户信息
*
...
...
@@ -994,6 +1026,9 @@ public class WechatNewServiceImpl implements WechatNewService {
return
JSONObject
.
parseObject
(
data
.
toJSONString
(),
WeChatAccessTokenVo
.
class
);
}
/**
* 微信异常处理
*
...
...
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