PHP code example of evondu / alipay-php-sdk

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

    

evondu / alipay-php-sdk example snippets


//引入Composer自动加载(例如YII等PHP框架则不需要,因为框架本身已经引入)
lient([
    'app_id' => "2017051207218***",                             //应用ID
    'merchant_private_key' => "***",                            //应用私钥
    'alipay_public_key' => "***",                               //支付宝公钥
    'gatewayUrl' => "https://openapi.alipay.com/gateway.do",    //沙盒环境时使用,正式环境去掉即可
]);
// 调用接口:alipay.trade.page.pay
$client->trade->payPage([
    "out_trade_no"  => time(),
    "total_amount"  => "0.01",
    "subject"       => "标题",
    "body"          => "支付内容",
],"支付通知地址(notify_url)","支付返回地址(return_url)");

$data = $client->trade->precreate([
    "out_trade_no"  => time(),
    "total_amount"  => "0.01",
    "subject"       => "标题",
    "body"          => "支付内容",
],"支付通知地址(notify_url)");

$data = $client->trade->query([
    "out_trade_no"  => "1234567",
]);

$data = $client->trade->close([
    "out_trade_no"  => "1234567",
]);

$data = $client->trade->cancel([
    "out_trade_no"  => "1234567",
]);

$data = $client->trade->refund([
    "out_trade_no"  => "1234567",
    "refund_amount" => 0.01
]);

$data = $client->trade->refundQuery([
    "out_trade_no"  => "1234567",
    "out_request_no" => "1234567"
]);