refund_test.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. header("Content-type: text/html; charset=utf-8");
  3. require_once 'model/builder/AlipayTradeRefundContentBuilder.php';
  4. require_once 'service/AlipayTradeService.php';
  5. if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!=""){
  6. $out_trade_no = trim($_POST['out_trade_no']);
  7. $refund_amount = trim($_POST['refund_amount']);
  8. $out_request_no = trim($_POST['out_request_no']);
  9. //第三方应用授权令牌,商户授权系统商开发模式下使用
  10. $appAuthToken = "";//根据真实值填写
  11. //创建退款请求builder,设置参数
  12. $refundRequestBuilder = new AlipayTradeRefundContentBuilder();
  13. $refundRequestBuilder->setOutTradeNo($out_trade_no);
  14. $refundRequestBuilder->setRefundAmount($refund_amount);
  15. $refundRequestBuilder->setOutRequestNo($out_request_no);
  16. $refundRequestBuilder->setAppAuthToken($appAuthToken);
  17. //初始化类对象,调用refund获取退款应答
  18. $refundResponse = new AlipayTradeService($config);
  19. $refundResult = $refundResponse->refund($refundRequestBuilder);
  20. //根据交易状态进行处理
  21. switch ($refundResult->getTradeStatus()){
  22. case "SUCCESS":
  23. echo "支付宝退款成功:"."<br>--------------------------<br>";
  24. print_r($refundResult->getResponse());
  25. break;
  26. case "FAILED":
  27. echo "支付宝退款失败!!!"."<br>--------------------------<br>";
  28. if(!empty($refundResult->getResponse())){
  29. print_r($refundResult->getResponse());
  30. }
  31. break;
  32. case "UNKNOWN":
  33. echo "系统异常,订单状态未知!!!"."<br>--------------------------<br>";
  34. if(!empty($refundResult->getResponse())){
  35. print_r($refundResult->getResponse());
  36. }
  37. break;
  38. default:
  39. echo "不支持的交易状态,交易返回异常!!!";
  40. break;
  41. }
  42. return ;
  43. }
  44. ?>
  45. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  46. <html>
  47. <head>
  48. <title>支付宝当面付 交易退款</title>
  49. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  50. <style>
  51. *{
  52. margin:0;
  53. padding:0;
  54. }
  55. ul,ol{
  56. list-style:none;
  57. }
  58. .title{
  59. color: #ADADAD;
  60. font-size: 14px;
  61. font-weight: bold;
  62. padding: 8px 16px 5px 10px;
  63. }
  64. .hidden{
  65. display:none;
  66. }
  67. .new-btn-login-sp{
  68. border:1px solid #D74C00;
  69. padding:1px;
  70. display:inline-block;
  71. }
  72. .new-btn-login{
  73. background-color: transparent;
  74. background-image: url("../img/new-btn-fixed.png");
  75. border: medium none;
  76. }
  77. .new-btn-login{
  78. background-position: 0 -198px;
  79. width: 82px;
  80. color: #FFFFFF;
  81. font-weight: bold;
  82. height: 28px;
  83. line-height: 28px;
  84. padding: 0 10px 3px;
  85. }
  86. .new-btn-login:hover{
  87. background-position: 0 -167px;
  88. width: 82px;
  89. color: #FFFFFF;
  90. font-weight: bold;
  91. height: 28px;
  92. line-height: 28px;
  93. padding: 0 10px 3px;
  94. }
  95. .bank-list{
  96. overflow:hidden;
  97. margin-top:5px;
  98. }
  99. .bank-list li{
  100. float:left;
  101. width:153px;
  102. margin-bottom:5px;
  103. }
  104. #main{
  105. width:750px;
  106. margin:0 auto;
  107. font-size:14px;
  108. font-family:'宋体';
  109. }
  110. #logo{
  111. background-color: transparent;
  112. background-image: url("../img/new-btn-fixed.png");
  113. border: medium none;
  114. background-position:0 0;
  115. width:166px;
  116. height:35px;
  117. float:left;
  118. }
  119. .red-star{
  120. color:#f00;
  121. width:10px;
  122. display:inline-block;
  123. }
  124. .null-star{
  125. color:#fff;
  126. }
  127. .content{
  128. margin-top:5px;
  129. }
  130. .content dt{
  131. width:160px;
  132. display:inline-block;
  133. text-align:right;
  134. float:left;
  135. }
  136. .content dd{
  137. margin-left:100px;
  138. margin-bottom:5px;
  139. }
  140. #foot{
  141. margin-top:10px;
  142. }
  143. .foot-ul li {
  144. text-align:center;
  145. }
  146. .note-help {
  147. color: #999999;
  148. font-size: 12px;
  149. line-height: 130%;
  150. padding-left: 3px;
  151. }
  152. .cashier-nav {
  153. font-size: 14px;
  154. margin: 15px 0 10px;
  155. text-align: left;
  156. height:30px;
  157. border-bottom:solid 2px #CFD2D7;
  158. }
  159. .cashier-nav ol li {
  160. float: left;
  161. }
  162. .cashier-nav li.current {
  163. color: #AB4400;
  164. font-weight: bold;
  165. }
  166. .cashier-nav li.last {
  167. clear:right;
  168. }
  169. .alipay_link {
  170. text-align:right;
  171. }
  172. .alipay_link a:link{
  173. text-decoration:none;
  174. color:#8D8D8D;
  175. }
  176. .alipay_link a:visited{
  177. text-decoration:none;
  178. color:#8D8D8D;
  179. }
  180. </style>
  181. </head>
  182. <body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
  183. <div id="main">
  184. <div id="head">
  185. <dl class="alipay_link">
  186. <a target="_blank" href="http://www.alipay.com/"><span>支付宝首页</span></a>|
  187. <a target="_blank" href="https://b.alipay.com/home.htm"><span>商家服务</span></a>|
  188. <a target="_blank" href="http://help.alipay.com/support/index_sh.htm"><span>帮助中心</span></a>
  189. </dl>
  190. <span class="title">支付宝 当面付2.0 订单退款接口</span>
  191. </div>
  192. <div class="cashier-nav">
  193. <ol>
  194. <li class="current">1、确认信息 →</li>
  195. <li>2、点击确认 →</li>
  196. <li class="last">3、确认完成</li>
  197. </ol>
  198. </div>
  199. <form name=alipayment action="" method=post target="_blank">
  200. <div id="body" style="clear:left">
  201. <dl class="content">
  202. <dt>商户订单号:</dt>
  203. <dd>
  204. <span class="null-star">*</span>
  205. <input size="30" name="out_trade_no" />
  206. <span>必填</span>
  207. </dd>
  208. <dt>退款金额:</dt>
  209. <dd>
  210. <span class="null-star">*</span>
  211. <input size="30" name="refund_amount" />
  212. <span>必填 , 不能超过订单总金额</span>
  213. </dd>
  214. <dt>退款批次号:</dt>
  215. <dd>
  216. <span class="null-star">*</span>
  217. <input size="30" name="out_request_no" />
  218. <span>必填 , 部分退款时,同一订单号不同批次号代表对同一笔订单进行多次退款</span>
  219. </dd>
  220. <dt></dt>
  221. <dd>
  222. <span class="new-btn-login-sp">
  223. <button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
  224. </span>
  225. </dd>
  226. </dl>
  227. </div>
  228. </form>
  229. <div id="foot">
  230. <ul class="foot-ul">
  231. <li><font class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。 </font></li>
  232. <li>
  233. 支付宝版权所有 2011-2015 ALIPAY.COM
  234. </li>
  235. </ul>
  236. </div>
  237. </div>
  238. </body>
  239. </html>