Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhny
Project
Project
Details
Activity
Releases
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
王夏晖
zhny
Commits
60eaa8ce
Commit
60eaa8ce
authored
May 23, 2018
by
张大伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加微信验证
parent
6109c59e
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
781 additions
and
5 deletions
+781
-5
pom.xml
pom.xml
+7
-0
AbstractBuilder.java
src/main/java/org/rcisoft/builder/AbstractBuilder.java
+17
-0
ImageBuilder.java
src/main/java/org/rcisoft/builder/ImageBuilder.java
+24
-0
TextBuilder.java
src/main/java/org/rcisoft/builder/TextBuilder.java
+22
-0
WechatMpConfiguration.java
src/main/java/org/rcisoft/config/WechatMpConfiguration.java
+155
-0
WechatMpProperties.java
src/main/java/org/rcisoft/config/WechatMpProperties.java
+71
-0
JsonUtils.java
src/main/java/org/rcisoft/core/util/JsonUtils.java
+12
-0
AbstractHandler.java
src/main/java/org/rcisoft/handler/AbstractHandler.java
+12
-0
KfSessionHandler.java
src/main/java/org/rcisoft/handler/KfSessionHandler.java
+25
-0
LocationHandler.java
src/main/java/org/rcisoft/handler/LocationHandler.java
+46
-0
LogHandler.java
src/main/java/org/rcisoft/handler/LogHandler.java
+25
-0
MenuHandler.java
src/main/java/org/rcisoft/handler/MenuHandler.java
+36
-0
MsgHandler.java
src/main/java/org/rcisoft/handler/MsgHandler.java
+52
-0
NullHandler.java
src/main/java/org/rcisoft/handler/NullHandler.java
+24
-0
ScanHandler.java
src/main/java/org/rcisoft/handler/ScanHandler.java
+8
-0
StoreCheckNotifyHandler.java
...ain/java/org/rcisoft/handler/StoreCheckNotifyHandler.java
+27
-0
SubscribeHandler.java
src/main/java/org/rcisoft/handler/SubscribeHandler.java
+64
-0
UnsubscribeHandler.java
src/main/java/org/rcisoft/handler/UnsubscribeHandler.java
+27
-0
WechatController.java
src/main/java/org/rcisoft/wechat/WechatController.java
+108
-0
application-dev.yml
src/main/resources/application-dev.yml
+10
-4
application-prod.yml
src/main/resources/application-prod.yml
+9
-1
No files found.
pom.xml
View file @
60eaa8ce
...
@@ -333,6 +333,13 @@
...
@@ -333,6 +333,13 @@
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<artifactId>
spring-test
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-mp
</artifactId>
<version>
3.0.0
</version>
</dependency>
</dependencies>
</dependencies>
...
...
src/main/java/org/rcisoft/builder/AbstractBuilder.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
builder
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
abstract
class
AbstractBuilder
{
protected
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
public
abstract
WxMpXmlOutMessage
build
(
String
content
,
WxMpXmlMessage
wxMessage
,
WxMpService
service
);
}
src/main/java/org/rcisoft/builder/ImageBuilder.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
builder
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
class
ImageBuilder
extends
AbstractBuilder
{
@Override
public
WxMpXmlOutMessage
build
(
String
content
,
WxMpXmlMessage
wxMessage
,
WxMpService
service
)
{
WxMpXmlOutImageMessage
m
=
WxMpXmlOutMessage
.
IMAGE
().
mediaId
(
content
)
.
fromUser
(
wxMessage
.
getToUser
()).
toUser
(
wxMessage
.
getFromUser
())
.
build
();
return
m
;
}
}
src/main/java/org/rcisoft/builder/TextBuilder.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
builder
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
class
TextBuilder
extends
AbstractBuilder
{
@Override
public
WxMpXmlOutMessage
build
(
String
content
,
WxMpXmlMessage
wxMessage
,
WxMpService
service
)
{
WxMpXmlOutTextMessage
m
=
WxMpXmlOutMessage
.
TEXT
().
content
(
content
)
.
fromUser
(
wxMessage
.
getToUser
()).
toUser
(
wxMessage
.
getFromUser
())
.
build
();
return
m
;
}
}
src/main/java/org/rcisoft/config/WechatMpConfiguration.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
config
;
import
me.chanjar.weixin.mp.api.WxMpConfigStorage
;
import
me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage
;
import
me.chanjar.weixin.mp.api.WxMpMessageRouter
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.constant.WxMpEventConstants
;
import
org.rcisoft.handler.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
me
.
chanjar
.
weixin
.
common
.
api
.
WxConsts
.*;
/**
* wechat mp configuration
*
* @author Binary Wang(https://github.com/binarywang)
*/
@Configuration
@ConditionalOnClass
(
WxMpService
.
class
)
@EnableConfigurationProperties
(
WechatMpProperties
.
class
)
public
class
WechatMpConfiguration
{
@Autowired
protected
LogHandler
logHandler
;
@Autowired
protected
NullHandler
nullHandler
;
@Autowired
protected
KfSessionHandler
kfSessionHandler
;
@Autowired
protected
StoreCheckNotifyHandler
storeCheckNotifyHandler
;
@Autowired
private
WechatMpProperties
properties
;
@Autowired
private
LocationHandler
locationHandler
;
@Autowired
private
MenuHandler
menuHandler
;
@Autowired
private
MsgHandler
msgHandler
;
@Autowired
private
UnsubscribeHandler
unsubscribeHandler
;
@Autowired
private
SubscribeHandler
subscribeHandler
;
@Bean
@ConditionalOnMissingBean
public
WxMpConfigStorage
configStorage
()
{
WxMpInMemoryConfigStorage
configStorage
=
new
WxMpInMemoryConfigStorage
();
configStorage
.
setAppId
(
this
.
properties
.
getAppId
());
configStorage
.
setSecret
(
this
.
properties
.
getSecret
());
configStorage
.
setToken
(
this
.
properties
.
getToken
());
configStorage
.
setAesKey
(
this
.
properties
.
getAesKey
());
return
configStorage
;
}
@Bean
@ConditionalOnMissingBean
public
WxMpService
wxMpService
(
WxMpConfigStorage
configStorage
)
{
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.okhttp.WxMpServiceImpl();
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.jodd.WxMpServiceImpl();
// WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl();
WxMpService
wxMpService
=
new
me
.
chanjar
.
weixin
.
mp
.
api
.
impl
.
WxMpServiceImpl
();
wxMpService
.
setWxMpConfigStorage
(
configStorage
);
return
wxMpService
;
}
@Bean
public
WxMpMessageRouter
router
(
WxMpService
wxMpService
)
{
final
WxMpMessageRouter
newRouter
=
new
WxMpMessageRouter
(
wxMpService
);
// 记录所有事件的日志 (异步执行)
newRouter
.
rule
().
handler
(
this
.
logHandler
).
next
();
// 接收客服会话管理事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
WxMpEventConstants
.
CustomerService
.
KF_CREATE_SESSION
)
.
handler
(
this
.
kfSessionHandler
).
end
();
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
WxMpEventConstants
.
CustomerService
.
KF_CLOSE_SESSION
)
.
handler
(
this
.
kfSessionHandler
)
.
end
();
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
WxMpEventConstants
.
CustomerService
.
KF_SWITCH_SESSION
)
.
handler
(
this
.
kfSessionHandler
).
end
();
// 门店审核事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
WxMpEventConstants
.
POI_CHECK_NOTIFY
)
.
handler
(
this
.
storeCheckNotifyHandler
).
end
();
// 自定义菜单事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
MenuButtonType
.
CLICK
).
handler
(
this
.
getMenuHandler
()).
end
();
// 点击菜单连接事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
MenuButtonType
.
VIEW
).
handler
(
this
.
nullHandler
).
end
();
// 关注事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
EventType
.
SUBSCRIBE
).
handler
(
this
.
getSubscribeHandler
())
.
end
();
// 取消关注事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
EventType
.
UNSUBSCRIBE
)
.
handler
(
this
.
getUnsubscribeHandler
()).
end
();
// 上报地理位置事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
EventType
.
LOCATION
).
handler
(
this
.
getLocationHandler
())
.
end
();
// 接收地理位置消息
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
LOCATION
)
.
handler
(
this
.
getLocationHandler
()).
end
();
// 扫码事件
newRouter
.
rule
().
async
(
false
).
msgType
(
XmlMsgType
.
EVENT
)
.
event
(
EventType
.
SCAN
).
handler
(
this
.
getScanHandler
()).
end
();
// 默认
newRouter
.
rule
().
async
(
false
).
handler
(
this
.
getMsgHandler
()).
end
();
return
newRouter
;
}
protected
MenuHandler
getMenuHandler
()
{
return
this
.
menuHandler
;
}
protected
SubscribeHandler
getSubscribeHandler
()
{
return
this
.
subscribeHandler
;
}
protected
UnsubscribeHandler
getUnsubscribeHandler
()
{
return
this
.
unsubscribeHandler
;
}
protected
AbstractHandler
getLocationHandler
()
{
return
this
.
locationHandler
;
}
protected
MsgHandler
getMsgHandler
()
{
return
this
.
msgHandler
;
}
protected
AbstractHandler
getScanHandler
()
{
return
null
;
}
}
src/main/java/org/rcisoft/config/WechatMpProperties.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
config
;
import
org.apache.commons.lang3.builder.ToStringBuilder
;
import
org.apache.commons.lang3.builder.ToStringStyle
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* wechat mp properties
*
* @author Binary Wang(https://github.com/binarywang)
*/
@ConfigurationProperties
(
prefix
=
"wechat.mp"
)
public
class
WechatMpProperties
{
/**
* 设置微信公众号的appid
*/
private
String
appId
;
/**
* 设置微信公众号的app secret
*/
private
String
secret
;
/**
* 设置微信公众号的token
*/
private
String
token
;
/**
* 设置微信公众号的EncodingAESKey
*/
private
String
aesKey
;
public
String
getAppId
()
{
return
this
.
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getSecret
()
{
return
this
.
secret
;
}
public
void
setSecret
(
String
secret
)
{
this
.
secret
=
secret
;
}
public
String
getToken
()
{
return
this
.
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
String
getAesKey
()
{
return
this
.
aesKey
;
}
public
void
setAesKey
(
String
aesKey
)
{
this
.
aesKey
=
aesKey
;
}
@Override
public
String
toString
()
{
return
ToStringBuilder
.
reflectionToString
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
);
}
}
src/main/java/org/rcisoft/core/util/JsonUtils.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
core
.
util
;
import
me.chanjar.weixin.mp.util.json.WxMpGsonBuilder
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
class
JsonUtils
{
public
static
String
toJson
(
Object
obj
)
{
return
WxMpGsonBuilder
.
create
().
toJson
(
obj
);
}
}
src/main/java/org/rcisoft/handler/AbstractHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.mp.api.WxMpMessageHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
abstract
class
AbstractHandler
implements
WxMpMessageHandler
{
protected
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
}
src/main/java/org/rcisoft/handler/KfSessionHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
KfSessionHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
//TODO 对会话做处理
return
null
;
}
}
src/main/java/org/rcisoft/handler/LocationHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.rcisoft.builder.TextBuilder
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
static
me
.
chanjar
.
weixin
.
common
.
api
.
WxConsts
.
XmlMsgType
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
LocationHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
if
(
wxMessage
.
getMsgType
().
equals
(
XmlMsgType
.
LOCATION
))
{
//TODO 接收处理用户发送的地理位置消息
try
{
String
content
=
"感谢反馈,您的的地理位置已收到!"
;
return
new
TextBuilder
().
build
(
content
,
wxMessage
,
null
);
}
catch
(
Exception
e
)
{
this
.
logger
.
error
(
"位置消息接收处理失败"
,
e
);
return
null
;
}
}
//上报地理位置事件
this
.
logger
.
info
(
"\n上报地理位置 。。。 "
);
this
.
logger
.
info
(
"\n纬度 : "
+
wxMessage
.
getLatitude
());
this
.
logger
.
info
(
"\n经度 : "
+
wxMessage
.
getLongitude
());
this
.
logger
.
info
(
"\n精度 : "
+
String
.
valueOf
(
wxMessage
.
getPrecision
()));
//TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用
return
null
;
}
}
src/main/java/org/rcisoft/handler/LogHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.rcisoft.core.util.JsonUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
LogHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
this
.
logger
.
info
(
"\n接收到请求消息,内容:{}"
,
JsonUtils
.
toJson
(
wxMessage
));
return
null
;
}
}
src/main/java/org/rcisoft/handler/MenuHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
static
me
.
chanjar
.
weixin
.
common
.
api
.
WxConsts
.
MenuButtonType
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
MenuHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
weixinService
,
WxSessionManager
sessionManager
)
{
String
msg
=
String
.
format
(
"type:%s, event:%s, key:%s"
,
wxMessage
.
getMsgType
(),
wxMessage
.
getEvent
(),
wxMessage
.
getEventKey
());
if
(
MenuButtonType
.
VIEW
.
equals
(
wxMessage
.
getEvent
()))
{
return
null
;
}
return
WxMpXmlOutMessage
.
TEXT
().
content
(
msg
)
.
fromUser
(
wxMessage
.
getToUser
()).
toUser
(
wxMessage
.
getFromUser
())
.
build
();
}
}
src/main/java/org/rcisoft/handler/MsgHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.exception.WxErrorException
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.apache.commons.lang3.StringUtils
;
import
org.rcisoft.builder.TextBuilder
;
import
org.rcisoft.core.util.JsonUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
static
me
.
chanjar
.
weixin
.
common
.
api
.
WxConsts
.
XmlMsgType
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
MsgHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
weixinService
,
WxSessionManager
sessionManager
)
{
if
(!
wxMessage
.
getMsgType
().
equals
(
XmlMsgType
.
EVENT
))
{
//TODO 可以选择将消息保存到本地
}
//当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
try
{
if
(
StringUtils
.
startsWithAny
(
wxMessage
.
getContent
(),
"你好"
,
"客服"
)
&&
weixinService
.
getKefuService
().
kfOnlineList
()
.
getKfOnlineList
().
size
()
>
0
)
{
return
WxMpXmlOutMessage
.
TRANSFER_CUSTOMER_SERVICE
()
.
fromUser
(
wxMessage
.
getToUser
())
.
toUser
(
wxMessage
.
getFromUser
()).
build
();
}
}
catch
(
WxErrorException
e
)
{
e
.
printStackTrace
();
}
//TODO 组装回复消息
String
content
=
"收到信息内容:"
+
JsonUtils
.
toJson
(
wxMessage
);
return
new
TextBuilder
().
build
(
content
,
wxMessage
,
weixinService
);
}
}
src/main/java/org/rcisoft/handler/NullHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
NullHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
return
null
;
}
}
src/main/java/org/rcisoft/handler/ScanHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
public
abstract
class
ScanHandler
extends
AbstractHandler
{
}
src/main/java/org/rcisoft/handler/StoreCheckNotifyHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* 门店审核事件处理
*
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
StoreCheckNotifyHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
// TODO 处理门店审核事件
return
null
;
}
}
src/main/java/org/rcisoft/handler/SubscribeHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.exception.WxErrorException
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
me.chanjar.weixin.mp.bean.result.WxMpUser
;
import
org.rcisoft.builder.TextBuilder
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
SubscribeHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
weixinService
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
this
.
logger
.
info
(
"新关注用户 OPENID: "
+
wxMessage
.
getFromUser
());
// 获取微信用户基本信息
WxMpUser
userWxInfo
=
weixinService
.
getUserService
()
.
userInfo
(
wxMessage
.
getFromUser
(),
null
);
if
(
userWxInfo
!=
null
)
{
// TODO 可以添加关注用户到本地
}
WxMpXmlOutMessage
responseResult
=
null
;
try
{
responseResult
=
handleSpecial
(
wxMessage
);
}
catch
(
Exception
e
)
{
this
.
logger
.
error
(
e
.
getMessage
(),
e
);
}
if
(
responseResult
!=
null
)
{
return
responseResult
;
}
try
{
return
new
TextBuilder
().
build
(
"感谢关注"
,
wxMessage
,
weixinService
);
}
catch
(
Exception
e
)
{
this
.
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
/**
* 处理特殊请求,比如如果是扫码进来的,可以做相应处理
*/
private
WxMpXmlOutMessage
handleSpecial
(
WxMpXmlMessage
wxMessage
)
throws
Exception
{
//TODO
return
null
;
}
}
src/main/java/org/rcisoft/handler/UnsubscribeHandler.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
handler
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@Component
public
class
UnsubscribeHandler
extends
AbstractHandler
{
@Override
public
WxMpXmlOutMessage
handle
(
WxMpXmlMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMpService
wxMpService
,
WxSessionManager
sessionManager
)
{
String
openId
=
wxMessage
.
getFromUser
();
this
.
logger
.
info
(
"取消关注用户 OPENID: "
+
openId
);
// TODO 可以更新本地数据库为取消关注状态
return
null
;
}
}
src/main/java/org/rcisoft/wechat/WechatController.java
0 → 100644
View file @
60eaa8ce
package
org
.
rcisoft
.
wechat
;
import
me.chanjar.weixin.mp.api.WxMpMessageRouter
;
import
me.chanjar.weixin.mp.api.WxMpService
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlMessage
;
import
me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author Binary Wang(https://github.com/binarywang)
*/
@RestController
@RequestMapping
(
"/wechat/portal"
)
public
class
WechatController
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
@Autowired
private
WxMpService
wxService
;
@Autowired
private
WxMpMessageRouter
router
;
@GetMapping
(
produces
=
"text/plain;charset=utf-8"
)
public
String
authGet
(
@RequestParam
(
name
=
"signature"
,
required
=
false
)
String
signature
,
@RequestParam
(
name
=
"timestamp"
,
required
=
false
)
String
timestamp
,
@RequestParam
(
name
=
"nonce"
,
required
=
false
)
String
nonce
,
@RequestParam
(
name
=
"echostr"
,
required
=
false
)
String
echostr
)
{
this
.
logger
.
info
(
"\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]"
,
signature
,
timestamp
,
nonce
,
echostr
);
if
(
StringUtils
.
isAnyBlank
(
signature
,
timestamp
,
nonce
,
echostr
))
{
throw
new
IllegalArgumentException
(
"请求参数非法,请核实!"
);
}
if
(
this
.
wxService
.
checkSignature
(
timestamp
,
nonce
,
signature
))
{
return
echostr
;
}
return
"非法请求"
;
}
@PostMapping
(
produces
=
"application/xml; charset=UTF-8"
)
public
String
post
(
@RequestBody
String
requestBody
,
@RequestParam
(
"signature"
)
String
signature
,
@RequestParam
(
"timestamp"
)
String
timestamp
,
@RequestParam
(
"nonce"
)
String
nonce
,
@RequestParam
(
name
=
"encrypt_type"
,
required
=
false
)
String
encType
,
@RequestParam
(
name
=
"msg_signature"
,
required
=
false
)
String
msgSignature
)
{
this
.
logger
.
info
(
"\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}],"
+
" timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] "
,
signature
,
encType
,
msgSignature
,
timestamp
,
nonce
,
requestBody
);
if
(!
this
.
wxService
.
checkSignature
(
timestamp
,
nonce
,
signature
))
{
throw
new
IllegalArgumentException
(
"非法请求,可能属于伪造的请求!"
);
}
String
out
=
null
;
if
(
encType
==
null
)
{
// 明文传输的消息
WxMpXmlMessage
inMessage
=
WxMpXmlMessage
.
fromXml
(
requestBody
);
WxMpXmlOutMessage
outMessage
=
this
.
route
(
inMessage
);
if
(
outMessage
==
null
)
{
return
""
;
}
out
=
outMessage
.
toXml
();
}
else
if
(
"aes"
.
equals
(
encType
))
{
// aes加密的消息
WxMpXmlMessage
inMessage
=
WxMpXmlMessage
.
fromEncryptedXml
(
requestBody
,
this
.
wxService
.
getWxMpConfigStorage
(),
timestamp
,
nonce
,
msgSignature
);
this
.
logger
.
debug
(
"\n消息解密后内容为:\n{} "
,
inMessage
.
toString
());
WxMpXmlOutMessage
outMessage
=
this
.
route
(
inMessage
);
if
(
outMessage
==
null
)
{
return
""
;
}
out
=
outMessage
.
toEncryptedXml
(
this
.
wxService
.
getWxMpConfigStorage
());
}
this
.
logger
.
debug
(
"\n组装回复信息:{}"
,
out
);
return
out
;
}
private
WxMpXmlOutMessage
route
(
WxMpXmlMessage
message
)
{
try
{
return
this
.
router
.
route
(
message
);
}
catch
(
Exception
e
)
{
this
.
logger
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
}
src/main/resources/application-dev.yml
View file @
60eaa8ce
server
:
server
:
port
:
808
2
port
:
808
0
context-path
:
/
project
#ContextPath must start with '/' and not end with '/'
context-path
:
/
#ContextPath must start with '/' and not end with '/'
tomcat
:
tomcat
:
max-threads
:
300
max-threads
:
300
max-http-header-size
:
10240000
#uri-encoding: UTF-8
#uri-encoding: UTF-8
# logging: #使用logback-spring 注释掉logging 否则影响
# logging: #使用logback-spring 注释掉logging 否则影响
...
@@ -23,7 +22,6 @@ druid:
...
@@ -23,7 +22,6 @@ druid:
mybatis
:
mybatis
:
mapper-locations
:
classpath:mapper/**/**/*.xml
mapper-locations
:
classpath:mapper/**/**/*.xml
config-location
:
classpath:mybatis-config.xml
mapper
:
mapper
:
...
@@ -102,6 +100,14 @@ global:
...
@@ -102,6 +100,14 @@ global:
code
:
code
:
admin
:
ROLE_1001
admin
:
ROLE_1001
#微信配置
wechat
:
mp
:
appId
:
wx3f3873643c1380ac
secret
:
4c473ce4285771f572d859f7696e370b
token
:
ruixinhuannneng2018
aesKey
:
BPhPqaGgl40uy7LuVe4SkMsqGXp9MjVeVVJMIrqTIW9
filepath
:
filepath
:
analysis
:
D:\zhny\filepath\analysis\
analysis
:
D:\zhny\filepath\analysis\
equipment
:
D:\zhny\filepath\equipment\
equipment
:
D:\zhny\filepath\equipment\
...
...
src/main/resources/application-prod.yml
View file @
60eaa8ce
...
@@ -101,4 +101,12 @@ filepath:
...
@@ -101,4 +101,12 @@ filepath:
devicetp
:
/home/zhny/filepath/devicetp/
devicetp
:
/home/zhny/filepath/devicetp/
loginimg
:
/home/zhny/filepath/loginimg/
loginimg
:
/home/zhny/filepath/loginimg/
serverimgurl
:
139.199.98.105:9000/
serverimgurl
:
139.199.98.105:9000/
\ No newline at end of file
#微信配置
wechat
:
mp
:
appId
:
secret
:
token
:
aesKey
:
\ No newline at end of file
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