refund.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /* *
  3. * 功能:支付宝手机网站alipay.trade.refund (统一收单交易退款接口)调试入口页面
  4. * 版本:2.0
  5. * 修改日期:2016-11-01
  6. * 说明:
  7. * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
  8. 请确保项目文件有可写权限,不然打印不了日志。
  9. */
  10. header("Content-type: text/html; charset=utf-8");
  11. require_once dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'service/AlipayTradeService.php';
  12. require_once dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'buildermodel/AlipayTradeRefundContentBuilder.php';
  13. require dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'./../config.php';
  14. if (!empty($_POST['WIDout_trade_no']) || !empty($_POST['WIDtrade_no'])){
  15. //商户订单号和支付宝交易号不能同时为空。 trade_no、 out_trade_no如果同时存在优先取trade_no
  16. //商户订单号,和支付宝交易号二选一
  17. $out_trade_no = trim($_POST['WIDout_trade_no']);
  18. //支付宝交易号,和商户订单号二选一
  19. $trade_no = trim($_POST['WIDtrade_no']);
  20. //退款金额,不能大于订单总金额
  21. $refund_amount=trim($_POST['WIDrefund_amount']);
  22. //退款的原因说明
  23. $refund_reason=trim($_POST['WIDrefund_reason']);
  24. //标识一次退款请求,同一笔交易多次退款需要保证唯一,如需部分退款,则此参数必传。
  25. $out_request_no=trim($_POST['WIDout_request_no']);
  26. $RequestBuilder = new AlipayTradeRefundContentBuilder();
  27. $RequestBuilder->setTradeNo($trade_no);
  28. $RequestBuilder->setOutTradeNo($out_trade_no);
  29. $RequestBuilder->setRefundAmount($refund_amount);
  30. $RequestBuilder->setRefundReason($refund_reason);
  31. $RequestBuilder->setOutRequestNo($out_request_no);
  32. $Response = new AlipayTradeService($config);
  33. $result=$Response->Refund($RequestBuilder);
  34. return ;
  35. }
  36. ?>
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40. <title>支付宝手机网站alipay.trade.refund (统一收单交易退款接口)</title>
  41. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  42. <style>
  43. *{
  44. margin:0;
  45. padding:0;
  46. }
  47. ul,ol{
  48. list-style:none;
  49. }
  50. body{
  51. font-family: "Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
  52. }
  53. .hidden{
  54. display:none;
  55. }
  56. .new-btn-login-sp{
  57. padding: 1px;
  58. display: inline-block;
  59. width: 75%;
  60. }
  61. .new-btn-login {
  62. background-color: #02aaf1;
  63. color: #FFFFFF;
  64. font-weight: bold;
  65. border: none;
  66. width: 100%;
  67. height: 30px;
  68. border-radius: 5px;
  69. font-size: 16px;
  70. }
  71. #main{
  72. width:100%;
  73. margin:0 auto;
  74. font-size:14px;
  75. }
  76. .red-star{
  77. color:#f00;
  78. width:10px;
  79. display:inline-block;
  80. }
  81. .null-star{
  82. color:#fff;
  83. }
  84. .content{
  85. margin-top:5px;
  86. }
  87. .content dt{
  88. width:100px;
  89. display:inline-block;
  90. float: left;
  91. margin-left: 20px;
  92. color: #666;
  93. font-size: 13px;
  94. margin-top: 8px;
  95. }
  96. .content dd{
  97. margin-left:120px;
  98. margin-bottom:5px;
  99. }
  100. .content dd input {
  101. width: 85%;
  102. height: 28px;
  103. border: 0;
  104. -webkit-border-radius: 0;
  105. -webkit-appearance: none;
  106. }
  107. #foot{
  108. margin-top:10px;
  109. position: absolute;
  110. bottom: 15px;
  111. width: 100%;
  112. }
  113. .foot-ul{
  114. width: 100%;
  115. }
  116. .foot-ul li {
  117. width: 100%;
  118. text-align:center;
  119. color: #666;
  120. }
  121. .note-help {
  122. color: #999999;
  123. font-size: 12px;
  124. line-height: 130%;
  125. margin-top: 5px;
  126. width: 100%;
  127. display: block;
  128. }
  129. #btn-dd{
  130. margin: 20px;
  131. text-align: center;
  132. }
  133. .foot-ul{
  134. width: 100%;
  135. }
  136. .one_line{
  137. display: block;
  138. height: 1px;
  139. border: 0;
  140. border-top: 1px solid #eeeeee;
  141. width: 100%;
  142. margin-left: 20px;
  143. }
  144. .am-header {
  145. display: -webkit-box;
  146. display: -ms-flexbox;
  147. display: box;
  148. width: 100%;
  149. position: relative;
  150. padding: 7px 0;
  151. -webkit-box-sizing: border-box;
  152. -ms-box-sizing: border-box;
  153. box-sizing: border-box;
  154. background: #1D222D;
  155. height: 50px;
  156. text-align: center;
  157. -webkit-box-pack: center;
  158. -ms-flex-pack: center;
  159. box-pack: center;
  160. -webkit-box-align: center;
  161. -ms-flex-align: center;
  162. box-align: center;
  163. }
  164. .am-header h1 {
  165. -webkit-box-flex: 1;
  166. -ms-flex: 1;
  167. box-flex: 1;
  168. line-height: 18px;
  169. text-align: center;
  170. font-size: 18px;
  171. font-weight: 300;
  172. color: #fff;
  173. }
  174. </style>
  175. </head>
  176. <body text=#000000 bgColor="#ffffff" leftMargin=0 topMargin=4>
  177. <header class="am-header">
  178. <h1>支付宝手机网站alipay.trade.refund (统一收单交易退款接口)</h1>
  179. </header>
  180. <div id="main">
  181. <form name=alipayment action='' method=post target="_blank">
  182. <div id="body" style="clear:left">
  183. <dl class="content">
  184. <dt>商户订单号
  185. :</dt>
  186. <dd>
  187. <input id="WIDout_trade_no" name="WIDout_trade_no" />
  188. </dd>
  189. <hr class="one_line">
  190. <dt>支付宝交易号:</dt>
  191. <dd>
  192. <input id="WIDtrade_no" name="WIDtrade_no" />
  193. </dd>
  194. <hr class="one_line">
  195. <dt></dt>
  196. <dd>
  197. <span style="line-height: 28px; color:red;">注意:商户订单号和支付宝交易号不能同时为空。 trade_no、 out_trade_no如果同时存在优先取trade_no</span>
  198. </dd>
  199. <hr class="one_line">
  200. <dt>退款金额:</dt>
  201. <dd>
  202. <input id="WIDrefund_amount" name="WIDrefund_amount" />
  203. </dd>
  204. <hr class="one_line">
  205. <dt>退款原因:</dt>
  206. <dd>
  207. <input id="WIDrefund_reason" name="WIDrefund_reason" />
  208. </dd>
  209. <hr class="one_line">
  210. <dt>退款单号:</dt>
  211. <dd>
  212. <input id="WIDout_request_no" name="WIDout_request_no" />
  213. </dd>
  214. <hr class="one_line">
  215. <dt></dt>
  216. <dd>
  217. <span style="line-height: 28px; color:red;">注意:如是部分退款,则参数退款单号(out_request_no)必传。</span>
  218. </dd>
  219. <hr class="one_line">
  220. <dd id="btn-dd">
  221. <span class="new-btn-login-sp">
  222. <button class="new-btn-login" type="submit" style="text-align:center;">确 认</button>
  223. </span>
  224. <span class="note-help">如果您点击“确认”按钮,即表示您同意该次的执行操作。</span>
  225. </dd>
  226. </dl>
  227. </div>
  228. </form>
  229. <div id="foot">
  230. <ul class="foot-ul">
  231. <li>
  232. 支付宝版权所有 2015-2018 ALIPAY.COM
  233. </li>
  234. </ul>
  235. </div>
  236. </div>
  237. </body>
  238. </html>