laravel5集成支付宝alipay扫码支付流程(Laravel 支付解决方案)

前端之家收集整理的这篇文章主要介绍了laravel5集成支付宝alipay扫码支付流程(Laravel 支付解决方案)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

首先我们来探讨如何在Laravel应用中使用支付宝进行支付,对此,GitHub上有很多相关的包,其中最流行的两个包:Omnipay For Laravel 5 & Lumen 和 Laravel AliPay。这里使用的是Laravel AliPay来做案例说明:

准备工作 :支付宝账号 /蚂蚁金服开放平台账号---> 支付宝签约(即时到账)到项目根目录执行命令安装包

composer require latrell/alipay dev-master

执行更新

composer update

执行更新后,到vendor目录里面看一下有没有latrell目录,如果有说明安装成功,反之没有。因为latrell目录下放的是alipay相关文件

找到 config/app.PHP 配置文件中,key为 providers 的数组,在数组中添加服务提供者。

403_25@403_25@403_25@ =>403_25@403_25@403_25@403_25@
      <span style="color: #800000"&gt;'@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@<span style="color: #800000"&gt;Latrell\Alipay\AlipayServiceProvider@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@<span style="color: #800000"&gt;'@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@<span style="color: #000000"&gt;,]@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@</pre>

执行命令,生成配置文件config/目录下

PHP artisan vendor:publish

配置说明

配置文件 config/latrell-alipay.PHP 为公共配置信息文件

config/latrell-alipay-web.PHP 为Web版支付宝SDK配置

config/latrell-alipay-mobile.PHP 为手机端支付宝SDK配置

打开config/latrell-alipay-web.PHP,设置安全检验码与通知页面

PHP @H_403_25@403_25@@H_40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 安全检验码,以数字和字母组成的32位字符。@H40325@
'key' => 'a6cq60*****zl',<span style="color: #008000">//@H
40325@<span style="color: #008000">签名方式@H403_25@
'signtype' => 'MD5',<span style="color: #008000">//@H403_25@<span style="color: #008000"> 服务器异步通知页面路径。根据自己项目路径做相应的修改@H_403_25@
'notifyurl' => 'http://web.wan.com/notify',<span style="color: #008000">//@H403_25@<span style="color: #008000"> 页面跳转同步通知页面路径。根据自己项目路径做相应的修改@H_403_25@
'returnurl' => 'http://web.wan.com/return'<span style="color: #000000">
];@H
403_25@

打开config/latrell-alipay.PHP,设置卖家支付宝帐户和合作身份者id

PHP @H_403_25@403_25@403_25@403_25@403_25@ 'partner_id' => '2088************',403_25@403_25@ 'seller_id' => '28*******4@qq.com'403_25@

设置支付请求路由

403_25@403_25@ Route::get('alipay','Home\alipayController@Alipay'); 403_25@403_25@ Route::any('notify','Home\alipayController@AliPayNotify'); 403_25@通知页面路径@H_403_25@ Route::any('return','Home\alipayController@AliPayReturn'); 403_25@页面跳转同步通知页面路径@H_403_25@

支付宝扫码支付案例代码

PHP @H_403_25@403_25@PHPStorm. * User: Administrator * Date: 2017/2/8 * Time: 20:19 @H_403_25@403_25@namespace App\Http\Controllers\Home;

@H_40325@<span style="color: #0000ff">use@H40325@<span style="color: #000000"> App\Http\Controllers\Controller;
@H
40325@<span style="color: #0000ff">use@H40325@<span style="color: #000000"> Illuminate\Http\Request;
@H
40325@<span style="color: #0000ff">use@H40325@ Illuminate\Support\Facades\<span style="color: #008080">Log@H403_25@<span style="color: #000000">;

