添加后台代理代码

This commit is contained in:
2026-03-15 01:27:05 +08:00
parent 11f9ac4dc1
commit ea08c9366a
5254 changed files with 721042 additions and 0 deletions

View File

@@ -0,0 +1,347 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/20
* Time: 下午3:31
*/
header("Content-type: text/html; charset=utf-8");
require_once 'model/builder/AlipayTradePayContentBuilder.php';
require_once 'service/AlipayTradeService.php';
if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!="") {
// (必填) 商户网站订单系统中唯一订单号64个字符以内只能包含字母、数字、下划线
// 需保证商户系统端不能重复建议通过数据库sequence生成
//$outTradeNo = "barpay" . date('Ymdhis') . mt_rand(100, 1000);
$outTradeNo = $_POST['out_trade_no'];
// (必填) 订单标题粗略描述用户的支付目的。如“XX品牌XXX门店消费”
$subject = $_POST['subject'];
// (必填) 订单总金额单位为元不能超过1亿元
// 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】
$totalAmount = $_POST['total_amount'];
// (必填) 付款条码用户支付宝钱包手机app点击“付款”产生的付款条码
$authCode = $_POST['auth_code']; //28开头18位数字
// (可选,根据需要使用) 订单可打折金额,可以配合商家平台配置折扣活动,如果订单部分商品参与打折,可以将部分商品总价填写至此字段,默认全部商品可打折
// 如果该值未传入,但传入了【订单总金额】,【不可打折金额】 则该值默认为【订单总金额】- 【不可打折金额】
//String discountableAmount = "1.00"; //
// (可选) 订单不可打折金额,可以配合商家平台配置折扣活动,如果酒水不参与打折,则将对应金额填写至此字段
// 如果该值未传入,但传入了【订单总金额】,【打折金额】,则该值默认为【订单总金额】-【打折金额】
$undiscountableAmount = "0.01";
// 卖家支付宝账号ID用于支持一个签约账号下支持打款到不同的收款账号(打款到sellerId对应的支付宝账号)
// 如果该字段为空则默认为与支付宝签约的商户的PID也就是appid对应的PID
$sellerId = "";
// 订单描述,可以对交易或商品进行一个详细地描述,比如填写"购买商品2件共15.00元"
$body = "购买商品2件共15.00元";
//商户操作员编号,添加此参数可以为商户操作员做销售统计
$operatorId = "test_operator_id";
// (可选) 商户门店编号,通过门店号和商家后台可以配置精准到门店的折扣信息,详询支付宝技术支持
$storeId = "test_store_id";
// 支付宝的店铺编号
$alipayStoreId = "test_alipay_store_id";
// 业务扩展参数,目前可添加由支付宝分配的系统商编号(通过setSysServiceProviderId方法),详情请咨询支付宝技术支持
$providerId = ""; //系统商pid,作为系统商返佣数据提取的依据
$extendParams = new ExtendParams();
$extendParams->setSysServiceProviderId($providerId);
$extendParamsArr = $extendParams->getExtendParams();
// 支付超时线下扫码交易定义为5分钟
$timeExpress = "5m";
// 商品明细列表,需填写购买商品详细信息,
$goodsDetailList = array();
// 创建一个商品信息参数含义分别为商品id使用国标、名称、单价单位为分、数量如果需要添加商品类别详见GoodsDetail
$goods1 = new GoodsDetail();
$goods1->setGoodsId("good_id001");
$goods1->setGoodsName("XXX商品1");
$goods1->setPrice(3000);
$goods1->setQuantity(1);
//得到商品1明细数组
$goods1Arr = $goods1->getGoodsDetail();
// 继续创建并添加第一条商品信息用户购买的产品为“xx牙刷”单价为5.05元,购买了两件
$goods2 = new GoodsDetail();
$goods2->setGoodsId("good_id002");
$goods2->setGoodsName("XXX商品2");
$goods2->setPrice(1000);
$goods2->setQuantity(1);
//得到商品1明细数组
$goods2Arr = $goods2->getGoodsDetail();
$goodsDetailList = array($goods1Arr, $goods2Arr);
//第三方应用授权令牌,商户授权系统商开发模式下使用
$appAuthToken = "";//根据真实值填写
// 创建请求builder设置请求参数
$barPayRequestBuilder = new AlipayTradePayContentBuilder();
$barPayRequestBuilder->setOutTradeNo($outTradeNo);
$barPayRequestBuilder->setTotalAmount($totalAmount);
$barPayRequestBuilder->setAuthCode($authCode);
$barPayRequestBuilder->setTimeExpress($timeExpress);
$barPayRequestBuilder->setSubject($subject);
$barPayRequestBuilder->setBody($body);
$barPayRequestBuilder->setUndiscountableAmount($undiscountableAmount);
$barPayRequestBuilder->setExtendParams($extendParamsArr);
$barPayRequestBuilder->setGoodsDetailList($goodsDetailList);
$barPayRequestBuilder->setStoreId($storeId);
$barPayRequestBuilder->setOperatorId($operatorId);
$barPayRequestBuilder->setAlipayStoreId($alipayStoreId);
$barPayRequestBuilder->setAppAuthToken($appAuthToken);
// 调用barPay方法获取当面付应答
$barPay = new AlipayTradeService($config);
$barPayResult = $barPay->barPay($barPayRequestBuilder);
switch ($barPayResult->getTradeStatus()) {
case "SUCCESS":
echo "支付宝支付成功:" . "<br>--------------------------<br>";
print_r($barPayResult->getResponse());
break;
case "FAILED":
echo "支付宝支付失败!!!" . "<br>--------------------------<br>";
if (!empty($barPayResult->getResponse())) {
print_r($barPayResult->getResponse());
}
break;
case "UNKNOWN":
echo "系统异常,订单状态未知!!!" . "<br>--------------------------<br>";
if (!empty($barPayResult->getResponse())) {
print_r($barPayResult->getResponse());
}
break;
default:
echo "不支持的交易状态,交易返回异常!!!";
break;
}
return;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>支付宝当面付 条码支付</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
*{
margin:0;
padding:0;
}
ul,ol{
list-style:none;
}
.title{
color: #ADADAD;
font-size: 14px;
font-weight: bold;
padding: 8px 16px 5px 10px;
}
.hidden{
display:none;
}
.new-btn-login-sp{
border:1px solid #D74C00;
padding:1px;
display:inline-block;
}
.new-btn-login{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
}
.new-btn-login{
background-position: 0 -198px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.new-btn-login:hover{
background-position: 0 -167px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.bank-list{
overflow:hidden;
margin-top:5px;
}
.bank-list li{
float:left;
width:153px;
margin-bottom:5px;
}
#main{
width:750px;
margin:0 auto;
font-size:14px;
font-family:'宋体';
}
#logo{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
background-position:0 0;
width:166px;
height:35px;
float:left;
}
.red-star{
color:#f00;
width:10px;
display:inline-block;
}
.null-star{
color:#fff;
}
.content{
margin-top:5px;
}
.content dt{
width:160px;
display:inline-block;
text-align:right;
float:left;
}
.content dd{
margin-left:100px;
margin-bottom:5px;
}
#foot{
margin-top:10px;
}
.foot-ul li {
text-align:center;
}
.note-help {
color: #999999;
font-size: 12px;
line-height: 130%;
padding-left: 3px;
}
.cashier-nav {
font-size: 14px;
margin: 15px 0 10px;
text-align: left;
height:30px;
border-bottom:solid 2px #CFD2D7;
}
.cashier-nav ol li {
float: left;
}
.cashier-nav li.current {
color: #AB4400;
font-weight: bold;
}
.cashier-nav li.last {
clear:right;
}
.alipay_link {
text-align:right;
}
.alipay_link a:link{
text-decoration:none;
color:#8D8D8D;
}
.alipay_link a:visited{
text-decoration:none;
color:#8D8D8D;
}
</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
<div id="main">
<div id="head">
<dl class="alipay_link">
<a target="_blank" href="http://www.alipay.com/"><span>支付宝首页</span></a>|
<a target="_blank" href="https://b.alipay.com/home.htm"><span>商家服务</span></a>|
<a target="_blank" href="http://help.alipay.com/support/index_sh.htm"><span>帮助中心</span></a>
</dl>
<span class="title">支付宝 当面付2.0 条码支付接口</span>
</div>
<div class="cashier-nav">
<ol>
<li class="current">1、确认信息 →</li>
<li>2、点击确认 →</li>
<li class="last">3、确认完成</li>
</ol>
</div>
<form name=alipayment action="" method=post target="_blank">
<div id="body" style="clear:left">
<dl class="content">
<dt>商户订单号:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="out_trade_no" />
<span>商户网站订单系统中唯一订单号,必填
</span>
</dd>
<dt>订单名称:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="subject" />
<span>必填
</span>
</dd>
<dt>付款金额:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="total_amount" />
<span>必填
</span>
</dd>
<dt>付款条码:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="auth_code" />
<span>必填
</span>
</dd>
<dt></dt>
<dd>
<span class="new-btn-login-sp">
<button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
</span>
</dd>
</dl>
</div>
</form>
<div id="foot">
<ul class="foot-ul">
<li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
<li>
支付宝版权所有 2011-2015 ALIPAY.COM
</li>
</ul>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,29 @@
<?php
$config = array(
//签名方式,默认为RSA2(RSA2048)
'sign_type' => "RSA2",
//支付宝公钥
'alipay_public_key' => "",
//商户私钥
'merchant_private_key' => "",
//编码格式
'charset' => "UTF-8",
//支付宝网关
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//应用ID
'app_id' => "",
//异步通知地址,只有扫码支付预下单可用
'notify_url' => "http://www.baidu.com",
//最大查询重试次数
'MaxQueryRetry' => "10",
//查询间隔
'QueryDuration' => "3",
);

