Passed
Push — master ( 65f1dc...1ff528 )
by ma
02:06
created
src/Gateways/Wechat.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         $this->saveState();
42 42
 
43 43
         //获取代理链接
44
-        if(isset($this->config['proxy_url'])){
44
+        if (isset($this->config['proxy_url'])) {
45 45
             return $this->getProxyURL();
46 46
         }
47 47
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'scope'         => $this->config['scope'],
55 55
             'state'         => $this->config['state'],
56 56
         ];
57
-        return $this->AuthorizeURL . '?' . http_build_query($params) . '#wechat_redirect';
57
+        return $this->AuthorizeURL.'?'.http_build_query($params).'#wechat_redirect';
58 58
     }
59 59
 
60 60
     /**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             'state'         => $this->config['state'],
73 73
             'redirect_uri'    => $this->config['callback'],
74 74
         ];
75
-        return $this->config['proxy_url'] . '?' . http_build_query($params);
75
+        return $this->config['proxy_url'].'?'.http_build_query($params);
76 76
     }
77 77
 
78 78
     /**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
             'union_id'=> isset($this->token['unionid']) ? $this->token['unionid'] : '',
110 110
             'access_token'=>isset($this->token['access_token']) ? $this->token['access_token'] : '',
111 111
             'channel' => ConstCode::TYPE_WECHAT,
112
-            'nickname'=> $result['nickname']??'',
112
+            'nickname'=> $result['nickname'] ?? '',
113 113
             'gender'  => isset($result['sex']) ? $result['sex'] : ConstCode::GENDER,
114
-            'avatar'  => $result['headimgurl']??'',
115
-            'session_key'  => $result['session_key']??'',
114
+            'avatar'  => $result['headimgurl'] ?? '',
115
+            'session_key'  => $result['session_key'] ?? '',
116 116
         ];
117
-        $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'],$this->type);
117
+        $userInfo['type'] = ConstCode::getTypeConst($userInfo['channel'], $this->type);
118 118
         return $userInfo;
119 119
     }
120 120
 
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getUserInfo()
129 129
     {
130
-        if($this->type == 'app'){//App登录
131
-            if(!isset($_REQUEST['access_token']) ){
130
+        if ($this->type == 'app') {//App登录
131
+            if (!isset($_REQUEST['access_token'])) {
132 132
                 throw new \Exception("Wechat APP登录 需要传输access_token参数! ");
133 133
             }
134 134
             $this->token['access_token'] = $_REQUEST['access_token'];
135
-        }elseif ($this->type == 'applets'){
135
+        }elseif ($this->type == 'applets') {
136 136
             //小程序
137 137
             return $this->applets();
138
-        }else {
138
+        } else {
139 139
             /** 获取token信息 */
140 140
             $this->getToken();
141 141
         }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
             'openid'=>$this->openid(),
147 147
             'lang'=>'zh_CN',
148 148
         ];
149
-        $data = $this->get(self::API_BASE . 'userinfo', $params);
149
+        $data = $this->get(self::API_BASE.'userinfo', $params);
150 150
         return json_decode($data, true);
151 151
     }
152 152
 
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
      * @return array|mixed|null
155 155
      * @throws \Exception
156 156
      */
