body()); return true; } if ($response->successful()) { $res = $response->json(); self::$request->response_data = json_encode($res, JSON_UNESCAPED_UNICODE); self::$request->save(); if ($res['code'] == "200") { return $res; } else { throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $res['msg'])); } } else { $status = $response->status(); // 获取响应体作为字符串 $body = $response->body(); self::$request->response_data = $body; self::$request->save(); throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $status . "body:" . $body)); } } public static function Post($url,$data,$mark) { self::RequestLog($url, $data, $mark, '.Net转发'); $response = Http::post($url,$data); if ($response->successful()) { $res = $response->json(); $res_string=json_encode($res, JSON_UNESCAPED_UNICODE); $str_len = mb_strlen($res_string, 'utf-8'); $str_size = $str_len / 1024; $save_res = $res_string; if ($str_size > 10) $save_res = '{"data":"Row size too large"}'; self::$request->response_data = $save_res; self::$request->save(); if ($res['code'] == "200") { return $res; } else { throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $res['msg'])); } } else { $status = $response->status(); // 获取响应体作为字符串 $body = $response->body(); self::$request->response_data = $body; self::$request->save(); throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $status . "body:" . $body)); } } public static function Post2($url,$data,$mark) { self::RequestLog($url, $data, $mark, '.Net转发'); $response = Http::post($url,$data); if ($response->successful()) { $res = $response->json(); $res_string=json_encode($res, JSON_UNESCAPED_UNICODE); $str_len = mb_strlen($res_string, 'utf-8'); $str_size = $str_len / 1024; $save_res = $res_string; if ($str_size > 10) $save_res = '{"data":"Row size too large"}'; self::$request->response_data = $save_res; self::$request->save(); return $res; } else { $status = $response->status(); // 获取响应体作为字符串 $body = $response->body(); self::$request->response_data = $body; self::$request->save(); throw new HttpResponseException(\Yz::echoError1("调用".$mark."接口失败:" . $status . "body:" . $body)); } } public static function RequestLog($url, $post_data, $mark, $code = 0) { self::CheckTableName(); foreach ($post_data as $key => $post_datum) { $str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE), 'utf-8'); $str_size = $str_len / 1024; if ($str_size > 10) { $post_data["$key"] = 'Row size too large'; } } $post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE); self::$request->code = $code; self::$request->mark = $mark; self::$request->post_data = $post_data == '[]' ? '{}' : $post_data; self::$request->request_url = $url; self::$request->save(); } public static function CheckTableName() { $table_name = 'zz_peis_log_' . date('ym'); $table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0]; if ($table_count->c === 0) { Schema::create($table_name, function (Blueprint $table) { $table->id(); $table->string('code', 50)->index(); $table->string('mark', 50)->index(); $table->text('post_data'); $table->text('response_data')->nullable(); $table->string('request_url', 1000); $table->timestamps(); }); } self::$request = new \App\Models\PEISLog(); self::$request->setTable($table_name); } }