@@ -17,7 +17,7 @@ |
||
17 | 17 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
18 | 18 | // +---------------------------------------------------------------------- |
19 | 19 | |
20 | -declare (strict_types=1); |
|
20 | +declare(strict_types=1); |
|
21 | 21 | |
22 | 22 | namespace DtApp\ThinkLibrary\facade; |
23 | 23 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | public function read(string $sessionId): string |
58 | 58 | { |
59 | 59 | return (string)Db::table($this->table_name) |
60 | - ->where('session_id', $this->config['session_prefix'] . $sessionId) |
|
60 | + ->where('session_id', $this->config['session_prefix'].$sessionId) |
|
61 | 61 | ->whereTime('session_expire', '>=', time()) |
62 | 62 | ->order('session_expire desc') |
63 | 63 | ->value('session_data', ''); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function delete(string $sessionId): bool |
73 | 73 | { |
74 | 74 | $result = Db::table($this->table_name) |
75 | - ->where('session_id', $this->config['session_prefix'] . $sessionId) |
|
75 | + ->where('session_id', $this->config['session_prefix'].$sessionId) |
|
76 | 76 | ->delete(); |
77 | 77 | return $result ? true : false; |
78 | 78 | } |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | public function write(string $sessionId, string $data): bool |
90 | 90 | { |
91 | 91 | $get = Db::table($this->table_name) |
92 | - ->where('session_id', $this->config['session_prefix'] . $sessionId) |
|
92 | + ->where('session_id', $this->config['session_prefix'].$sessionId) |
|
93 | 93 | ->whereTime('session_expire', '>=', time()) |
94 | 94 | ->field('id') |
95 | 95 | ->find(); |
96 | 96 | if (empty($get)) { |
97 | 97 | $params = [ |
98 | - 'session_id' => $this->config['session_prefix'] . $sessionId, |
|
98 | + 'session_id' => $this->config['session_prefix'].$sessionId, |
|
99 | 99 | 'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']), |
100 | 100 | 'session_data' => $data |
101 | 101 | ]; |
102 | 102 | $result = Db::table($this->table_name) |
103 | 103 | ->insert($params); |
104 | 104 | return $result ? true : false; |
105 | - } else { |
|
105 | + }else { |
|
106 | 106 | $params = [ |
107 | 107 | 'session_expire' => Times::dateRear("Y-m-d H:i:s", $this->config['session_expire']), |
108 | 108 | 'session_data' => $data |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | if (isset($this->aes_decrypt_data[$name])) { |
188 | 188 | return $this->aes_decrypt_data[$name]; |
189 | - } else { |
|
189 | + }else { |
|
190 | 190 | return $default; |
191 | 191 | } |
192 | 192 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $rear = strtotime('+2minute'); |
219 | 219 | if ($timestamp <= $rear && $timestamp >= $before) { |
220 | 220 | $this->aes_decrypt_data = $data; |
221 | - } else { |
|
221 | + }else { |
|
222 | 222 | $this->error('已超时,请重新尝试!'); |
223 | 223 | } |
224 | 224 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | if (!empty(is_array($data))) { |
241 | 241 | $data = json_encode($data); |
242 | 242 | } |
243 | - return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv . $timestamp))); |
|
243 | + return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv.$timestamp))); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -257,6 +257,6 @@ discard block |
||
257 | 257 | if (empty($this->aes_md5_iv)) { |
258 | 258 | $this->setAesMd5Iv(); |
259 | 259 | } |
260 | - return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv . $timestamp); |
|
260 | + return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv.$timestamp); |
|
261 | 261 | } |
262 | 262 | } |
@@ -105,7 +105,7 @@ |
||
105 | 105 | 'domain' => request()->domain(), |
106 | 106 | 'url' => request()->url(), |
107 | 107 | 'node' => config('dtapp.exception.wechat.node', ''), |
108 | - 'info' => "ServerIp:" . $ip . ";CdnIp:" . $_SERVER['REMOTE_ADDR'] . ";ClientIp:" . get_ip(), |
|
108 | + 'info' => "ServerIp:".$ip.";CdnIp:".$_SERVER['REMOTE_ADDR'].";ClientIp:".get_ip(), |
|
109 | 109 | 'ip' => $ipinfo['location_all'], |
110 | 110 | 'error' => base64_encode($msg) |
111 | 111 | ]) |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | if (empty($ip)) { |
41 | 41 | if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
42 | 42 | $ip = $_SERVER['REMOTE_ADDR']; |
43 | - } else { |
|
43 | + }else { |
|
44 | 44 | //为了兼容百度的CDN,所以转成数组 |
45 | 45 | $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
46 | 46 | $ip = $arr[0]; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | //为了兼容百度的CDN,所以转成数组 |
62 | 62 | $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
63 | 63 | return $arr[0]; |
64 | - } else { |
|
64 | + }else { |
|
65 | 65 | return $_SERVER['REMOTE_ADDR']; |
66 | 66 | } |
67 | 67 | } |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | if (empty($value)) { |
100 | 100 | return $myc->name($name) |
101 | 101 | ->get(); |
102 | - } else { |
|
102 | + }else { |
|
103 | 103 | if (empty($myc->name($name) |
104 | 104 | ->get())) { |
105 | 105 | $myc->name($name) |
106 | 106 | ->expire($expire) |
107 | 107 | ->set($value); |
108 | - } else { |
|
108 | + }else { |
|
109 | 109 | $myc->name($name) |
110 | 110 | ->expire($expire) |
111 | 111 | ->update($value); |
@@ -50,7 +50,7 @@ |
||
50 | 50 | if (empty($this->ipPath)) { |
51 | 51 | throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置'); |
52 | 52 | } |
53 | - $this->reader = new IpIpReader($this->ipPath . 'ipipfree.ipdb'); |
|
53 | + $this->reader = new IpIpReader($this->ipPath.'ipipfree.ipdb'); |
|
54 | 54 | parent::__construct($app); |
55 | 55 | } |
56 | 56 |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | throw new DtaException('请检查阿里-阿里云配置信息 appcode'); |
222 | 222 | } |
223 | 223 | $headers = array(); |
224 | - array_push($headers, "Authorization:APPCODE " . $appcode); |
|
224 | + array_push($headers, "Authorization:APPCODE ".$appcode); |
|
225 | 225 | $querys = "ip={$this->ip}"; |
226 | 226 | $bodys = ""; |
227 | - $url = $host . $path . "?" . $querys; |
|
227 | + $url = $host.$path."?".$querys; |
|
228 | 228 | |
229 | 229 | $curl = curl_init(); |
230 | 230 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | curl_setopt($curl, CURLOPT_FAILONERROR, false); |
234 | 234 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
235 | 235 | curl_setopt($curl, CURLOPT_HEADER, false); |
236 | - if (1 == strpos("$" . $host, "https://")) { |
|
236 | + if (1 == strpos("$".$host, "https://")) { |
|
237 | 237 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
238 | 238 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
239 | 239 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | throw new Exception('IP Database metadata error.'); |
73 | 73 | } |
74 | 74 | |
75 | - $fileSize = 4 + $metaLength + $this->meta['total_size']; |
|
75 | + $fileSize = 4+$metaLength+$this->meta['total_size']; |
|
76 | 76 | if ($fileSize != $this->fileSize) { |
77 | 77 | throw new Exception('IP Database size error.'); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $this->nodeCount = $this->meta['node_count']; |
81 | - $this->nodeOffset = 4 + $metaLength; |
|
81 | + $this->nodeOffset = 4+$metaLength; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | private function findNode($ip) |
145 | 145 | { |
146 | 146 | $binary = inet_pton($ip); |
147 | - $bitCount = strlen($binary) * 8; // 32 | 128 |
|
147 | + $bitCount = strlen($binary)*8; // 32 | 128 |
|
148 | 148 | $key = substr($binary, 0, 2); |
149 | 149 | $node = 0; |
150 | 150 | $index = 0; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | for ($i = 0; $i < 96 && $node < $this->nodeCount; $i++) { |
154 | 154 | if ($i >= 80) { |
155 | 155 | $idx = 1; |
156 | - } else { |
|
156 | + }else { |
|
157 | 157 | $idx = 0; |
158 | 158 | } |
159 | 159 | $node = $this->readNode($node, $idx); |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | $this->v4offset = $node; |
165 | - } else { |
|
165 | + }else { |
|
166 | 166 | $node = $this->v4offset; |
167 | 167 | } |
168 | - } else { |
|
168 | + }else { |
|
169 | 169 | if (isset($this->v6offsetCache[$key])) { |
170 | 170 | $index = 16; |
171 | 171 | $node = $this->v6offsetCache[$key]; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | break; |
178 | 178 | } |
179 | 179 | |
180 | - $node = $this->readNode($node, 1 & ((0xFF & ord($binary[$i >> 3])) >> 7 - ($i % 8))); |
|
180 | + $node = $this->readNode($node, 1 & ((0xFF & ord($binary[$i >> 3])) >> 7-($i%8))); |
|
181 | 181 | |
182 | 182 | if ($i == 15) { |
183 | 183 | $this->v6offsetCache[$key] = $node; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | private function readNode($node, $index) |
203 | 203 | { |
204 | - return unpack('N', $this->read($this->file, $node * 8 + $index * 4, 4))[1]; |
|
204 | + return unpack('N', $this->read($this->file, $node*8+$index*4, 4))[1]; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | private function resolve($node) |
213 | 213 | { |
214 | - $resolved = $node - $this->nodeCount + $this->nodeCount * 8; |
|
214 | + $resolved = $node-$this->nodeCount+$this->nodeCount*8; |
|
215 | 215 | if ($resolved >= $this->fileSize) { |
216 | 216 | return NULL; |
217 | 217 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | private function read($stream, $offset, $length) |
242 | 242 | { |
243 | 243 | if ($length > 0) { |
244 | - if (fseek($stream, $offset + $this->nodeOffset) === 0) { |
|
244 | + if (fseek($stream, $offset+$this->nodeOffset) === 0) { |
|
245 | 245 | $value = fread($stream, $length); |
246 | 246 | if (strlen($value) === $length) { |
247 | 247 | return $value; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $this->scope = $scope; |
166 | 166 | } elseif ($scope === "snsapi_userinfo") { |
167 | 167 | $this->scope = $scope; |
168 | - } else { |
|
168 | + }else { |
|
169 | 169 | throw new DtaException("请检查scope参数"); |
170 | 170 | } |
171 | 171 | return $this; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | // 获取数据 |
314 | 314 | $accessToken = $this->getAccessToken(); |
315 | 315 | if (!isset($accessToken['access_token'])) { |
316 | - throw new DtaException("获取access_token错误," . $accessToken['errmsg']); |
|
316 | + throw new DtaException("获取access_token错误,".$accessToken['errmsg']); |
|
317 | 317 | } |
318 | 318 | $res = HttpService::instance() |
319 | 319 | ->url("{$this->api_url}cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi") |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | // 获取数据 |
323 | 323 | $accessToken = $this->getAccessToken(); |
324 | 324 | if (!isset($accessToken['access_token'])) { |
325 | - throw new DtaException("获取access_token错误," . $accessToken['errmsg']); |
|
325 | + throw new DtaException("获取access_token错误,".$accessToken['errmsg']); |
|
326 | 326 | } |
327 | 327 | $res = HttpService::instance() |
328 | 328 | ->url("{$this->api_url}cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi") |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
356 | 356 | $str = ""; |
357 | 357 | for ($i = 0; $i < $length; $i++) { |
358 | - $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); |
|
358 | + $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1); |
|
359 | 359 | } |
360 | 360 | return $str; |
361 | 361 | } |
@@ -627,22 +627,22 @@ discard block |
||
627 | 627 | $accessToken_res = HttpService::instance() |
628 | 628 | ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") |
629 | 629 | ->toArray(); |
630 | - $accessToken_res['expires_time'] = time() + 6000; |
|
630 | + $accessToken_res['expires_time'] = time()+6000; |
|
631 | 631 | file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); |
632 | 632 | $accessToken = $accessToken_res; |
633 | - } else if (!isset($accessToken['access_token'])) { |
|
633 | + }else if (!isset($accessToken['access_token'])) { |
|
634 | 634 | // 内容不存在 |
635 | 635 | $accessToken_res = HttpService::instance() |
636 | 636 | ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") |
637 | 637 | ->toArray(); |
638 | - $accessToken_res['expires_time'] = time() + 6000; |
|
638 | + $accessToken_res['expires_time'] = time()+6000; |
|
639 | 639 | file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); |
640 | 640 | $accessToken = $accessToken_res; |
641 | - } else if ($accessToken['expires_time'] <= time()) { |
|
641 | + }else if ($accessToken['expires_time'] <= time()) { |
|
642 | 642 | $accessToken_res = HttpService::instance() |
643 | 643 | ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") |
644 | 644 | ->toArray(); |
645 | - $accessToken_res['expires_time'] = time() + 6000; |
|
645 | + $accessToken_res['expires_time'] = time()+6000; |
|
646 | 646 | file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); |
647 | 647 | $accessToken = $accessToken_res; |
648 | 648 | } |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | $accessToken_res = HttpService::instance() |
654 | 654 | ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") |
655 | 655 | ->toArray(); |
656 | - $accessToken_res['expires_time'] = time() + 6000; |
|
656 | + $accessToken_res['expires_time'] = time()+6000; |
|
657 | 657 | file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE)); |
658 | 658 | $accessToken = $accessToken_res; |
659 | 659 | } |
660 | 660 | return $accessToken; |
661 | - } else if ($this->cache == "mysql") { |
|
661 | + }else if ($this->cache == "mysql") { |
|
662 | 662 | $access_token = []; |
663 | 663 | // 文件名 |
664 | 664 | $file = "{$this->app_id}_access_token"; |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | $cache_mysql_value = dtacache($file); |
667 | 667 | if (!empty($cache_mysql_value)) { |
668 | 668 | $access_token['access_token'] = $cache_mysql_value; |
669 | - } else { |
|
669 | + }else { |
|
670 | 670 | $accessToken_res = HttpService::instance() |
671 | 671 | ->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}") |
672 | 672 | ->toArray(); |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | $access_token['access_token'] = $accessToken_res['access_token']; |
685 | 685 | } |
686 | 686 | return $access_token; |
687 | - } else { |
|
687 | + }else { |
|
688 | 688 | throw new DtaException("驱动方式错误"); |
689 | 689 | } |
690 | 690 | } |
@@ -735,11 +735,11 @@ discard block |
||
735 | 735 | // 转成字符串 |
736 | 736 | $stringA = Urls::toParams($array); |
737 | 737 | // 在字符串接商户支付秘钥 |
738 | - $stringSignTemp = "{$stringA}&key=" . $this->mch_key; |
|
738 | + $stringSignTemp = "{$stringA}&key=".$this->mch_key; |
|
739 | 739 | //步骤四:MD5或HMAC-SHA256C加密 |
740 | 740 | if ($hmacsha256) { |
741 | 741 | $str = hash_hmac("sha256", $stringSignTemp, $this->mch_key); |
742 | - } else { |
|
742 | + }else { |
|
743 | 743 | $str = md5($stringSignTemp); |
744 | 744 | } |
745 | 745 | //符转大写 |
@@ -759,8 +759,8 @@ discard block |
||
759 | 759 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
760 | 760 | |
761 | 761 | //试试手气新增,增加之后 curl 不报 60# 错误,可以请求到微信的响应 |
762 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证 SSL 证书 |
|
763 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不验证 SSL 证书域名 |
|
762 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证 SSL 证书 |
|
763 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证 SSL 证书域名 |
|
764 | 764 | //post提交方式 |
765 | 765 | curl_setopt($ch, CURLOPT_POST, TRUE); |
766 | 766 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); |
@@ -770,10 +770,10 @@ discard block |
||
770 | 770 | if ($data) { |
771 | 771 | curl_close($ch); |
772 | 772 | return $data; |
773 | - } else { |
|
773 | + }else { |
|
774 | 774 | $error = curl_errno($ch); |
775 | 775 | curl_close($ch); |
776 | - return "curl error, error code " . $error; |
|
776 | + return "curl error, error code ".$error; |
|
777 | 777 | //throw new WxPayException("curl出错,错误码:$error"); |
778 | 778 | } |
779 | 779 | } |