欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP模拟QQ登录,发送和接收信息的例子

程序员文章站 2022-05-06 20:21:27
...
下面我们一起来看一个PHP模拟QQ登录,发送和接收信息的例子,希望此例子对各位同学会有所帮助.

PHP实例代码如下:

';
        echo $v['msg'] . '
'; echo '————————
'; } } function qqLogin($qq_num, $qq_pwd) { //登录帐号 $data = httpGet('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; $data = httpPost($action, $params, 1); $action = preg_match("/sid=(.+?)&/", $data, $matches); $sid = $matches[1]; if ($sid) { return $sid; } else { echo '登录失败'; } } function sendMsg($sid, $to_num, $msg) { //发送消息 $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; $data = httpPost($url, $params); if (preg_match('/消息发送成功/', $data)) echo '发送成功
'; else echo '发送失败'; } function getMsg($sid, $qq_num) { //获取消息 $url = "http://q16.3g.qq.com/g/s?sid=" . $sid . "&u=" . $qq_num . "&saveURL=0&aid=nqqChat"; $data = httpGet($url); preg_match_all('/
s+

(.+?)

s+

(.+?)

/s', str_replace("rn", "", $data) , $m); foreach ($m[1] as $k => $v) { $tmp['title'] = $v; $tmp['msg'] = $m[2][$k]; $r[] = $tmp; } return $r; } function httpGet($url, $header = 0) { //GET请求 $opt = array( CURLOPT_URL => $url, CURLOPT_HEADER => $header, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 60, CURLOPT_USERAGENT => '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' ); return curlRun($opt); } function httpPost($url, $data, $header = 0) { //POST请求 $opt = array( CURLOPT_URL => $url, CURLOPT_HEADER => $header, CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 60, CURLOPT_POSTFIELDS => http_build_query($data) , CURLOPT_USERAGENT => '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' ); return curlRun($opt); } function curlRun($opt) { $ch = curl_init(); curl_setopt_array($ch, $opt); $r = curl_exec($ch); curl_close($ch); return $r; } ?>