1
1
package com .github .binarywang .demo .wx .mp .controller ;
2
2
3
+ import lombok .AllArgsConstructor ;
4
+ import lombok .extern .log4j .Log4j ;
5
+ import lombok .extern .slf4j .Slf4j ;
3
6
import me .chanjar .weixin .mp .api .WxMpMessageRouter ;
4
7
import org .apache .commons .lang3 .StringUtils ;
5
8
import org .slf4j .Logger ;
20
23
/**
21
24
* @author Binary Wang(https://github.com/binarywang)
22
25
*/
26
+ @ Slf4j
27
+ @ AllArgsConstructor
23
28
@ RestController
24
29
@ RequestMapping ("/wx/portal/{appid}" )
25
30
public class WxPortalController {
26
- private final Logger logger = LoggerFactory .getLogger (this .getClass ());
27
-
28
- private WxMpService wxService ;
29
-
30
- private WxMpMessageRouter messageRouter ;
31
-
32
- @ Autowired
33
- public WxPortalController (WxMpService wxService , WxMpMessageRouter messageRouter ) {
34
- this .wxService = wxService ;
35
- this .messageRouter = messageRouter ;
36
- }
31
+ private final WxMpService wxService ;
32
+ private final WxMpMessageRouter messageRouter ;
37
33
38
34
@ GetMapping (produces = "text/plain;charset=utf-8" )
39
35
public String authGet (@ PathVariable String appid ,
@@ -42,7 +38,7 @@ public String authGet(@PathVariable String appid,
42
38
@ RequestParam (name = "nonce" , required = false ) String nonce ,
43
39
@ RequestParam (name = "echostr" , required = false ) String echostr ) {
44
40
45
- this . logger .info ("\n 接收到来自微信服务器的认证消息:[{}, {}, {}, {}]" , signature ,
41
+ log .info ("\n 接收到来自微信服务器的认证消息:[{}, {}, {}, {}]" , signature ,
46
42
timestamp , nonce , echostr );
47
43
if (StringUtils .isAnyBlank (signature , timestamp , nonce , echostr )) {
48
44
throw new IllegalArgumentException ("请求参数非法,请核实!" );
@@ -68,7 +64,7 @@ public String post(@PathVariable String appid,
68
64
@ RequestParam ("openid" ) String openid ,
69
65
@ RequestParam (name = "encrypt_type" , required = false ) String encType ,
70
66
@ RequestParam (name = "msg_signature" , required = false ) String msgSignature ) {
71
- this . logger .info ("\n 接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}],"
67
+ log .info ("\n 接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}],"
72
68
+ " timestamp=[{}], nonce=[{}], requestBody=[\n {}\n ] " ,
73
69
openid , signature , encType , msgSignature , timestamp , nonce , requestBody );
74
70
@@ -94,7 +90,7 @@ public String post(@PathVariable String appid,
94
90
// aes加密的消息
95
91
WxMpXmlMessage inMessage = WxMpXmlMessage .fromEncryptedXml (requestBody , wxService .getWxMpConfigStorage (),
96
92
timestamp , nonce , msgSignature );
97
- this . logger .debug ("\n 消息解密后内容为:\n {} " , inMessage .toString ());
93
+ log .debug ("\n 消息解密后内容为:\n {} " , inMessage .toString ());
98
94
WxMpXmlOutMessage outMessage = this .route (inMessage );
99
95
if (outMessage == null ) {
100
96
return "" ;
@@ -103,15 +99,15 @@ public String post(@PathVariable String appid,
103
99
out = outMessage .toEncryptedXml (wxService .getWxMpConfigStorage ());
104
100
}
105
101
106
- this . logger .debug ("\n 组装回复信息:{}" , out );
102
+ log .debug ("\n 组装回复信息:{}" , out );
107
103
return out ;
108
104
}
109
105
110
106
private WxMpXmlOutMessage route (WxMpXmlMessage message ) {
111
107
try {
112
108
return this .messageRouter .route (message );
113
109
} catch (Exception e ) {
114
- this . logger .error ("路由消息时出现异常!" , e );
110
+ log .error ("路由消息时出现异常!" , e );
115
111
}
116
112
117
113
return null ;
0 commit comments