-
Notifications
You must be signed in to change notification settings - Fork 2
Alipay
nilnice edited this page Mar 2, 2018
·
3 revisions
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';
$config = $config['alipay'];
$action = $_REQUEST['action'] ?? 'pay';
if ($action === 'pay') {
$order = [
'out_trade_no' => time(),
'total_amount' => 0.01,
'subject' => '这是一个测试订单',
];
$alipay = new \Nilnice\Payment\Alipay($config);
/** @var \Symfony\Component\HttpFoundation\Response $object */
$object = $alipay->app($order);
if ($object->getStatusCode() === 200) {
$object->send();
}
}
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';
$config = $config['alipay'];
$action = $_REQUEST['action'] ?? 'pay';
$alipay = new \Nilnice\Payment\Alipay($config);
if ($action === 'pay') {
$order = [
'out_trade_no' => time(),
'total_amount' => 0.01,
'subject' => '测试订单 - ' . random_int(100, 999),
];
/** @var \Symfony\Component\HttpFoundation\Response $object */
$object = $alipay->web($order);
if ($object->getStatusCode() === 200) {
$object->send();
}
} elseif ($action === 'query') {
$order = 'order_id';
$object = $alipay->query($order);
dd($object);
} elseif ($action === 'close') {
$order = 'order_id';
$object = $alipay->close($order);
dd($object);
} elseif ($action === 'cancel') {
$order = 'order_id';
$object = $alipay->cancel($order);
dd($object);
} elseif ($action === 'refund') {
$order = ['out_trade_no' => 'order_id', 'refund_amount' => '0.01'];
$object = $alipay->refund($order);
dd($object);
}
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';
$config = $config['alipay'];
$action = $_REQUEST['action'] ?? 'pay';
$alipay = new \Nilnice\Payment\Alipay($config);
if ($action === 'pay') {
$order = [
'out_trade_no' => time(),
'total_amount' => 0.01,
'subject' => '这是一个测试订单',
];
/** @var \Symfony\Component\HttpFoundation\Response $object */
$object = $alipay->wap($order);
if ($object->getStatusCode() === 200) {
$object->send();
}
} elseif ($action === 'query') {
$order = 'order_id';
$info = $alipay->query($order);
dd($info);
} elseif ($action === 'close') {
$order = 'order_id';
$object = $alipay->close($order);
dd($object);
} elseif ($action === 'cancel') {
$order = 'order_id';
$object = $alipay->cancel($order);
dd($object);
} elseif ($action === 'refund') {
$order = ['out_trade_no' => 'order_id', 'refund_amount' => '0.01'];
$object = $alipay->refund($order);
dd($object);
}
<?php
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';
$config = $config['alipay'];
$action = $_REQUEST['action'] ?? 'pay';
if ($action === 'pay') {
$order = [
'out_trade_no' => time(),
'total_amount' => 0.01,
'subject' => '这是一个测试订单',
];
$alipay = new \Nilnice\Payment\Alipay($config);
/** @var \Illuminate\Support\Collection $object */
$object = $alipay->scan($order);
$labelFontPath = '/../vendor/endroid/qr-code/assets/fonts/noto_sans.otf';
$logoPath = '/../vendor/endroid/qr-code/assets/images/symfony.png';
$qrCode = new \Endroid\QrCode\QrCode($object->get('qr_code'));
$qrCode->setSize(300);
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(\Endroid\QrCode\ErrorCorrectionLevel::HIGH);
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
$qrCode->setLabel(
'请打开支付宝扫描二维码',
16,
__DIR__ . $labelFontPath,
\Endroid\QrCode\LabelAlignment::CENTER
);
$qrCode->setLogoPath(__DIR__ . $logoPath);
$qrCode->setLogoWidth(150);
$qrCode->setRoundBlockSize(true);
$qrCode->setValidateResult(false);
$response = new \Endroid\QrCode\Response\QrCodeResponse($qrCode);
$response->send();
}
💥 让支付宝,微信支付更加容易