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

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
