@@ 67-75 (lines=9) @@ | ||
64 | * @param string $string 需要编码的数据 |
|
65 | * @return string 编码后的base64串,失败返回false |
|
66 | */ |
|
67 | private function base64Encode($string) |
|
68 | { |
|
69 | static $replace = array('+' => '*', '/' => '-', '=' => '_'); |
|
70 | $base64 = base64_encode($string); |
|
71 | if ($base64 === false) { |
|
72 | throw new OpensslException('base64_encode error'); |
|
73 | } |
|
74 | return str_replace(array_keys($replace), array_values($replace), $base64); |
|
75 | } |
|
76 | ||
77 | /** |
|
78 | * 用于url的base64decode |
|
@@ 83-92 (lines=10) @@ | ||
80 | * @param string $base64 需要解码的base64串 |
|
81 | * @return string 解码后的数据,失败返回false |
|
82 | */ |
|
83 | private function base64Decode($base64) |
|
84 | { |
|
85 | static $replace = array('+' => '*', '/' => '-', '=' => '_'); |
|
86 | $string = str_replace(array_values($replace), array_keys($replace), $base64); |
|
87 | $result = base64_decode($string); |
|
88 | if ($result == false) { |
|
89 | throw new OpensslException('base64_decode error'); |
|
90 | } |
|
91 | return $result; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * 根据json内容生成需要签名的buf串 |