前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >获取QQ头像外链的加密URL

获取QQ头像外链的加密URL

作者头像
Qicloud-W
发布2023-11-17 18:24:49
2210
发布2023-11-17 18:24:49
举报
文章被收录于专栏:七云's Blog
代码语言:javascript
复制
<?php
/*
 * @Author: Qicloud
 * @Date: 2020-12-05 22:03:33
 * @Title: API
 * @Project: 获取QQ头像外链的加密URL
 * @QQ: 66547997
 * @当浑浊变成一种常态,清白就是一种罪。
 */
class Api
{
    public static function get_curl($url,$header = 0, $ua = 0, $nobaody = 0)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $clwl[] = "Accept:*/*";
        $clwl[] = "Accept-Encoding:gzip,deflate,sdch";
        $clwl[] = "Accept-Language:zh-CN,zh;q=0.8";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $clwl);
        if ($header) {
            curl_setopt($ch, CURLOPT_HEADER, TRUE);
        }
        if ($ua) {
            curl_setopt($ch, CURLOPT_USERAGENT, $ua);
        } else {
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0');
        }
        if ($nobaody) {
            curl_setopt($ch, CURLOPT_NOBODY, 1);
            //主要头部
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //跟随重定向
        }
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }
    /**
     * @param Json信息输出
     * @arr:需要转换的数组
     */
    public static function json($arr = array(), $code = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
    {
        header("Content-Type:text/json");
        header("Access-Control-Allow-Origin: *");
        exit(json_encode($arr, $code));
    }
    /**
     * 获取GET POST表单数据
     */
    public static function GetData($key = "")
    {
        if (empty($key)) {
            return $_REQUEST;
        }
        if (isset($_REQUEST[$key])) {
            return $_REQUEST[$key];
        } else {
            return null;
        }
    }
}
$qquin = Api::GetData('qq'); //qq参数
if (!empty($qquin)) {
    $size = Api::GetData('size');
    if ($size == 640) {
        $add = Api::get_curl('https://ptlogin2.qq.com/getface?uin=' . $qquin . '&imgtype=3');
        $preg = '#https://.*s=100#'; //使用正则匹配图像URL
        preg_match($preg, $add, $match);
        //var_dump($match);
        $imgurl = $match['0'];
        $deimg = str_replace("s=100", "s=640", $imgurl); //替换图片尺寸
        $qrand = 'q' . rand(1, 4);
        $img = str_replace("thirdqq", $qrand, "$deimg"); //替换域名前缀
        Api::json(['code' => 200, 'msg' => 'success', 'imgurl' => $img]);
    } else {
        $add = Api::get_curl('https://ptlogin2.qq.com/getface?uin=' . $qquin . '&imgtype=3');
        $preg = '#https://.*s=100#'; //使用正则匹配图像URL
        preg_match($preg, $add, $match);
        //var_dump($match);
        $imgurl = $match['0'];
        $qrand = 'q' . rand(1, 4);
        $img = str_replace("thirdqq", $qrand, $imgurl); //替换域名前缀
        Api::json(['code' => 200, 'msg' => 'success', 'imgurl' => $img]);
    }
} else {
    Api::json(['code' => -1, 'msg' => 'errors', 'imgurl' => null]);
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档