PHP code example of moephp / alipay
1. Go to this page and download the library: Download moephp/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' );
moephp / alipay example snippets
'providers' => [
'Latrell\Alipay\AlipayServiceProvider' ,
]
$alipay = app('alipay.web' );
$alipay->setOutTradeNo('order_id' );
$alipay->setTotalFee('order_price' );
$alipay->setSubject('goods_name' );
$alipay->setBody('goods_description' );
$alipay->setQrPayMode('4' );
return redirect()->to($alipay->getPayLink());
$alipay = app('alipay.mobile' );
$alipay->setOutTradeNo('order_id' );
$alipay->setTotalFee('order_price' );
$alipay->setSubject('goods_name' );
$alipay->setBody('goods_description' );
return $alipay->getPayPara();
public function webNotify ()
{
if (! app('alipay.web' )->verify()) {
Log::notice('Alipay notify post data verification fail.' , [
'data' => Request::instance()->getContent()
]);
return 'fail' ;
}
switch (Input::get('trade_status' )) {
case 'TRADE_SUCCESS' :
case 'TRADE_FINISHED' :
Log::debug('Alipay notify post data verification success.' , [
'out_trade_no' => Input::get('out_trade_no' ),
'trade_no' => Input::get('trade_no' )
]);
break ;
}
return 'success' ;
}
public function webReturn ()
{
if (! app('alipay.web' )->verify()) {
Log::notice('Alipay return query data verification fail.' , [
'data' => Request::getQueryString()
]);
return view('alipay.fail' );
}
switch (Input::get('trade_status' )) {
case 'TRADE_SUCCESS' :
case 'TRADE_FINISHED' :
Log::debug('Alipay notify get data verification success.' , [
'out_trade_no' => Input::get('out_trade_no' ),
'trade_no' => Input::get('trade_no' )
]);
break ;
}
return view('alipay.success' );
}
public function alipayNotify ()
{
if (! app('alipay.mobile' )->verify()) {
Log::notice('Alipay notify post data verification fail.' , [
'data' => Request::instance()->getContent()
]);
return 'fail' ;
}
switch (Input::get('trade_status' )) {
case 'TRADE_SUCCESS' :
case 'TRADE_FINISHED' :
Log::debug('Alipay notify get data verification success.' , [
'out_trade_no' => Input::get('out_trade_no' ),
'trade_no' => Input::get('trade_no' )
]);
break ;
}
return 'success' ;
}