php 支付宝支付接口
我用的官方sdk https://docs.open.alipay.com/270/106291/
直接aop文件夹放到PHP环境
配置 AopClient.php这个文件 秘钥和公钥搞了一会 这个一定要配置正确
//应用ID
public $appId
//私钥值
public $rsaPrivateKey
//支付宝公钥
public $alipayrsaPublicKey
然后我写了一个 alipay_functions.php放在aop同级目录 写了退款和查询订单两个函数 代码如下
<?php
//获取 支付编号 支付信息
function alipay_get_pay_info($trade_no){
include('aop/AopClient.php');
include('aop/SignData.php');
include('aop/request/AlipayTradeQueryRequest.php');
$aop = new AopClient;
$request = new AlipayTradeQueryRequest();
$bizcontent = json_encode(['trade_no'=>$trade_no,]);
$request->setBizContent($bizcontent);
$result = $aop->execute($request);
var_dump($result);
}
//订单 退款
function alipay_refund($trade_no,$order_amount){
include('aop/AopClient.php');
include('aop/SignData.php');
include('aop/request/AlipayTradeRefundRequest.php');
$aop = new AopClient;
$request = new AlipayTradeRefundRequest();
$bizcontent = json_encode(['trade_no'=>$trade_no,'refund_amount'=>$order_amount]);
$request->setBizContent($bizcontent);
$result = $aop->execute($request);
//var_dump($result);
}
添加对账单查询函数
//对账单 账单时间:日账单格式为yyyy-MM-dd,月账单格式为yyyy-MM。
function alipay_bills($date){
include('aop/AopClient.php');
include('aop/SignData.php');
include('aop/request/AlipayDataDataserviceBillDownloadurlQueryRequest.php');
$aop = new AopClient;
$request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
$bizcontent = json_encode(['bill_type'=>'trade','bill_date'=>$date]);
$request->setBizContent($bizcontent);
$result = $aop->execute($request);
header("Location: ".$result->alipay_data_dataservice_bill_downloadurl_query_response->bill_download_url);
}
然后项目内调用
include(ROOT_PATH.'666plugins/alipay_functions.php');
alipay_refund($order['transaction_id'],$order['order_amount']);
问题 1 如果原有项目中有 function encrypt() 这个函数 会报错函数名冲突
打开 AopEncrypt.php 修改 函数名 encrypt 为 encrypt_aop
打开 AopClient.php 修改两处调用函数的地方
摘自(原文:https://blog.csdn.net/varius/article/details/78740449 )