Laravel develops Alipay payment and cash transfer methods
这篇文章主要介绍了关于Laravel 开发支付宝支付与提现转账的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
由于项目需要,所以需要开发支付宝支付与微信支付,支付部分采用了
yansongda/pay https://packagist.org/packages/yansongda/pay https://yansongda.gitbooks.io/pay/(文档说明地址)
第三方扩展包 , 简单配置一下就可以使用,没有遇到什么问题
但是由于业务需要, 需要用到提现业务,也就是支付宝支付的
alipay.fund.trans.toaccount.transfer(单笔转账到支付宝账户接口)
找了很久也没有找到很简单的集成支付宝单笔转账接口的扩展包,所以没办法只能自己来用支付宝给的SDK进行开发
首先下载了支付宝服务端SDK PHP版 下载地址https://docs.open.alipay.com/54/103419/
然后解压添加进项目目录 app\Libs\Alipay Libs为自己建的目录,用来装第三方类库
之后打开composer.json文件 在autoload里面的classmap里面添加入新添加的SDK
"autoload": { "classmap": [ "database/seeds", "database/factories", "app/Libs/Alipay-php-sdk" ], "psr-4": { "App\\": "app/" }, 。。。。。。
之后再执行composer dump-autoload 这样第三方的SDK就引入成功了
然后在控制器或者自己定义的业务层中就可以直接use这个SDK了 在new 类的时候会在前面出现 \ 属于正常
然后将给出的PHP示例粘贴进自己的业务代码中 点击查看官方请求示例https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer#s4
注意事项:
1、粘贴到自己的业务逻辑中之后 所有new的类必须删除自己手打引入 比如: AopClient() 、 AlipayFundTransToaccountTransferRequest() 否则会爆出class not found 等错误
2、按照说明配置所有参数之后,请求会爆出 “ 文件编码:[UTF-8] 与表单提交编码:[GBK]两者不一致!”错误,只要将复制的代码中 $aop->postCharset 值的GBK修改成为UTF-8即可
3、支付宝SDK与Laravel都自定义了encrypt与decrypt函数,所以会产生冲突,只要将支付宝SDK中的 \aop\AopClient.php \aop\AopEncrypt.php \lotusphp_runtime\Cookie\Cokkie.php 下的这两个函数全部重新命名即可,注意所有的 包括引用函数 直接在编辑器中查找替换也可以。
然后根据自己的业务来进行修改就可以了
如果爆出 “$sign”错误,请检查自己的公钥、私钥、AppID等是否正确,如果使用沙箱测试,请将网关修改为
<em><strong><span style="color: #ff0000">$aop->gatewayUrl =</span></strong></em><span style="color: #ff0000"> 'https://openapi.alipaydev.com/gateway.do';</span><span style="color: #ff0000"><br/></span><span style="color: #ff0000"><span style="color: #ffffff">最后贴上自己的代码,欢迎指教</span></span>
/* *支付宝提现接口 */ public function toTransfer($orderNo, $account, $amount, $payName, $payeeRealName, $remark) { $aop = new \AopClient(); $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do'; $aop->appId = config('Alipay.AppId'); $aop->rsaPrivateKey = config('Alipay.PriKey'); $aop->alipayrsaPublicKey = config('Alipay.PubKey'); $aop->apiVersion = '1.0'; $aop->signType = 'RSA2'; $aop->postCharset = 'UTF-8'; $aop->format = 'json'; $request = new \AlipayFundTransToaccountTransferRequest (); $request->setBizContent("{" . "\"out_biz_no\":\"$orderNo\"," . "\"payee_type\":\"ALIPAY_LOGONID\"," . "\"payee_account\":\"$account\"," . "\"amount\":\"$amount\"," . "\"payer_show_name\":\"$payName\"," . "\"payee_real_name\":\"$payeeRealName\"," . "\"remark\":\"$remark\"" . "}"); $result = $aop->execute($request); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; if (!empty($resultCode) && $resultCode == 10000) { echo "成功"; } else { echo "失败"; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
php bug 调试助手 debug_print_backtrace()的介绍
The above is the detailed content of Laravel develops Alipay payment and cash transfer methods. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.
