Toggle navigation
Toggle navigation
This project
Loading...
Sign in
jiujian
/
client-customer-order-api
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
孟苏慧
2026-04-10 14:21:45 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
348a5c237d2e3494af578462bbf502e7033e248d
348a5c23
1 parent
138c9918
fix
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
src/main/java/com/infoloop/tianting/service/client/WxOfficialAccountHttpClient.java
src/main/java/com/infoloop/tianting/service/client/WxOfficialAccountHttpClient.java
View file @
348a5c2
...
...
@@ -2,6 +2,7 @@ package com.infoloop.tianting.service.client;
import
com.infoloop.tianting.model.dto.WxUserDto.SendSubscriptionMessageResponse
;
import
com.infoloop.tianting.model.dto.WxUserDto.WxUserTokenDto
;
import
org.springframework.lang.Nullable
;
import
com.infoloop.tianting.utils.JsonUtil
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -51,10 +52,21 @@ public class WxOfficialAccountHttpClient {
private
final
Object
lock
=
new
Object
();
private
boolean
isOfficialAccountConfigured
()
{
return
StringUtils
.
isNotBlank
(
appId
)
&&
StringUtils
.
isNotBlank
(
appSecret
);
}
/**
* 获取公众号 access_token(带缓存)
*
* @return token;未配置 appId/appSecret 时返回 null(不请求微信接口)
*/
@Nullable
public
String
fetchStableAccessToken
()
{
if
(!
isOfficialAccountConfigured
())
{
log
.
warn
(
"未配置 officialAccount.appId / officialAccount.appSecret,跳过获取公众号 access_token"
);
return
null
;
}
log
.
info
(
"Fetching Official Account access token..."
);
String
cachedToken
=
stringRedisTemplate
.
opsForValue
().
get
(
ACCESS_TOKEN_CACHE_KEY
);
if
(
StringUtils
.
isNotEmpty
(
cachedToken
))
{
...
...
@@ -117,8 +129,15 @@ public class WxOfficialAccountHttpClient {
Map
<
String
,
Object
>
data
,
String
url
,
Map
<
String
,
String
>
miniprogram
)
{
if
(!
isOfficialAccountConfigured
())
{
log
.
warn
(
"未配置公众号,跳过发送订阅消息 openId={}"
,
openId
);
return
new
SendSubscriptionMessageResponse
(-
1
,
"微信公众号未配置"
);
}
try
{
String
accessToken
=
fetchStableAccessToken
();
if
(
accessToken
==
null
)
{
return
new
SendSubscriptionMessageResponse
(-
1
,
"未获取到公众号 access_token"
);
}
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
...
...
Please
register
or
login
to post a comment