-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhgutil.php
More file actions
94 lines (76 loc) · 2.49 KB
/
hgutil.php
File metadata and controls
94 lines (76 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
class hgutil {
var $gateway = "https://api.allpayx.com/pay?"; //Purchase gateway address
var $parameter;
var $security_code;
var $mysign;
function hgutil($parameter,$security_code,$sign_type = "MD5",$debug=false) {
$this->parameter = $this->para_filter($parameter);
$this->security_code = $security_code;
$this->sign_type = $sign_type;
$this->mysign = '';
//$this->transport = $transport;
if($parameter['charSet'] == "")
$this->parameter['charSet']='UTF-8';
if($debug == true)
$this->gateway = "https://testapi.allpayx.com/pay?";
$sort_array = array();
$arg = "";
$sort_array = $this->arg_sort($this->parameter);
while (list ($key, $val) = each ($sort_array)) {
$arg.=$key."=".$this->charset_encode($val,$this->parameter['charSet'])."&";
}
$prestr = substr($arg,0,count($arg)-2);
// echo $prestr.$this->security_code;
$this->mysign = $this->sign($prestr.$this->security_code);
}
function create_url() {
$url = $this->gateway;
$sort_array = array();
$arg = "";
$sort_array = $this->arg_sort($this->parameter);
while (list ($key, $val) = each ($sort_array)) {
$arg.=$key."=".urlencode($this->charset_encode($val,$this->parameter['charSet']))."&";
}
$url.= $arg."signature=" .$this->mysign;
return $url;
}
function arg_sort($array) {
ksort($array);
reset($array);
return $array;
}
function sign($prestr) {
$mysign = "";
if($this->sign_type == 'MD5') {
$mysign = md5($prestr);
}elseif($this->sign_type =='DSA') {
die("DSA is not supported today,please use MD5");
}else {
die("Not supported today".$this->sign_type."signature algorithm");
}
return $mysign;
}
function para_filter($parameter) {
$para = array();
while (list ($key, $val) = each ($parameter)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para[$key] = $parameter[$key];
}
return $para;
}
//using multiply encoding.
function charset_encode($input,$_output_charset ,$charSet ="UTF-8" ) {
$output = "";
if(!isset($_output_charset) )$_output_charset = $this->parameter['charSet'];
if($charSet == $_output_charset || $input ==null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")){
$output = mb_convert_encoding($input,$_output_charset,$charSet);
} elseif(function_exists("iconv")) {
$output = iconv($charSet,$_output_charset,$input);
} else die("sorry, you have no libs support for charset change.");
return $output;
}
}
?>