PHP code example of lvht / alipay
1. Go to this page and download the library: Download lvht/alipay 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/ */
lvht / alipay example snippets
$alipay = new Lv\Alipay\SdkPayment;
// 设置商家合作id
$alipay->setPartner('2088xxxx')
// 设置商家私钥
->setPrivateKey(file_get_contents(__DIR__ . '/rsa_private_key.pem'))
// 设置支付宝公钥
->setPublicKey(file_get_contents(__DIR__ . '/alipay_public_key.pem'))
// 设置异步通知链接
->setNotifyUrl('http://api.xxx.cn/alipay-confirmation')
// 设置商品标题
->setSubject('XXXX咨询费')
// 设置商品详情
->setBody('XXXX咨询费')
// 设置商家订单号
->setOutTradeNo("123")
// 设置商家支付宝账号
->setSellerId('[email protected] ')
// 设置支付费用
->setTotalFee('0.01');
$info = $alipay->getPayInfo();
$ali_pub_key = file_get_contents(__DIR__ . '/alipay_public_key.pem');
// POST原始数据
// 通过 file_get_contents('php://stdin') 获取
// 此处为方便测试,我们将获取的内容存入文件
$post_data = file_get_contents(__DIR__ . '/notify_raw_post.txt');
$alipay = new Lv\Alipay\SdkPayment;
$alipay->setPublicKey($ali_pub_key);
$data = $alipay->getNotifyInfo($post_data);
return [
'ali' => [
// 合作标识
'partner_id' => '2088xxx',
// 商户私钥
'rsa_private_key' => file_get_contents('path/to/key.pem'),
// 阿里公钥
'ali_rsa_public_key' => file_get_contents('path/to/ali_key.pem'),
// 商品名称
'subject' => 'XXX咨询费',
// 商品详情
'body' => 'XXX咨询费',
// 收款账号
'account' => '[email protected] ',
// 异步通知连接
'notify_url' => 'http://api.xxx.cn/alipay-confirmation',
],
];
'providers' => array(
'Lv\Alipay\AlipayServiceProvider',
)