PHP实现第四方QQ微信扫码登陆,不接入qq互联以及微信开发者平台

PHP实现第四方QQ微信扫码登陆,不接入qq互联以及微信开发者平台

作者 : 资源客 本文共5270个字,预计阅读时间需要14分钟 发布时间: 2020-04-10 共197人阅读

php实现不接入鹅厂官方接口用户微信qq扫码登陆的实现

前言:想找一个整合工具,方便自己直接拿来用。找了半天,没找到(或许搜索关键字不对)。只能自己造个轮子出来了PS:微信是直接拿论坛大佬写好了的。
目前也就整合了下QQ微信的扫码登陆。

自己抓的QQ包以及整合了网上一些已经封装好了的代码
具体如下:
QQ:

 preg_match('/qrsig=(.*?);/',$arr['header'],$match);
if($qrsig=$match[1])
return array('code'=>200,'qrsig'=>$qrsig,'data'=>base64_encode($arr['body']));
else
return array('code'=>400,'msg'=>'二维码获取失败');
}%0s[1];
}
if($pskey){
if(isset($_GET['findpwd'])){
$_SESSION['findpwd_qq']=$uin;
}
return array('code'=>200,'uin'=>$uin,'skey'=>'@'.$skey[1],'pskey'=>$pskey,'superkey'=>$superkey[1],'nick'=>$r[5]);
}else{
return array('code'=>201,'msg'=>'登录成功,获取相关信息失败!'.$r[2]);
}
}elseif($r[0]==65){
return array('code'=>400,'msg'=>'二维码已失效。');
}elseif($r[0]==66){
return array('code'=>202,'msg'=>'二维码未失效。');
}elseif($r[0]==67){
return de);
preg_match('/redirect_uri="(.*?)"/', $body, $url);
if ($code[0] == '200') {

$body = $this->curl($url[1]);
if (strpos($body,'1203'))
{
$ret['code'] = 400;
$ret['msg'] = "短时间内不能重复进行微信登陆";
return $ret;
} 
preg_match('/<wxuin>(\d*?)<\/wxuin>/', $body, $wxuin);
$ret['code'] = 200;
$ret['data']['uin'] = $wxuin[1];
$ret['data']['type'] = 'wx';
$ret['msg'] = '登录成功';
} else {
$ret['code'] = 408;
$ret['msg'] = '请使用手机微信扫码登录';
}
return $ret;
}
}

为了方便跳用,这里我又封装了一个类
动态传入QQ微信的类名字符串快速实例化

Tencent类:

<?php Class Tencent{ protected $path = __DIR__ . '/'; private $cl; /* * 动态传入QQ或WX字符串,自动转换对应的api类登录 */ public function __construct($type) { //注册自动加载函数 spl_autoload_register([$this,'Psr4Autoload']); //引入curl $this->cl = new $type();
    }
    public function Psr4Autoload($class)
    {
    $class_file = $this->path .'/'. $class . '.php';
    if (file_exists($class_file))
    {
        include "$class_file";
    }else{
        die('类文件'.$class_file .'不存在');
    }
    }
    public function QRcode()
    {
        return call_user_func([$this->cl,__FUNCTION__]);
    }
    public function ListenQR(...$args)
    {
        return call_user_func([$this->cl,__FUNCTION__],$args);
    }
    public function __call($name, $arguments)
    {
       call_user_func_array([$this->cl,$name],(array)$arguments);
    }
}

以及最后一个curl类:

<?php class Curl_Api { public $ua = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"; public function get_curl($url,$post=0,$referer=0,$cookie=0,$header=0,$ua=0,$nobaody=0){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $httpheader[] = "Accept: application/json"; $httpheader[] = "Accept-Encoding: gzip,deflate,sdch"; $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; $httpheader[] = "Connection: keep-alive"; curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); if($post){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if($header){ curl_setopt($ch, CURLOPT_HEADER, TRUE); } if($cookie){ curl_setopt($ch, CURLOPT_COOKIE, $cookie); } if($referer){ curl_setopt($ch, CURLOPT_REFERER, $referer); } if($ua){ curl_setopt($ch, CURLOPT_USERAGENT,$ua); }else{ curl_setopt($ch, CURLOPT_USERAGENT,$this->ua);
        }
        if($nobaody){
            curl_setopt($ch, CURLOPT_NOBODY,1);
 
        }
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }
    function curl($url, $paras = array()) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $httpheader[] = "Accept:*/*";
        $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
        $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
        $httpheader[] = "Connection:close";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
        if ($paras['ctime']) { // 连接超时
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $paras['ctime']);
        }
        if ($paras['rtime']) { // 读取超时
            curl_setopt($ch, CURLOPT_TIMEOUT_MS, $paras['rtime']);
        }
        if ($paras['post']) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
        }
        if ($paras['header']) {
            curl_setopt($ch, CURLOPT_HEADER, true);
        }
        if ($paras['cookie']) {
            curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
        }
        if ($paras['refer']) {
            if ($paras['refer'] == 1) {
                curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
            } else {
                curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
            }
        }
        if ($paras['ua']) {
            curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
        } else {
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
        }
        if ($paras['nobody']) {
            curl_setopt($ch, CURLOPT_NOBODY, 1);
        }
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }
     public function get_curl_split($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt(%2件就好

include "Lib/Tencent/Tencent.php";
$wx = new Tencent("Wechat");
$ret = $wx->QRcode();
?>
<!--直接生成QR码、记得把uuid给带上-->
<img id="wx" src="data:text/html;base64,<?=$ret['qrcode']?>" uuid="<?=$ret['uuid']?>">
 
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
    // setTimeout(function () {
    //     var uuid = document.getElementById('wx').getAttribute("uuid");
    //     var url ="/ajax.php?uuid="+uuid;
    //     console.log(url);
    // },1000);
    //每秒去查询一次二维码状态
    $(document).ready(function () {
        setInterval(function () {
            var uuid = document.getElementById('wx').getAttribute("uuid");
            var url ="/ajax.php?uuid="+uuid;
            $.ajax({type:"GET",url:url,success:function (data) {
                    if (data.code == 200)
                    {
                        alert("登陆成功,uin为:"+data.uid);
                    }
                }});
        },1000);
    });
 
</script>

ajax.php :

//var_dump($ret);
echo json_encode($ret,true);exit;

数据库用户表多一个qq和wxuin字段、用于保存用户绑定的QQ和微信
上面那个仅仅只是个例子,可能写的不是很好。大佬勿喷
有什么疑问可在帖子下方发表一下

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请不要用于商业用途!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"qq301.com",如遇到无法解压的请联系管理员!
资源客是一个优秀的分享资源站,本站资源均为各位友友分享而来,特殊原创会标明如有侵犯版权等可联系772955675@qq.com 删除

资源客 » PHP实现第四方QQ微信扫码登陆,不接入qq互联以及微信开发者平台