Implementation:A616567126 GPT WEB JAVA WxApi
| Knowledge Sources | |
|---|---|
| Domains | WeChat_Integration, Authentication |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for handling WeChat Official Account webhook verification, message callbacks, and QR ticket generation for scan-to-login, provided by the Spring Web framework.
Description
The WxApi class is the REST controller for WeChat integration. Endpoints:
GET /wx/callBack— WeChat signature verification (returns echostr)POST /wx/callBack— Message callback, delegates toWxServiceImpl.callbackEvent()POST /wx/getTicket— Creates a temporary QR code ticket linked to a tempUserId for scan-to-login
The getTicket() method creates a 10-minute temporary QR ticket via wxMpService.getQrcodeService().qrCodeCreateTmpTicket(), stores the QR URL in Redis, and returns it to the web client.
Usage
Import this controller when you need to:
- Handle WeChat webhook verification and message callbacks
- Generate temporary QR codes for WeChat scan-to-login
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/api/wx/WxApi.java
Signature
@RestController
@RequestMapping(value = "/wx", produces = "application/json; charset=UTF-8")
public class WxApi {
@RequestMapping(value = "/callBack", method = RequestMethod.GET)
public String token(String signature, String timestamp, String nonce, String echostr);
@RequestMapping(value = "/callBack", method = RequestMethod.POST)
public String message(HttpServletRequest request) throws Exception;
@RequestMapping(value = "getTicket", method = RequestMethod.POST)
public B<String> getTicket(@Validated @RequestBody GetTicketReq req) throws WxErrorException;
}
Import
import com.intelligent.bot.api.wx.WxApi;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| signature, timestamp, nonce, echostr | String | Yes (GET) | WeChat verification parameters |
| request | HttpServletRequest | Yes (POST) | Raw WeChat XML message |
| req | GetTicketReq | Yes (getTicket) | tempUserId for QR scene ID |
Outputs
| Name | Type | Description |
|---|---|---|
| token returns | String | echostr for verification |
| message returns | String | XML response |
| getTicket returns | B<String> | QR code URL stored in Redis (10min TTL) |
Usage Examples
QR Ticket for Scan Login
// POST /wx/getTicket
// Body: {"tempUserId": 12345}
// Creates temp QR ticket with scene_id="12345", 10min expiry
// Returns QR code URL
// Redis stores: "token:12345" → qrCodeUrl (10min TTL)
WeChat Verification
// GET /wx/callBack?signature=...×tamp=...&nonce=...&echostr=...
// Verifies signature via wxMpService.checkSignature()
// Returns echostr to confirm server ownership
Related Pages
Implements Principle
- Principle:A616567126_GPT_WEB_JAVA_WeChat_Official_Account
- Principle:A616567126_GPT_WEB_JAVA_Cross_Platform_Login_Binding