这篇文章主要介绍了关于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!

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

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

WebStorm Mac version
Useful JavaScript development tools
