Skip to content
Loki Else edited this page Sep 24, 2016 · 3 revisions

Gateway (网关)

/**
 * @var LegacyAppGateway $gateway
 */
$gateway = Omnipay::create('Alipay_LegacyApp');
$gateway->setPartner('the_partner_id');
$gateway->setSellerId('the_partner_id');
$gateway->setPrivateKey('the_private_key');
$gateway->setNotifyUrl('https://www.example.com/notify');

Purchase (购买)

$request = $gateway->purchase();
$request->setBizContent([
    'subject'      => 'test',
    'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
    'total_fee' => '0.01',
]);

/**
 * @var LegacyAppPurchaseResponse $response
 */
$response = $request->send();

$response->getOrderString();

Return (同步验证)

$request = $gateway->completePurchase();
$request->setParams([
    'memo'         => '',
    'result'       => '_input_charset="UTF-8"&alipay_sdk="lokielse/omnipay-alipay"&notify_url="https://www.example.com/notify"&out_trade_no="2016092309184123456"&partner="80123456789"&payment_type="1"&seller_id="80123456789"&service="mobile.securitypay.pay"&subject="test"&total_fee="0.01"&success="true"',
    'resultStatus' => '9000'
]);

/**
 * @var LegacyCompletePurchaseResponse $response
 */
try {
    $response = $request->send();
    
    if($response->isPaid()){
        /**
         * Payment is successful
         */
    }else{
        /**
         * Payment is not successful
         */
    }
} catch (Exception $e) {
    /**
     * Payment is not successful
     */
}

Notify (异步通知)

$request = $gateway->completePurchase();
$request->setParams($_POST);

/**
 * @var LegacyCompletePurchaseResponse $response
 */
try {
    $response = $request->send();
    
    if($response->isPaid()){
        /**
         * Payment is successful
         */
        die('success'); //The response should be 'success' only
    }else{
        /**
         * Payment is not successful
         */
        die('fail');
    }
} catch (Exception $e) {
    /**
     * Payment is not successful
     */
    die('fail');
}
Clone this wiki locally