CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-github-binarywang--weixin-java-miniapp

Comprehensive Java SDK for WeChat MiniApp development with complete platform integration

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

WeChat MiniApp Java SDK

A comprehensive Java SDK for WeChat MiniApp development providing complete platform integration. This library enables Java developers to interact with WeChat's mini program ecosystem through well-structured interfaces covering authentication, messaging, e-commerce, analytics, live streaming, and 40+ other service areas.

Package Information

  • Package Name: com.github.binarywang:weixin-java-miniapp
  • Language: Java
  • Version: 4.7.0
  • Installation: Maven/Gradle dependency

Maven Dependency

<dependency>
    <groupId>com.github.binarywang</groupId>
    <artifactId>weixin-java-miniapp</artifactId>
    <version>4.7.0</version>
</dependency>

Gradle Dependency

implementation 'com.github.binarywang:weixin-java-miniapp:4.7.0'

Core Imports

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;

Basic Usage

// Configure the service
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
config.setAppid("your-appid");
config.setSecret("your-secret");
config.setToken("your-token");  // For message encryption
config.setAesKey("your-aes-key");  // For message encryption

// Create service instance
WxMaService wxService = new WxMaServiceImpl();
wxService.setWxMaConfig(config);

// Get access token (managed automatically)
String accessToken = wxService.getAccessToken();

// User authentication - exchange login code for session
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(jsCode);
String openid = session.getOpenid();
String sessionKey = session.getSessionKey();

// Send customer service message
WxMaKefuMessage message = WxMaKefuMessage.newTextBuilder()
    .toUser(openid)
    .content("Welcome to our mini program!")
    .build();
wxService.getMsgService().sendKefuMsg(message);

// Generate QR code
File qrFile = wxService.getQrcodeService().createWxaCodeUnlimit(
    "scene=user123", "pages/index/index"
);

Architecture

The WeChat MiniApp SDK follows a service-oriented architecture:

  • WxMaService: Central service interface providing access to all functionality
  • Specialized Services: 40+ domain-specific services for different WeChat features
  • Configuration Management: Flexible config system supporting memory and Redis storage
  • Data Models: Complete bean classes for all API requests and responses
  • Multi-HTTP Client Support: Apache HttpClient, OkHttp, and Jodd HTTP implementations

The SDK is designed for production use with thread-safe operations, automatic token management, built-in retry logic, and comprehensive error handling.

Capabilities

Core Services

Essential functionality including service configuration, authentication, access token management, and basic WeChat platform operations.

public interface WxMaService {
    // Configuration
    WxMaConfig getWxMaConfig();
    void setWxMaConfig(WxMaConfig maConfig);
    boolean switchover(String mpId);
    
    // Authentication & Tokens
    String getAccessToken();
    String getAccessToken(boolean forceRefresh);
    WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode);
    String getPaidUnionId(String openid, String transactionId, String mchId, String outTradeNo);
    
    // Platform Operations
    boolean checkSignature(String timestamp, String nonce, String signature);
    void setDynamicData(int lifespan, String type, int scene, String data);
}

Core Services

User Management

User authentication, profile information, phone number access, and user data management for WeChat MiniApp users.

public interface WxMaUserService {
    WxMaJscode2SessionResult getSessionInfo(String jsCode);
    WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr);
    WxMaPhoneNumberInfo getPhoneNumber(String code);
    boolean checkUserInfo(String sessionKey, String rawData, String signature);
    void setUserStorage(Map<String, String> kvMap, String sessionKey, String openid);
}

User Management

Messaging

Comprehensive messaging capabilities including customer service messages, subscription messages, template messages, and dynamic messages.

public interface WxMaMsgService {
    boolean sendKefuMsg(WxMaKefuMessage message);
    void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage);
    void sendUniformMsg(WxMaUniformMessage uniformMessage);
    JsonObject createUpdatableMessageActivityId();
    void setUpdatableMsg(WxMaUpdatableMsg msg);
}

Messaging

QR Code Generation

Generate various types of QR codes and mini program codes with customizable styling and parameters.

public interface WxMaQrcodeService {
    // Mini Program Codes (Interface A)
    File createWxaCode(String path, int width);
    byte[] createWxaCodeBytes(String path, String envVersion, int width, boolean autoColor, 
                              WxMaCodeLineColor lineColor, boolean isHyaline);
    
    // Unlimited Mini Program Codes (Interface B) 
    File createWxaCodeUnlimit(String scene, String page);
    byte[] createWxaCodeUnlimitBytes(String scene, String page, boolean checkPath, 
                                     String envVersion, int width, boolean autoColor, 
                                     WxMaCodeLineColor lineColor, boolean isHyaline);
    
    // Traditional QR Codes (Interface C)
    File createQrcode(String path, int width);
    byte[] createQrcodeBytes(String path, int width);
}

