2
2
3
3
import com .github .binarywang .demo .wechat .service .WxOpenServiceDemo ;
4
4
import me .chanjar .weixin .common .exception .WxErrorException ;
5
+ import me .chanjar .weixin .mp .bean .kefu .WxMpKefuMessage ;
5
6
import me .chanjar .weixin .mp .bean .message .WxMpXmlMessage ;
7
+ import me .chanjar .weixin .mp .bean .message .WxMpXmlOutMessage ;
6
8
import me .chanjar .weixin .open .bean .message .WxOpenXmlMessage ;
7
9
import org .apache .commons .lang3 .StringUtils ;
8
10
import org .slf4j .Logger ;
9
11
import org .slf4j .LoggerFactory ;
10
12
import org .springframework .beans .factory .annotation .Autowired ;
11
13
import org .springframework .web .bind .annotation .*;
14
+
12
15
/**
13
16
* @author <a href="https://github.com/007gzs">007</a>
14
17
*/
@@ -18,6 +21,7 @@ public class WechatNotifyController {
18
21
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
19
22
@ Autowired
20
23
protected WxOpenServiceDemo wxOpenService ;
24
+
21
25
@ RequestMapping ("receive_ticket" )
22
26
public Object receiveTicket (@ RequestBody (required = false ) String requestBody , @ RequestParam ("timestamp" ) String timestamp ,
23
27
@ RequestParam ("nonce" ) String nonce , @ RequestParam ("signature" ) String signature ,
@@ -46,8 +50,9 @@ public Object receiveTicket(@RequestBody(required = false) String requestBody, @
46
50
47
51
return out ;
48
52
}
53
+
49
54
@ RequestMapping ("{appId}/callback" )
50
- public Object callback (@ RequestBody (required = false )String requestBody ,
55
+ public Object callback (@ RequestBody (required = false ) String requestBody ,
51
56
@ PathVariable ("appId" ) String appId ,
52
57
@ RequestParam ("signature" ) String signature ,
53
58
@ RequestParam ("timestamp" ) String timestamp ,
@@ -67,7 +72,31 @@ public Object callback(@RequestBody(required = false)String requestBody,
67
72
// aes加密的消息
68
73
WxMpXmlMessage inMessage = WxOpenXmlMessage .fromEncryptedMpXml (requestBody , wxOpenService .getWxOpenConfigStorage (), timestamp , nonce , msgSignature );
69
74
this .logger .debug ("\n 消息解密后内容为:\n {} " , inMessage .toString ());
70
- //wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId);
75
+ // 全网发布测试用例
76
+ if (StringUtils .equalsAnyIgnoreCase (appId , "wxd101a85aa106f53e" , "wx570bc396a51b8ff8" )) {
77
+ try {
78
+ if (StringUtils .equals (inMessage .getMsgType (), "text" )) {
79
+ if (StringUtils .equals (inMessage .getContent (), "TESTCOMPONENT_MSG_TYPE_TEXT" )) {
80
+ out = WxOpenXmlMessage .wxMpOutXmlMessageToEncryptedXml (
81
+ WxMpXmlOutMessage .TEXT ().content ("TESTCOMPONENT_MSG_TYPE_TEXT_callback" )
82
+ .fromUser (inMessage .getToUser ())
83
+ .toUser (inMessage .getFromUser ())
84
+ .build (),
85
+ wxOpenService .getWxOpenConfigStorage ()
86
+ );
87
+ } else if (StringUtils .startsWith (inMessage .getContent (), "QUERY_AUTH_CODE:" )) {
88
+ String msg = inMessage .getContent ().replace ("QUERY_AUTH_CODE:" , "" ) + "_from_api" ;
89
+ WxMpKefuMessage kefuMessage = WxMpKefuMessage .TEXT ().content (msg ).toUser (inMessage .getFromUser ()).build ();
90
+ wxOpenService .getWxOpenComponentService ().getWxMpServiceByAppid (appId ).getKefuService ().sendKefuMessage (kefuMessage );
91
+ }
92
+ } else if (StringUtils .equals (inMessage .getMsgType (), "event" )) {
93
+ WxMpKefuMessage kefuMessage = WxMpKefuMessage .TEXT ().content (inMessage .getEvent () + "from_callback" ).toUser (inMessage .getFromUser ()).build ();
94
+ wxOpenService .getWxOpenComponentService ().getWxMpServiceByAppid (appId ).getKefuService ().sendKefuMessage (kefuMessage );
95
+ }
96
+ } catch (WxErrorException e ) {
97
+ logger .error ("callback" , e );
98
+ }
99
+ }
71
100
return out ;
72
101
}
73
102
}
0 commit comments