Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-sfa-common-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-sfa-common-core
Commits
2d4d1e4c
提交
2d4d1e4c
authored
12月 10, 2025
作者:
吕本才
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(wechat): 新增微信小程序和公众号用户缓存常量及优化工具类
上级
a322cc4c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
12 行增加
和
4 行删除
+12
-4
CacheConstants.java
...ain/java/com/sfa/common/core/constant/CacheConstants.java
+2
-0
WeChatPlatFormUtils.java
...com/sfa/common/core/utils/wechat/WeChatPlatFormUtils.java
+10
-4
没有找到文件。
src/main/java/com/sfa/common/core/constant/CacheConstants.java
浏览文件 @
2d4d1e4c
...
...
@@ -61,4 +61,6 @@ public class CacheConstants
*/
public
static
final
String
FRONT_VERSION_KEY
=
"frontVersion:info"
;
public
static
final
String
HUB_USER_MINI_PROGRAM
=
"fortune_hub:user:mini_program:"
;
public
static
final
String
HUB_USER_OFFICE_ACCOUNT
=
"fortune_hub:user:office_account:"
;
}
src/main/java/com/sfa/common/core/utils/wechat/WeChatPlatFormUtils.java
浏览文件 @
2d4d1e4c
...
...
@@ -19,10 +19,10 @@ import org.apache.http.util.EntityUtils;
@Slf4j
public
class
WeChatPlatFormUtils
{
// 微信模板消息接口地址
private
static
final
String
TEMPLATE_SEND_URL
=
"https://api.weixin.qq.com/cgi-bin/message/
wxopen/
template/send"
;
private
static
final
String
TEMPLATE_SEND_URL
=
"https://api.weixin.qq.com/cgi-bin/message/template/send"
;
private
static
final
String
MINI_PROGRAM_CODE2SESSION_URL
=
"https://api.weixin.qq.com/sns/jscode2session"
;
private
static
final
String
ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/"
;
private
static
final
String
ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/
token
"
;
public
static
Object
isSubscribe
(
String
openId
,
String
templateId
,
String
accessToken
)
{
String
url
=
TEMPLATE_SEND_URL
+
"?access_token="
+
accessToken
;
...
...
@@ -40,8 +40,9 @@ public class WeChatPlatFormUtils {
try
(
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
))
{
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
log
.
info
(
"result: {}"
,
jsonObject
.
toString
());
Integer
errCode
=
jsonObject
.
getInteger
(
"errcode"
);
log
.
info
(
"errCode: {}"
,
errCode
);
// 根据错误码判断
if
(
errCode
!=
null
)
{
return
errCode
!=
43004
;
...
...
@@ -49,6 +50,7 @@ public class WeChatPlatFormUtils {
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"获取"
+
templateId
+
"是否订阅"
+
openId
+
"失败"
+
e
.
getMessage
(),
e
);
}
return
false
;
}
...
...
@@ -59,10 +61,14 @@ public class WeChatPlatFormUtils {
* @param appSecret
* @return
*/
public
static
JSONObject
getMiniappToken
(
String
appId
,
String
appSecret
)
{
public
static
JSONObject
getMiniappAccessToken
(
String
appId
,
String
appSecret
)
{
// 需要缓存
String
cacheKey
=
"wx_access_token:"
+
appId
;
String
url
=
ACCESS_TOKEN_URL
+
"?grant_type=client_credential&appid="
+
appId
+
"&secret="
+
appSecret
;
String
body
=
HttpUtil
.
createGet
(
url
).
execute
().
body
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
body
);
return
jsonObject
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论