Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
14bc821e
Unverified
Commit
14bc821e
authored
Jan 14, 2022
by
linlinjava
Committed by
Gitee
Jan 14, 2022
Browse files
!62 解决微信退款问题,增加微信小程序消息推送配置
Merge pull request !62 from 李阳/liyang
parents
7d79dfc6
f25c6a33
Changes
5
Hide whitespace changes
Inline
Side-by-side
litemall-core/src/main/java/org/linlinjava/litemall/core/config/WxConfig.java
View file @
14bc821e
...
...
@@ -3,7 +3,7 @@ package org.linlinjava.litemall.core.config;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl
;
import
cn.binarywang.wx.miniapp.config.WxMaConfig
;
import
cn.binarywang.wx.miniapp.config.
WxMaInMemory
Config
;
import
cn.binarywang.wx.miniapp.config.
impl.WxMaDefault
Config
Impl
;
import
com.github.binarywang.wxpay.config.WxPayConfig
;
import
com.github.binarywang.wxpay.service.WxPayService
;
import
com.github.binarywang.wxpay.service.impl.WxPayServiceImpl
;
...
...
@@ -18,9 +18,11 @@ public class WxConfig {
@Bean
public
WxMaConfig
wxMaConfig
()
{
WxMa
InMemory
Config
config
=
new
WxMa
InMemory
Config
();
WxMa
Default
Config
Impl
config
=
new
WxMa
Default
Config
Impl
();
config
.
setAppid
(
properties
.
getAppId
());
config
.
setSecret
(
properties
.
getAppSecret
());
config
.
setToken
(
properties
.
getToken
());
config
.
setAesKey
(
properties
.
getAesKey
());
return
config
;
}
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/config/WxProperties.java
View file @
14bc821e
...
...
@@ -19,6 +19,26 @@ public class WxProperties {
private
String
keyPath
;
private
String
token
;
private
String
aesKey
;
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
String
getAesKey
()
{
return
aesKey
;
}
public
void
setAesKey
(
String
aesKey
)
{
this
.
aesKey
=
aesKey
;
}
public
String
getNotifyUrl
()
{
return
notifyUrl
;
}
...
...
litemall-core/src/main/resources/application-core.yml
View file @
14bc821e
...
...
@@ -9,6 +9,10 @@ litemall:
# 商户证书文件路径
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
key-path
:
xxxxx
# 消息推送配置token
token
:
# 消息推送配置AesKey
aes-key
:
#通知相关配置
notify
:
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxMsgController.java
0 → 100644
View file @
14bc821e
package
org.linlinjava.litemall.wx.web
;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.bean.WxMaKefuMessage
;
import
cn.binarywang.wx.miniapp.bean.WxMaMessage
;
import
cn.binarywang.wx.miniapp.message.WxMaXmlOutMessage
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* @author liyang
* @Description 微信消息推送配置
* @date 2021-11-10 17:32:25
*/
@RestController
@RequestMapping
(
value
=
"/wx/msg"
)
public
class
WxMsgController
{
private
final
Log
logger
=
LogFactory
.
getLog
(
WxMsgController
.
class
);
@Autowired
private
WxMaService
wxMaService
;
/**
* token校验
*
* @param signature
* @param timestamp
* @param nonce
* @param echostr
* @return
*/
@GetMapping
(
value
=
"/config"
,
produces
=
"text/plain;charset=utf-8"
)
public
String
config
(
@RequestParam
(
required
=
false
)
String
signature
,
@RequestParam
(
required
=
false
)
String
timestamp
,
@RequestParam
(
required
=
false
)
String
nonce
,
@RequestParam
(
required
=
false
)
String
echostr
)
{
return
!
wxMaService
.
checkSignature
(
timestamp
,
nonce
,
signature
)
?
"fail"
:
echostr
;
}
/**
* 消息回复
*
* @param request
* @param response
* @return
*/
@PostMapping
(
value
=
"/config"
,
produces
=
"application/xml;charset=utf-8"
)
public
String
config
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
WxMaMessage
wxMaMessage
=
null
;
try
{
wxMaMessage
=
WxMaMessage
.
fromXml
(
request
.
getInputStream
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
wxMaMessage
!=
null
)
{
String
msgType
=
wxMaMessage
.
getMsgType
();
if
(
"text"
.
equals
(
msgType
))
{
try
{
wxMaService
.
getMsgService
().
sendKefuMsg
(
WxMaKefuMessage
.
newTextBuilder
().
content
(
wxMaMessage
.
getContent
()).
toUser
(
wxMaMessage
.
getFromUser
()).
build
());
}
catch
(
WxErrorException
e
)
{
logger
.
error
(
"消息自动回复失败"
);
}
}
WxMaXmlOutMessage
wxMaXmlOutMessage
=
new
WxMaXmlOutMessage
();
wxMaXmlOutMessage
.
setMsgType
(
"transfer_customer_service"
);
wxMaXmlOutMessage
.
setToUserName
(
wxMaMessage
.
getFromUser
());
wxMaXmlOutMessage
.
setFromUserName
(
wxMaMessage
.
getToUser
());
wxMaXmlOutMessage
.
setCreateTime
(
wxMaMessage
.
getCreateTime
().
longValue
());
final
String
xml
=
wxMaXmlOutMessage
.
toXml
();
logger
.
info
(
xml
);
return
xml
;
}
return
null
;
}
}
pom.xml
View file @
14bc821e
...
...
@@ -98,13 +98,13 @@
<dependency>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-pay
</artifactId>
<version>
3.3
.0
</version>
<version>
4.1
.0
</version>
</dependency>
<dependency>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-miniapp
</artifactId>
<version>
3.3
.0
</version>
<version>
4.1
.0
</version>
</dependency>
<dependency>
...
...
Write
Preview
Supports
Markdown
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