Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA WxServiceImpl

From Leeroopedia
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:

  1. Parses the WeChat XML message via WxMpXmlMessage.fromXml()
  2. Handles REQ_MESSAGE_TYPE_EVENT — subscribe/scan events, WeChat QR login binding
  3. Handles REQ_MESSAGE_TYPE_TEXT — routes by content prefix to WxOutService methods
  4. Handles REQ_MESSAGE_TYPE_IMAGE — returns image URL with draw/analyze instructions
  5. 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

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment