@@ 12-111 (lines=100) @@ | ||
9 | * 版权 Copyright2006 Buybay NetTech |
|
10 | */ |
|
11 | ||
12 | class alipay_service { |
|
13 | ||
14 | var $gateway = "http://www.alipay3.net/cooperate/gateway.do?"; //支付接口 |
|
15 | var $parameter; //全部需要传递的参数 |
|
16 | var $security_code; //安全校验码 |
|
17 | var $mysign; //签名 |
|
18 | ||
19 | //构造支付宝外部服务接口控制 |
|
20 | function alipay_service($parameter,$security_code,$sign_type = "MD5",$transport= "https") { |
|
21 | $this->parameter = $this->para_filter($parameter); |
|
22 | $this->security_code = $security_code; |
|
23 | $this->sign_type = $sign_type; |
|
24 | $this->mysign = ''; |
|
25 | $this->transport = $transport; |
|
26 | if($parameter['_input_charset'] == "") |
|
27 | $this->parameter['_input_charset']='utf-8'; |
|
28 | if($this->transport == "https") { |
|
29 | $this->gateway = "https://www.alipay.com/cooperate/gateway.do?"; |
|
30 | } else $this->gateway = "httsp://www.alipay.com/cooperate/gateway.do?"; |
|
31 | $sort_array = array(); |
|
32 | $arg = ""; |
|
33 | $sort_array = $this->arg_sort($this->parameter); |
|
34 | while (list ($key, $val) = each ($sort_array)) { |
|
35 | $arg.=$key."=".$this->charset_encode($val,$this->parameter['_input_charset'])."&"; |
|
36 | } |
|
37 | $prestr = substr($arg,0,count($arg)-2); //去掉最后一个问号 |
|
38 | $this->mysign = $this->sign($prestr.$this->security_code); |
|
39 | } |
|
40 | ||
41 | ||
42 | function create_url() { |
|
43 | $url = $this->gateway; |
|
44 | $sort_array = array(); |
|
45 | $arg = ""; |
|
46 | $sort_array = $this->arg_sort($this->parameter); |
|
47 | while (list ($key, $val) = each ($sort_array)) { |
|
48 | $arg.=$key."=".urlencode($this->charset_encode($val,$this->parameter['_input_charset']))."&"; |
|
49 | } |
|
50 | $url.= $arg."sign=" .$this->mysign ."&sign_type=".$this->sign_type; |
|
51 | ||
52 | return $url; |
|
53 | ||
54 | } |
|
55 | ||
56 | function signParams() { |
|
57 | $url = $this->gateway; |
|
58 | $sort_array = array(); |
|
59 | $arg = ""; |
|
60 | $sort_array = $this->arg_sort($this->parameter); |
|
61 | while (list ($key, $val) = each ($sort_array)) { |
|
62 | $arg.=$key."=".urlencode($this->charset_encode($val,$this->parameter['_input_charset']))."&"; |
|
63 | } |
|
64 | return $this->mysign; |
|
65 | } |
|
66 | ||
67 | function arg_sort($array) { |
|
68 | ksort($array); |
|
69 | reset($array); |
|
70 | return $array; |
|
71 | ||
72 | } |
|
73 | ||
74 | function sign($prestr) { |
|
75 | $mysign = ""; |
|
76 | if($this->sign_type == 'MD5') { |
|
77 | $mysign = md5($prestr); |
|
78 | }elseif($this->sign_type =='DSA') { |
|
79 | //DSA 签名方法待后续开发 |
|
80 | die("DSA 签名方法待后续开发,请先使用MD5签名方式"); |
|
81 | }else { |
|
82 | die("支付宝暂不支持".$this->sign_type."类型的签名方式"); |
|
83 | } |
|
84 | return $mysign; |
|
85 | ||
86 | } |
|
87 | function para_filter($parameter) { //除去数组中的空值和签名模式 |
|
88 | $para = array(); |
|
89 | while (list ($key, $val) = each ($parameter)) { |
|
90 | if($key == "sign" || $key == "sign_type" || $val == "")continue; |
|
91 | else $para[$key] = $parameter[$key]; |
|
92 | ||
93 | } |
|
94 | return $para; |
|
95 | } |
|
96 | //实现多种字符编码方式 |
|
97 | function charset_encode($input,$_output_charset ,$_input_charset ="utf-8" ) { |
|
98 | $output = ""; |
|
99 | if(!isset($_output_charset) )$_output_charset = $this->parameter['_input_charset ']; |
|
100 | if($_input_charset == $_output_charset || $input ==null) { |
|
101 | $output = $input; |
|
102 | } elseif (function_exists("mb_convert_encoding")){ |
|
103 | $output = mb_convert_encoding($input,$_output_charset,$_input_charset); |
|
104 | } elseif(function_exists("iconv")) { |
|
105 | $output = iconv($_input_charset,$_output_charset,$input); |
|
106 | } else die("sorry, you have no libs support for charset change."); |
|
107 | return $output; |
|
108 | } |
|
109 | ||
110 | ||
111 | } |
|
112 | ||
113 | ||
114 | ?> |
@@ 12-111 (lines=100) @@ | ||
9 | ��* ��Ȩ Copyright2006 Buybay NetTech |
|
10 | ��*/ |
|
11 | ||
12 | class alipay_service { |
|
13 | ||
14 | var $gateway = "http://www.alipay3.net/cooperate/gateway.do?"; //֧���ӿ� |
|
15 | var $parameter; //ȫ����Ҫ���ݵIJ�� |
|
16 | var $security_code; //��ȫУ���� |
|
17 | var $mysign; //ǩ� |
|
18 | ||
19 | //����֧�����ⲿ����ӿڿ��� |
|
20 | function alipay_service($parameter,$security_code,$sign_type = "MD5",$transport= "https") { |
|
21 | $this->parameter = $this->para_filter($parameter); |
|
22 | $this->security_code = $security_code; |
|
23 | $this->sign_type = $sign_type; |
|
24 | $this->mysign = ''; |
|
25 | $this->transport = $transport; |
|
26 | if($parameter['_input_charset'] == "") |
|
27 | $this->parameter['_input_charset']='GBK'; |
|
28 | if($this->transport == "https") { |
|
29 | $this->gateway = "https://www.alipay.com/cooperate/gateway.do?"; |
|
30 | } else $this->gateway = "httsp://www.alipay.com/cooperate/gateway.do?"; |
|
31 | $sort_array = array(); |
|
32 | $arg = ""; |
|
33 | $sort_array = $this->arg_sort($this->parameter); |
|
34 | while (list ($key, $val) = each ($sort_array)) { |
|
35 | $arg.=$key."=".$this->charset_encode($val,$this->parameter['_input_charset'])."&"; |
|
36 | } |
|
37 | $prestr = substr($arg,0,count($arg)-2); //ȥ�����һ���ʺ� |
|
38 | $this->mysign = $this->sign($prestr.$this->security_code); |
|
39 | } |
|
40 | ||
41 | ||
42 | function create_url() { |
|
43 | $url = $this->gateway; |
|
44 | $sort_array = array(); |
|
45 | $arg = ""; |
|
46 | $sort_array = $this->arg_sort($this->parameter); |
|
47 | while (list ($key, $val) = each ($sort_array)) { |
|
48 | $arg.=$key."=".urlencode($this->charset_encode($val,$this->parameter['_input_charset']))."&"; |
|
49 | } |
|
50 | $url.= $arg."sign=" .$this->mysign ."&sign_type=".$this->sign_type; |
|
51 | ||
52 | return $url; |
|
53 | ||
54 | } |
|
55 | ||
56 | function signParams() { |
|
57 | $url = $this->gateway; |
|
58 | $sort_array = array(); |
|
59 | $arg = ""; |
|
60 | $sort_array = $this->arg_sort($this->parameter); |
|
61 | while (list ($key, $val) = each ($sort_array)) { |
|
62 | $arg.=$key."=".urlencode($this->charset_encode($val,$this->parameter['_input_charset']))."&"; |
|
63 | } |
|
64 | return $this->mysign; |
|
65 | } |
|
66 | ||
67 | function arg_sort($array) { |
|
68 | ksort($array); |
|
69 | reset($array); |
|
70 | return $array; |
|
71 | ||
72 | } |
|
73 | ||
74 | function sign($prestr) { |
|
75 | $mysign = ""; |
|
76 | if($this->sign_type == 'MD5') { |
|
77 | $mysign = md5($prestr); |
|
78 | }elseif($this->sign_type =='DSA') { |
|
79 | //DSA ǩ�������������� |
|
80 | die("DSA ǩ��������������������ʹ��MD5ǩ���ʽ"); |
|
81 | }else { |
|
82 | die("֧�����ݲ�֧��".$this->sign_type."���͵�ǩ���ʽ"); |
|
83 | } |
|
84 | return $mysign; |
|
85 | ||
86 | } |
|
87 | function para_filter($parameter) { //��ȥ����еĿ�ֵ��ǩ�ģʽ |
|
88 | $para = array(); |
|
89 | while (list ($key, $val) = each ($parameter)) { |
|
90 | if($key == "sign" || $key == "sign_type" || $val == "")continue; |
|
91 | else $para[$key] = $parameter[$key]; |
|
92 | ||
93 | } |
|
94 | return $para; |
|
95 | } |
|
96 | //ʵ�ֶ����ַ����뷽ʽ |
|
97 | function charset_encode($input,$_output_charset ,$_input_charset ="GBK" ) { |
|
98 | $output = ""; |
|
99 | if(!isset($_output_charset) )$_output_charset = $this->parameter['_input_charset ']; |
|
100 | if($_input_charset == $_output_charset || $input ==null) { |
|
101 | $output = $input; |
|
102 | } elseif (function_exists("mb_convert_encoding")){ |
|
103 | $output = mb_convert_encoding($input,$_output_charset,$_input_charset); |
|
104 | } elseif(function_exists("iconv")) { |
|
105 | $output = iconv($_input_charset,$_output_charset,$input); |
|
106 | } else die("sorry, you have no libs support for charset change."); |
|
107 | return $output; |
|
108 | } |
|
109 | ||
110 | ||
111 | } |
|
112 | ||
113 | ||
114 | ?> |