or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-services.mdconfiguration-security.mdcore-payment.mdenterprise-services.mdindex.mdnotification-processing.mdpayment-methods.mdrefund-management.md
tile.json

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

Comprehensive Java SDK for integrating with WeChat Pay services including unified orders, refunds, enterprise payments, red packets, profit sharing, and marketing services

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.github.binarywang/weixin-java-pay@4.7.x

To install, run

npx @tessl/cli install tessl/maven-com-github-binarywang--weixin-java-pay@4.7.0

index.mddocs/

WeChat Payment Java SDK (weixin-java-pay)

WeChat Payment Java SDK is a comprehensive Java library for integrating with WeChat Pay (微信支付) services. It provides complete support for both WeChat Pay API v2 and v3, enabling developers to implement various payment functionalities including unified orders, refunds, enterprise payments, red packets, profit sharing, and marketing services with built-in security, certificate management, and multi-merchant support.

Package Information

  • Package Name: com.github.binarywang:weixin-java-pay
  • Package Type: maven
  • Language: Java
  • Installation: <dependency><groupId>com.github.binarywang</groupId><artifactId>weixin-java-pay</artifactId><version>4.7.0</version></dependency>

Core Imports

import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.github.binarywang.wxpay.config.WxPayConfig;

For specific services:

import com.github.binarywang.wxpay.service.EntPayService;
import com.github.binarywang.wxpay.service.RedpackService;
import com.github.binarywang.wxpay.service.ProfitSharingService;

For request/response beans:

import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;

Basic Usage

import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
import com.github.binarywang.wxpay.constant.WxPayConstants;

// Initialize configuration
WxPayConfig config = new WxPayConfig();
config.setAppId("your-app-id");
config.setMchId("your-merchant-id");
config.setMchKey("your-merchant-key");
config.setKeyPath("/path/to/cert.p12"); // Certificate path for secure operations

// Create service instance
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(config);

// Create unified order for payment
WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder()
    .outTradeNo("order-20230101-001")
    .totalFee(1) // Amount in cents
    .body("Test Product")
    .tradeType(WxPayConstants.TradeType.JSAPI)
    .openid("user-openid-for-jsapi")
    .build();

// Execute payment request
WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(request);

// Extract payment parameters for frontend
Map<String, String> payParams = result.getPayInfo();

Architecture

WeChat Payment Java SDK is built around several key components:

  • Service Layer: Primary interfaces (WxPayService) and specialized services for different payment scenarios
  • Configuration Management: WxPayConfig for merchant credentials, certificates, and environment settings
  • Request/Response Beans: Strongly-typed objects for API communication with automatic XML/JSON serialization
  • Multi-Merchant Support: Built-in support for managing multiple merchant configurations
  • Protocol Support: Comprehensive support for both WeChat Pay API v2 (XML-based) and v3 (JSON-based)
  • Security Layer: Certificate management, signature generation/validation, and encryption utilities
  • Notification Handling: Webhook processing with signature verification for payment callbacks

Capabilities

Core Payment Operations

Essential payment processing functionality including order creation, querying, and cancellation. Supports all major WeChat Pay payment methods with both v2 and v3 API protocols.

// Unified order creation (v2)
WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException;

// Unified order creation (v3)
WxPayUnifiedOrderV3Result unifiedOrderV3(TradeTypeEnum tradeType, WxPayUnifiedOrderV3Request request) throws WxPayException;

// Order querying
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException;

// Order closing
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException;

Core Payment Operations

Refund Management

Comprehensive refund processing with support for full and partial refunds, refund querying, and notification handling for both API versions.

// Create refund (v2)
WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException;

// Create refund (v3)
WxPayRefundV3Result refundV3(WxPayRefundV3Request request) throws WxPayException;

// Query refund status
WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request) throws WxPayException;

Refund Management

Payment Methods Integration

