|
@@ -3,19 +3,23 @@
|
|
|
namespace App\Utils;
|
|
|
|
|
|
use Http;
|
|
|
+use Illuminate\Http\Client\PendingRequest;
|
|
|
|
|
|
class QQInfo
|
|
|
{
|
|
|
+ private static PendingRequest $basicRequest;
|
|
|
+
|
|
|
public static function getQQAvatar(string $qq): ?string
|
|
|
{
|
|
|
+ self::$basicRequest = Http::timeout(15)->withOptions(['http_errors' => false])->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36')->replaceHeaders(['Referer' => null]);
|
|
|
+
|
|
|
$ret = null;
|
|
|
- $source = 0;
|
|
|
+ $source = 1;
|
|
|
|
|
|
while ($source <= 4 && $ret === null) {
|
|
|
$ret = match ($source) {
|
|
|
- 0 => self::qZonePortrait("https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins=$qq", $qq),
|
|
|
- 1 => self::qZonePortrait("https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=$qq", $qq),
|
|
|
- 2 => self::qLogo("https://q.qlogo.cn/g?b=qq&nk=$qq&s=100"),
|
|
|
+ 1 => self::qLogo("https://q.qlogo.cn/g?b=qq&nk=$qq&s=100"),
|
|
|
+ 2 => self::qZonePortrait("https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=$qq", $qq),
|
|
|
3 => self::qLogo("https://thirdqq.qlogo.cn/g?b=qq&nk=$qq&s=100"),
|
|
|
4 => self::qqLogin($qq),
|
|
|
};
|
|
@@ -27,7 +31,7 @@ class QQInfo
|
|
|
|
|
|
private static function qZonePortrait(string $url, string $qq): ?string
|
|
|
{ //向接口发起请求获取json数据
|
|
|
- $response = Http::timeout(15)->get($url);
|
|
|
+ $response = self::$basicRequest->get($url);
|
|
|
if ($response->ok()) {
|
|
|
$message = mb_convert_encoding($response->body(), 'UTF-8', 'GBK');
|
|
|
if (str_contains($message, $qq)) { // 接口是否异常
|
|
@@ -42,7 +46,7 @@ class QQInfo
|
|
|
|
|
|
private static function qLogo(string $url): ?string
|
|
|
{
|
|
|
- $response = Http::timeout(15)->get($url);
|
|
|
+ $response = self::$basicRequest->get($url);
|
|
|
if ($response->ok()) {
|
|
|
return $url;
|
|
|
}
|
|
@@ -52,7 +56,7 @@ class QQInfo
|
|
|
|
|
|
private static function qqLogin(string $qq): ?string
|
|
|
{
|
|
|
- $response = Http::timeout(15)->get("https://ptlogin.qq.com/getface?imgtype=3&uin=$qq");
|
|
|
+ $response = self::$basicRequest->get("https://ptlogin.qq.com/getface?imgtype=3&uin=$qq");
|
|
|
if ($response->ok()) {
|
|
|
$data = $response->body();
|
|
|
if ($data) {
|