官方参考文档:
可以使用默认应用,也可以自建新应用,此处以默认应用来讲解【默认应用默认支持该API】
一:给应用配置加签方式



按照下面的提示,在本地电脑上安装密钥工具并生成密钥文件。









二:下载SDK
https://opendocs.alipay.com/open/54/103419/


把代码放在服务器项目目录中【sdk/ali_transfer】
目录请根据自己实际项目需要自定义即可。

使用命令行将压缩包解压 unzip 压缩包名称

最后调整为如下格式:

在官方文档页面,找到集成工具

选择在线调试


注意:此API在线调试工具里的代码是沙箱环境下的代码,不能作为正常业务逻辑操作代码。
复制右侧的php代码到自己的项目中,并把代码加以改造。
php
require_once ROOT_PATH.'sdk/ali_transfer/v2/aop/AopClient.php';
require_once ROOT_PATH.'sdk/ali_transfer/v2/aop/AopCertClient.php';
require_once ROOT_PATH.'sdk/ali_transfer/v2/aop/AopCertification.php';
require_once ROOT_PATH.'sdk/ali_transfer/v2/aop/AlipayConfig.php';
require_once ROOT_PATH.'sdk/ali_transfer/v2/aop/request/AlipayFundTransUniTransferRequest.php';
$privateKey = "MIIEvQIBADANBgkqhki*********************EFAgiCdrM61I=";//支付宝密钥工具生成的应用私钥
$alipayConfig = new \AlipayConfig();
$alipayConfig->setPrivateKey($privateKey);
$alipayConfig->setServerUrl("https://openapi.alipay.com/gateway.do");
$alipayConfig->setAppId("2021********2401"); //支付宝后台应用appID
$alipayConfig->setCharset("UTF-8");
$alipayConfig->setSignType("RSA2");
$alipayConfig->setEncryptKey(""); //为空即可
$alipayConfig->setFormat("json");
$appCertPublicKey = file_get_contents(ROOT_PATH.'addons/epay/certs/appCertPublicKey.crt'); //证书路径自行修改
$alipayConfig->setAppCertContent($appCertPublicKey); //应用公钥
$alipayCertPublicKey = file_get_contents(ROOT_PATH.'addons/epay/certs/alipayCertPublicKey.crt');//证书路径自行修改
$alipayConfig->setAlipayPublicCertContent($alipayCertPublicKey); //支付宝公钥证书
$alipayRootCert = file_get_contents(ROOT_PATH.'addons/epay/certs/alipayRootCert.crt');//证书路径自行修改
$alipayConfig->setRootCertContent($alipayRootCert); //支付宝根证书
$alipayClient = new \AopCertClient($alipayConfig);
$alipayClient->isCheckAlipayPublicCert = true;
$request = new \AlipayFundTransUniTransferRequest();
$out_biz_no = "ybjz".date('YmdHis',time()).rand(10000000,99999999);
$data=[
'out_biz_no'=>$out_biz_no,
'trans_amount'=>0.1, //转账金额(单位为元)
'biz_scene'=>'DIRECT_TRANSFER',
'product_code'=>'TRANS_ACCOUNT_NO_PWD',
'order_title'=>'提现',
'payee_info'=>[
'identity'=>'138********', //支付宝手机号
'identity_type'=>'ALIPAY_LOGON_ID',
'name'=>'张某某', //支付宝姓名
]
];
$request->setBizContent(json_encode($data));
$responseResult = $alipayClient->execute($request);
$responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
$response = $responseResult->$responseApiName;
if(!empty($response->code)&&$response->code==10000){
//业务处理逻辑,如记录订单号,改变订单状态等
//**********
echo("调用成功");
}
else{
echo("调用失败");
}
调用成功后返回的信息如下:
