PHP code example of ixiaomu / yii2-payment

1. Go to this page and download the library: Download ixiaomu/yii2-payment 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/ */

    

ixiaomu / yii2-payment example snippets


<?= 
    use ixiaomu\payment\Pay;

    $payConfig = [ //换成自己的
        'app_id'        => 'wx69f7d561891b969d',  // 公众账号ID
        'mch_id'        => '1597082962',// 商户id
        'mch_key'           => '1n156wnp3qtihtht93y2xte7bxeoz2ub',// 秘钥
        'app_secret'    => '9e261fd174495ef81989daebfdcd9c05',
        'fee_type'      => 'CNY',// 货币类型  当前仅支持该字段
        'sslcert_path'  => Yii::getAlias('@common').'/lib/payment/wechat/cert/apiclient_cert.pem',
        'sslkey_path'   => Yii::getAlias('@common').'/lib/payment/wechat/cert/apiclient_key.pem',
        'notify_url'    => Yii::getAlias('@apiUrl').'/RestApi/v1/wechat-callback/wx-notify',
    ];
    
    $payData = [
         'out_trade_no'     => '12345678901', // 订单号
         'total_fee'        => '520000', // 订单金额,**单位:分**
         'body'             => '订单描述', // 订单描述
         'openid'           => 'o89PEv2vT_niCY9n5nNAsQWK4D_Q', // 支付人的 openID
    ];
    $pay = new Pay($payConfig);
    try{
        $redult = $pay->driver('wechat')->gateway('mp')->apply($payData);
        var_dump($redult);die;
    }catch (Exception $e){
        throw new Exception('支付失败:'.$e->getMessage());
    }
    

php composer.phar