157
-    public function applets(){
157
+    public function applets() {
158 158
         /** 获取参数 */
159 159
         $params = $this->accessTokenParams();
160 160
         $params['js_code'] = $params['code'];
161 161
 
162 162
         /** 获取access_token */
163
-        $token =  $this->get($this->jsCode2Session, $params);
163
+        $token = $this->get($this->jsCode2Session, $params);
164 164
         /** 解析token值(子类实现此方法) */
165 165
         $this->token = $this->parseToken($token);
166 166
         return $this->token;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         $data = json_decode($token, true);
217 217
         if (isset($data['access_token'])) {
218 218
             return $data;
219
-        }elseif (isset($data['session_key'])){
219
+        }elseif (isset($data['session_key'])) {
220 220
             //小程序登录
221 221
             return $data;
222 222
         } else {
Please login to merge, or discard this patch.
src/Connector/Gateway.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         if (!$config) {
86 86
             throw new \Exception('传入的配置不能为空');
87 87
         }
88
-        if(isset($_GET['referer']) && $config['callback']){
88
+        if (isset($_GET['referer']) && $config['callback']) {
89 89
             $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer'];
90 90
         }
91 91
         //默认参数
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
             'proxy'         => '',
99 99
             'state'         => '',
100 100
             'type'          => '',
101
-            'is_sandbox'    => false,//是否是沙箱环境
101
+            'is_sandbox'    => false, //是否是沙箱环境
102 102
         ];
103
-        $this->config    = array_merge($_config, $config);
104
-        foreach($this->config as $key=>$val){
105
-            if(property_exists($this,$key)) $this->$key=$val;
103
+        $this->config = array_merge($_config, $config);
104
+        foreach ($this->config as $key=>$val) {
105
+            if (property_exists($this, $key)) $this->$key = $val;
106 106
         }
107 107
         $this->timestamp = time();
108 108
     }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * Updater:
139 139
      * @return $this
140 140
      */
141
-    public function mustCheckState(){
141
+    public function mustCheckState() {
142 142
         $this->checkState = true;
143 143
         return $this;
144 144
     }
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      * @Author: TinyMeng <[email protected]>
149 149
      * @return array
150 150
      */
151
-    public function getConfig(){
151
+    public function getConfig() {
152 152
         return $this->config;
153 153
     }
154 154
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @param $token
158 158
      * @return $this
159 159
      */
160
-    public function setToken($token){
160
+    public function setToken($token) {
161 161
         $this->token = $token;
162 162
         return $this;
163 163
     }
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
      * 存储state
167 167
      * @Author: TinyMeng <[email protected]>
168 168
      */
169
-    public function saveState(){
169
+    public function saveState() {
170 170
         if ($this->checkState === true) {
171 171
             //是否开启session
172 172
             if (session_status() !== PHP_SESSION_ACTIVE) {
173 173
                 session_start();
174 174
             }
175
-            if(empty($this->config['state'])){
176
-                $this->config['state'] = Str::random();//生成随机state
175
+            if (empty($this->config['state'])) {
176
+                $this->config['state'] = Str::random(); //生成随机state
177 177
             }
178 178
             //存储到session
179 179
             $_SESSION['tinymeng_oauth_state'] = $this->config['state'];
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      * @Author: TinyMeng <[email protected]>
186 186
      * @throws \Exception
187 187
      */
188
-    public function checkState(){
188
+    public function checkState() {
189 189
         if ($this->checkState === true) {
190 190
             if (session_status() !== PHP_SESSION_ACTIVE) {
191 191
                 session_start();
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * Updater:
203 203
      * @return array
204 204
      */
205
-    protected function accessTokenParams(){
205
+    protected function accessTokenParams() {
206 206
         $params = [
207 207
             'client_id'     => $this->config['app_id'],
208 208
             'client_secret' => $this->config['app_secret'],
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @author: JiaMeng <[email protected]>
219 219
      * Updater:
220 220
      */
221
-    protected function getToken(){
221
+    protected function getToken() {
222 222
         if (empty($this->token)) {
223 223
             /** 验证state参数 */
224 224
             $this->checkState();
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             $params = $this->accessTokenParams();
228 228
 
229 229
             /** 获取access_token */
230
-            $token =  $this->POST($this->AccessTokenURL, $params);
230
+            $token = $this->POST($this->AccessTokenURL, $params);
231 231
             /** 解析token值(子类实现此方法) */
232 232
             $this->token = $this->parseToken($token);
233 233
         }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     protected function get($url, $params = [], $headers = [])
246 246
     {
247
-        return \tinymeng\tools\HttpRequest::httpGet($url, $params,$headers);
247
+        return \tinymeng\tools\HttpRequest::httpGet($url, $params, $headers);
248 248
     }
249 249
 
250 250
     /**
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
      */
259 259
     protected function post($url, $params = [], $headers = [])
260 260
     {
261
-        $headers[] = 'Accept: application/json';//GitHub需要的header
262
-        return \tinymeng\tools\HttpRequest::httpPost($url, $params,$headers);
261
+        $headers[] = 'Accept: application/json'; //GitHub需要的header
262
+        return \tinymeng\tools\HttpRequest::httpPost($url, $params, $headers);
263 263
     }
264 264
 
265 265
     /**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
      * M代表男性,F代表女性
268 268
      * @param $gender
269 269
      */
270
-    public function getGender($gender){
271
-        return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN;
270
+    public function getGender($gender) {
271
+        return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN;
272 272
     }
273 273
 }
Please login to merge, or discard this patch.