Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica-weixin
提交
1f4c63fc
M
mica-weixin
项目概览
mica
/
mica-weixin
通知
8
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mica-weixin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1f4c63fc
编写于
5月 01, 2020
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
支持多小程序和自定义 app 配置加载.
上级
3fd70296
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
141 addition
and
79 deletion
+141
-79
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/annotation/ApiType.java
.../src/main/java/net/dreamlu/weixin/annotation/ApiType.java
+0
-13
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/annotation/WxApi.java
...in/src/main/java/net/dreamlu/weixin/annotation/WxApi.java
+0
-6
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
...java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
+5
-0
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
...t/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
+4
-7
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
.../main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
+37
-29
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxConf.java
...eixin/src/main/java/net/dreamlu/weixin/config/WxConf.java
+22
-0
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxConfigLoader.java
...c/main/java/net/dreamlu/weixin/config/WxConfigLoader.java
+32
-0
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxaConf.java
...ixin/src/main/java/net/dreamlu/weixin/config/WxaConf.java
+22
-0
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxaMsgParser.java
...src/main/java/net/dreamlu/weixin/config/WxaMsgParser.java
+3
-0
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/properties/DreamWeixinProperties.java
.../net/dreamlu/weixin/properties/DreamWeixinProperties.java
+9
-22
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java
...c/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java
+7
-2
未找到文件。
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/annotation/ApiType.java
已删除
100644 → 0
浏览文件 @
3fd70296
package
net.dreamlu.weixin.annotation
;
public
enum
ApiType
{
/**
* 微信
*/
WX
,
/**
* 小程序
*/
WXA
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/annotation/WxApi.java
浏览文件 @
1f4c63fc
...
...
@@ -26,10 +26,4 @@ public @interface WxApi {
@AliasFor
(
annotation
=
RequestMapping
.
class
)
String
[]
value
()
default
{};
/**
* 目前不支持多小程序
* @return {ApiType}
*/
ApiType
type
()
default
ApiType
.
WX
;
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
浏览文件 @
1f4c63fc
...
...
@@ -4,6 +4,11 @@ import com.jfinal.weixin.sdk.cache.IAccessTokenCache;
import
lombok.AllArgsConstructor
;
import
org.springframework.cache.Cache
;
/**
* 基于 spring cache 的 weixin token 缓存
*
* @author L.cm
*/
@AllArgsConstructor
public
class
SpringAccessTokenCache
implements
IAccessTokenCache
{
private
final
static
String
ACCESS_TOKEN_PREFIX
=
"dream-weixin:token:"
;
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
浏览文件 @
1f4c63fc
package
net.dreamlu.weixin.config
;
import
lombok.
All
ArgsConstructor
;
import
lombok.
Required
ArgsConstructor
;
import
net.dreamlu.weixin.cache.SpringAccessTokenCache
;
import
net.dreamlu.weixin.properties.DreamWeixinProperties
;
import
net.dreamlu.weixin.spring.MsgInterceptor
;
...
...
@@ -17,8 +17,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
*
* @author L.cm
*/
@
Configuration
@
AllArgsConstructor
@
RequiredArgsConstructor
@
Configuration
(
proxyBeanMethods
=
false
)
@EnableConfigurationProperties
(
DreamWeixinProperties
.
class
)
public
class
DreamWeixinAutoConfiguration
{
private
final
CacheManager
cacheManager
;
...
...
@@ -30,13 +30,10 @@ public class DreamWeixinAutoConfiguration {
}
@Configuration
@RequiredArgsConstructor
public
static
class
MsgConfiguration
extends
WebMvcConfigurerAdapter
{
private
final
DreamWeixinProperties
properties
;
public
MsgConfiguration
(
DreamWeixinProperties
properties
)
{
this
.
properties
=
properties
;
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
String
urlPattern
=
properties
.
getUrlPatterns
();
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
浏览文件 @
1f4c63fc
...
...
@@ -7,12 +7,14 @@ import com.jfinal.weixin.sdk.api.ApiConfigKit;
import
com.jfinal.weixin.sdk.utils.JsonUtils
;
import
com.jfinal.wxaapp.WxaConfig
;
import
com.jfinal.wxaapp.WxaConfigKit
;
import
lombok.
All
ArgsConstructor
;
import
lombok.
Required
ArgsConstructor
;
import
net.dreamlu.weixin.cache.SpringAccessTokenCache
;
import
net.dreamlu.weixin.properties.DreamWeixinProperties
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.SmartInitializingSingleton
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -20,52 +22,58 @@ import java.util.List;
*
* @author L.cm
*/
@
Configuration
@
AllArgsConstructor
@
RequiredArgsConstructor
@
Configuration
(
proxyBeanMethods
=
false
)
public
class
WeixinAppConfig
implements
SmartInitializingSingleton
{
private
final
DreamWeixinProperties
weixinProperties
;
private
final
SpringAccessTokenCache
accessTokenCache
;
private
final
ObjectProvider
<
WxConfigLoader
>
provider
;
@Override
public
void
afterSingletonsInstantiated
()
{
boolean
isdev
=
weixinProperties
.
isDevMode
();
ApiConfigKit
.
setDevMode
(
isdev
);
ApiConfigKit
.
setAccessTokenCache
(
accessTokenCache
);
List
<
DreamWeixinProperties
.
ApiConfig
>
list
=
weixinProperties
.
getWxConfigs
();
for
(
DreamWeixinProperties
.
ApiConfig
apiConfig
:
list
)
{
WxConfigLoader
configLoader
=
provider
.
getIfAvailable
(()
->
WxConfigLoader
.
DEFAULT
);
List
<
WxConf
>
wxConfList
=
new
ArrayList
<>(
weixinProperties
.
getWxConfigs
());
wxConfList
.
addAll
(
configLoader
.
loadWx
());
for
(
WxConf
conf
:
wxConfList
)
{
ApiConfig
config
=
new
ApiConfig
();
if
(
StrKit
.
notBlank
(
apiConfig
.
getAppId
()))
{
config
.
setAppId
(
apiConfig
.
getAppId
());
if
(
StrKit
.
notBlank
(
conf
.
getAppId
()))
{
config
.
setAppId
(
conf
.
getAppId
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getAppSecret
()))
{
config
.
setAppSecret
(
apiConfig
.
getAppSecret
());
if
(
StrKit
.
notBlank
(
conf
.
getAppSecret
()))
{
config
.
setAppSecret
(
conf
.
getAppSecret
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getToken
()))
{
config
.
setToken
(
apiConfig
.
getToken
());
if
(
StrKit
.
notBlank
(
conf
.
getToken
()))
{
config
.
setToken
(
conf
.
getToken
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getEncodingAesKey
()))
{
config
.
setEncodingAesKey
(
apiConfig
.
getEncodingAesKey
());
if
(
StrKit
.
notBlank
(
conf
.
getEncodingAesKey
()))
{
config
.
setEncodingAesKey
(
conf
.
getEncodingAesKey
());
}
config
.
setEncryptMessage
(
apiConfig
.
isMessageEncrypt
());
config
.
setEncryptMessage
(
conf
.
isMessageEncrypt
());
ApiConfigKit
.
putApiConfig
(
config
);
}
DreamWeixinProperties
.
WxaConfig
apiConfig
=
weixinProperties
.
getWxaConfig
();
List
<
WxaConf
>
wxaConfList
=
new
ArrayList
<>(
weixinProperties
.
getWxaConfigs
());
wxaConfList
.
addAll
(
configLoader
.
loadWxa
());
for
(
WxaConf
conf
:
wxaConfList
)
{
WxaConfig
config
=
new
WxaConfig
();
if
(
StrKit
.
notBlank
(
apiConfig
.
getAppId
()))
{
config
.
setAppId
(
apiConfig
.
getAppId
());
if
(
StrKit
.
notBlank
(
conf
.
getAppId
()))
{
config
.
setAppId
(
conf
.
getAppId
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getAppSecret
()))
{
config
.
setAppSecret
(
apiConfig
.
getAppSecret
());
if
(
StrKit
.
notBlank
(
conf
.
getAppSecret
()))
{
config
.
setAppSecret
(
conf
.
getAppSecret
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getToken
()))
{
config
.
setToken
(
apiConfig
.
getToken
());
if
(
StrKit
.
notBlank
(
conf
.
getToken
()))
{
config
.
setToken
(
conf
.
getToken
());
}
if
(
StrKit
.
notBlank
(
apiConfig
.
getEncodingAesKey
()))
{
config
.
setEncodingAesKey
(
apiConfig
.
getEncodingAesKey
());
if
(
StrKit
.
notBlank
(
conf
.
getEncodingAesKey
()))
{
config
.
setEncodingAesKey
(
conf
.
getEncodingAesKey
());
}
config
.
setMessageEncrypt
(
apiConfig
.
isMessageEncrypt
());
WxaConfigKit
.
setDevMode
(
isdev
);
config
.
setMessageEncrypt
(
conf
.
isMessageEncrypt
());
WxaConfigKit
.
setWxaConfig
(
config
);
}
WxaConfigKit
.
setDevMode
(
isdev
);
if
(
WxaMsgParser
.
JSON
==
weixinProperties
.
getWxaMsgParser
())
{
WxaConfigKit
.
useJsonMsgParser
();
}
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxConf.java
0 → 100644
浏览文件 @
1f4c63fc
package
net.dreamlu.weixin.config
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* 微信配置
*
* @author L.cm
*/
@Getter
@Setter
public
class
WxConf
{
private
String
token
;
private
String
appId
;
private
String
appSecret
;
private
String
encodingAesKey
;
/**
* 消息加密与否
*/
private
boolean
messageEncrypt
=
false
;
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxConfigLoader.java
0 → 100644
浏览文件 @
1f4c63fc
package
net.dreamlu.weixin.config
;
import
java.util.Collections
;
import
java.util.List
;
/**
* 微信配置加载器,用于实现数据库读取自定义配置等
*
* @author L.cm
*/
public
interface
WxConfigLoader
{
WxConfigLoader
DEFAULT
=
new
WxConfigLoader
()
{};
/**
* 加载微信配置
*
* @return 微信配置列表
*/
default
List
<
WxConf
>
loadWx
()
{
return
Collections
.
emptyList
();
}
/**
* 加载小程序配置
*
* @return 小程序配置列表
*/
default
List
<
WxaConf
>
loadWxa
()
{
return
Collections
.
emptyList
();
}
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxaConf.java
0 → 100644
浏览文件 @
1f4c63fc
package
net.dreamlu.weixin.config
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* 小程序的配置
*
* @author L.cm
*/
@Getter
@Setter
public
class
WxaConf
{
private
String
appId
;
private
String
appSecret
;
private
String
token
;
private
String
encodingAesKey
;
/**
* 消息加密与否
*/
private
boolean
messageEncrypt
=
false
;
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WxaMsgParser.java
浏览文件 @
1f4c63fc
...
...
@@ -6,5 +6,8 @@ package net.dreamlu.weixin.config;
* @author L.cm
*/
public
enum
WxaMsgParser
{
/**
* json 、xml
*/
JSON
,
XML
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/properties/DreamWeixinProperties.java
浏览文件 @
1f4c63fc
...
...
@@ -2,12 +2,19 @@ package net.dreamlu.weixin.properties;
import
lombok.Getter
;
import
lombok.Setter
;
import
net.dreamlu.weixin.config.WxConf
;
import
net.dreamlu.weixin.config.WxaConf
;
import
net.dreamlu.weixin.config.WxaMsgParser
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 配置
*
* @author L.cm
*/
@Getter
@Setter
@ConfigurationProperties
(
"dream.weixin"
)
...
...
@@ -32,11 +39,11 @@ public class DreamWeixinProperties {
/**
* 多公众号配置
*/
private
List
<
ApiConfig
>
wxConfigs
=
new
ArrayList
<>();
private
List
<
WxConf
>
wxConfigs
=
new
ArrayList
<>();
/**
* 小程序配置
*/
private
WxaConfig
wxaConfig
=
new
WxaConfig
();
private
List
<
WxaConf
>
wxaConfigs
=
new
ArrayList
<>
();
/**
* 小程序消息解析,默认xml,支持json和xml
*/
...
...
@@ -46,25 +53,5 @@ public class DreamWeixinProperties {
*/
private
String
jsonType
=
"jackson"
;
@Getter
@Setter
public
static
class
ApiConfig
{
private
String
token
;
private
String
appId
;
private
String
appSecret
;
private
String
encodingAesKey
;
// 消息加密与否
private
boolean
messageEncrypt
=
false
;
}
@Getter
@Setter
public
static
class
WxaConfig
{
private
String
appId
;
private
String
appSecret
;
private
String
token
;
private
String
encodingAesKey
;
// 消息加密与否
private
boolean
messageEncrypt
=
false
;
}
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgInterceptor.java
浏览文件 @
1f4c63fc
...
...
@@ -26,7 +26,6 @@ import java.util.Arrays;
@RequiredArgsConstructor
public
class
MsgInterceptor
extends
HandlerInterceptorAdapter
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
MsgInterceptor
.
class
);
private
final
DreamWeixinProperties
weixinProperties
;
@Override
...
...
@@ -58,9 +57,14 @@ public class MsgInterceptor extends HandlerInterceptorAdapter {
}
else
{
token
=
ApiConfigKit
.
getApiConfig
().
getToken
();
}
}
else
{
if
(
StringUtils
.
hasText
(
appId
))
{
ApiConfigKit
.
setThreadLocalAppId
(
appId
);
token
=
WxaConfigKit
.
getWxaConfig
(
appId
).
getToken
();
}
else
{
token
=
WxaConfigKit
.
getWxaConfig
().
getToken
();
}
}
// 如果是服务器配置请求,则配置服务器并返回
if
(
isConfigServerRequest
(
request
))
{
configServer
(
request
,
response
,
token
);
...
...
@@ -142,5 +146,6 @@ public class MsgInterceptor extends HandlerInterceptorAdapter {
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
super
.
afterCompletion
(
request
,
response
,
handler
,
ex
);
ApiConfigKit
.
removeThreadLocalAppId
();
WxaConfigKit
.
removeThreadLocalAppId
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录