支付宝单笔转账开发
2023-12-20 16:23:03
1、下载SDK??https://github.com/alipay/alipay-sdk-php-all/tree/master?使用v2
2、引入SDK (沙箱测试:https://open.alipay.com/develop/sandbox/app)
<?php
require_once './v2/aop/AopClient.php';
require_once './v2/aop/AopCertClient.php';
require_once './v2/aop/AopCertification.php';
require_once './v2/aop/AlipayConfig.php';
require_once './v2/aop/request/AlipayFundTransUniTransferRequest.php';
$privateKey = "填写商户私钥";
$alipayConfig = new AlipayConfig();
$alipayConfig->setPrivateKey($privateKey);
$alipayConfig->setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
//沙箱地址,上线时需要切换正式地址
$alipayConfig->setAppId("9021000133613273");
$alipayConfig->setCharset("UTF-8");//注意这里是UTF - 8,坑爹的玩意
$alipayConfig->setSignType("RSA2");
$alipayConfig->setEncryptKey("");
$alipayConfig->setFormat("json");
$alipayConfig->setAppCertPath("商户公钥证书");
$alipayConfig->setAlipayPublicCertPath("支付宝公钥证书");
$alipayConfig->setRootCertPath("支付宝根证书");
$alipayClient = new AopCertClient($alipayConfig);
$alipayClient->isCheckAlipayPublicCert = true;
$request = new AlipayFundTransUniTransferRequest();
$data = array();
$oid = date("YmdHis").rand(1,9); //处理单号
$money = 0.01; //转账金额
$phone = 'zhangsan123'; //用户账号
$name = '张三'; //用户真实姓名
$data["out_biz_no"] = $oid;
$data["trans_amount"] = $money;
$data["product_code"] = 'TRANS_ACCOUNT_NO_PWD';
$data["biz_scene"] = 'DIRECT_TRANSFER';
$data["order_title"] = '转账介绍';
$data["payee_info"] = array();
$data["payee_info"]["identity"] = $phone;
$data["payee_info"]["identity_type"] = 'ALIPAY_LOGON_ID';
$data["payee_info"]["name"] = $name;
$request->setBizContent(json_encode($data, true));
$responseResult = $alipayClient->execute($request);
$responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
$response = $responseResult->$responseApiName;
if(!empty($response->code)&&$response->code==10000){
echo "success";
}
else{
echo json_encode($responseResult);
}
文章来源:https://blog.csdn.net/qq_24138677/article/details/135108232
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!