@@ -25,20 +25,16 @@ public static function start(\Swoole\Http\Request $request, \Swoole\Http\Respons
25
25
null
26
26
];
27
27
}
28
- /**
29
- *
30
- * @var \Controller $controller
31
- */
32
28
$ controller = $ router ->getController ($ response );
33
29
if ($ controller instanceof Controller \StaticResourceController) {
34
30
$ controller ->begin ()->endRequest ();
35
31
} else {
36
32
if ($ router ->isWebhook ()) {
37
33
\session::startForWebhook ();
38
34
} else {
39
- if ($ router ->getMethod () == ' POST ' ) {
35
+ if (' POST ' === $ router ->getMethod ()) {
40
36
$ session_started = self ::parseRequest ($ request , $ response , $ controller );
41
- if ($ session_started === null ) {
37
+ if (null === $ session_started ) {
42
38
return [
43
39
200 ,
44
40
'replay request ' ,
@@ -54,7 +50,7 @@ public static function start(\Swoole\Http\Request $request, \Swoole\Http\Respons
54
50
}
55
51
\cache::select (1 );
56
52
$ controller ->checkAuthority ()->validate ()->begin ();
57
- if ($ router ->getMethod () != ' GET ' ) {
53
+ if (' GET ' !== $ router ->getMethod ()) {
58
54
$ controller ->jsonResponse ();
59
55
} else {
60
56
$ controller ->endRequest ();
@@ -99,7 +95,7 @@ public static function start(\Swoole\Http\Request $request, \Swoole\Http\Respons
99
95
$ cnmsg = '服务器出现内部错误,请稍后重试 ' ;
100
96
$ data = null ;
101
97
}
102
- if (isset ($ router ) && $ router ->getMethod () == ' GET ' &&
98
+ if (isset ($ router ) && ' GET ' === $ router ->getMethod () &&
103
99
\session::getAgentMap ()->echoErrorMsgWhenMethodGet (\session::getAgent ())) {
104
100
$ response ->header ('Content-Type ' , 'text/html; charset=UTF-8 ' );
105
101
$ response ->end ($ cnmsg );
@@ -221,6 +217,10 @@ private static function parseRequest(\Swoole\Http\Request $request, \Swoole\Http
221
217
} else {
222
218
$ sid = null ;
223
219
}
220
+ if (! isset ($ data ->ua )) {
221
+ throw new \ExceptionToResponse ('Unrecognizable data ' , '报文无法识别 ' );
222
+ }
223
+ \session::getAgentMap ()->getAgentId ($ data ->ua );
224
224
if ($ flag ) {
225
225
if (! property_exists ($ data , 'timestamp ' ) || abs ($ data ->timestamp / 1000 - \Time \now ()) > 1200 * 3600 ) {
226
226
throw new \ExceptionToResponse \TimeTooDifferentException ();
@@ -246,11 +246,11 @@ private static function parseRequest(\Swoole\Http\Request $request, \Swoole\Http
246
246
} else {
247
247
$ response_string = null ;
248
248
}
249
+ \cache::select (1 );
249
250
} catch (\Swango \Cache \RedisErrorException $ e ) {
250
251
\cache::select (1 );
251
252
throw $ e ;
252
253
}
253
- \cache::select (1 );
254
254
if (isset ($ response_string ) && is_string ($ response_string )) {
255
255
$ response ->header ('Access-Control-Allow-Headers ' ,
256
256
'Rsa-Certificate-Id, Mango-Rsa-Cert, Mango-Request-Rand, Content-Type ' );
@@ -273,7 +273,7 @@ private static function parseRequest(\Swoole\Http\Request $request, \Swoole\Http
273
273
}
274
274
\SysContext::set ('request_post ' , $ data ->data );
275
275
if ($ controller ::USE_SESSION && ! $ controller ::START_SESSION_LATER && property_exists ($ data , 'sid ' )) {
276
- \session::start ($ request , $ response , $ sid , $ data ->ua ?? ' wmp ' );
276
+ \session::start ($ request , $ response , $ sid , $ data ->ua );
277
277
return true ;
278
278
} else {
279
279
return false ;
0 commit comments