Building a WeChat Subscription Account Bot with Spring Boot
This tutorial walks through configuring a WeChat public account, setting up a Spring Boot backend with the wechat‑spring‑boot‑starter, implementing verification and message‑receiving endpoints, handling image messages, and adding content‑moderation logic to create a functional subscription‑account robot.
The article explains how to create a WeChat subscription‑account robot, describing the overall message flow: user messages are sent to the WeChat platform, forwarded to a custom server, processed, and the response is returned to the user.
First, it shows how to configure the public account by filling in fields such as Developer ID, Developer Password, Server URL, Token, Encryption settings, and notes that only the Server URL, Token, and Encryption mode are needed for the simple image‑reply bot.
Next, it adds a Maven repository and the <dependency> <groupId>com.github.developer.weapons</groupId> <artifactId>wechat-spring-boot-starter</artifactId> <version>1.2.6</version> </dependency> to a Spring Boot project, enabling easy WeChat integration.
Then it implements a GET endpoint @RequestMapping(value="/weixin/receive", method=RequestMethod.GET) that validates the signature using wechatOfficialService.isValid and returns the echostr when verification succeeds.
The core POST endpoint @RequestMapping(value="/weixin/receive", method=RequestMethod.POST) validates the request, parses the XML payload with wechatOfficialService.toMap , checks if the message type is "image", and replies with the image URL; otherwise it returns a generic success response.
For content moderation, the article adds a snippet that calls checkService.check(publicKey, privateKey, map.get("PicUrl")) and replies with a warning if the result is "forbid" or a normal acknowledgment otherwise, demonstrating how to integrate a simple image‑censorship service.
Finally, it advises deploying the server, completing the verification, and enabling the bot, with a link to the full source code on GitHub.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.