QR Code Generation

Analytics

Comprehensive analytics and data insights including user trends, visit patterns, retention analysis, and user demographics.

public interface WxMaAnalysisService {
    // Trend Analysis
    List<WxMaSummaryTrend> getDailySummaryTrend(Date beginDate, Date endDate);
    List<WxMaVisitTrend> getDailyVisitTrend(Date beginDate, Date endDate);
    List<WxMaVisitTrend> getWeeklyVisitTrend(Date beginDate, Date endDate);
    List<WxMaVisitTrend> getMonthlyVisitTrend(Date beginDate, Date endDate);
    
    // User Analysis
    WxMaVisitDistribution getVisitDistribution(Date beginDate, Date endDate);
    WxMaRetainInfo getDailyRetainInfo(Date beginDate, Date endDate);
    List<WxMaVisitPage> getVisitPage(Date beginDate, Date endDate);
    WxMaUserPortrait getUserPortrait(Date beginDate, Date endDate);
}

Analytics

E-commerce

Complete e-commerce platform integration including shop management, product catalogs, order processing, payments, and logistics.

// Shop Management
public interface WxMaShopAccountService {
    // Account operations
}

public interface WxMaShopSpuService {
    // Product management
}

public interface WxMaShopOrderService {
    // Order processing
}

public interface WxMaShopPayService {
    // Payment handling
}

public interface WxMaShopDeliveryService {
    // Logistics management
}

E-commerce

Live Streaming

Complete live streaming functionality including room management, broadcast control, product integration, and audience management.

public interface WxMaLiveService {
    // Room Management
    WxMaCreateRoomResult createRoom(WxMaLiveRoomInfo roomInfo);
    boolean deleteRoom(Integer roomId);
    boolean editRoom(WxMaLiveRoomInfo roomInfo);
    WxMaLiveResult getLiveInfo(Integer start, Integer limit);
    
    // Room Features
    String getPushUrl(Integer roomId);
    WxMaLiveSharedCode getSharedCode(Integer roomId, String params);
    boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic);
    boolean updatereplay(Integer roomId, Integer closeReplay);
    
    // Product Management
    boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds);
    boolean onsale(Integer roomId, Integer goodsId, Integer onSale);
    boolean push(Integer roomId, Integer goodsId);
}

Live Streaming

Media & Content

Media file management, content security, and content moderation services for images, videos, and other media types.

public interface WxMaMediaService {
    // Media upload and management
}

public interface WxMaSecurityService {
    // Content security and moderation
}

Media & Content

Cloud Development

WeChat Cloud Development integration including cloud functions, database operations, and cloud storage management.

public interface WxMaCloudService {
    // Cloud development operations
}

Cloud Development

Express & Logistics

Express delivery integration and logistics management including shipping, tracking, and delivery services.

public interface WxMaExpressService {
    // Express delivery operations
}

public interface WxMaImmediateDeliveryService {
    // Immediate delivery services
}

Express & Logistics

Development Tools

Comprehensive development and management tools including code deployment, API management, plugin support, and testing utilities for the complete mini program development lifecycle.

public interface WxMaCodeService {
    // Version Control and Deployment
    boolean commitCode(String templateId, String userVersion, String userDesc, ExtJson extJson);
    WxMaCodeVersionsResult getCodeVersions();
    boolean releaseCode(String userVersion);
    boolean rollbackRelease();
    
    // Code Auditing
    WxMaSubmitAuditResult submitAudit();
    WxMaSubmitAuditResult submitAudit(List<WxMaCategory> categoryList);
    WxMaGetAuditStatusResult getAuditStatus(String auditId);
    WxMaGetLatestAuditStatusResult getLatestAuditStatus();
    boolean undoCodeAudit();
}

public interface WxMaJsapiService {
    // JSAPI Configuration
    String getJsapiTicket();
    String getJsapiTicket(boolean forceRefresh);
    WxJsapiSignature createJsapiSignature(String url);
}

public interface WxMaPluginService {
    // Plugin Management
    boolean applyPlugin(String action, String pluginAppid, String reason);
    WxMaPluginListResult getPluginList();
    boolean setDevPluginList(String action, String appid, String userVersion);
    WxMaDevPluginResult getDevPlugin();
}

public interface WxMaOpenApiService {
    // API Quota Management
    WxOpenMaQuotaGetResult getApiQuota(String cgiPath);
    WxOpenMaQueryQuotaResult queryQuota(String cgiPath);
    boolean clearQuota(String appid, String cgiPath);
}

Development Tools

Video on Demand

Short drama and video content management including content publishing, review, and analytics.

