Alipay - timely arrival

To the project directory execute command to install package

composer require latrell/alipay dev-master

To perform the update

composer update

Find config / app.php profile, key array of providers, adding service provider in the array.

'providers' => [
         /*
          * Laravel Framework Service Providers...
          */
          
          'Latrell\Alipay\AlipayServiceProvider',
        ]

Execute commands, configuration files to generate the config / directory

php artisan vendor:publish

Configuration instructions

Configuration file config / latrell-alipay.php configuration information for the public file

config / latrell-alipay-web.php Alipay SDK is configured to Web version

config / latrell-alipay-mobile.php Alipay SDK configured as a mobile terminal

Open the config / latrell-alipay-web.php, set the security check code and notification page

<? PHP
 return [ 

   // security check code, 32 characters with numbers and letters. 
   ' Key ' => ' a6cq60 ***************** ZL ' , 

   // signature way 
   ' sign_type ' => ' MD5 ' , 

   // server asynchronous notification page path. Make the appropriate changes according to their own project path 
   ' notify_url ' => ' http://web.wan.com/notify ' , 

   // page jump sync notification page path. Modified accordingly based on their path item 
   ' return_url ' => ' http://web.wan.com/return ' 
];

Open the config / latrell-alipay.php, set the seller Alipay account identity and cooperation by id

<? PHP
   return [
      // Cooperation identity by id, to 16 pure digital beginning of 2088. 
     ' Partner_id ' => ' 2088 ************ ' , 

     // seller Alipay account. 
     ' Seller_id ' => ' 28*******[email protected] ' 
  ];

Setting payment request routing

// Alipay payment processing route 
Route :: GET ( ' alipay ' , ' Home \ alipayController @ Alipay ' );   // initiate a payment request 
Route :: the any ( ' the Notify ' , ' Home \ alipayController @ AliPayNotify ' ); // server asynchronous notification page path 
route :: the any ( ' return ' , ' Home \ alipayController @ AliPayReturn ' );   // page jump sync notifications page path

Alipay payment Case Code scan code

<?php
namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class alipayController extends Controller{

// 发起支付请求
public function Alipay(){
    $alipay = app('alipay.web');
    $alipay->setOutTradeNo('E0002332039');
    $alipay->setTotalFee('0.01');
    $alipay->setSubject('小米5s');
    alipay $-> setBody ( ' Goods: Alipay test ' ); 

    $ alipay -> setQrPayMode ( ' 5 ' ); // this setting is optional 1-5, add the parameter settings, support for two-dimensional code to pay. 

    // Jump to the payment page. 
    return the redirect () -> to ($ alipay-> getPayLink ()); 
} 

// asynchronous notification of the result of payment 
public function AliPayNotify (the Request Request $) {
 // authentication request. 
IF (App (! ' alipay.web ' ) -> Verify ()) { 
    the Log :: Notice ( ' . Alipay Notify the Verification Data POST Fail ' , [
         ' Data' => $ Request-> instance () -> getContent () 
    ]); 
    return  ' Fail ' ; 
} 
// Analyzing notification type. 
Switch ($ Request -> the INPUT ( ' trade_status ' , '' )) {
     Case  ' TRADE_SUCCESS ' :
     Case  ' TRADE_FINISHED ' :
         // TODO: payment successful and the order number for other related operations. 
        Debug :: log ( ' Alipay POST Data Notify the Verification Success. ' , [
             ' Out_trade_no ' =>' Out_trade_no ' , '' ),
             ' trade_no ' => $ Request -> INPUT ( ' trade_no ' , '' ) 
        ]); 
        BREAK ; 
} 
return  ' Success ' ; 
} 

// sync notifications result of payment 
public function AliPayReturn (the Request $ request) {
 // authentication request. 
IF (App (! ' alipay.web ' ) -> the Verify ()) { 
    the Log :: Notice ( ' Alipay return query data validation failed. ' ,
         ' => $ request-> the getQueryString () 
    ]); 
    return View ( ' alipayfail ' ); 
} 
// Analyzing notification type. 
Switch ($ Request -> the INPUT ( ' trade_status ' , '' )) {
     Case  ' TRADE_SUCCESS ' :
     Case  ' TRADE_FINISHED ' :
         // TODO: payment successful and the order number for other related operations. 
        :: Debug the Log ( ' Alipay notify obtain data validation is successful. ' , [
             ' Out_trade_no ' => $ Request ->out_trade_no',''),
            'trade_no' => $request -> input('trade_no','')
        ]);
        break;
}
return view('alipaysuccess');
}
}

Alipay mobile client:

<?php
namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class alipayController extends Controller{
// 发起支付请求
public function Alipay(){
    $alipay = app('alipay.mobile');
    $alipay->setOutTradeNo('E0002332039');
    $alipay->setTotalFee('0.01');
    $alipay->setSubject('小米5s');
    alipay $ -> setBody ( ' Goods: Alipay test ' ); 
   
   // SDK paid parameters return signature to the end of Alipay move. 
    return $ alipay-> getPayPara (); 
} 

// Alipay asynchronous notification of the result of payment 
public function AliPayNotify (the Request Request $) {
 // authentication request. 
IF (App (! ' alipay.mobile ' ) -> Verify ()) { 
    the Log :: Notice ( ' . Alipay Notify the Verification Data POST Fail ' , [
         ' Data ' => $ request-> instance () -> getContent ( ) 
    ]); 
    return  '; 
} 
// Analyzing notification type. 
Switch ($ Request -> the INPUT ( ' trade_status ' , '' )) {
     Case  ' TRADE_SUCCESS ' :
     Case  ' TRADE_FINISHED ' :
         // TODO: payment successful and the order number for other related operations. 
        Debug :: log ( ' . Notify POST Data Alipay the Verification Success ' , [
             ' out_trade_no ' => $ Request -> INPUT ( ' out_trade_no ' , ' ' ),
             ' => $request -> input('trade_no','')
        ]);
        break;
}
return 'success';
}

 Blog: https://www.cnblogs.com/zmdComeOn/p/10345650.html

Guess you like

Origin www.cnblogs.com/yingyong/p/11519993.html