Current Location: Home> Latest Articles> Complete Guide to Implementing WeChat Enterprise Payment to Wallet with PHP

Complete Guide to Implementing WeChat Enterprise Payment to Wallet with PHP

gitbox 2025-07-02

Function Overview

WeChat Pay offers an enterprise payment to wallet interface that allows merchants to transfer funds directly to users' WeChat Wallet balances programmatically. This feature is commonly used for user withdrawals, reward distribution, and similar scenarios. This article explains the complete integration process using PHP.

Preparation

Before development, complete the following preparation steps:

Register a WeChat Merchant Account

Visit the WeChat Pay Open Platform to register and verify your merchant account.

Obtain API Key

Log into the merchant platform, go to the account center, and set your API key. Keep this key secure and do not disclose it.

Download and Include WeChat Payment SDK

Download the PHP SDK from the WeChat Pay developer documentation and include it in your project directory to prepare for API calls.

Include the SDK File

Include the WeChat payment SDK file in your PHP project as follows:


require_once 'path/to/wxpay.sdk.php';

Configure Merchant Information

Before making API calls, configure the merchant information as shown:


$config = new WxPayConfig();
$config->SetMerchantId('your_merchant_id');
$config->SetAppId('your_app_id');
$config->SetAppKey('your_app_key');

Replace the placeholders with your actual merchant ID, AppID, and API key.

Initiate Enterprise Payment Request

After configuration, use the following PHP code to initiate an enterprise payment to a user's WeChat Wallet:


$input = new WxPayEnterprisePay();
$input->SetOpenId('user_openid');
$input->SetAmount(100); // Amount in cents
$input->SetDesc('Enterprise Payment');

$result = WxPayApi::enterprisePay($config, $input);
if ($result['success']) {
    // Payment succeeded, proceed with business logic
} else {
    // Payment failed, handle failure
}

Here, SetOpenId sets the recipient's WeChat OpenID, SetAmount specifies the payment amount in cents, and SetDesc provides the payment description.

Development Considerations

  • You must use a fully verified service account AppID.
  • API requests require mutual TLS certificates.
  • For testing, it is recommended to apply for the whitelist on the merchant platform.

Summary

This guide has walked you through the basic process of implementing WeChat enterprise payment to wallet using PHP. From preparation to coding, each step is essential. After development, conduct thorough testing in the production environment to ensure fund security and a smooth user experience.