public interface WxMaVodService {
    // Content Management
    WxMaVodUploadDramaResult uploadDrama(WxMaVodDramaInfo dramaInfo);
    WxMaVodSingleVideoResult singleFileTest(String mediaUrl, Integer mediaType);
    WxMaVodListDramasResult listDramas(Integer start, Integer limit);
    
    // Audit and Review
    WxMaVodAuditDramaResult auditDrama(String dramaId);
    WxMaVodGetDramaResult getDrama(String dramaId);
}

Virtual Payment

Virtual goods payment processing for mini games and digital content purchases.

public interface WxMaXPayService {
    // Virtual Payment Operations
    WxMaXPayCreateOrderResult createOrder(WxMaXPayCreateOrderRequest request);
    WxMaXPayQueryOrderResult queryOrder(String orderId);
    WxMaXPayRefundResult refundOrder(WxMaXPayRefundRequest request);
    
    // Goods Management
    boolean presentGoods(String openid, String billNo);
    WxMaXPayGoodsResult queryUserGoods(String openid, String goodsType);
}

Marketing & Promotion

Marketing campaign management, promotion codes, and advertising integration services.

public interface WxMaMarketingService {
    // Campaign Management
    WxMaMarketingCampaignResult createCampaign(WxMaMarketingCampaignRequest request);
    boolean pauseCampaign(String campaignId);
    boolean resumeCampaign(String campaignId);
    
    // Promotion Codes
    WxMaPromotionCodeResult generatePromotionCode(String campaignId, Integer count);
}

Electronic Invoice

Electronic invoice management for reimbursement and expense tracking integration.

public interface WxMaReimburseInvoiceService {
    // Invoice Operations
    WxMaInvoiceResult getInvoiceInfo(String cardId, String encryptCode);
    WxMaInvoiceBatchResult getInvoiceBatch(List<WxMaInvoiceItem> items);
    boolean updateInvoiceStatus(String cardId, String encryptCode, String reimburseStatus);
}

Order Shipping

Order shipping and logistics coordination for physical goods delivery management.

public interface WxMaOrderShippingService {
    // Shipping Management
    boolean uploadShippingInfo(String orderId, WxMaShippingInfo shippingInfo);
    WxMaShippingResult queryShipping(String orderId);
    boolean notifyConfirmReceive(String orderId, Integer received);
    
    // Delivery Templates
    WxMaDeliveryTemplateResult getDeliveryTemplate();
}

Configuration

Comprehensive configuration management supporting memory-based and Redis-based storage with multi-app support.

public interface WxMaConfig {
    // Basic Configuration
    String getAppid();
    String getSecret();
    String getToken();
    String getAesKey();
    
    // Access Token Management
    String getAccessToken();
    boolean isAccessTokenExpired();
    void updateAccessToken(String accessToken, int expiresInSeconds);
    Lock getAccessTokenLock();
    
    // HTTP Configuration
    String getHttpProxyHost();
    int getHttpProxyPort();
    int getRetrySleepMillis();
    int getMaxRetryTimes();
}

Configuration

Multi-App Support

// Configure multiple mini programs
WxMaService wxService = new WxMaServiceImpl();
wxService.addConfig("app1", config1);
wxService.addConfig("app2", config2);

// Switch between apps dynamically
wxService.switchoverTo("app1");
// All operations now use app1's configuration

wxService.switchoverTo("app2"); 
// All operations now use app2's configuration

Error Handling

All service methods that interact with WeChat APIs throw WxErrorException on failure:

try {
    WxMaJscode2SessionResult result = wxService.getUserService().getSessionInfo(jsCode);
    // Process successful result
} catch (WxErrorException e) {
    int errorCode = e.getError().getErrorCode();
    String errorMsg = e.getError().getErrorMsg();
    
    // Handle specific WeChat error codes
    switch (errorCode) {
        case 40029:
            // Invalid js_code
            break;
        case 45011:
            // API quota exceeded  
            break;
        case 40001:
            // Invalid access token
            break;
    }
}

Thread Safety & Production Usage

The SDK is designed for production environments:

  • Thread Safety: All service instances are thread-safe with proper synchronization
  • Token Management: Automatic access token refresh with lock-based concurrency control
  • Retry Logic: Built-in retry mechanism for transient failures
  • Connection Pooling: Configurable HTTP client with connection pooling support
  • Redis Support: Distributed configuration storage for multi-instance deployments

Performance Considerations

  • Create one WxMaService instance per mini program and reuse it
  • Use Redis-based configuration in distributed systems
  • Monitor API quota usage with WxMaOpenApiService
  • Cache frequently accessed data like QR codes
  • Configure appropriate timeout values for your use case
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.github.binarywang/weixin-java-miniapp@4.7.x
Publish Source
CLI
Badge
tessl/maven-com-github-binarywang--weixin-java-miniapp badge