PHP code example of hinet / omnipay-alipay
1. Go to this page and download the library: Download hinet/omnipay-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/ */
hinet / omnipay-alipay example snippets
/**
* @var AopAppGateway $gateway
*/
$gateway = Omnipay::create('Alipay_AopPage');
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5. Use certificate mode must set RSA2
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key'); // Need not set this when used certificate mode
$gateway->setReturnUrl('https://www.example.com/return');
$gateway->setNotifyUrl('https://www.example.com/notify');
// Must set cert path if you used certificate mode
//$gateway->setAlipayRootCert('the_alipay_root_cert'); // alipayRootCert.crt
//$gateway->setAlipayPublicCert('the_alipay_public_cert'); // alipayCertPublicKey_RSA2.crt
//$gateway->setAppCert('the_app_public_cert'); // appCertPublicKey.crt
//$gateway->setCheckAlipayPublicCert(true);
/**
* @var AopTradePagePayResponse $response
*/
$response = $gateway->purchase()->setBizContent([
'subject' => 'test',
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
'total_amount' => '0.01',
'product_code' => 'FAST_INSTANT_TRADE_PAY',
])->send();
$url = $response->getRedirectUrl();