Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica-weixin
提交
b39565a9
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 搜索 >>
提交
b39565a9
编写于
9月 08, 2018
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
v1.3.0
上级
184ed687
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
129 addition
and
105 deletion
+129
-105
README.md
README.md
+2
-2
spring-boot-starter-weixin/build.gradle
spring-boot-starter-weixin/build.gradle
+21
-6
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/aspect/WxApiAspect.java
.../src/main/java/net/dreamlu/weixin/aspect/WxApiAspect.java
+2
-7
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
...java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
+3
-5
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
...t/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
+9
-18
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
.../main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
+34
-19
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/properties/DreamWeixinProperties.java
.../net/dreamlu/weixin/properties/DreamWeixinProperties.java
+49
-43
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/spring/MsgController.java
...rc/main/java/net/dreamlu/weixin/spring/MsgController.java
+4
-1
spring-boot-starter-weixin/src/main/resources/META-INF/spring.factories
...arter-weixin/src/main/resources/META-INF/spring.factories
+2
-0
spring-boot-starter-weixin/src/main/resources/META-INF/spring.provides
...tarter-weixin/src/main/resources/META-INF/spring.provides
+1
-1
spring-boot-weixin-demo/src/main/java/com/example/demo/WeixinController.java
...demo/src/main/java/com/example/demo/WeixinController.java
+0
-1
spring-boot-weixin-demo/src/main/resources/application.yml
spring-boot-weixin-demo/src/main/resources/application.yml
+2
-2
未找到文件。
README.md
浏览文件 @
b39565a9
...
...
@@ -52,8 +52,8 @@ dream:
appSecret
:
11ed9e2b8e3e3c131e7be320a42b2b5a
token
:
123456
wxa-config
:
appid
:
wx4f53594f9a6b3dcb
app
S
ecret
:
eec6482ba3804df05bd10895bace0579
app
-
id
:
wx4f53594f9a6b3dcb
app
-s
ecret
:
eec6482ba3804df05bd10895bace0579
```
-
cache使用spring的cache,需要
`@EnableCaching`
开启。
...
...
spring-boot-starter-weixin/build.gradle
浏览文件 @
b39565a9
...
...
@@ -12,15 +12,15 @@ apply plugin: 'maven'
apply
plugin:
'signing'
apply
plugin:
'propdeps'
apply
plugin:
'propdeps-maven'
apply
plugin:
'maven-publish'
apply
plugin:
'io.spring.dependency-management'
ext
{
javaVersion
=
JavaVersion
.
VERSION_1_8
springVersion
=
"4.3.14.RELEASE"
springBootVersion
=
"1.5.10.RELEASE"
jfinalVersion
=
"3.3"
jfinalWeixinVersion
=
"1.9"
junitVersion
=
"4.12"
springVersion
=
"4.3.18.RELEASE"
springBootVersion
=
"1.5.15.RELEASE"
jfinalVersion
=
"3.4"
jfinalWeixinVersion
=
"2.1"
lombokVersion
=
'1.16.20'
}
...
...
@@ -39,7 +39,7 @@ dependencies {
provided
"org.springframework.boot:spring-boot-starter-aop"
optional
"org.springframework.boot:spring-boot-configuration-processor"
provided
"org.projectlombok:lombok:${lombokVersion}"
testCompile
"
junit:junit:${junitVersion}
"
testCompile
"
org.springframework.boot:spring-boot-starter-test
"
}
dependencyManagement
{
...
...
@@ -53,6 +53,21 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from
sourceSets
.
main
.
allSource
}
jar
{
into
(
"META-INF/maven/$project.group/$project.name"
)
{
from
{
generatePomFileForMavenJavaPublication
}
rename
".*"
,
"pom.xml"
}
}
publishing
{
publications
{
mavenJava
(
MavenPublication
)
{
from
components
.
java
}
}
}
javadoc
{
options
{
encoding
"UTF-8"
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/aspect/WxApiAspect.java
浏览文件 @
b39565a9
package
net.dreamlu.weixin.aspect
;
import
com.jfinal.weixin.sdk.api.ApiConfigKit
;
import
lombok.
extern.slf4j.Slf4j
;
import
lombok.
AllArgsConstructor
;
import
net.dreamlu.weixin.annotation.WxApi
;
import
net.dreamlu.weixin.properties.DreamWeixinProperties
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -15,15 +15,10 @@ import javax.servlet.http.HttpServletRequest;
@Aspect
@Order
@
Slf4j
@
AllArgsConstructor
public
class
WxApiAspect
{
private
final
DreamWeixinProperties
weixinProperties
;
public
WxApiAspect
(
DreamWeixinProperties
weixinProperties
)
{
this
.
weixinProperties
=
weixinProperties
;
}
@Around
(
"@annotation(wxApi)"
)
public
Object
aroundWxApi
(
ProceedingJoinPoint
point
,
WxApi
wxApi
)
throws
Throwable
{
// 目前不支持多小程序,所以不用判断是否为小程序
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/cache/SpringAccessTokenCache.java
浏览文件 @
b39565a9
package
net.dreamlu.weixin.cache
;
import
com.jfinal.weixin.sdk.cache.IAccessTokenCache
;
import
lombok.AllArgsConstructor
;
import
org.springframework.cache.Cache
;
@AllArgsConstructor
public
class
SpringAccessTokenCache
implements
IAccessTokenCache
{
private
final
String
ACCESS_TOKEN_PREFIX
=
"dream-weixin:token:"
;
private
final
static
String
ACCESS_TOKEN_PREFIX
=
"dream-weixin:token:"
;
private
final
Cache
cache
;
public
SpringAccessTokenCache
(
Cache
cache
)
{
this
.
cache
=
cache
;
}
@Override
public
String
get
(
String
key
)
{
return
cache
.
get
(
ACCESS_TOKEN_PREFIX
+
key
,
String
.
class
);
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/DreamWeixinAutoConfiguration.java
浏览文件 @
b39565a9
package
net.dreamlu.weixin.config
;
import
lombok.AllArgsConstructor
;
import
net.dreamlu.weixin.aspect.WxApiAspect
;
import
net.dreamlu.weixin.cache.SpringAccessTokenCache
;
import
net.dreamlu.weixin.properties.DreamWeixinProperties
;
import
net.dreamlu.weixin.spring.MsgInterceptor
;
import
org.springframework.boot.
context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.
autoconfigure.AutoConfigureAfter
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -13,34 +14,24 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
@Configuration
@EnableConfigurationProperties
(
DreamWeixinProperties
.
class
)
@AutoConfigureAfter
(
DreamWeixinProperties
.
class
)
@AllArgsConstructor
public
class
DreamWeixinAutoConfiguration
{
private
final
CacheManager
cacheManager
;
private
final
DreamWeixinProperties
weixinProperties
;
public
DreamWeixinAutoConfiguration
(
CacheManager
cacheManager
,
DreamWeixinProperties
weixinProperties
)
{
this
.
cacheManager
=
cacheManager
;
this
.
weixinProperties
=
weixinProperties
;
}
@Bean
public
WeixinAppConfig
weixinAppConfig
()
{
return
new
WeixinAppConfig
(
weixinProperties
);
}
@Bean
public
SpringAccessTokenCache
springAccessTokenCache
()
{
Cache
cache
=
cacheManager
.
getCache
(
weixinP
roperties
.
getAccessTokenCache
());
public
SpringAccessTokenCache
springAccessTokenCache
(
DreamWeixinProperties
properties
)
{
Cache
cache
=
cacheManager
.
getCache
(
p
roperties
.
getAccessTokenCache
());
return
new
SpringAccessTokenCache
(
cache
);
}
@Bean
public
WxApiAspect
wxApiAspect
()
{
return
new
WxApiAspect
(
weixinP
roperties
);
public
WxApiAspect
wxApiAspect
(
DreamWeixinProperties
properties
)
{
return
new
WxApiAspect
(
p
roperties
);
}
@Configuration
public
class
MsgConfiguration
extends
WebMvcConfigurerAdapter
{
public
static
class
MsgConfiguration
extends
WebMvcConfigurerAdapter
{
private
final
DreamWeixinProperties
properties
;
public
MsgConfiguration
(
DreamWeixinProperties
properties
)
{
...
...
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/config/WeixinAppConfig.java
浏览文件 @
b39565a9
...
...
@@ -4,31 +4,46 @@ import com.jfinal.weixin.sdk.api.ApiConfig;
import
com.jfinal.weixin.sdk.api.ApiConfigKit
;
import
com.jfinal.wxaapp.WxaConfig
;
import
com.jfinal.wxaapp.WxaConfigKit
;
import
lombok.AllArgsConstructor
;
import
net.dreamlu.weixin.properties.DreamWeixinProperties
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.List
;
@Configuration
@AutoConfigureAfter
(
DreamWeixinAutoConfiguration
.
class
)
@AllArgsConstructor
public
class
WeixinAppConfig
implements
InitializingBean
{
private
final
DreamWeixinProperties
weixinProperties
;
private
final
DreamWeixinProperties
weixinProperties
;
public
WeixinAppConfig
(
DreamWeixinProperties
weixinProperties
)
{
this
.
weixinProperties
=
weixinProperties
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
boolean
isdev
=
weixinProperties
.
isDevMode
();
ApiConfigKit
.
setDevMode
(
isdev
);
List
<
DreamWeixinProperties
.
ApiConfig
>
list
=
weixinProperties
.
getWxConfigs
();
for
(
DreamWeixinProperties
.
ApiConfig
apiConfig
:
list
)
{
ApiConfig
config
=
new
ApiConfig
();
config
.
setAppId
(
apiConfig
.
getAppId
());
config
.
setAppSecret
(
apiConfig
.
getAppSecret
());
config
.
setToken
(
apiConfig
.
getToken
());
config
.
setEncodingAesKey
(
apiConfig
.
getEncodingAesKey
());
config
.
setEncryptMessage
(
apiConfig
.
isMessageEncrypt
());
ApiConfigKit
.
putApiConfig
(
config
);
}
DreamWeixinProperties
.
WxaConfig
wxaConfig
=
weixinProperties
.
getWxaConfig
();
WxaConfig
config
=
new
WxaConfig
();
config
.
setAppId
(
wxaConfig
.
getAppId
());
config
.
setAppSecret
(
wxaConfig
.
getAppSecret
());
config
.
setToken
(
wxaConfig
.
getToken
());
config
.
setEncodingAesKey
(
wxaConfig
.
getEncodingAesKey
());
config
.
setMessageEncrypt
(
wxaConfig
.
isMessageEncrypt
());
WxaConfigKit
.
setDevMode
(
isdev
);
WxaConfigKit
.
setWxaConfig
(
config
);
if
(
WxaMsgParser
.
JSON
==
weixinProperties
.
getWxaMsgParser
())
{
WxaConfigKit
.
useJsonMsgParser
();
}
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
boolean
isdev
=
weixinProperties
.
isDevMode
();
ApiConfigKit
.
setDevMode
(
isdev
);
List
<
ApiConfig
>
list
=
weixinProperties
.
getWxConfigs
();
for
(
ApiConfig
apiConfig
:
list
)
{
ApiConfigKit
.
putApiConfig
(
apiConfig
);
}
WxaConfig
wxaConfig
=
weixinProperties
.
getWxaConfig
();
WxaConfigKit
.
setDevMode
(
isdev
);
WxaConfigKit
.
setWxaConfig
(
wxaConfig
);
if
(
WxaMsgParser
.
JSON
==
weixinProperties
.
getWxaMsgParser
())
{
WxaConfigKit
.
useJsonMsgParser
();
}
}
}
spring-boot-starter-weixin/src/main/java/net/dreamlu/weixin/properties/DreamWeixinProperties.java
浏览文件 @
b39565a9
package
net.dreamlu.weixin.properties
;
import
com.jfinal.weixin.sdk.api.ApiConfig
;
import
com.jfinal.wxaapp.WxaConfig
;
import
lombok.Getter
;
import
lombok.Setter
;
import
net.dreamlu.weixin.config.WxaMsgParser
;
...
...
@@ -10,55 +8,63 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@Setter
@ConfigurationProperties
(
"dream.weixin"
)
public
class
DreamWeixinProperties
{
/**
* JFinal filter拦截的路由,默认:/weixin/*
*/
@Getter
@Setter
private
String
urlPatterns
=
"/weixin/*"
;
/**
* 拦截的路由,默认:/weixin/*
*/
private
String
urlPatterns
=
"/weixin/*"
;
/**
* 是否开发模式,默认:false
*/
@Getter
@Setter
private
boolean
devMode
=
false
;
/**
* 是否开发模式,默认:false
*/
private
boolean
devMode
=
false
;
/**
* Spring cache name,需要开启spring cache,默认:dreamWeixinCache
*/
@Getter
@Setter
private
String
accessTokenCache
=
"dreamWeixinCache"
;
/**
* Spring cache name,需要开启spring cache,默认:dreamWeixinCache
*/
private
String
accessTokenCache
=
"dreamWeixinCache"
;
/**
* 多公众号url挂参,默认:appId
*/
@Getter
@Setter
private
String
appIdKey
=
"appId"
;
/**
* 多公众号url挂参,默认:appId
*/
private
String
appIdKey
=
"appId"
;
/**
* 多公众号配置
*/
@Getter
private
List
<
ApiConfig
>
wxConfigs
=
new
ArrayList
<
ApiConfig
>();
/**
* 多公众号配置
*/
private
List
<
ApiConfig
>
wxConfigs
=
new
ArrayList
<>();
/**
* 小程序配置
*/
@Getter
@Setter
private
WxaConfig
wxaConfig
=
new
WxaConfig
();
/**
* 小程序配置
*/
private
WxaConfig
wxaConfig
=
new
WxaConfig
();
/**
* 小程序消息解析,默认xml,支持json和xml
*/
@Getter
@Setter
private
WxaMsgParser
wxaMsgParser
=
WxaMsgParser
.
XML
;
/**
* 小程序消息解析,默认xml,支持json和xml
*/
private
WxaMsgParser
wxaMsgParser
=
WxaMsgParser
.
XML
;
@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/MsgController.java
浏览文件 @
b39565a9
...
...
@@ -16,6 +16,7 @@ import com.jfinal.weixin.sdk.msg.out.OutTextMsg;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -34,9 +35,10 @@ public abstract class MsgController {
/**
* weixin 公众号服务器调用唯一入口,即在开发者中心输入的 URL 必须要指向此 action
* @param imXmlMsg imXmlMsg
* @return {ResponseEntity}
*/
@RequestMapping
(
""
)
public
void
index
(
@RequestBody
String
imXmlMsg
)
{
public
ResponseEntity
<
Void
>
index
(
@RequestBody
String
imXmlMsg
)
{
// 开发模式输出微信服务发送过来的 xml 消息
if
(
ApiConfigKit
.
isDevMode
())
{
System
.
out
.
println
(
"接收消息:"
);
...
...
@@ -133,6 +135,7 @@ public abstract class MsgController {
logger
.
error
(
"未能识别的消息类型。 消息 xml 内容为:\n"
+
imXmlMsg
);
processIsNotDefinedMsg
((
InNotDefinedMsg
)
msg
);
}
return
ResponseEntity
.
ok
().
build
();
}
/**
...
...
spring-boot-starter-weixin/src/main/resources/META-INF/spring.factories
浏览文件 @
b39565a9
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
net.dreamlu.weixin.properties.DreamWeixinProperties,\
net.dreamlu.weixin.config.WeixinAppConfig,\
net.dreamlu.weixin.config.DreamWeixinAutoConfiguration
spring-boot-starter-weixin/src/main/resources/META-INF/spring.provides
浏览文件 @
b39565a9
provides: jfinal, jfinal-weixin
, cglib
provides: jfinal, jfinal-weixin
spring-boot-weixin-demo/src/main/java/com/example/demo/WeixinController.java
浏览文件 @
b39565a9
package
com.example.demo
;
import
com.jfinal.weixin.sdk.jfinal.MsgControllerAdapter
;
import
com.jfinal.weixin.sdk.msg.in.InTextMsg
;
import
com.jfinal.weixin.sdk.msg.in.event.InFollowEvent
;
import
com.jfinal.weixin.sdk.msg.in.event.InMenuEvent
;
...
...
spring-boot-weixin-demo/src/main/resources/application.yml
浏览文件 @
b39565a9
...
...
@@ -8,5 +8,5 @@ dream:
appSecret
:
11ed9e2b8e3e3c131e7be320a42b2b5a
token
:
123456
wxa-config
:
appid
:
wx4f53594f9a6b3dcb
appSecret
:
eec6482ba3804df05bd10895bace0579
\ No newline at end of file
app-id
:
wx4f53594f9a6b3dcb
app-secret
:
eec6482ba3804df05bd10895bace0579
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录