@H_40325@<span style="color: #0000ff">class@H40325@ alipayController <span style="color: #0000ff">extends@H403_25@<span style="color: #000000"> Controller{

@H_40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 发起支付请求@H40325@
<span style="color: #0000ff">public@H
40325@ <span style="color: #0000ff">function@H40325@<span style="color: #000000"> Alipay(){
@H
40325@<span style="color: #800080">$alipay@H40325@ = app('alipay.web'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setOutTradeNo('E0002332039'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setTotalFee('0.01'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setSubject('小米5s'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H403_25@->setBody('商品:支付宝支付测试'<span style="color: #000000">);

@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@<span style="color: #800080"&gt;$alipay@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@->setQrPayMode('5'); <span style="color: #008000"&gt;//@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@<span style="color: #008000"&gt;该设置为可选1-5,<a href="/tag/tianjia/" target="_blank" class="keywords">添加</a>该参数设置,<a href="/tag/zhichi/" target="_blank" class="keywords">支持</a><a href="/tag/erweima/" target="_blank" class="keywords">二维码</a>支付。

// <a href="/tag/tiaozhuan/" target="_blank" class="keywords">跳转</a>到支付<a href="/tag/yemian/" target="_blank" class="keywords">页面</a>。@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@
<span style="color: #0000ff"&gt;return@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@ redirect()->to(<span style="color: #800080"&gt;$alipay@H_<a href="/tag/403/" target="_blank" class="keywords">403</a>_25@-><span style="color: #000000"&gt;getPayLink());

}

@H_40325@<span style="color: #008000">//@H403_25@<span style="color: #008000"> 异步通知支付结果@H_40325@
<span style="color: #0000ff">public@H
40325@ <span style="color: #0000ff">function@H40325@ AliPayNotify(Request <span style="color: #800080">$request@H40325@<span style="color: #000000">){
@H
40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 验证请求。@H40325@
<span style="color: #0000ff">if@H
40325@ (!app('alipay.web')-><span style="color: #000000">verify()) {
@H
40325@<span style="color: #008080">Log@H40325@::notice('Alipay notify post data verification fail.',<span style="color: #000000"> [
@H
40325@'data' => <span style="color: #800080">$request@H40325@->instance()-><span style="color: #000000">getContent()
]);
@H
40325@<span style="color: #0000ff">return@H40325@ 'fail'<span style="color: #000000">;
}
@H
40325@<span style="color: #008000">//@H403_25@<span style="color: #008000"> 判断通知类型。@H_40325@
<span style="color: #0000ff">switch@H
40325@ (<span style="color: #800080">$request@H403_25@ ->input('tradestatus',''<span style="color: #000000">)) {
@H
40325@<span style="color: #0000ff">case@H403_25@ 'TRADESUCCESS':
<span style="color: #0000ff">case@H
403_25@ 'TRADEFINISHED':
<span style="color: #008000">//@H
40325@<span style="color: #008000"> TODO: 支付成功,取得订单号进行其它相关操作。@H40325@
<span style="color: #008080">Log@H
40325@::debug('Alipay notify post data verification success.',<span style="color: #000000"> [
@H
403_25@'out_tradeno' => <span style="color: #800080">$request@H403_25@ -> input('out_trade_no',''),'tradeno' => <span style="color: #800080">$request@H403_25@ -> input('tradeno',''<span style="color: #000000">)
]);
@H
40325@<span style="color: #0000ff">break@H40325@<span style="color: #000000">;
}
@H
40325@<span style="color: #0000ff">return@H403_25@ 'success'<span style="color: #000000">;
}

@H_40325@<span style="color: #008000">//@H403_25@<span style="color: #008000"> 同步通知支付结果@H_40325@
<span style="color: #0000ff">public@H
40325@ <span style="color: #0000ff">function@H40325@ AliPayReturn(Request <span style="color: #800080">$request@H40325@<span style="color: #000000">){
@H
40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 验证请求。@H40325@
<span style="color: #0000ff">if@H
40325@ (!app('alipay.web')-><span style="color: #000000">verify()) {
@H
40325@<span style="color: #008080">Log@H403_25@::notice('支付宝返回查询数据验证失败。',<span style="color: #000000"> [
@H_40325@'data' => <span style="color: #800080">$request@H40325@-><span style="color: #000000">getQueryString()
]);
@H
40325@<span style="color: #0000ff">return@H40325@ view('alipayfail'<span style="color: #000000">);
}
@H
40325@<span style="color: #008000">//@H403_25@<span style="color: #008000"> 判断通知类型。@H_40325@
<span style="color: #0000ff">switch@H
40325@ (<span style="color: #800080">$request@H403_25@ ->input('tradestatus',''<span style="color: #000000">)) {
@H
40325@<span style="color: #0000ff">case@H403_25@ 'TRADESUCCESS':
<span style="color: #0000ff">case@H
403_25@ 'TRADEFINISHED':
<span style="color: #008000">//@H
40325@<span style="color: #008000"> TODO: 支付成功,取得订单号进行其它相关操作。@H40325@
<span style="color: #008080">Log@H
403_25@::debug('支付宝通知获得数据验证成功。',<span style="color: #000000"> [
@H_403_25@'out_tradeno' => <span style="color: #800080">$request@H403_25@ ->input('out_tradeno',''<span style="color: #000000">)
]);
@H
40325@<span style="color: #0000ff">break@H40325@<span style="color: #000000">;
}
@H
40325@<span style="color: #0000ff">return@H40325@ view('alipaysuccess'<span style="color: #000000">);
}
}@H
403_25@

 支付宝支付手机端:

PHP @H_403_25@403_25@PHPStorm. * User: Administrator * Date: 2017/2/8 * Time: 22:19 @H_403_25@403_25@@H_40325@<span style="color: #0000ff">use@H40325@<span style="color: #000000"> App\Http\Controllers\Controller;
@H
40325@<span style="color: #0000ff">use@H40325@<span style="color: #000000"> Illuminate\Http\Request;
@H
40325@<span style="color: #0000ff">use@H40325@ Illuminate\Support\Facades\<span style="color: #008080">Log@H403_25@<span style="color: #000000">;

@H_40325@<span style="color: #0000ff">class@H40325@ alipayController <span style="color: #0000ff">extends@H40325@<span style="color: #000000"> Controller{
@H
40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 发起支付请求@H40325@
<span style="color: #0000ff">public@H
40325@ <span style="color: #0000ff">function@H40325@<span style="color: #000000"> Alipay(){
@H
40325@<span style="color: #800080">$alipay@H40325@ = app('alipay.mobile'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setOutTradeNo('E0002332039'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setTotalFee('0.01'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H40325@->setSubject('小米5s'<span style="color: #000000">);
@H
40325@<span style="color: #800080">$alipay@H403_25@->setBody('商品:支付宝支付测试'<span style="color: #000000">);

@H_40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 返回签名后的支付参数给支付宝移动端的SDK。@H40325@
<span style="color: #0000ff">return@H
40325@ <span style="color: #800080">$alipay@H403_25@-><span style="color: #000000">getPayPara();
}

@H_40325@<span style="color: #008000">//@H403_25@<span style="color: #008000"> 支付宝异步通知支付结果@H_40325@
<span style="color: #0000ff">public@H
40325@ <span style="color: #0000ff">function@H40325@ AliPayNotify(Request <span style="color: #800080">$request@H40325@<span style="color: #000000">){
@H
40325@<span style="color: #008000">//@H40325@<span style="color: #008000"> 验证请求。@H40325@
<span style="color: #0000ff">if@H
40325@ (!app('alipay.mobile')-><span style="color: #000000">verify()) {
@H
40325@<span style="color: #008080">Log@H40325@::notice('Alipay notify post data verification fail.',''<span style="color: #000000">)
]);
@H
40325@<span style="color: #0000ff">break@H40325@<span style="color: #000000">;
}
@H
40325@<span style="color: #0000ff">return@H40325@ 'success'<span style="color: #000000">;
}@H
403_25@

AliPay。其GitHub项目地址是:https://github.com/Latrell/Alipay。该项目是中文版,使用说明GitHub上说的很清楚明白

猜你在找的Laravel相关文章