Home php教程 PHP源码 phpQQ登陆

phpQQ登陆

May 25, 2016 pm 05:10 PM

代码

class qq {

    public $sid;
    public $http;
    public $qq_num;

    function __construct() {
        $this->http = new http_no_cookie;
    }

    function login($qq_num, $qq_pwd) {
       echo  $data = $this->http->get("http://pt.3g.qq.com/");
        $action = preg_match("/action=\"(.+)?\"/", $data, $matches);
        $action = $matches[1];
        $params = array();
        $params["login_url"] = "http://pt.3g.qq.com/s?aid=nLogin";
        $params["sidtype"] = 1;
        $params["loginTitle"] = "手机腾讯网";
        $params["bid"] = 0;
        $params["qq"] = $qq_num;
        $params["pwd"] = $qq_pwd;
        $params["loginType"] =1;
        echo $data = $this->http->post($action, http_build_query($params));
		if(preg_match("/http:\/\/vc.gtimg.com\//",$data,$matches)){
			echo "需要输入验证码";
			return 0;
			exit;
		}

		if(preg_match("/密码错误/",$data,$matches)){
		    echo "密码错误";
			return 1;
			exit;
		}
        $action = preg_match("/sid=(.+?)&/", $data, $matches);
        $this->sid = $matches[1];
		return $this->sid;
    }

    function sendMsg($to_num, $msg, $sid = 0) {
        $sid = $sid ? $sid : $this->sid;
        if (!$sid)
            exit("sid值未传入进去");
        $params = array();
        $params["msg"] = $msg;
        $params["u"] = $to_num;
        $params["saveURL"] = 0;
        $params["do"] = "send";
        $params["on"] = 1;
        $params["aid"] = "发送";
        $url = "http://q16.3g.qq.com/g/s?sid=" . $sid;
        echo $data = $this->http->post($url, http_build_query($params));
		return $data;
    }

    function getMsg($qq_num = 0, $sid = 0) {
        $qq_num = $qq_num ? $qq_num : $this->qq_num;
        if (!$qq_num)
            exit("qq_num值未传入进去");
	    $sid = $sid ? $sid : $this->sid;
        if (!$sid)
            exit("sid值未传入进去");
        $url = "http://q16.3g.qq.com/g/s?sid=" . $sid . "&3G_UIN=" . $qq_num . "&saveURL=0&aid=nqqChat";
        $data = $this->http->get($url);
        preg_match("/name=\"u\" value=\"(\d+)\"/", $data, $matches);
        $result["qq"] = $matches[1];
        $data = explode("<form", $data);
        $data = $data[0];
        preg_match_all("/<p>(.+)?<\/p>/", $data, $matches);
        unset($matches[1][0]);
        $result["content"] = $matches[1];
        return $result;
    }
	function logout($sid){
		$url="http://pt.3g.qq.com/s?sid=".$sid."&aid=nLogout";
		echo $url;
		echo $this->http->get($url);
	}
	function getFriendsList($qq_num = 0, $sid = 0){
	    $result=array();

		$qq_num = $qq_num ? $qq_num : $this->qq_num;
        if (!$qq_num)
            exit("qq_num值未传入进去");
        $sid = $sid ? $sid : $this->sid;
        if (!$sid)
            exit("sid值未传入进去");
		$url="http://q16.3g.qq.com/g/s?aid=nqqchatMain&sid=".$sid."&myqq=".$qq_num;
		while(true){
	    $i=1;
		$url.="&p=".$i;
		$data=$this->http->get($url);
		preg_match_all("/u=(.+?)&/",$data,$matches);
		foreach($matches[1] as $key=>$value){
			$result[]=$value;
		}
		if(count($matches[1])<13)
			break;
		$i++;
	   }
	   return $result;
	}
}
Copy after login

2. http.class.php

<?php
class http {
    private $curl;
    public $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13";
     
    public function get($url) {
        $this->curl = curl_init();
        curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt($this->curl, CURLOPT_URL, $url);
        curl_setopt($this->curl, CURLOPT_HEADER, 1);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $this->user_agent);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($this->curl);
        curl_close($this->curl);
        return $data;
    }
    public function post($url, $params) {
        $this->curl = curl_init();
        curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt($this->curl, CURLOPT_URL, $url);
        curl_setopt($this->curl, CURLOPT_HEADER, 1);
        //curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($this->curl, CURLOPT_POST, 1);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $this->user_agent);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($this->curl);
        curl_close($this->curl);
        return $data;
    }
}
?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)