天天看點

laravel架構下的pc支付寶支付接入

參考https://github.com/gaoxuxu123/laravel-alipay

composer require laravel-alipay/alipay dev-master

或者在composer.json中加入

"require": {

"laravel-alipay/alipay": "dev-master"

}

更新依賴 composer update

##使用說明

找到 config/app.php 檔案

'providers' => [

Lxu\Alipay\AlipayServiceProvider::class,

]

運作 php artisan vendor:publish 指令

配置檔案 config/lxu-alipay.php 已經生成,按照要求配置即可

<?php

/**

Created by PhpStorm.

User: xu.gao

Date: 2016/2/23

Time: 14:22

*/

return [

//pc配置

'pcconfig'=>

[

'partner' =>'2088302186611', //這裡是你在成功申請支付寶接口後擷取到的PID;

'key' =>'sxevk9h1vekjlx4y12arl6pryrz111', //這裡是你在成功申請支付寶接口後擷取到的Key

'seller_id' =>'208830211', //就是partner

'sign_type' =>strtoupper('MD5'), //不需修改

'input_charset' =>strtolower('utf-8'), //不需修改

'transport' =>'http',

'notify_url' =>getenv('APP_URL').'/alipay/getnotifyurl',//異步通知

'return_url' =>getenv('APP_URL').'/alipay/getreturnurl',//同步通知

'service' =>'create_direct_pay_by_user', //不需修改,支付service

'refundservice' =>'refund_fastpay_by_platform_pwd',//退款service

'payment_type' =>'1', //不需修改

//賣家賬戶資訊

'seller_email' =>'[email protected]', //賣家郵箱

//手機配置

'mobileconfig'=>

'partner' =>'xxxxxxxxxxxxxxxxxxxxxx',

'seller_id' =>'xxxxxxxxxxxxxxxxxxxxxx',

'key' =>'xxxxxxxxxxxxxxxxxxxxxx',

'sign_type' =>strtoupper('RSA'), //不需修改

'service' =>'alipay.wap.create.direct.pay.by.user',//不需修改

'payment_type' =>'1',

'seller_email' =>'[email protected]',

];

再配置路由通路控制器進行回調即可

namespace App\Http\Controllers\Alipay;

use App\Http\Controllers\Controller;

use Omnipay\Omnipay;

use Illuminate\Http\Request;

use App\Http\Models\Painting;

use Auth;

use DB;

use App\Tools\OssUpload;

use App\Http\Models\SystemArea;

use App\Http\Models\Order;

use App\Http\Models\Cart;

use App\Http\Models\MemberAddress;

use App\Http\Models\MemberDistribution;

use App\Http\Models\MemberUpload;

use App\Http\Models\MemberCoupon;

use App\Http\Models\Warehouse;

use App\Http\Models\Collection;

use App\Http\Models\Member;

use App\Http\Models\Message;

use Symfony\Component\Console\Input\Input;

Class IndexController

@package App\Http\Controllers\Alipay

pc 支付寶支付

class IndexController extends Controller

{

跳轉到支付寶付款

@param $request

入參如下:

訂單id主鍵非訂單編号(主/子訂單編号),

物品名字name,

物品總價格price.

@return mixed

public function getPay(Request $request){

$data=$request->all();

$alipay = app('alipay.web');

$alipay->setOutTradeNo($data['order_id']);

$alipay->setTotalFee($data['price']);

$alipay->setSubject('藝飛萬家畫品購買畫品');

$alipay->setBody('藝飛萬家畫品購買畫品');

$alipay->setQrPayMode('5'); //該設定為可選1-5,添加該參數設定,支援二維碼支付。

// 跳轉到支付頁面。

return redirect()->to($alipay->getPayLink());

支付寶伺服器異步通知

public function getNotifyurl(Request $request)

// 驗證請求。

if (!app('alipay.web')->verify()) {

return redirect('/buy');

// 判斷通知類型。

if($request->trade_status=='TRADE_SUCCESS'||$request->trade_status=='TRADE_FINISHED'){

//TODO: 支付成功,取得訂單号進行其它相關操作。

Order::doOrder($data['out_trade_no']); //傳訂單id

echo "success"; //請不要修改或删除

}else{

echo "fail";

支付寶頁面跳轉同步通知

public function getReturnurl(Request $request)

return redirect('/');

return redirect('/member');

本文轉自 liang3391 51CTO部落格,原文連結:http://blog.51cto.com/liang3391/2055241