支付宝当面付接入Demo
第三方库
1 2 |
composer require league/omnipay:^3 lokielse/omnipay-alipay composer require endroid/qr-code |
Demo代码
运行后在浏览器打开生成付款二维码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?php require 'vendor/autoload.php'; use Omnipay\Omnipay; use Endroid\QrCode\QrCode; /** @var \Omnipay\Alipay\AopF2FGateway $gateway */ $gateway = Omnipay::create('Alipay_AopF2F'); $gateway->setSignType('RSA2'); //RSA/RSA2 $gateway->setAppId('');// 应用APPID,必填 $gateway->setPrivateKey(''); // 商户密钥,必填 $gateway->setAlipayPublicKey(''); // 支付宝公钥,必填 $gateway->setNotifyUrl('');// 回调地址,必填 $request = $gateway->purchase(); $request->setBizContent([ 'subject' => 'test测试订单', 'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999), 'total_amount' => 0.1 ]); /** @var \Omnipay\Alipay\Responses\AopTradePreCreateResponse $response */ $response = $request->send(); // var_dump($response); // echo "\n"; // 获取收款二维码内容 $qrCodeContent = $response->getQrCode(); // var_dump($qrCodeContent); // echo "\n"; // 生成收款二维码 $qrCode = new QrCode($qrCodeContent); header('Content-Type: '.$qrCode->getContentType()); echo $qrCode->writeString(); |
There are no comments yet