支付宝退款
支付宝批量退款
包含文件:
lib
refund.php 发送退款信息
1 <?php
2 /* *
3 * 功能:即时到账批量退款有密接口接入页
4 * 版本:3.2
5 * 修改日期:2011-03-25
6 * 说明:
7 * 退款类
8 * 格式:第一笔交易#第二笔交易#第三笔交易
9 * 第N笔交易格式:交易退款信息
10 * 交易退款信息格式:原付款支付宝交易号^退款总金额^退款理由
11 * 注意:
12 * 1.detail_data中的退款笔数总和要等于参数batch_num的值
13 * 2.detail_data的值中不能有“^”、“|”、“#”、“$”等影响detail_data的格式的特殊字符
14 * 3.detail_data中退款总金额不能大于交易总金额
15 * 4.一笔交易可以多次退款,只需要遵守多次退款的总金额不超过该笔交易付款时金额。
16 * 5.有密退款接口不支持退分润功能
17 *
18 */
19 class refund{
20 var $aliapy_config=array();
21 //日期
22 var $refund_date;
23 //批号
24 var $batch_no;
25 //退款笔数,即参数detail_data的值中,“#”字符出现的数量加1,最大支持1000笔(即“#”字符出现的数量999个)
26 var $batch_num;
27 //退款详细数据
28 var $detail_data;
29 /**
30 * 配置方法
31 *
32 */
33 public function refund_config($partner,$key,$seller_email){
34 /**
35 * 得到配置信息
36 */
37 // 合作身份者id,以2088开头的16位纯数字
38 $this->aliapy_config['partner']=$partner;
39 // 安全检验码,以数字和字母组成的32位字符
40 $this->aliapy_config['key']=$key;
41 // 签约支付宝账号或卖家支付宝帐户
42 $this->aliapy_config['seller_email']=$seller_email;
43 // 服务器异步通知页面路径,要用http://格式的完整路径,不允许加?id=123这类自定义参数
44 $this->aliapy_config['notify_url'] = SiteUrl."/api/payment/refund/notify_url.php";
45 // 签名方式 不需修改
46 $this->aliapy_config['sign_type'] = 'MD5';
47 // 字符编码格式 目前支持 gbk 或 utf-8
48 $this->aliapy_config['input_charset']= 'utf-8';
49 // 访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
50 $this->aliapy_config['transport'] = 'http';
51 // 退款当天日期,获取当天日期,格式:年[4位]-月[2位]-日[2位] 小时[2位 24小时制]:分[2位]:秒[2位],如:2007-10-01 13:13:13
52 $this->refund_date= date('Y-m-d H:i:s',time());
53 // 商家网站里的批次号,保证其唯一性,格式:当天日期[8位]+序列号[3至24位],如:201008010000001
54 $this->batch_no = date('YmdHis',time());
55 }
56 /**
57 * 接收退款信息
58 * 输出退款页
59 *
60 */
61 public function refund_now($batch_num,$detail_data){
62 require_once("lib/alipay_service.class.php");
63 //构造要请求的参数数组,无需改动
64 $parameter = array(
65 "service" => "refund_fastpay_by_platform_pwd",
66 "partner" => trim($this->aliapy_config['partner']),
67
68 "seller_email" => trim($this->aliapy_config['seller_email']),
69 "notify_url" => trim($this->aliapy_config['notify_url']),
70 "_input_charset" => trim(strtolower($this->aliapy_config['input_charset'])),
71 "refund_date" => $this->refund_date,
72 "batch_no" => $this->batch_no,
73 "batch_num" => $batch_num,
74 "detail_data" => $detail_data
75 );
76
77 //构造即时到账批量退款有密接口
78 $alipayService = new AlipayService($this->aliapy_config);
79 $html_text = $alipayService->refund_fastpay_by_platform_pwd($parameter);
80 echo $html_text;
81 }
82 }
83 ?>