PHP code example of mofing / omnipay-alipay

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

    

mofing / omnipay-alipay example snippets


/**
 *
 * @var \Omnipay\Alipay\OauthGateway $gateway
 */
$gateway = Omnipay::create("Alipay_Oauth");
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5
$gateway->setAppId($this->getConfig("appId"));
$gateway->setPrivateKey($this->getConfig("privateKey"));
$gateway->setAlipayPublicKey($this->getConfig("alipayPublicKey"));

/**
 *
 * @var \Omnipay\Alipay\Requests\SystemOauthTokenRequest $request
 */
$request = $gateway->purchase();
if (! empty($refreshToken)) {
    $request->setRefreshToken($refreshToken);
} else {
    $request->setCode($code);
}
$response = $request->send();
if($response->isSuccessful()){
    return $response->getData();
}
return false;

/**
 * @var AopAppGateway $gateway
 */
$gateway = Omnipay::create('Alipay_AopPage');
$gateway->setSignType('RSA2'); // RSA/RSA2/MD5
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$gateway->setReturnUrl('https://www.example.com/return');
$gateway->setNotifyUrl('https://www.example.com/notify');

/**
 * @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();

$gateway = Omnipay::create("Alipay_Sdk");
$gateway->setSignType('RSA2');
$gateway->setAppId('the_app_id');
$gateway->setPid("parter_id");
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$request = $gateway->purchase();
$data= $request->getData();