Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站alipay.trade.close (统一收单交易关闭接口)业务参数封装
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
|
||||
class AlipayTradeCloseContentBuilder
|
||||
{
|
||||
|
||||
// 商户订单号.
|
||||
private $outTradeNo;
|
||||
|
||||
// 支付宝交易号
|
||||
private $tradeNo;
|
||||
|
||||
//卖家端自定义的的操作员 ID
|
||||
private $operatorId;
|
||||
|
||||
private $bizContentarr = array();
|
||||
|
||||
private $bizContent = NULL;
|
||||
|
||||
public function getBizContent()
|
||||
{
|
||||
if(!empty($this->bizContentarr)){
|
||||
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $this->bizContent;
|
||||
}
|
||||
|
||||
public function getTradeNo()
|
||||
{
|
||||
return $this->tradeNo;
|
||||
}
|
||||
|
||||
public function setTradeNo($tradeNo)
|
||||
{
|
||||
$this->tradeNo = $tradeNo;
|
||||
$this->bizContentarr['trade_no'] = $tradeNo;
|
||||
}
|
||||
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->outTradeNo;
|
||||
}
|
||||
|
||||
public function setOutTradeNo($outTradeNo)
|
||||
{
|
||||
$this->outTradeNo = $outTradeNo;
|
||||
$this->bizContentarr['out_trade_no'] = $outTradeNo;
|
||||
}
|
||||
public function getOperatorId()
|
||||
{
|
||||
return $this->operatorId;
|
||||
}
|
||||
|
||||
public function setOperatorId($operatorId)
|
||||
{
|
||||
$this->operatorId = $operatorId;
|
||||
$this->bizContentarr['operator_id'] = $operatorId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站支付alipay.trade.fastpay.refund.query (统一收单交易退款查询)业务参数封装
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
|
||||
class AlipayTradeFastpayRefundQueryContentBuilder
|
||||
{
|
||||
|
||||
// 商户订单号.
|
||||
private $outTradeNo;
|
||||
// 支付宝交易号
|
||||
private $tradeNo;
|
||||
// 请求退款接口时,传入的退款请求号,如果在退款请求时未传入,则该值为创建交易时的外部交易号
|
||||
private $outRequestNo;
|
||||
|
||||
private $bizContentarr = array();
|
||||
|
||||
private $bizContent = NULL;
|
||||
|
||||
public function getBizContent()
|
||||
{
|
||||
if(!empty($this->bizContentarr)){
|
||||
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $this->bizContent;
|
||||
}
|
||||
|
||||
public function getTradeNo()
|
||||
{
|
||||
return $this->tradeNo;
|
||||
}
|
||||
|
||||
public function setTradeNo($tradeNo)
|
||||
{
|
||||
$this->tradeNo = $tradeNo;
|
||||
$this->bizContentarr['trade_no'] = $tradeNo;
|
||||
}
|
||||
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->outTradeNo;
|
||||
}
|
||||
|
||||
public function setOutTradeNo($outTradeNo)
|
||||
{
|
||||
$this->outTradeNo = $outTradeNo;
|
||||
$this->bizContentarr['out_trade_no'] = $outTradeNo;
|
||||
}
|
||||
public function getOutRequestNo()
|
||||
{
|
||||
return $this->outRequestNo;
|
||||
}
|
||||
public function setOutRequestNo($outRequestNo)
|
||||
{
|
||||
$this->outRequestNo = $outRequestNo;
|
||||
$this->bizContentarr['out_request_no'] = $outRequestNo;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站支付(alipay.trade.page.pay)接口业务参数封装
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
|
||||
class AlipayTradePagePayContentBuilder
|
||||
{
|
||||
|
||||
// 订单描述,可以对交易或商品进行一个详细地描述,比如填写"购买商品2件共15.00元"
|
||||
private $body;
|
||||
|
||||
// 订单标题,粗略描述用户的支付目的。
|
||||
private $subject;
|
||||
|
||||
// 商户订单号.
|
||||
private $outTradeNo;
|
||||
|
||||
// (推荐使用,相对时间) 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m
|
||||
private $timeExpress;
|
||||
|
||||
// 订单总金额,整形,此处单位为元,精确到小数点后2位,不能超过1亿元
|
||||
private $totalAmount;
|
||||
|
||||
// 产品标示码,固定值:QUICK_WAP_PAY
|
||||
private $productCode;
|
||||
|
||||
private $bizContentarr = array();
|
||||
|
||||
private $bizContent = NULL;
|
||||
|
||||
public function getBizContent()
|
||||
{
|
||||
if(!empty($this->bizContentarr)){
|
||||
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $this->bizContent;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bizContentarr['product_code'] = "FAST_INSTANT_TRADE_PAY";
|
||||
}
|
||||
|
||||
public function AlipayTradeWapPayContentBuilder()
|
||||
{
|
||||
$this->__construct();
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->body = $body;
|
||||
$this->bizContentarr['body'] = $body;
|
||||
}
|
||||
|
||||
public function setSubject($subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->bizContentarr['subject'] = $subject;
|
||||
}
|
||||
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->outTradeNo;
|
||||
}
|
||||
|
||||
public function setOutTradeNo($outTradeNo)
|
||||
{
|
||||
$this->outTradeNo = $outTradeNo;
|
||||
$this->bizContentarr['out_trade_no'] = $outTradeNo;
|
||||
}
|
||||
|
||||
public function setTimeExpress($timeExpress)
|
||||
{
|
||||
$this->timeExpress = $timeExpress;
|
||||
$this->bizContentarr['timeout_express'] = $timeExpress;
|
||||
}
|
||||
|
||||
public function getTimeExpress()
|
||||
{
|
||||
return $this->timeExpress;
|
||||
}
|
||||
|
||||
public function setTotalAmount($totalAmount)
|
||||
{
|
||||
$this->totalAmount = $totalAmount;
|
||||
$this->bizContentarr['total_amount'] = $totalAmount;
|
||||
}
|
||||
|
||||
public function getTotalAmount()
|
||||
{
|
||||
return $this->totalAmount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站支付查询接口(alipay.trade.query)接口业务参数封装
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
|
||||
class AlipayTradeQueryContentBuilder
|
||||
{
|
||||
|
||||
// 商户订单号.
|
||||
private $outTradeNo;
|
||||
|
||||
// 支付宝交易号
|
||||
private $tradeNo;
|
||||
|
||||
private $bizContentarr = array();
|
||||
|
||||
private $bizContent = NULL;
|
||||
|
||||
public function getBizContent()
|
||||
{
|
||||
if(!empty($this->bizContentarr)){
|
||||
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $this->bizContent;
|
||||
}
|
||||
|
||||
public function getTradeNo()
|
||||
{
|
||||
return $this->tradeNo;
|
||||
}
|
||||
|
||||
public function setTradeNo($tradeNo)
|
||||
{
|
||||
$this->tradeNo = $tradeNo;
|
||||
$this->bizContentarr['trade_no'] = $tradeNo;
|
||||
}
|
||||
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->outTradeNo;
|
||||
}
|
||||
|
||||
public function setOutTradeNo($outTradeNo)
|
||||
{
|
||||
$this->outTradeNo = $outTradeNo;
|
||||
$this->bizContentarr['out_trade_no'] = $outTradeNo;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站支付退款接口(alipay.trade.refund)接口业务参数封装
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
|
||||
class AlipayTradeRefundContentBuilder
|
||||
{
|
||||
|
||||
// 商户订单号.
|
||||
private $outTradeNo;
|
||||
|
||||
// 支付宝交易号
|
||||
private $tradeNo;
|
||||
|
||||
// 退款的金额
|
||||
private $refundAmount;
|
||||
|
||||
// 退款原因说明
|
||||
private $refundReason;
|
||||
|
||||
// 标识一次退款请求号,同一笔交易多次退款保证唯一,部分退款此参数必填
|
||||
private $outRequestNo;
|
||||
|
||||
private $bizContentarr = array();
|
||||
|
||||
private $bizContent = NULL;
|
||||
|
||||
public function getBizContent()
|
||||
{
|
||||
if(!empty($this->bizContentarr)){
|
||||
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $this->bizContent;
|
||||
}
|
||||
|
||||
public function getTradeNo()
|
||||
{
|
||||
return $this->tradeNo;
|
||||
}
|
||||
|
||||
public function setTradeNo($tradeNo)
|
||||
{
|
||||
$this->tradeNo = $tradeNo;
|
||||
$this->bizContentarr['trade_no'] = $tradeNo;
|
||||
}
|
||||
|
||||
public function getOutTradeNo()
|
||||
{
|
||||
return $this->outTradeNo;
|
||||
}
|
||||
|
||||
public function setOutTradeNo($outTradeNo)
|
||||
{
|
||||
$this->outTradeNo = $outTradeNo;
|
||||
$this->bizContentarr['out_trade_no'] = $outTradeNo;
|
||||
}
|
||||
|
||||
public function getRefundAmount()
|
||||
{
|
||||
return $this->refundAmount;
|
||||
}
|
||||
|
||||
public function setRefundAmount($refundAmount)
|
||||
{
|
||||
$this->refundAmount = $refundAmount;
|
||||
$this->bizContentarr['refund_amount'] = $refundAmount;
|
||||
}
|
||||
|
||||
public function getRefundReason()
|
||||
{
|
||||
return $this->refundReason;
|
||||
}
|
||||
|
||||
public function setRefundReason($refundReason)
|
||||
{
|
||||
$this->refundReason = $refundReason;
|
||||
$this->bizContentarr['refund_reason'] = $refundReason;
|
||||
}
|
||||
|
||||
public function getOutRequestNo()
|
||||
{
|
||||
return $this->outRequestNo;
|
||||
}
|
||||
|
||||
public function setOutRequestNo($outRequestNo)
|
||||
{
|
||||
$this->outRequestNo = $outRequestNo;
|
||||
$this->bizContentarr['out_request_no'] = $outRequestNo;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>交易关闭</title>
|
||||
</head>
|
||||
<?php
|
||||
|
||||
require_once dirname(dirname(__FILE__)).'/config.php';
|
||||
require_once dirname(__FILE__).'/service/AlipayTradeService.php';
|
||||
require_once dirname(__FILE__).'/buildermodel/AlipayTradeCloseContentBuilder.php';
|
||||
|
||||
//商户订单号,商户网站订单系统中唯一订单号
|
||||
$out_trade_no = trim($_POST['WIDTCout_trade_no']);
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = trim($_POST['WIDTCtrade_no']);
|
||||
//请二选一设置
|
||||
|
||||
//构造参数
|
||||
$RequestBuilder=new AlipayTradeCloseContentBuilder();
|
||||
$RequestBuilder->setOutTradeNo($out_trade_no);
|
||||
$RequestBuilder->setTradeNo($trade_no);
|
||||
|
||||
$aop = new AlipayTradeService($config);
|
||||
|
||||
/**
|
||||
* alipay.trade.close (统一收单交易关闭接口)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
$response = $aop->Close($RequestBuilder);
|
||||
var_dump($response);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>支付</title>
|
||||
</head>
|
||||
<?php
|
||||
require_once dirname(dirname(__FILE__)).'/config.php';
|
||||
require_once dirname(__FILE__).'/service/AlipayTradeService.php';
|
||||
require_once dirname(__FILE__).'/buildermodel/AlipayTradePagePayContentBuilder.php';
|
||||
|
||||
//商户订单号,商户网站订单系统中唯一订单号,必填
|
||||
$out_trade_no = trim($_POST['WIDout_trade_no']);
|
||||
|
||||
//订单名称,必填
|
||||
$subject = trim($_POST['WIDsubject']);
|
||||
|
||||
//付款金额,必填
|
||||
$total_amount = trim($_POST['WIDtotal_amount']);
|
||||
|
||||
//商品描述,可空
|
||||
$body = trim($_POST['WIDbody']);
|
||||
|
||||
//构造参数
|
||||
$payRequestBuilder = new AlipayTradePagePayContentBuilder();
|
||||
$payRequestBuilder->setBody($body);
|
||||
$payRequestBuilder->setSubject($subject);
|
||||
$payRequestBuilder->setTotalAmount($total_amount);
|
||||
$payRequestBuilder->setOutTradeNo($out_trade_no);
|
||||
|
||||
$aop = new AlipayTradeService($config);
|
||||
|
||||
/**
|
||||
* pagePay 电脑网站支付请求
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @param $return_url 同步跳转地址,公网可以访问
|
||||
* @param $notify_url 异步通知地址,公网可以访问
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
$response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);
|
||||
|
||||
//输出表单
|
||||
var_dump($response);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>交易查询</title>
|
||||
</head>
|
||||
<?php
|
||||
|
||||
require_once dirname(dirname(__FILE__)).'/config.php';
|
||||
require_once dirname(__FILE__).'/service/AlipayTradeService.php';
|
||||
require_once dirname(__FILE__).'/buildermodel/AlipayTradeQueryContentBuilder.php';
|
||||
|
||||
//商户订单号,商户网站订单系统中唯一订单号
|
||||
$out_trade_no = trim($_POST['WIDTQout_trade_no']);
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = trim($_POST['WIDTQtrade_no']);
|
||||
//请二选一设置
|
||||
//构造参数
|
||||
$RequestBuilder = new AlipayTradeQueryContentBuilder();
|
||||
$RequestBuilder->setOutTradeNo($out_trade_no);
|
||||
$RequestBuilder->setTradeNo($trade_no);
|
||||
|
||||
$aop = new AlipayTradeService($config);
|
||||
|
||||
/**
|
||||
* alipay.trade.query (统一收单线下交易查询)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
$response = $aop->Query($RequestBuilder);
|
||||
var_dump($response);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>退款</title>
|
||||
</head>
|
||||
<?php
|
||||
|
||||
require_once dirname(dirname(__FILE__)).'/config.php';
|
||||
require_once dirname(__FILE__).'/service/AlipayTradeService.php';
|
||||
require_once dirname(__FILE__).'/buildermodel/AlipayTradeRefundContentBuilder.php';
|
||||
|
||||
//商户订单号,商户网站订单系统中唯一订单号
|
||||
$out_trade_no = trim($_POST['WIDTRout_trade_no']);
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = trim($_POST['WIDTRtrade_no']);
|
||||
//请二选一设置
|
||||
|
||||
//需要退款的金额,该金额不能大于订单金额,必填
|
||||
$refund_amount = trim($_POST['WIDTRrefund_amount']);
|
||||
|
||||
//退款的原因说明
|
||||
$refund_reason = trim($_POST['WIDTRrefund_reason']);
|
||||
|
||||
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传
|
||||
$out_request_no = trim($_POST['WIDTRout_request_no']);
|
||||
|
||||
//构造参数
|
||||
$RequestBuilder=new AlipayTradeRefundContentBuilder();
|
||||
$RequestBuilder->setOutTradeNo($out_trade_no);
|
||||
$RequestBuilder->setTradeNo($trade_no);
|
||||
$RequestBuilder->setRefundAmount($refund_amount);
|
||||
$RequestBuilder->setOutRequestNo($out_request_no);
|
||||
$RequestBuilder->setRefundReason($refund_reason);
|
||||
|
||||
$aop = new AlipayTradeService($config);
|
||||
|
||||
/**
|
||||
* alipay.trade.refund (统一收单交易退款接口)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
$response = $aop->Refund($RequestBuilder);
|
||||
var_dump($response);;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>退款查询</title>
|
||||
</head>
|
||||
<?php
|
||||
|
||||
require_once dirname(dirname(__FILE__)).'/config.php';
|
||||
require_once dirname(__FILE__).'/service/AlipayTradeService.php';
|
||||
require_once dirname(__FILE__).'/buildermodel/AlipayTradeFastpayRefundQueryContentBuilder.php';
|
||||
|
||||
//商户订单号,商户网站订单系统中唯一订单号
|
||||
$out_trade_no = trim($_POST['WIDRQout_trade_no']);
|
||||
|
||||
//支付宝交易号
|
||||
$trade_no = trim($_POST['WIDRQtrade_no']);
|
||||
//请二选一设置
|
||||
|
||||
//请求退款接口时,传入的退款请求号,如果在退款请求时未传入,则该值为创建交易时的外部交易号,必填
|
||||
$out_request_no = trim($_POST['WIDRQout_request_no']);
|
||||
|
||||
//构造参数
|
||||
$RequestBuilder=new AlipayTradeFastpayRefundQueryContentBuilder();
|
||||
$RequestBuilder->setOutTradeNo($out_trade_no);
|
||||
$RequestBuilder->setTradeNo($trade_no);
|
||||
$RequestBuilder->setOutRequestNo($out_request_no);
|
||||
|
||||
$aop = new AlipayTradeService($config);
|
||||
|
||||
/**
|
||||
* 退款查询 alipay.trade.fastpay.refund.query (统一收单交易退款查询)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
$response = $aop->refundQuery($RequestBuilder);
|
||||
var_dump($response);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
/* *
|
||||
* 功能:支付宝电脑网站支付
|
||||
* 版本:2.0
|
||||
* 修改日期:2017-05-01
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
*/
|
||||
|
||||
require_once dirname(dirname(dirname ( __FILE__ ))).'/AopSdk.php';
|
||||
|
||||
class AlipayTradeService {
|
||||
|
||||
//支付宝网关地址
|
||||
public $gateway_url = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
//支付宝公钥
|
||||
public $alipay_public_key;
|
||||
|
||||
//商户私钥
|
||||
public $private_key;
|
||||
|
||||
//应用id
|
||||
public $appid;
|
||||
|
||||
//编码格式
|
||||
public $charset = "UTF-8";
|
||||
|
||||
public $token = NULL;
|
||||
|
||||
//返回数据格式
|
||||
public $format = "json";
|
||||
|
||||
//签名方式
|
||||
public $signtype = "RSA2";
|
||||
|
||||
function __construct($alipay_config){
|
||||
$this->gateway_url = $alipay_config['gatewayUrl'];
|
||||
$this->appid = $alipay_config['app_id'];
|
||||
$this->private_key = $alipay_config['merchant_private_key'];
|
||||
$this->alipay_public_key = $alipay_config['alipay_public_key'];
|
||||
$this->charset = $alipay_config['charset'];
|
||||
$this->signtype=$alipay_config['sign_type'];
|
||||
|
||||
if(empty($this->appid)||trim($this->appid)==""){
|
||||
throw new Exception("appid should not be NULL!");
|
||||
}
|
||||
if(empty($this->private_key)||trim($this->private_key)==""){
|
||||
throw new Exception("private_key should not be NULL!");
|
||||
}
|
||||
if(empty($this->alipay_public_key)||trim($this->alipay_public_key)==""){
|
||||
throw new Exception("alipay_public_key should not be NULL!");
|
||||
}
|
||||
if(empty($this->charset)||trim($this->charset)==""){
|
||||
throw new Exception("charset should not be NULL!");
|
||||
}
|
||||
if(empty($this->gateway_url)||trim($this->gateway_url)==""){
|
||||
throw new Exception("gateway_url should not be NULL!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* alipay.trade.page.pay
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @param $return_url 同步跳转地址,公网可以访问
|
||||
* @param $notify_url 异步通知地址,公网可以访问
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function pagePay($builder,$return_url,$notify_url) {
|
||||
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
|
||||
$request = new AlipayTradePagePayRequest();
|
||||
|
||||
$request->setNotifyUrl($notify_url);
|
||||
$request->setReturnUrl($return_url);
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
// 首先调用支付api
|
||||
$response = $this->aopclientRequestExecute ($request,true);
|
||||
// $response = $response->alipay_trade_wap_pay_response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* sdkClient
|
||||
* @param $request 接口请求参数对象。
|
||||
* @param $ispage 是否是页面接口,电脑网站支付是页面表单接口。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function aopclientRequestExecute($request,$ispage=false) {
|
||||
|
||||
$aop = new AopClient ();
|
||||
$aop->gatewayUrl = $this->gateway_url;
|
||||
$aop->appId = $this->appid;
|
||||
$aop->rsaPrivateKey = $this->private_key;
|
||||
$aop->alipayrsaPublicKey = $this->alipay_public_key;
|
||||
$aop->apiVersion ="1.0";
|
||||
$aop->postCharset = $this->charset;
|
||||
$aop->format= $this->format;
|
||||
$aop->signType=$this->signtype;
|
||||
// 开启页面信息输出
|
||||
$aop->debugInfo=false;
|
||||
if($ispage)
|
||||
{
|
||||
$result = $aop->pageExecute($request,"get");
|
||||
//echo $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $aop->Execute($request);
|
||||
}
|
||||
|
||||
//打开后,将报文写入log文件
|
||||
$this->writeLog("response: ".var_export($result,true));
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* alipay.trade.query (统一收单线下交易查询)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function Query($builder){
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
$request = new AlipayTradeQueryRequest();
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
$response = $this->aopclientRequestExecute ($request);
|
||||
$response = $response->alipay_trade_query_response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* alipay.trade.refund (统一收单交易退款接口)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function Refund($builder){
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
$request = new AlipayTradeRefundRequest();
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
$response = $this->aopclientRequestExecute ($request);
|
||||
$response = $response->alipay_trade_refund_response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* alipay.trade.close (统一收单交易关闭接口)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function Close($builder){
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
$request = new AlipayTradeCloseRequest();
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
$response = $this->aopclientRequestExecute ($request);
|
||||
$response = $response->alipay_trade_close_response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款查询 alipay.trade.fastpay.refund.query (统一收单交易退款查询)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function refundQuery($builder){
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
$request = new AlipayTradeFastpayRefundQueryRequest();
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
$response = $this->aopclientRequestExecute ($request);
|
||||
return $response;
|
||||
}
|
||||
/**
|
||||
* alipay.data.dataservice.bill.downloadurl.query (查询对账单下载地址)
|
||||
* @param $builder 业务参数,使用buildmodel中的对象生成。
|
||||
* @return $response 支付宝返回的信息
|
||||
*/
|
||||
function downloadurlQuery($builder){
|
||||
$biz_content=$builder->getBizContent();
|
||||
//打印业务参数
|
||||
$this->writeLog($biz_content);
|
||||
$request = new alipaydatadataservicebilldownloadurlqueryRequest();
|
||||
$request->setBizContent ( $biz_content );
|
||||
|
||||
$response = $this->aopclientRequestExecute ($request);
|
||||
$response = $response->alipay_data_dataservice_bill_downloadurl_query_response;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验签方法
|
||||
* @param $arr 验签支付宝返回的信息,使用支付宝公钥。
|
||||
* @return boolean
|
||||
*/
|
||||
function check($arr){
|
||||
$aop = new AopClient();
|
||||
$aop->alipayrsaPublicKey = $this->alipay_public_key;
|
||||
$result = $aop->rsaCheckV1($arr, $this->alipay_public_key, $this->signtype);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请确保项目文件有可写权限,不然打印不了日志。
|
||||
*/
|
||||
function writeLog($text) {
|
||||
// $text=iconv("GBK", "UTF-8//IGNORE", $text);
|
||||
//$text = characet ( $text );
|
||||
file_put_contents ( dirname ( __FILE__ ).DIRECTORY_SEPARATOR."./../../log.txt", date ( "Y-m-d H:i:s" ) . " " . $text . "\r\n", FILE_APPEND );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user