Support for all WeChat Pay payment methods including JSAPI (Mini Program/Official Account), Native (QR Code), APP, H5 (Mobile Web), Micropay (Barcode), and Face Payment.

// Micropay (barcode/QR scanning)
WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException;

// Face payment
WxPayFacepayResult facepay(WxPayFacepayRequest request) throws WxPayException;

// Generate payment parameters for different platforms
Map<String, String> getPayInfo();
WxPayAppOrderResult createAppOrder(WxPayUnifiedOrderResult result);
WxPayMpOrderResult createMpOrder(WxPayUnifiedOrderResult result);

Payment Methods

Enterprise Services

Enterprise-level payment services including payments to individuals, red packet distribution, and profit sharing functionality.

// Enterprise payments to individuals
EntPayResult entPay(EntPayRequest request) throws WxPayException;

// Red packet distribution
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;

// Profit sharing
ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;

Enterprise Services

Configuration and Security

Configuration management, certificate handling, signature processing, and multi-merchant support for enterprise deployments.

// Configuration management
void setConfig(WxPayConfig config);
void addConfig(String mchId, WxPayConfig wxPayConfig);
boolean switchover(String mchId);

// Certificate management
void initV3HttpClient() throws WxPayException;
String getCertSerialNo();

// Security utilities
String createSign(Map<String, String> params, SignType signType) throws WxPayException;
boolean checkSign(Map<String, String> params) throws WxPayException;

Configuration and Security

Notification Processing

Webhook processing for payment notifications with automatic signature verification and result parsing for various event types.

// Parse payment notifications
WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException;
WxPayNotifyV3Result parseOrderNotifyV3Result(String jsonData, SignatureHeader header) throws WxPayException;

// Parse refund notifications
WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData) throws WxPayException;
WxPayRefundNotifyV3Result parseRefundNotifyV3Result(String jsonData, SignatureHeader header) throws WxPayException;

Notification Processing

Advanced Services

Specialized services including e-commerce platform support, marketing coupons, transfer services, Pay Score, complaint management, payroll, business circle, and bill downloads.

// Marketing and coupons
MarketingFavorService getMarketingFavorService();
MarketingBusiFavorService getMarketingBusiFavorService();

// E-commerce platform
EcommerceService getEcommerceService();

// Transfer services
TransferService getTransferService();
MerchantTransferService getMerchantTransferService();
PartnerTransferService getPartnerTransferService();

// Pay Score services
PayScoreService getPayScoreService();
PartnerPayScoreService getPartnerPayScoreService();

// Payroll and business services
PayrollService getPayrollService();
BusinessCircleService getBusinessCircleService();

// Complaint management
ComplaintService getComplaintsService();

// Bill downloads
WxPayBillResult downloadBill(WxPayBillRequest request) throws WxPayException;

Advanced Services

Key Features Supported

Payment Scenarios

  • B2C Payments: Standard customer payments via all major channels
  • B2B Payments: Business-to-business payment processing
  • C2B Payments: Customer-initiated payments via QR codes and barcodes
  • Subscription Billing: Recurring payment setups with entrust PAP
  • Multi-party Transactions: Profit sharing among multiple recipients

Business Functions

  • Order Management: Complete lifecycle from creation to completion
  • Financial Operations: Refunds, transfers, and settlement management
  • Marketing Tools: Red packets, coupons, and promotional campaigns
  • Enterprise Features: Payroll, expense reimbursements, and bulk transfers
  • Platform Services: Multi-merchant and e-commerce platform support

Technical Features

  • Protocol Flexibility: Full support for both WeChat Pay v2 and v3 APIs
  • Security: Certificate-based authentication, signature validation, encryption
  • Multi-tenant: Support for multiple merchant configurations in single application
  • Error Handling: Comprehensive exception handling with detailed error information
  • Thread Safety: Concurrent request processing with proper resource management
  • Environment Support: Production, sandbox, and development environment configurations