Signature.php
928 Bytes
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
<?php
namespace WebPlugin\Pay;
/**
* 接口签名
*/
class Signature
{
/**
* 排序参数
* @param array $package
* @return array
*/
static function packageSort(array $package)
{
ksort($package);
reset($package);
return $package;
}
/**
* 组合签名
* @param array $package
* @return string
*/
static function makeSign(array $package)
{
$packageList = array();
foreach ($package as $key => $val) {
$packageList[] = trim($key . '=' . $val);
}
return strtolower(md5(implode('&', $packageList)));
}
/**
* 校验签名
* @param $submitSign
* @param $makeSign
* @return bool
*/
static function verifySign($submitSign, $makeSign)
{
return strtolower($submitSign) == strtolower($makeSign);
}
}