PHP code example of zoujingli / pay-php-sdk

1. Go to this page and download the library: Download zoujingli/pay-php-sdk 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/ */

    

zoujingli / pay-php-sdk example snippets


$config = [
    // 微信支付参数
    'wechat' => [
        'debug'      => false, // 沙箱模式
        'app_id'     => '', // 应用ID
        'mch_id'     => '', // 微信支付商户号
        'mch_key'    => '', // 微信支付密钥
        'ssl_cer'    => '', // 微信证书 cert 文件
        'ssl_key'    => '', // 微信证书 key 文件
        'notify_url' => '', // 支付通知URL
        'cache_path' => '',// 缓存目录配置(沙箱模式需要用到)
    ],
    // 支付宝支付参数
    'alipay' => [
        'debug'       => false, // 沙箱模式
        'app_id'      => '', // 应用ID
        'public_key'  => '', // 支付宝公钥(1行填写)
        'private_key' => '', // 支付宝私钥(1行填写)
        'notify_url'  => '', // 支付通知URL
    ]
];

// 实例支付对象
$pay = new \Pay\Pay($config);

try {
    $options = $pay->driver('alipay')->gateway('app')->apply($payOrder);
    var_dump($options);
} catch (Exception $e) {
    echo "创建订单失败," . $e->getMessage();
}

// 实例支付对象
$pay = new \Pay\Pay($config);

if ($pay->driver('alipay')->gateway()->verify($_POST)) {
    file_put_contents('notify.txt', "收到来自支付宝的异步通知\r\n", FILE_APPEND);
    file_put_contents('notify.txt', "订单单号:{$_POST['out_trade_no']}\r\n", FILE_APPEND);
    file_put_contents('notify.txt', "订单金额:{$_POST['total_amount']}\r\n\r\n", FILE_APPEND);
} else {
    file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND);
}

$pay = new \Pay\Pay($config);
$verify = $pay->driver('wechat')->gateway('mp')->verify(file_get_contents('php://input'));

if ($verify) {
    file_put_contents('notify.txt', "收到来自微信的异步通知\r\n", FILE_APPEND);
    file_put_contents('notify.txt', "订单单号:{$verify['out_trade_no']}\r\n", FILE_APPEND);
    file_put_contents('notify.txt', "订单金额:{$verify['total_fee']}\r\n\r\n", FILE_APPEND);
} else {
    file_put_contents('notify.txt', "收到异步通知\r\n", FILE_APPEND);
}

echo '<xml><return_code>SUCCESS</return_code><return_msg>OK</return_msg></xml>';
shell
// 方法一、 使用composer安装
composer it.php'