Implementation:A616567126 GPT WEB JAVA WxServiceImpl
| Knowledge Sources | |
|---|---|
| Domains | WeChat_Integration, Bot_Framework |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for receiving and routing WeChat Official Account messages, handling subscribe/scan events, and binding WeChat users to web sessions via QR scan login, provided by the Spring framework.
Description
The WxServiceImpl class implements the WxService interface. The callbackEvent() method:
- Parses the WeChat XML message via
WxMpXmlMessage.fromXml() - Handles
REQ_MESSAGE_TYPE_EVENT— subscribe/scan events, WeChat QR login binding - Handles
REQ_MESSAGE_TYPE_TEXT— routes by content prefix toWxOutServicemethods - Handles
REQ_MESSAGE_TYPE_IMAGE— returns image URL with draw/analyze instructions - Returns an XML text message via
WxMpXmlOutTextMessage
The wxUserLogin() method handles cross-platform login: updates user login time/IP, generates a JWT via AuthController.createLoginResult(), pushes it to the web client via SendMessageUtil, and deletes the Redis temp key.
Usage
Import this service when you need to:
- Handle WeChat Official Account callbacks
- Route user commands to the appropriate handler
- Bind WeChat scan events to web login sessions
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/service/wx/impl/WxServiceImpl.java
Signature
@Service("WxService")
public class WxServiceImpl implements WxService {
@Override
public String callbackEvent(HttpServletRequest request) throws Exception;
public void wxUserLogin(User user, HttpServletRequest request, Long tempUserId);
}
Import
import com.intelligent.bot.service.wx.WxService;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | HttpServletRequest | Yes | Raw WeChat POST with XML body |
| user | User | Yes (wxUserLogin) | WeChat user entity |
| tempUserId | Long | Yes (wxUserLogin) | Temp ID from QR scan event key |
Outputs
| Name | Type | Description |
|---|---|---|
| callbackEvent returns | String | XML text message for WeChat |
| wxUserLogin | void | UserAuthRes pushed to web client via SSE/WS |
Usage Examples
Command Routing
// callbackEvent routes by content prefix:
if (content.startsWith("/画画")) → wxOutService.draw(content, fromUser)
if (content.startsWith("/U") or "/V") → wxOutService.paintingChanges(content, fromUser)
if (content.startsWith("/咒语解析")) → wxOutService.spellAnalysis(content, fromUser)
if (content.startsWith("兑换")) → wxOutService.exchange(content, fromUser)
if (content.startsWith("绑定-")) → wxOutService.bind(content, fromUser)
if (content.startsWith("开通")) → wxOutService.opened(content, fromUser)
if (content.equals("查询")) → wxOutService.query(content, fromUser)
if (content.startsWith("/recharge")) → wxOutService.recharge(content, fromUser)
WeChat QR Login
// On subscribe event with tempUserId > 0:
wxUserLogin(user, request, tempUserId);
// 1. Update user.lastLoginTime and ipAddress
// 2. Generate JWT via AuthController.createLoginResult(user)
// 3. Push UserAuthRes to tempUserId via SendMessageUtil
// 4. Delete Redis key: REDIS_KEY_PREFIX_TOKEN + tempUserId
Related Pages
Implements Principle
- Principle:A616567126_GPT_WEB_JAVA_WeChat_Official_Account
- Principle:A616567126_GPT_WEB_JAVA_Cross_Platform_Login_Binding