Customizing WxMpMessageRouter - Hippoom/wechat-mp-starter GitHub Wiki
weixin-java-tools provides WxMpMessageRouter to dispatch inbound WeChat message/event to custom handlers. You can provide a subclass of WeChatMpInboundMessagingConfigurerAdapter
to configure the dispatching rules:
import com.github.hippoom.wechat.mp.autoconfigure.messaging.WeChatMpInboundMessagingConfigurerAdapter;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import org.springframework.context.annotation.Configuration;
@Configuration
@RequiredArgsConstructor
public class WeChatMpInboundMessageConfiguration
extends WeChatMpInboundMessagingConfigurerAdapter {
private final QrCodeScannedEventHandler qrCodeScannedEventHandler;
@Override
protected void configure(WxMpMessageRouter router) {
// @formatter:off
router
.rule()
.msgType(WxConsts.XML_MSG_EVENT)
.event(WxConsts.EVT_SCAN).event(WxConsts.EVT_SUBSCRIBE)
.handler(qrCodeScannedEventHandler)
.end();
// @formatter:on
}
}