Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the payment of Alipay Mobile website by Laravel5.5

Shulou Source: shulou.com Published: 2022-06-03 17:50:14 10月01日 Update

This article mainly introduces Laravel5.5 how to achieve Alipay mobile site payment, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1. Install and use the Laravel extension library yansongda/laravel-pay

Yansongda/laravel-pay Github address

Install via composer

$composer require yansongda/laravel-pay

Generate configuration file

Php artisan vendor:publish-- provider= "Yansongda\\ LaravelPay\\ PayServiceProvider"-- tag=laravel-pay

2. Configure the payment information and enter it into the configuration file pay.php

Run the tools provided by Alipay to generate as follows:

Remove-BEGIN PUBLIC KEY- and-END PUBLIC KEY-, in the public key file, merge the rest into one line, and add them to the application public key.

Remove-BEGIN RSA PRIVATE KEY- and-END RSA PRIVATE KEY-, in the private key file and merge the rest into one line, which needs to be added to the configuration file.

Fill in the corresponding content in the configuration file

3. Pull up the payment

When the payment is pulled up in yansongda/laravel-pay, the payment form information is returned directly to the page. Considering the business requirements, it is more convenient to return the payment through json.

Use Yansongda\ Pay\ Pay;/** * Class SecondPay * @ package App * Alipay mobile web payment interface * / class ZfbWapPay extends Model {/ / send payment request public function send (Request $request,$outTradeNum,$payAmount) {$config = config ('pay.alipay'); / / take out the configuration information and dynamically change $config [' return_url'] = 'http://api.aiwangyouxi.com/web/pay/jump/'.$outTradeNum;' according to the demand $order = ['out_trade_no' = > $outTradeNum, / / our order number' total_amount' = > $payAmount, / / payment amount, unit (yuan) 'subject' = >' Game payment',]; $alipay = Pay::alipay ($config)-> wap ($order); return $alipay; / / return form form information}

Successfully return the form form information and insert the information into the page to complete the pull-up payment

$("body") .append (data.form_text)

4. Payment callback

Use Yansongda\ Pay\ Pay;/** * Class WxwebController * @ package App\ Http\ Controllers\ Web * Alipay h6 payment callback * / class ZfbwebController extends Controller {private $pay_order; / / our order number private $call_order; / / third-party order number public function notify (Request $request) {$pay_config = config ('pay.alipay'); $alipay = Pay::alipay ($pay_config); $this- > pay_order = $request- > out_trade_no $this- > call_order = $request- > trade_no; $save_back = $paid payback backback> addback ($this- > pay_order,json_encode ($request- > all ()); / / record the payment callback information to the database $check_result = $alipay- > verify (); if (! $check_result) {/ / callback check check failed return';} return $alipay- > success () }} Thank you for reading this article carefully. I hope the article "how to realize the payment of Alipay mobile website by Laravel5.5" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Payment information file configuration article mobile phone content order order number website line public key form demand page generation success business lieutenant general value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Docker Xiaomi Linux