View File

@@ -0,0 +1,12 @@
2016-12-07 10:38:04 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:40:24 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:44:54 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:45:02 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:45:39 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:49:17 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-07 10:53:43 {"scene":"bar_code","out_trade_no":"1231231231231231","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"1231","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-09 04:07:41 {"scene":"bar_code","out_trade_no":"2016120912341","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"2.1测试","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-09 04:08:38 {"scene":"bar_code","out_trade_no":"2016120912341","total_amount":"0.01","auth_code":"1231231231231","timeout_express":"5m","subject":"2.1测试","body":"购买商品2件共15.00元","undiscountable_amount":"0.01","extend_params":{"sys_service_provider_id":""},"goods_detail":[{"goods_id":"good_id001","goods_name":"XXX商品1","price":3000,"quantity":1},{"goods_id":"good_id002","goods_name":"XXX商品2","price":1000,"quantity":1}],"store_id":"test_store_id","operator_id":"test_operator_id","alipay_store_id":"test_alipay_store_id"}
2016-12-09 04:09:08 {"out_trade_no":"2016120912341"}
2016-12-10 11:37:27 {"out_trade_no":"2016120912341"}
2016-12-10 11:39:41 {"out_trade_no":"2016120912341"}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
require_once 'ContentBuilder.php';
class AlipayTradeCancelContentBuilder extends ContentBuilder
{
// 支付宝交易号,和商户订单号不能同时为空
private $tradeNo;
// 商户订单号,通过商户订单号撤销相关交易
private $outTradeNo;
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 getOutTradeNo()
{
return $this->outTradeNo;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->bizContentarr['out_trade_no'] = $outTradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->bizContentarr['trade_no'] = $tradeNo;
}
}
?>

View File

@@ -0,0 +1,266 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/18
* Time: 下午2:09
*/
require_once 'GoodsDetail.php';
require_once 'ExtendParams.php';
require_once 'RoyaltyDetailInfo.php';
require_once 'ContentBuilder.php';
class AlipayTradePayContentBuilder extends ContentBuilder
{
//支付场景码,此处为条码支付bar_code
private $scene;
//支付授权码,用户支付宝钱包app点击"付款",在条码下对应的一串数字
private $authCode;
// 商户网站订单系统中唯一订单号64个字符以内只能包含字母、数字、下划线
// 需保证商户系统端不能重复建议通过数据库sequence生成
private $outTradeNo;
// 卖家支付宝账号ID用于支持一个签约账号下支持打款到不同的收款账号(打款到sellerId对应的支付宝账号)
// 如果该字段为空则默认为与支付宝签约的商户的PID也就是appid对应的PID
private $sellerId;
// 订单总金额整形此处单位为元精确到小数点后2位不能超过1亿元
// 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】
private $totalAmount;
// 订单可打折金额此处单位为元精确到小数点后2位
// 可以配合商家平台配置折扣活动,如果订单部分商品参与打折,可以将部分商品总价填写至此字段,默认全部商品可打折
// 如果该值未传入,但传入了【订单总金额】,【不可打折金额】 则该值默认为【订单总金额】- 【不可打折金额】
private $discountableAmount;
// 订单不可打折金额此处单位为元精确到小数点后2位可以配合商家平台配置折扣活动如果酒水不参与打折则将对应金额填写至此字段
// 如果该值未传入,但传入了【订单总金额】,【打折金额】,则该值默认为【订单总金额】-【打折金额】
private $undiscountableAmount;
// 订单标题粗略描述用户的支付目的。如“XX品牌XXX门店消费”
private $subject;
// 订单描述,可以对交易或商品进行一个详细地描述,比如填写"购买商品2件共15.00元"
private $body;
// 商品明细列表,需填写购买商品详细信息,
private $goodsDetailList = array();
// 商户操作员编号,添加此参数可以为商户操作员做销售统
private $operatorId;
// 商户门店编号,通过门店号和商家后台可以配置精准到门店的折扣信息,详询支付宝技术支持
private $storeId;
// 支付宝商家平台中配置的商户门店号,详询支付宝技术支持
private $alipayStoreId;
// 商户机具终端编号,当以机具方式接入支付宝时必传,详询支付宝技术支持
private $terminalId;
// 业务扩展参数,目前可添加由支付宝分配的系统商编号(通过setSysServiceProviderId方法),详情请咨询支付宝技术支持
private $extendParams = array();
// (推荐使用,相对时间) 支付超时时间5m 5分钟
private $timeExpress;
private $bizContent = NULL;
private $bizParas = array();
public function __construct()
{
$this->bizParas['scene'] = "bar_code";
}
public function AlipayTradePayContentBuilder()
{
$this->__construct();
}
public function getBizContent()
{
/*$this->bizContent = "{";
foreach ($this->bizParas as $k=>$v){
$this->bizContent.= "\"".$k."\":\"".$v."\",";
}
$this->bizContent = substr($this->bizContent,0,-1);
$this->bizContent.= "}";*/
if(!empty($this->bizParas)){
$this->bizContent = json_encode($this->bizParas,JSON_UNESCAPED_UNICODE);
}
return $this->bizContent;
}
public function getAuthCode()
{
return $this->authCode;
}
public function setAuthCode($authCode)
{
$this->authCode = $authCode;
$this->bizParas['auth_code'] = $authCode;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->bizParas['out_trade_no'] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setSellerId($sellerId)
{
$this->sellerId = $sellerId;
$this->bizParas['seller_id'] = $sellerId;
}
public function getSellerId()
{
return $this->sellerId;
}
public function setTotalAmount($totalAmount)
{
$this->totalAmount = $totalAmount;
$this->bizParas['total_amount'] = $totalAmount;
}
public function getTotalAmount()
{
return $this->totalAmount;
}
public function setDiscountableAmount($discountableAmount)
{
$this->discountableAmount = $discountableAmount;
$this->bizParas['discountable_amount'] = $discountableAmount;
}
public function getDiscountableAmount()
{
return $this->discountableAmount;
}
public function setUndiscountableAmount($undiscountableAmount)
{
$this->undiscountableAmount = $undiscountableAmount;
$this->bizParas['undiscountable_amount'] = $undiscountableAmount;
}
public function getUndiscountableAmount()
{
return $this->undiscountableAmount;
}
public function setSubject($subject)
{
$this->subject = $subject;
$this->bizParas['subject'] = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setBody($body)
{
$this->body = $body;
$this->bizParas['body'] = $body;
}
public function getBody()
{
return $this->body;
}
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->bizParas['operator_id'] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setStoreId($storeId)
{
$this->storeId = $storeId;
$this->bizParas['store_id'] = $storeId;
}
public function getStoreId()
{
return $this->storeId;
}
public function setTerminalId($terminalId)
{
$this->terminalId = $terminalId;
$this->bizParas['terminal_id'] = $terminalId;
}
public function getTerminalId()
{
return $this->terminalId;
}
public function setTimeExpress($timeExpress)
{
$this->timeExpress = $timeExpress;
$this->bizParas['timeout_express'] = $timeExpress;
}
public function getTimeExpress()
{
return $this->timeExpress;
}
public function getAlipayStoreId()
{
return $this->alipayStoreId;
}
public function setAlipayStoreId($alipayStoreId)
{
$this->alipayStoreId = $alipayStoreId;
$this->bizParas['alipay_store_id'] = $alipayStoreId;
}
public function getExtendParams()
{
return $this->extendParams;
}
public function setExtendParams($extendParams)
{
$this->extendParams = $extendParams;
$this->bizParas['extend_params'] = $extendParams;
}
public function getGoodsDetailList()
{
return $this->goodsDetailList;
}
public function setGoodsDetailList($goodsDetailList)
{
$this->goodsDetailList = $goodsDetailList;
$this->bizParas['goods_detail'] = $goodsDetailList;
}
}
?>

View File

@@ -0,0 +1,253 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
require_once 'GoodsDetail.php';
require_once 'ExtendParams.php';
require_once 'RoyaltyDetailInfo.php';
require_once 'ContentBuilder.php';
class AlipayTradePrecreateContentBuilder extends ContentBuilder
{
// 商户网站订单系统中唯一订单号64个字符以内只能包含字母、数字、下划线
// 需保证商户系统端不能重复建议通过数据库sequence生成
private $outTradeNo;
// 卖家支付宝账号ID用于支持一个签约账号下支持打款到不同的收款账号(打款到sellerId对应的支付宝账号)
// 如果该字段为空则默认为与支付宝签约的商户的PID也就是appid对应的PID
private $sellerId;
// 订单总金额整形此处单位为元精确到小数点后2位不能超过1亿元
// 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】
private $totalAmount;
// 订单可打折金额此处单位为元精确到小数点后2位
// 可以配合商家平台配置折扣活动,如果订单部分商品参与打折,可以将部分商品总价填写至此字段,默认全部商品可打折
// 如果该值未传入,但传入了【订单总金额】,【不可打折金额】 则该值默认为【订单总金额】- 【不可打折金额】
private $discountableAmount;
// 订单不可打折金额此处单位为元精确到小数点后2位可以配合商家平台配置折扣活动如果酒水不参与打折则将对应金额填写至此字段
// 如果该值未传入,但传入了【订单总金额】,【打折金额】,则该值默认为【订单总金额】-【打折金额】
private $undiscountableAmount;
//买家支付宝账号
private $buyerLogonId;
// 订单标题,粗略描述用户的支付目的。如“喜士多(浦东店)消费”
private $subject;
// 订单描述,可以对交易或商品进行一个详细地描述,比如填写"购买商品2件共15.00元"
private $body;
// 商品明细列表,需填写购买商品详细信息,
private $goodsDetailList = array();
// 商户操作员编号,添加此参数可以为商户操作员做销售统
private $operatorId;
// 商户门店编号,通过门店号和商家后台可以配置精准到门店的折扣信息,详询支付宝技术支持
private $storeId;
// 支付宝商家平台中配置的商户门店号,详询支付宝技术支持
private $alipayStoreId;
// 商户机具终端编号,当以机具方式接入支付宝时必传,详询支付宝技术支持
private $terminalId;
// 业务扩展参数,目前可添加由支付宝分配的系统商编号(通过setSysServiceProviderId方法),详情请咨询支付宝技术支持
private $extendParams = array();
// (推荐使用,相对时间) 支付超时时间5m 5分钟
private $timeExpress;
private $bizContent = null;
private $bizParas = array();
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->bizParas['out_trade_no'] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setSellerId($sellerId)
{
$this->sellerId = $sellerId;
$this->bizParas['seller_id'] = $sellerId;
}
public function getSellerId()
{
return $this->sellerId;
}
public function setTotalAmount($totalAmount)
{
$this->totalAmount = $totalAmount;
$this->bizParas['total_amount'] = $totalAmount;
}
public function getTotalAmount()
{
return $this->totalAmount;
}
public function setDiscountableAmount($discountableAmount)
{
$this->discountableAmount = $discountableAmount;
$this->bizParas['discountable_amount'] = $discountableAmount;
}
public function getDiscountableAmount()
{
return $this->discountableAmount;
}
public function setUndiscountableAmount($undiscountableAmount)
{
$this->undiscountableAmount = $undiscountableAmount;
$this->bizParas['undiscountable_amount'] = $undiscountableAmount;
}
public function getUndiscountableAmount()
{
return $this->undiscountableAmount;
}
public function setBuyerLogonId($buyerLogonId)
{
$this->buyerLogonId = $buyerLogonId;
$this->bizParas['buyer_logon_id'] = $buyerLogonId;
}
public function getBuyerLogonId()
{
return $this->buyerLogonId;
}
public function setSubject($subject)
{
$this->subject = $subject;
$this->bizParas['subject'] = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setBody($body)
{
$this->body = $body;
$this->bizParas['body'] = $body;
}
public function getBody()
{
return $this->body;
}
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->bizParas['operator_id'] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setStoreId($storeId)
{
$this->storeId = $storeId;
$this->bizParas['store_id'] = $storeId;
}
public function getStoreId()
{
return $this->storeId;
}
public function setTerminalId($terminalId)
{
$this->terminalId = $terminalId;
$this->bizParas['terminal_id'] = $terminalId;
}
public function getTerminalId()
{
return $this->terminalId;
}
public function setTimeExpress($timeExpress)
{
$this->timeExpress = $timeExpress;
$this->bizParas['timeout_express'] = $timeExpress;
}
public function getTimeExpress()
{
return $this->timeExpress;
}
public function getAlipayStoreId()
{
return $this->alipayStoreId;
}
public function setAlipayStoreId($alipayStoreId)
{
$this->alipayStoreId = $alipayStoreId;
$this->bizParas['alipay_store_id'] = $alipayStoreId;
}
public function getExtendParams()
{
return $this->extendParams;
}
public function setExtendParams($extendParams)
{
$this->extendParams = $extendParams;
$this->bizParas['extend_params'] = $extendParams;
}
public function getGoodsDetailList()
{
return $this->goodsDetailList;
}
public function setGoodsDetailList($goodsDetailList)
{
$this->goodsDetailList = $goodsDetailList;
$this->bizParas['goods_detail'] = $goodsDetailList;
}
public function getBizContent()
{
/*$this->bizContent = "{";
foreach ($this->bizParas as $k=>$v){
$this->bizContent.= "\"".$k."\":\"".$v."\",";
}
$this->bizContent = substr($this->bizContent,0,-1);
$this->bizContent.= "}";*/
if (!empty($this->bizParas))
$this->bizContent = json_encode($this->bizParas, JSON_UNESCAPED_UNICODE);
return $this->bizContent;
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
require_once 'ContentBuilder.php';
class AlipayTradeQueryContentBuilder extends ContentBuilder
{
// 支付宝交易号,和商户订单号不能同时为空, 如果同时存在则通过tradeNo查询支付宝交易
private $tradeNo;
// 商户订单号,通过此商户订单号查询当面付的交易状态
private $outTradeNo;
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 getOutTradeNo()
{
return $this->outTradeNo;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->bizContentarr['out_trade_no'] = $outTradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->bizContentarr['trade_no'] = $tradeNo;
}
}
?>

View File

@@ -0,0 +1,149 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
require_once 'ContentBuilder.php';
class AlipayTradeRefundContentBuilder_f2fpay extends ContentBuilder
{
// 支付宝交易号,当面付支付成功后支付宝会返回给商户系统。通过此支付宝交易号进行交易退款
private $tradeNo;
// (推荐) 外部订单号,可通过外部订单号申请退款,推荐使用
private $outTradeNo;
// 退款金额该金额必须小于等于订单的支付金额此处单位为元精确到小数点后2位
private $refundAmount;
// (可选,需要支持重复退货时必填) 商户退款请求号,相同支付宝交易号下的不同退款请求号对应同一笔交易的不同退款申请,
// 对于相同支付宝交易号下多笔相同商户退款请求号的退款交易,支付宝只会进行一次退款
private $outRequestNo;
// (必填) 退款原因,可以说明用户退款原因,方便为商家后台提供统计
private $refundReason;
// (必填) 商户门店编号,退款情况下可以为商家后台提供退款权限判定和统计等作用,详询支付宝技术支持
private $storeId;
// 商户操作员编号,添加此参数可以为商户操作员做销售统
private $operatorId;
// 商户机具终端编号,当以机具方式接入支付宝时必传,详询支付宝技术支持
private $terminalId;
private $bizContentarr = array();
private $bizContent = NULL;
/* public function __construct()
{
$this->response = $response;
}
public function AlipayTradeRefundContentBuilder()
{
$this->__construct();
}*/
public function getBizContent()
{
if(!empty($this->bizContentarr)){
$this->bizContent = json_encode($this->bizContentarr,JSON_UNESCAPED_UNICODE);
}
return $this->bizContent;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->bizContentarr['trade_no'] = $tradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->bizContentarr['out_trade_no'] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->bizContentarr['operator_id'] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOutRequestNo($outRequestNo)
{
$this->outRequestNo = $outRequestNo;
$this->bizContentarr['out_request_no'] = $outRequestNo;
}
public function getOutRequestNo()
{
return $this->outRequestNo;
}
public function setRefundAmount($refundAmount)
{
$this->refundAmount = $refundAmount;
$this->bizContentarr['refund_amount'] = $refundAmount;
}
public function getRefundAmount()
{
return $this->refundAmount;
}
public function setRefundReason($refundReason)
{
$this->refundReason = $refundReason;
$this->bizContentarr['refund_reason'] = $refundReason;
}
public function getRefundReason()
{
return $this->refundReason;
}
public function setStoreId($storeId)
{
$this->storeId = $storeId;
$this->bizContentarr['store_id'] = $storeId;
}
public function getStoreId()
{
return $this->storeId;
}
public function setTerminalId($terminalId)
{
$this->terminalId = $terminalId;
$this->bizContentarr['terminal_id'] =$terminalId;
}
public function getTerminalId()
{
return $this->terminalId;
}
}
?>

View File

@@ -0,0 +1,36 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/6/27
* Time: 下午3:31
*/
class ContentBuilder
{
//第三方应用授权令牌
private $appAuthToken;
//异步通知地址(仅扫码支付使用)
private $notifyUrl;
public function setAppAuthToken($appAuthToken)
{
$this->appAuthToken = $appAuthToken;
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl = $notifyUrl;
}
public function getAppAuthToken()
{
return $this->appAuthToken;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Created by PhpStorm.
* User: airwalk
* Date: 16/5/19
* Time: 下午3:56
*/
class ExtendParams
{
// 系统商编号
private $sysServiceProviderId;
//使用花呗分期要进行的分期数,非必填项
private $hbFqNum;
//使用花呗分期需要卖家承担的手续费比例的百分值
private $hbFqSellerPercent;
private $extendParamsArr = array();
public function getExtendParams()
{
if(!empty($this->extendParamsArr)) {
return $this->extendParamsArr;
}
}
public function getSysServiceProviderId()
{
return $this->sysServiceProviderId;
}
public function setSysServiceProviderId($sysServiceProviderId)
{
$this->sysServiceProviderId = $sysServiceProviderId;
$this->extendParamsArr['sys_service_provider_id'] = $sysServiceProviderId;
}
public function getHbFqNum()
{
return $this->hbFqNum;
}
public function setHbFqNum($hbFqNum)
{
$this->hbFqNum = $hbFqNum;
$this->extendParamsArr['hb_fq_num'] = $hbFqNum;
}
public function getHbFqSellerPercent()
{
return $this->hbFqSellerPercent;
}
public function setHbFqSellerPercent($hbFqSellerPercent)
{
$this->hbFqSellerPercent = $hbFqSellerPercent;
$this->extendParamsArr['hb_fq_seller_percent'] = $hbFqSellerPercent;
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
class GoodsDetail
{
// 商品编号(国标)
private $goodsId;
//支付宝定义的统一商品编号
private $alipayGoodsId;
// 商品名称
private $goodsName;
// 商品数量
private $quantity;
// 商品价格此处单位为元精确到小数点后2位
private $price;
// 商品类别
private $goodsCategory;
// 商品详情
private $body;
private $goodsDetail = array();
//单个商品json字符串
//private $goodsDetailStr = NULL;
//获取单个商品的json字符串
public function getGoodsDetail()
{
return $this->goodsDetail;
/*$this->goodsDetailStr = "{";
foreach ($this->goodsDetail as $k => $v){
$this->goodsDetailStr.= "\"".$k."\":\"".$v."\",";
}
$this->goodsDetailStr = substr($this->goodsDetailStr,0,-1);
$this->goodsDetailStr.= "}";
return $this->goodsDetailStr;*/
}
public function setGoodsId($goodsId)
{
$this->goodsId = $goodsId;
$this->goodsDetail['goods_id'] = $goodsId;
}
public function getGoodsId()
{
return $this->goodsId;
}
public function setAlipayGoodsId($alipayGoodsId)
{
$this->alipayGoodsId = $alipayGoodsId;
$this->goodsDetail['alipay_goods_id'] = $alipayGoodsId;
}
public function getAlipayGoodsId()
{
return $this->alipayGoodsId;
}
public function setGoodsName($goodsName)
{
$this->goodsName = $goodsName;
$this->goodsDetail['goods_name'] = $goodsName;
}
public function getGoodsName()
{
return $this->goodsName;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
$this->goodsDetail['quantity'] = $quantity;
}
public function getQuantity()
{
return $this->quantity;
}
public function setPrice($price)
{
$this->price = $price;
$this->goodsDetail['price'] = $price;
}
public function getPrice()
{
return $this->price;
}
public function setGoodsCategory($goodsCategory)
{
$this->goodsCategory = $goodsCategory;
$this->goodsDetail['goods_category'] = $goodsCategory;
}
public function getGoodsCategory()
{
return $this->goodsCategory;
}
public function setBody($body)
{
$this->body = $body;
$this->goodsDetail['body'] = $body;
}
public function getBody()
{
return $this->body;
}
}
?>

View File

@@ -0,0 +1,161 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/20
* Time: 上午11:33
*/
class RoyaltyDetailInfo
{
//分账序列号,表示分账执行的顺序,必须为正整数
private $serialNo;
//接受分账金额的账户类型默认值为userId。
//userId支付宝账号对应的支付宝唯一用户号。
//bankIndex分账到银行账户的银行编号。目前暂时只支持分账到一个银行编号。
//storeId分账到门店对应的银行卡编号。
private $transInType;
//(必填)分账批次号 分账批次号。 目前需要和转入账号类型为bankIndex配合使用
private $batchNo;
//商户分账的外部关联号,用于关联到每一笔分账信息,商户需保证其唯一性。
//如果为空,该值则默认为“商户网站唯一订单号+分账序列号”
private $outRelationId;
//(必填)要分账的账户类型,默认值为userId
//目前只支持userId支付宝账号对应的支付宝唯一用户号
private $transOutType;
//(必填)如果转出账号类型为userId本参数为要分账的支付宝账号对应的支付宝唯一用户号。
//以2088开头的纯16位数字。
private $transOut;
//(必填)如果转入账号类型为userId本参数为接受分账金额的支付宝账号对应的支付宝唯一用户号。以2088开头的纯16位数字。
//如果转入账号类型为bankIndex本参数为28位的银行编号商户和支付宝签约时确定
//如果转入账号类型为storeId本参数为商户的门店ID。
private $transIn;
//(必填)分账的金额,单位为元
private $amount;
//分账描述信息
private $desc;
private $royaltyDetailInfo = array();
public function __construct()
{
$this->setTransInType("userId");
$this->setTransOutType("userId");
}
public function RoyaltyDetailInfo(){
$this->__construct();
}
public function getRoyaltyDetailInfo()
{
return $this->royaltyDetailInfo;
}
public function getAmount()
{
return $this->amount;
}
public function getBatchNo()
{
return $this->batchNo;
}
public function getDesc()
{
return $this->desc;
}
public function getOutRelationId()
{
return $this->outRelationId;
}
public function getSerialNo()
{
return $this->serialNo;
}
public function getTransIn()
{
return $this->transIn;
}
public function getTransInType()
{
return $this->transInType;
}
public function getTransOut()
{
return $this->transOut;
}
public function getTransOutType()
{
return $this->transOutType;
}
public function setAmount($amount)
{
$this->amount = $amount;
$this->royaltyDetailInfo['amount'] = $amount;
}
public function setBatchNo($batchNo)
{
$this->batchNo = $batchNo;
$this->royaltyDetailInfo['batch_no'] = $batchNo;
}
public function setDesc($desc)
{
$this->desc = $desc;
$this->royaltyDetailInfo['desc'] = $desc;
}
public function setOutRelationId($outRelationId)
{
$this->outRelationId = $outRelationId;
$this->royaltyDetailInfo['out_relation_id'] = $outRelationId;
}
public function setSerialNo($serialNo)
{
$this->serialNo = $serialNo;
$this->royaltyDetailInfo['serial_no'] = $serialNo;
}
public function setTransIn($transIn)
{
$this->transIn = $transIn;
$this->royaltyDetailInfo['trans_in'] = $transIn;
}
public function setTransInType($transInType)
{
$this->transInType = $transInType;
$this->royaltyDetailInfo['trans_in_type'] = $transInType;
}
public function setTransOut($transOut)
{
$this->transOut = $transOut;
$this->royaltyDetailInfo['trans_out'] = $transOut;
}
public function setTransOutType($transOutType)
{
$this->transOutType = $transOutType;
$this->royaltyDetailInfo['trans_out_type'] = $transOutType;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
class AlipayF2FPayResult
{
private $tradeStatus;
private $response;
public function __construct($response)
{
$this->response = $response;
}
public function AlipayF2FPayResult($response)
{
$this->__construct($response);
}
public function setTradeStatus($tradeStatus)
{
$this->tradeStatus = $tradeStatus;
}
public function getTradeStatus()
{
return $this->tradeStatus;
}
public function setResponse($response)
{
$this->response = $response;
}
public function getResponse()
{
return $this->response;
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
class AlipayF2FPrecreateResult
{
private $tradeStatus;
private $response;
public function __construct($response)
{
$this->response = $response;
}
public function AlipayF2FPrecreateResult($response)
{
$this->__construct($response);
}
public function setTradeStatus($tradeStatus)
{
$this->tradeStatus = $tradeStatus;
}
public function getTradeStatus()
{
return $this->tradeStatus;
}
public function setResponse($response)
{
$this->response = $response;
}
public function getResponse()
{
return $this->response;
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
class AlipayF2FQueryResult
{
private $tradeStatus;
private $response;
public function __construct($response)
{
$this->response = $response;
}
public function AlipayF2FPayResult($response)
{
$this->__construct($response);
}
public function setTradeStatus($tradeStatus)
{
$this->tradeStatus = $tradeStatus;
}
public function getTradeStatus()
{
return $this->tradeStatus;
}
public function setResponse($response)
{
$this->response = $response;
}
public function getResponse()
{
return $this->response;
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
class AlipayF2FRefundResult
{
private $tradeStatus;
private $response;
public function __construct($response)
{
$this->response = $response;
}
public function AlipayF2FPayResult($response)
{
$this->__construct($response);
}
public function setTradeStatus($tradeStatus)
{
$this->tradeStatus = $tradeStatus;
}
public function getTradeStatus()
{
return $this->tradeStatus;
}
public function setResponse($response)
{
$this->response = $response;
}
public function getResponse()
{
return $this->response;
}
}
?>

View File

@@ -0,0 +1,336 @@
<?php
header("Content-type: text/html; charset=utf-8");
require_once 'model/builder/AlipayTradePrecreateContentBuilder.php';
require_once 'service/AlipayTradeService.php';
if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!=""){
// (必填) 商户网站订单系统中唯一订单号64个字符以内只能包含字母、数字、下划线
// 需保证商户系统端不能重复建议通过数据库sequence生成
//$outTradeNo = "qrpay".date('Ymdhis').mt_rand(100,1000);
$outTradeNo = $_POST['out_trade_no'];
// (必填) 订单标题粗略描述用户的支付目的。如“xxx品牌xxx门店当面付扫码消费”
$subject = $_POST['subject'];
// (必填) 订单总金额单位为元不能超过1亿元
// 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】
$totalAmount = $_POST['total_amount'];
// (不推荐使用) 订单可打折金额,可以配合商家平台配置折扣活动,如果订单部分商品参与打折,可以将部分商品总价填写至此字段,默认全部商品可打折
// 如果该值未传入,但传入了【订单总金额】,【不可打折金额】 则该值默认为【订单总金额】- 【不可打折金额】
//String discountableAmount = "1.00"; //
// (可选) 订单不可打折金额,可以配合商家平台配置折扣活动,如果酒水不参与打折,则将对应金额填写至此字段
// 如果该值未传入,但传入了【订单总金额】,【打折金额】,则该值默认为【订单总金额】-【打折金额】
$undiscountableAmount = "0.01";
// 卖家支付宝账号ID用于支持一个签约账号下支持打款到不同的收款账号(打款到sellerId对应的支付宝账号)
// 如果该字段为空则默认为与支付宝签约的商户的PID也就是appid对应的PID
//$sellerId = "";
// 订单描述,可以对交易或商品进行一个详细地描述,比如填写"购买商品2件共15.00元"
$body = "购买商品2件共15.00元";
//商户操作员编号,添加此参数可以为商户操作员做销售统计
$operatorId = "test_operator_id";
// (可选) 商户门店编号,通过门店号和商家后台可以配置精准到门店的折扣信息,详询支付宝技术支持
$storeId = "test_store_id";
// 支付宝的店铺编号
$alipayStoreId= "test_alipay_store_id";
// 业务扩展参数,目前可添加由支付宝分配的系统商编号(通过setSysServiceProviderId方法),系统商开发使用,详情请咨询支付宝技术支持
$providerId = ""; //系统商pid,作为系统商返佣数据提取的依据
$extendParams = new ExtendParams();
$extendParams->setSysServiceProviderId($providerId);
$extendParamsArr = $extendParams->getExtendParams();
// 支付超时线下扫码交易定义为5分钟
$timeExpress = "5m";
// 商品明细列表,需填写购买商品详细信息,
$goodsDetailList = array();
// 创建一个商品信息参数含义分别为商品id使用国标、名称、单价单位为分、数量如果需要添加商品类别详见GoodsDetail
$goods1 = new GoodsDetail();
$goods1->setGoodsId("apple-01");
$goods1->setGoodsName("iphone");
$goods1->setPrice(3000);
$goods1->setQuantity(1);
//得到商品1明细数组
$goods1Arr = $goods1->getGoodsDetail();
// 继续创建并添加第一条商品信息用户购买的产品为“xx牙刷”单价为5.05元,购买了两件
$goods2 = new GoodsDetail();
$goods2->setGoodsId("apple-02");
$goods2->setGoodsName("ipad");
$goods2->setPrice(1000);
$goods2->setQuantity(1);
//得到商品1明细数组
$goods2Arr = $goods2->getGoodsDetail();
$goodsDetailList = array($goods1Arr,$goods2Arr);
//第三方应用授权令牌,商户授权系统商开发模式下使用
$appAuthToken = "";//根据真实值填写
// 创建请求builder设置请求参数
$qrPayRequestBuilder = new AlipayTradePrecreateContentBuilder();
$qrPayRequestBuilder->setOutTradeNo($outTradeNo);
$qrPayRequestBuilder->setTotalAmount($totalAmount);
$qrPayRequestBuilder->setTimeExpress($timeExpress);
$qrPayRequestBuilder->setSubject($subject);
$qrPayRequestBuilder->setBody($body);
$qrPayRequestBuilder->setUndiscountableAmount($undiscountableAmount);
$qrPayRequestBuilder->setExtendParams($extendParamsArr);
$qrPayRequestBuilder->setGoodsDetailList($goodsDetailList);
$qrPayRequestBuilder->setStoreId($storeId);
$qrPayRequestBuilder->setOperatorId($operatorId);
$qrPayRequestBuilder->setAlipayStoreId($alipayStoreId);
$qrPayRequestBuilder->setAppAuthToken($appAuthToken);
// 调用qrPay方法获取当面付应答
$qrPay = new AlipayTradeService($config);
$qrPayResult = $qrPay->qrPay($qrPayRequestBuilder);
// 根据状态值进行业务处理
switch ($qrPayResult->getTradeStatus()){
case "SUCCESS":
echo "支付宝创建订单二维码成功:"."<br>---------------------------------------<br>";
$response = $qrPayResult->getResponse();
$qrcode = $qrPay->create_erweima($response->qr_code);
echo $qrcode;
print_r($response);
break;
case "FAILED":
echo "支付宝创建订单二维码失败!!!"."<br>--------------------------<br>";
if(!empty($qrPayResult->getResponse())){
print_r($qrPayResult->getResponse());
}
break;
case "UNKNOWN":
echo "系统异常,状态未知!!!"."<br>--------------------------<br>";
if(!empty($qrPayResult->getResponse())){
print_r($qrPayResult->getResponse());
}
break;
default:
echo "不支持的返回状态,创建订单二维码返回异常!!!";
break;
}
return ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>支付宝当面付 二维码支付</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
*{
margin:0;
padding:0;
}
ul,ol{
list-style:none;
}
.title{
color: #ADADAD;
font-size: 14px;
font-weight: bold;
padding: 8px 16px 5px 10px;
}
.hidden{
display:none;
}
.new-btn-login-sp{
border:1px solid #D74C00;
padding:1px;
display:inline-block;
}
.new-btn-login{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
}
.new-btn-login{
background-position: 0 -198px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.new-btn-login:hover{
background-position: 0 -167px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.bank-list{
overflow:hidden;
margin-top:5px;
}
.bank-list li{
float:left;
width:153px;
margin-bottom:5px;
}
#main{
width:750px;
margin:0 auto;
font-size:14px;
font-family:'宋体';
}
#logo{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
background-position:0 0;
width:166px;
height:35px;
float:left;
}
.red-star{
color:#f00;
width:10px;
display:inline-block;
}
.null-star{
color:#fff;
}
.content{
margin-top:5px;
}
.content dt{
width:160px;
display:inline-block;
text-align:right;
float:left;
}
.content dd{
margin-left:100px;
margin-bottom:5px;
}
#foot{
margin-top:10px;
}
.foot-ul li {
text-align:center;
}
.note-help {
color: #999999;
font-size: 12px;
line-height: 130%;
padding-left: 3px;
}
.cashier-nav {
font-size: 14px;
margin: 15px 0 10px;
text-align: left;
height:30px;
border-bottom:solid 2px #CFD2D7;
}
.cashier-nav ol li {
float: left;
}
.cashier-nav li.current {
color: #AB4400;
font-weight: bold;
}
.cashier-nav li.last {
clear:right;
}
.alipay_link {
text-align:right;
}
.alipay_link a:link{
text-decoration:none;
color:#8D8D8D;
}
.alipay_link a:visited{
text-decoration:none;
color:#8D8D8D;
}
</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
<div id="main">
<div id="head">
<dl class="alipay_link">
<a target="_blank" href="http://www.alipay.com/"><span>支付宝首页</span></a>|
<a target="_blank" href="https://b.alipay.com/home.htm"><span>商家服务</span></a>|
<a target="_blank" href="http://help.alipay.com/support/index_sh.htm"><span>帮助中心</span></a>
</dl>
<span class="title">支付宝统一预下单接口快速通道</span>
</div>
<div class="cashier-nav">
<ol>
<li class="current">1、确认信息 →</li>
<li>2、点击确认 →</li>
<li class="last">3、确认完成</li>
</ol>
</div>
<form name=alipayment action="" method=post target="_blank">
<div id="body" style="clear:left">
<dl class="content">
<dt>商户订单号:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="out_trade_no" />
<span>商户网站订单系统中唯一订单号,必填
</span>
</dd>
<dt>订单名称:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="subject" />
<span>必填
</span>
</dd>
<dt>付款金额:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="total_amount" />
<span>必填
</span>
</dd>
<dt></dt>
<dd>
<span class="new-btn-login-sp">
<button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
</span>
</dd>
</dl>
</div>
</form>
<div id="foot">
<ul class="foot-ul">
<li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
<li>
支付宝版权所有 2011-2015 ALIPAY.COM
</li>
</ul>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,248 @@
<?php
/**
* Created by PhpStorm.
* User: airwalk
* Date: 16/5/20
* Time: 下午7:54
*/
header("Content-type: text/html; charset=utf-8");
require_once 'service/AlipayTradeService.php';
if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!=""){
////获取商户订单号
$out_trade_no = trim($_POST['out_trade_no']);
//第三方应用授权令牌,商户授权系统商开发模式下使用
$appAuthToken = "";//根据真实值填写
//构造查询业务请求参数对象
$queryContentBuilder = new AlipayTradeQueryContentBuilder();
$queryContentBuilder->setOutTradeNo($out_trade_no);
$queryContentBuilder->setAppAuthToken($appAuthToken);
//初始化类对象调用queryTradeResult方法获取查询应答
$queryResponse = new AlipayTradeService($config);
$queryResult = $queryResponse->queryTradeResult($queryContentBuilder);
//根据查询返回结果状态进行业务处理
switch ($queryResult->getTradeStatus()){
case "SUCCESS":
echo "支付宝查询交易成功:"."<br>--------------------------<br>";
print_r($queryResult->getResponse());
break;
case "FAILED":
echo "支付宝查询交易失败或者交易已关闭!!!"."<br>--------------------------<br>";
if(!empty($queryResult->getResponse())){
print_r($queryResult->getResponse());
}
break;
case "UNKNOWN":
echo "系统异常,订单状态未知!!!"."<br>--------------------------<br>";
if(!empty($queryResult->getResponse())){
print_r($queryResult->getResponse());
}
break;
default:
echo "不支持的查询状态,交易返回异常!!!";
break;
}
return ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>支付宝当面付 消费查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
*{
margin:0;
padding:0;
}
ul,ol{
list-style:none;
}
.title{
color: #ADADAD;
font-size: 14px;
font-weight: bold;
padding: 8px 16px 5px 10px;
}
.hidden{
display:none;
}
.new-btn-login-sp{
border:1px solid #D74C00;
padding:1px;
display:inline-block;
}
.new-btn-login{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
}
.new-btn-login{
background-position: 0 -198px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.new-btn-login:hover{
background-position: 0 -167px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.bank-list{
overflow:hidden;
margin-top:5px;
}
.bank-list li{
float:left;
width:153px;
margin-bottom:5px;
}
#main{
width:750px;
margin:0 auto;
font-size:14px;
font-family:'宋体';
}
#logo{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
background-position:0 0;
width:166px;
height:35px;
float:left;
}
.red-star{
color:#f00;
width:10px;
display:inline-block;
}
.null-star{
color:#fff;
}
.content{
margin-top:5px;
}
.content dt{
width:160px;
display:inline-block;
text-align:right;
float:left;
}
.content dd{
margin-left:100px;
margin-bottom:5px;
}
#foot{
margin-top:10px;
}
.foot-ul li {
text-align:center;
}
.note-help {
color: #999999;
font-size: 12px;
line-height: 130%;
padding-left: 3px;
}
.cashier-nav {
font-size: 14px;
margin: 15px 0 10px;
text-align: left;
height:30px;
border-bottom:solid 2px #CFD2D7;
}
.cashier-nav ol li {
float: left;
}
.cashier-nav li.current {
color: #AB4400;
font-weight: bold;
}
.cashier-nav li.last {
clear:right;
}
.alipay_link {
text-align:right;
}
.alipay_link a:link{
text-decoration:none;
color:#8D8D8D;
}
.alipay_link a:visited{
text-decoration:none;
color:#8D8D8D;
}
</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
<div id="main">
<div id="head">
<dl class="alipay_link">
<a target="_blank" href="http://www.alipay.com/"><span>支付宝首页</span></a>|
<a target="_blank" href="https://b.alipay.com/home.htm"><span>商家服务</span></a>|
<a target="_blank" href="http://help.alipay.com/support/index_sh.htm"><span>帮助中心</span></a>
</dl>
<span class="title">支付宝 当面付2.0 订单查询接口</span>
</div>
<div class="cashier-nav">
<ol>
<li class="current">1、确认信息 →</li>
<li>2、点击确认 →</li>
<li class="last">3、确认完成</li>
</ol>
</div>
<form name=alipayment action="" method=post target="_blank">
<div id="body" style="clear:left">
<dl class="content">
<dt>商户订单号:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="out_trade_no" />
<span>商户网站订单系统中唯一订单号,必填
</span>
</dd>
<dt></dt>
<dd>
<span class="new-btn-login-sp">
<button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
</span>
</dd>
</dl>
</div>
</form>
<div id="foot">
<ul class="foot-ul">
<li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
<li>
支付宝版权所有 2011-2015 ALIPAY.COM
</li>
</ul>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,257 @@
<?php
header("Content-type: text/html; charset=utf-8");
require_once 'model/builder/AlipayTradeRefundContentBuilder.php';
require_once 'service/AlipayTradeService.php';
if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!=""){
$out_trade_no = trim($_POST['out_trade_no']);
$refund_amount = trim($_POST['refund_amount']);
$out_request_no = trim($_POST['out_request_no']);
//第三方应用授权令牌,商户授权系统商开发模式下使用
$appAuthToken = "";//根据真实值填写
//创建退款请求builder,设置参数
$refundRequestBuilder = new AlipayTradeRefundContentBuilder();
$refundRequestBuilder->setOutTradeNo($out_trade_no);
$refundRequestBuilder->setRefundAmount($refund_amount);
$refundRequestBuilder->setOutRequestNo($out_request_no);
$refundRequestBuilder->setAppAuthToken($appAuthToken);
//初始化类对象,调用refund获取退款应答
$refundResponse = new AlipayTradeService($config);
$refundResult = $refundResponse->refund($refundRequestBuilder);
//根据交易状态进行处理
switch ($refundResult->getTradeStatus()){
case "SUCCESS":
echo "支付宝退款成功:"."<br>--------------------------<br>";
print_r($refundResult->getResponse());
break;
case "FAILED":
echo "支付宝退款失败!!!"."<br>--------------------------<br>";
if(!empty($refundResult->getResponse())){
print_r($refundResult->getResponse());
}
break;
case "UNKNOWN":
echo "系统异常,订单状态未知!!!"."<br>--------------------------<br>";
if(!empty($refundResult->getResponse())){
print_r($refundResult->getResponse());
}
break;
default:
echo "不支持的交易状态,交易返回异常!!!";
break;
}
return ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>支付宝当面付 交易退款</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
*{
margin:0;
padding:0;
}
ul,ol{
list-style:none;
}
.title{
color: #ADADAD;
font-size: 14px;
font-weight: bold;
padding: 8px 16px 5px 10px;
}
.hidden{
display:none;
}
.new-btn-login-sp{
border:1px solid #D74C00;
padding:1px;
display:inline-block;
}
.new-btn-login{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
}
.new-btn-login{
background-position: 0 -198px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.new-btn-login:hover{
background-position: 0 -167px;
width: 82px;
color: #FFFFFF;
font-weight: bold;
height: 28px;
line-height: 28px;
padding: 0 10px 3px;
}
.bank-list{
overflow:hidden;
margin-top:5px;
}
.bank-list li{
float:left;
width:153px;
margin-bottom:5px;
}
#main{
width:750px;
margin:0 auto;
font-size:14px;
font-family:'宋体';
}
#logo{
background-color: transparent;
background-image: url("../img/new-btn-fixed.png");
border: medium none;
background-position:0 0;
width:166px;
height:35px;
float:left;
}
.red-star{
color:#f00;
width:10px;
display:inline-block;
}
.null-star{
color:#fff;
}
.content{
margin-top:5px;
}
.content dt{
width:160px;
display:inline-block;
text-align:right;
float:left;
}
.content dd{
margin-left:100px;
margin-bottom:5px;
}
#foot{
margin-top:10px;
}
.foot-ul li {
text-align:center;
}
.note-help {
color: #999999;
font-size: 12px;
line-height: 130%;
padding-left: 3px;
}
.cashier-nav {
font-size: 14px;
margin: 15px 0 10px;
text-align: left;
height:30px;
border-bottom:solid 2px #CFD2D7;
}
.cashier-nav ol li {
float: left;
}
.cashier-nav li.current {
color: #AB4400;
font-weight: bold;
}
.cashier-nav li.last {
clear:right;
}
.alipay_link {
text-align:right;
}
.alipay_link a:link{
text-decoration:none;
color:#8D8D8D;
}
.alipay_link a:visited{
text-decoration:none;
color:#8D8D8D;
}
</style>
</head>
<body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
<div id="main">
<div id="head">
<dl class="alipay_link">
<a target="_blank" href="http://www.alipay.com/"><span>支付宝首页</span></a>|
<a target="_blank" href="https://b.alipay.com/home.htm"><span>商家服务</span></a>|
<a target="_blank" href="http://help.alipay.com/support/index_sh.htm"><span>帮助中心</span></a>
</dl>
<span class="title">支付宝 当面付2.0 订单退款接口</span>
</div>
<div class="cashier-nav">
<ol>
<li class="current">1、确认信息 →</li>
<li>2、点击确认 →</li>
<li class="last">3、确认完成</li>
</ol>
</div>
<form name=alipayment action="" method=post target="_blank">
<div id="body" style="clear:left">
<dl class="content">
<dt>商户订单号:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="out_trade_no" />
<span>必填</span>
</dd>
<dt>退款金额:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="refund_amount" />
<span>必填 不能超过订单总金额</span>
</dd>
<dt>退款批次号:</dt>
<dd>
<span class="null-star">*</span>
<input size="30" name="out_request_no" />
<span>必填 部分退款时,同一订单号不同批次号代表对同一笔订单进行多次退款</span>
</dd>
<dt></dt>
<dd>
<span class="new-btn-login-sp">
<button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
</span>
</dd>
</dl>
</div>
</form>
<div id="foot">
<ul class="foot-ul">
<li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
<li>
支付宝版权所有 2011-2015 ALIPAY.COM
</li>
</ul>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,395 @@
<?php
/**
* Created by PhpStorm.
* User: xudong.ding
* Date: 16/5/19
* Time: 下午2:09
*/
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'AopSdk.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/result/AlipayF2FPayResult.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/result/AlipayF2FQueryResult.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/result/AlipayF2FRefundResult.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/result/AlipayF2FPrecreateResult.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/builder/AlipayTradeQueryContentBuilder.php';
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'model/builder/AlipayTradeCancelContentBuilder.php';
class AlipayTradeService_f2fpay
{
//支付宝网关地址
public $gateway_url = "https://openapi.alipay.com/gateway.do";
//异步通知回调地址
public $notify_url;
//签名类型
public $sign_type;
//支付宝公钥地址
public $alipay_public_key;
public $alipay_public_key_filepath;
//商户私钥地址
public $private_key;
public $private_key_filepath;
//应用id
public $appid;
//编码格式
public $charset = "UTF-8";
public $token = null;
//重试次数
private $MaxQueryRetry;
//重试间隔
private $QueryDuration;
//返回数据格式
public $format = "json";
function __construct($alipay_config)
{
$this->gateway_url = $alipay_config['gatewayUrl'];
$this->appid = $alipay_config['app_id'];
$this->sign_type = $alipay_config['sign_type'];
//$this->private_key = $alipay_config['merchant_private_key_file'];
$this->private_key_filepath = $alipay_config['merchant_private_key_filepath'];
$this->private_key = $alipay_config['merchant_private_key'];
//$this->alipay_public_key = $alipay_config['alipay_public_key_file'];
$this->alipay_public_key_filepath = $alipay_config['alipay_public_key_filepath'];
$this->alipay_public_key = $alipay_config['alipay_public_key'];
$this->charset = $alipay_config['charset'];
$this->MaxQueryRetry = $alipay_config['MaxQueryRetry'];
$this->QueryDuration = $alipay_config['QueryDuration'];
$this->notify_url = $alipay_config['notify_url'];
if (empty($this->appid) || trim($this->appid) == "")
throw new Exception("appid should not be NULL!");
if ((empty($this->private_key) || trim($this->private_key) == "") && (empty($this->private_key_filepath) || trim($this->private_key_filepath) == ''))
throw new Exception("private_key should not be NULL!");
if ((empty($this->alipay_public_key) || trim($this->alipay_public_key) == "") && (empty($this->alipay_public_key_filepath) || trim($this->alipay_public_key_filepath) == ''))
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->QueryDuration) || trim($this->QueryDuration) == "")
throw new Exception("QueryDuration should not be NULL!");
if (empty($this->gateway_url) || trim($this->gateway_url) == "")
throw new Exception("gateway_url should not be NULL!");
if (empty($this->MaxQueryRetry) || trim($this->MaxQueryRetry) == "")
throw new Exception("MaxQueryRetry should not be NULL!");
if (empty($this->sign_type) || trim($this->sign_type) == "")
throw new Exception("sign_type should not be NULL");
}
function AlipayWapPayService($alipay_config)
{
$this->__construct($alipay_config);
}
// 当面付2.0条码支付(带轮询逻辑)
public function barPay($req)
{
$outTradeNo = $req->getOutTradeNo();
$bizContent = $req->getBizContent();
$appAuthToken = $req->getAppAuthToken();
$this->writeLog($bizContent);
//echo $bizContent;
$request = new AlipayTradePayRequest();
$request->setBizContent($bizContent);
$response = $this->aopclientRequestExecute($request, null, $appAuthToken);
//获取alipay_trade_pay_response对象数据,方便后续处理
$response = $response->alipay_trade_pay_response;
$result = new AlipayF2FPayResult($response);
if (!empty($response) && ("10000" == $response->code))
{
// 支付交易明确成功
$result->setTradeStatus("SUCCESS");
}
elseif (!empty($response) && ("10003" == $response->code))
{
// 返回用户处理中,则轮询查询交易是否成功,如果查询超时,则调用撤销
$queryContentBuilder = new AlipayTradeQueryContentBuilder();
$queryContentBuilder->setOutTradeNo($outTradeNo);
$queryContentBuilder->setAppAuthToken($appAuthToken);
$loopQueryResponse = $this->loopQueryResult($queryContentBuilder);
return $this->checkQueryAndCancel($outTradeNo, $appAuthToken, $result, $loopQueryResponse);
}
elseif ($this->tradeError($response))
{
// 系统错误或者网络异常未响应,则查询一次交易,如果交易没有支付成功,则调用撤销
$queryContentBuilder = new AlipayTradeQueryContentBuilder();
$queryContentBuilder->setOutTradeNo($outTradeNo);
$queryContentBuilder->setAppAuthToken($appAuthToken);
$queryResponse = $this->query($queryContentBuilder);
return $this->checkQueryAndCancel($outTradeNo, $appAuthToken, $result, $queryResponse);
}
else
{
// 其他情况表明该订单支付明确失败
$result->setTradeStatus("FAILED");
}
return $result;
}
// 当面付2.0消费查询
public function queryTradeResult($req)
{
$response = $this->query($req);
$result = new AlipayF2FQueryResult($response);
if ($this->querySuccess($response))
// 查询返回该订单交易支付成功
$result->setTradeStatus("SUCCESS");
elseif ($this->tradeError($response))
//查询发生异常或无返回,交易状态未知
$result->setTradeStatus("UNKNOWN");
else
//其他情况均表明该订单号交易失败
$result->setTradeStatus("FAILED");
return $result;
}
// 当面付2.0消费退款,$req为对象变量
public function refund($req)
{
$bizContent = $req->getBizContent();
$this->writeLog($bizContent);
$request = new AlipayTradeRefundRequest();
$request->setBizContent($bizContent);
$response = $this->aopclientRequestExecute($request, null, $req->getAppAuthToken());
$response = $response->alipay_trade_refund_response;
$result = new AlipayF2FRefundResult($response);
if (!empty($response) && ("10000" == $response->code))
$result->setTradeStatus("SUCCESS");
elseif ($this->tradeError($response))
$result->setTradeStatus("UNKNOWN");
else
$result->setTradeStatus("FAILED");
return $result;
}
//当面付2.0预下单(生成二维码,带轮询)
public function qrPay($req)
{
$bizContent = $req->getBizContent();
$this->writeLog($bizContent);
$request = new AlipayTradePrecreateRequest();
$request->setBizContent($bizContent);
$request->setNotifyUrl($this->notify_url);
// 首先调用支付api
$response = $this->aopclientRequestExecute($request, null, $req->getAppAuthToken());
$response = $response->alipay_trade_precreate_response;
$result = new AlipayF2FPrecreateResult($response);
if (!empty($response) && ("10000" == $response->code))
$result->setTradeStatus("SUCCESS");
elseif ($this->tradeError($response))
$result->setTradeStatus("UNKNOWN");
else
$result->setTradeStatus("FAILED");
return $result;
}
public function query($queryContentBuilder)
{
$biz_content = $queryContentBuilder->getBizContent();
$this->writeLog($biz_content);
$request = new AlipayTradeQueryRequest();
$request->setBizContent($biz_content);
$response = $this->aopclientRequestExecute($request, null, $queryContentBuilder->getAppAuthToken());
return $response->alipay_trade_query_response;
}
// 轮询查询订单支付结果
protected function loopQueryResult($queryContentBuilder)
{
$queryResult = null;
for ($i = 1; $i < $this->MaxQueryRetry; $i++)
{
try
{
sleep($this->QueryDuration);
}
catch (Exception $e)
{
print $e->getMessage();
exit();
}
$queryResponse = $this->query($queryContentBuilder);
if (!empty($queryResponse))
{
if ($this->stopQuery($queryResponse))
return $queryResponse;
$queryResult = $queryResponse;
}
}
return $queryResult;
}
// 判断是否停止查询
protected function stopQuery($response)
{
if ("10000" == $response->code)
{
if ("TRADE_FINISHED" == $response->trade_status || "TRADE_SUCCESS" == $response->trade_status || "TRADE_CLOSED" == $response->trade_status)
return true;
}
return false;
}
// 根据查询结果queryResponse判断交易是否支付成功如果支付成功则更新result并返回如果不成功则调用撤销
private function checkQueryAndCancel($outTradeNo, $appAuthToken, $result, $queryResponse)
{
if ($this->querySuccess($queryResponse))
{
// 如果查询返回支付成功,则返回相应结果
$result->setTradeStatus("SUCCESS");
$result->setResponse($queryResponse);
return $result;
}
elseif ($this->queryClose($queryResponse))
{
// 如果查询返回交易关闭,标记交易失败
$result->setTradeStatus("FAILED");
return $result;
}
// 如果查询结果不为成功,则调用撤销
$cancelContentBuilder = new AlipayTradeCancelContentBuilder();
$cancelContentBuilder->setAppAuthToken($appAuthToken);
$cancelContentBuilder->setOutTradeNo($outTradeNo);
$cancelResponse = $this->cancel($cancelContentBuilder);
if ($this->tradeError($cancelResponse))
{
// 如果第一次同步撤销返回异常,则标记支付交易为未知状态
$result->setTradeStatus("UNKNOWN");
}
else
{
// 标记支付为失败,如果撤销未能成功,产生的单边帐由人工处理
$result->setTradeStatus("FAILED");
}
return $result;
}
// 查询返回“支付成功”
protected function querySuccess($queryResponse)
{
return !empty($queryResponse) &&
$queryResponse->code == "10000" &&
($queryResponse->trade_status == "TRADE_SUCCESS" ||
$queryResponse->trade_status == "TRADE_FINISHED");
}
// 查询返回“交易关闭”
protected function queryClose($queryResponse)
{
return !empty($queryResponse) &&
$queryResponse->code == "10000" &&
$queryResponse->trade_status == "TRADE_CLOSED";
}
// 交易异常,或发生系统错误
protected function tradeError($response)
{
return empty($response) ||
$response->code == "20000";
}
public function cancel($cancelContentBuilder)
{
$biz_content = $cancelContentBuilder->getBizContent();
$this->writeLog($biz_content);
$request = new AlipayTradeCancelRequest();
$request->setBizContent($biz_content);
$response = $this->aopclientRequestExecute($request, null, $cancelContentBuilder->getAppAuthToken());
return $response->alipay_trade_cancel_response;
}
/**
* 使用SDK执行提交页面接口请求
* @param unknown $request
* @param string $token
* @param string $appAuthToken
* @return string $$result
*/
private function aopclientRequestExecute($request, $token = null, $appAuthToken = null)
{
$aop = new AopClient ();
$aop->gatewayUrl = $this->gateway_url;
$aop->appId = $this->appid;
$aop->signType = $this->sign_type;
//$aop->rsaPrivateKeyFilePath = $this->private_key;
$aop->rsaPrivateKeyFilePath = $this->private_key_filepath;
$aop->rsaPrivateKey = $this->private_key;
//$aop->alipayPublicKey = $this->alipay_public_key;
$aop->alipayPublicKey = $this->alipay_public_key_filepath;
$aop->alipayrsaPublicKey = $this->alipay_public_key;
$aop->apiVersion = "1.0";
$aop->postCharset = $this->charset;
$aop->format = $this->format;
// 开启页面信息输出
$aop->debugInfo = true;
$result = $aop->execute($request, $token, $appAuthToken);
//打开后将url形式请求报文写入log文件
//$this->writeLog("response: ".var_export($result,true));
return $result;
}
function writeLog($text)
{
// $text=iconv("GBK", "UTF-8//IGNORE", $text);
//$text = characet ( $text );
file_put_contents("log/log.txt", date("Y-m-d H:i:s") . " " . $text . "\r\n", FILE_APPEND);
}
/** *利用google api生成二维码图片
* $content二维码内容参数
* $size生成二维码的尺寸宽度和高度的值
* $lev可选参数纠错等级
* $margin生成的二维码离边框的距离
*/
function create_erweima($content, $size = '200', $lev = 'L', $margin = '0')
{
$content = urlencode($content);
$image = '<img src="http://chart.apis.google.com/chart?chs=' . $size . 'x' . $size . '&amp;cht=qr&chld=' . $lev . '|' . $margin . '&amp;chl=' . $content . '" widht="' . $size . '" height="' . $size . '" />';
return $image;
}
}