PHP code example of sevming / union-pay

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

    

sevming / union-pay example snippets




use Sevming\UnionPay\UnionPay;;

$unionPay = new UnionPay([
    'log' => [
        'default' => 'prod',
        'channels' => [
            'prod' => [
                'driver' => 'daily',
                'path' => 'unionpay.log',
                'level' => 'info',
            ],
        ],
    ],
    'msg_src' => '',
    'msg_src_id' => '',
    'mid' => '',
    'tid' => '',
    'inst_mid' => '',
    'key' => '',
    'notify_url' => '', 
    'return_url' => '',
]);
// 支付
$paymentUrl = $unionPay->web->wxpay([
    'merOrderId' => date('YmdHis'), 
    'totalAmount' => 1
]);
header('location:' . $paymentUrl);
exit;

// 异步通知
$result = $unionPay->web->verify();
// 响应银联
$unionPay->web->success();