PHP code example of busyphp / wechat-pay

1. Go to this page and download the library: Download busyphp/wechat-pay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

busyphp / wechat-pay example snippets



return [
    // 支付配置
    'pay'    => [
        
        // 微信内部JS支付
        //'js'     => [
        //    'type'          => PayType::WECHAT_JS,
        //    'app_id'        => '',
        //    'pay_key'       => '',
        //    'mch_id'        => '',
        //    'ssl_cert_path' => app()->getRootPath() . 'config/cert/wechat/apiclient_cert.pem',
        //    'ssl_key_path'  => app()->getRootPath() . 'config/cert/wechat/apiclient_key.pem',
        //    'ca_cert_path'  => app()->getRootPath() . 'config/cert/wechat/rootca.pem',
        //],
        
        
        // 微信H5支付
        // 'h5'     => [
        //     'type'          => '',
        //     'app_id'        => '',
        //     'pay_key'       => '',
        //     'mch_id'        => '',
        //     'ssl_cert_path' => app()->getRootPath() . 'config/cert/wechat/apiclient_cert.pem',
        //     'ssl_key_path'  => app()->getRootPath() . 'config/cert/wechat/apiclient_key.pem',
        //     'ca_cert_path'  => app()->getRootPath() . 'config/cert/wechat/rootca.pem',
        // ],
        
        
        // 扫码支付
        // 'native' => [
        //     'type'          => '',
        //     'app_id'        => '',
        //     'pay_key'       => '',
        //     'mch_id'        => '',
        //     'ssl_cert_path' => app()->getRootPath() . 'config/cert/wechat/apiclient_cert.pem',
        //     'ssl_key_path'  => app()->getRootPath() . 'config/cert/wechat/apiclient_key.pem',
        //     'ca_cert_path'  => app()->getRootPath() . 'config/cert/wechat/rootca.pem',
        // ],
        
        
        // APP端支付
        //'app'    => [
        //    'type'          => PayType::WECHAT_APP,
        //    'app_id'        => '',
        //    'pay_key'       => '',
        //    'mch_id'        => '',
        //    'ssl_cert_path' => app()->getRootPath() . 'config/cert/wechat/apiclient_cert.p12',
        //    'ssl_key_path'  => app()->getRootPath() . 'config/cert/wechat/apiclient_key.pem',
        //    'ca_cert_path'  => app()->getRootPath() . 'config/cert/wechat/rootca.pem',
        //],
        
        
        // 小程序端支付
        //'mini'    => [
        //    'type'          => PayType::WECHAT_APP,
        //    'app_id'        => '',
        //    'pay_key'       => '',
        //    'mch_id'        => '',
        //    'ssl_cert_path' => app()->getRootPath() . 'config/cert/wechat/apiclient_cert.p12',
        //    'ssl_key_path'  => app()->getRootPath() . 'config/cert/wechat/apiclient_key.pem',
        //    'ca_cert_path'  => app()->getRootPath() . 'config/cert/wechat/rootca.pem',
        //]
    ]
];


use BusyPHP\trade\defines\PayType;
use BusyPHP\wechat\pay\WeChatPay;

return [
    // 支付接口绑定
    'apis'            => [
        PayType::WECHAT_JS => WeChatPay::js(),
        PayType::WECHAT_H5 => WeChatPay::h5(),
        PayType::WECHAT_APP => WeChatPay::app(),
        PayType::WECHAT_MINI => WeChatPay::mini(),
        PayType::WECHAT_NATIVE => WeChatPay::native(),
    ]
];