Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add JSON format support for WeChat Mini Program message push #3723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Copilot wants to merge 2 commits into develop
base: develop
Choose a base branch
Loading
from copilot/fix-7cdffe6f-47dd-430c-9832-5bb69314dad6

Conversation

Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025
edited
Loading

Implements JSON format support for WeChat Mini Program outbound messages by adding the WxMaJsonOutMessage class.

Problem

Currently, the WeChat Mini Program SDK only supports XML format for message push responses through WxMaXmlOutMessage. According to WeChat's official documentation, JSON format should also be supported for message push scenarios.

Solution

Added WxMaJsonOutMessage class that provides JSON format support while maintaining full compatibility with existing XML functionality:

// Create JSON format message
WxMaJsonOutMessage jsonMessage = WxMaJsonOutMessage.builder()
 .fromUserName("your_mini_program")
 .toUserName("user_openid")
 .msgType(WxConsts.XmlMsgType.TEXT)
 .createTime(System.currentTimeMillis() / 1000)
 .build();
// Convert to JSON
String jsonResponse = jsonMessage.toJson();
// Output: {"toUserName":"user_openid","fromUserName":"your_mini_program","createTime":1758727378,"msgType":"text"}
// Encrypted JSON support
String encryptedJson = jsonMessage.toEncryptedJson(config);

Key Features

  • JSON Serialization: Uses existing WxMaGsonBuilder for consistent JSON formatting
  • Encryption Support: Includes toEncryptedJson(WxMaConfig) method for encrypted responses
  • Builder Pattern: Follows the same builder pattern as WxMaXmlOutMessage
  • Zero Breaking Changes: Existing XML functionality remains unchanged
  • Consistent API: Mirrors the interface of WxMaXmlOutMessage for familiar usage

Implementation Details

The new class follows established patterns from other WxJava modules (like weixin-java-cp's WxCpMessage.toJson()) and maintains the project's coding standards:

  • Uses Lombok annotations for consistency
  • Includes comprehensive unit tests
  • Passes all checkstyle validations
  • Follows the existing serialization patterns

This minimal implementation provides developers the flexibility to choose between XML and JSON formats based on their specific needs while keeping the codebase clean and maintainable.

Fixes #小程序消息推送没有对消息体是json数据格式支持

Fixes #3376


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Implement WxMaJsonOutMessage class with JSON serialization
- Add toJson() method for basic JSON formatting
- Add toEncryptedJson() method for encrypted JSON support
- Include comprehensive tests for the new functionality
- Follow existing patterns from other modules like weixin-java-cp
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@Copilot Copilot AI changed the title (削除) [WIP] 小程序消息推送没有对消息体是 json 数据格式支持 (削除ここまで) (追記) Add JSON format support for WeChat Mini Program message push (追記ここまで) Sep 24, 2025
Copilot finished work on behalf of binarywang September 24, 2025 15:26
@binarywang binarywang marked this pull request as ready for review September 25, 2025 08:20
Copy link
Owner

你只是定义了WxMaJsonOutMessage类,并没有在项目中使用

@binarywang binarywang added this to the 4.7.9 milestone Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@binarywang binarywang Awaiting requested review from binarywang

Labels
None yet
Projects
None yet
Milestone
4.7.9
Development

Successfully merging this pull request may close these issues.

小程序消息推送没有对消息体是 json 数据格式支持

AltStyle によって変換されたページ (->オリジナル) /