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 )