PHP 获取MSN好友列表的代码(2009-05-14测试通过)

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
<head>
<title>MSN 测试</title>
<meta name="generator" content="Bluefish 1.0.6"/>
<meta name="keywords" content="MSN"/>
<meta name="description" content="MSN test"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style type="text/css">
<!--
div {
font-family: arial, helvetica, sans-serif;
font-size : 13px ;
margin: 10px;
padding: 2px 10px 1px;
background-color: #C60;
color: #FFFFFF;
border-top: 1px solid #C90;
border-left: 1px solid #C90;
border-bottom: 1px solid #333;
border-right: 1px solid #333;
}
a:link {
color: #00FFBE;
}
--></style>
</head>
<body>
<div>

<?php
# filename: fm.php
# purpose: get MSN contact list
# author: http://qartis.com/?qmsn modified by Druggo

$username = $_POST['username'];
$password = $_POST['password'];
$debug = 0;
$trid = 0;
$proto = "MSNP10";

# start here
echo "通讯协议 $proto<br/>";
echo "开始登录<br/>";
# login now
$sbconn = fsockopen("messenger.hotmail.com",1863) or die("Can't connect to MSN server");
flush();
data_out("VER $trid $proto CVR0");
data_in();
data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username");
data_in();
data_out("USR $trid TWN I $username");

$temp = data_in();

if (!stristr($temp,":")){
if (substr($temp,0,3)==601){
#echo "Error: The MSN servers are currently unavailable.";
echo "很不幸,MSN的服务器又挂了 >.<<br/>";
die();
} else {
echo "连接失败!<br/>";
fclose($sbconn);
die();
}
}

@fclose($sbconn);
$temp_array = explode(" ",$temp);
$temp_array = explode(":",$temp_array[3]);
flush();
$sbconn = fsockopen($temp_array[0],$temp_array[1]) or die("error -_-#");
data_out("VER $trid $proto CVR0");
data_in();
flush();
data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username");
data_in();
data_out("USR $trid TWN I $username");
$temp = data_in();
$temp_array = explode(" ",$temp);
flush();
$TOKENSTRING = trim(end($temp_array));
#echo "authenticating";
echo "身份验证中……<br/>";
flush();

$nexus_socket = fsockopen("ssl://nexus.passport.com",443);
fputs($nexus_socket,"GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n");

while ($temp != "\r\n"){
$temp = fgets($nexus_socket,1024);
if (substr($temp,0,12)=="PassportURLs"){
$urls = substr($temp,14);
}
}

$temp_array = explode(",",$urls);
$temp = $temp_array[1];
$temp = substr($temp,8);

$temp_array = explode("/",$temp);
@fclose($nexus_socket);

$ssl_conn = fsockopen("ssl://".$temp_array[0],443);
fputs($ssl_conn,"GET /{$temp_array[1]} HTTP/1.1\r\n");
fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n");
fputs($ssl_conn,"User-Agent: MSMSGS\r\n");
fputs($ssl_conn,"Host: {$temp_array[0]}\r\n");
fputs($ssl_conn,"Connection: Keep-Alive\r\n");
fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n");
$temp = fgets($ssl_conn,512);

if (rtrim($temp) == "HTTP/1.1 302 Found"){
#echo "redirection";
echo "开始重定向<br/>";
flush();
while ($temp != "\r\n"){
$temp = fgets($ssl_conn,256);
if (substr($temp,0,9)=="Location:"){
$temp_array = explode(":",$temp);
$temp_array = explode("/",trim(end($temp_array)));
break;
}
}
@fclose($ssl_conn);
$ssl_conn = fsockopen("ssl://".$temp_array[2],443);
fputs($ssl_conn,"GET /{$temp_array[3]} HTTP/1.1\r\n");
fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n");
fputs($ssl_conn,"User-Agent: MSMSGS\r\n");
fputs($ssl_conn,"Host: {$temp_array[2]}\r\n");
fputs($ssl_conn,"Connection: Keep-Alive\r\n");
fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n");
} elseif (rtrim($temp)=="HTTP/1.1 401 Unauthorized"){
#echo "invalidcreds";
echo "验证失败!<br/>";
@fclose($ssl_conn);
die();
} else {
if (rtrim($temp) != "HTTP/1.1 200 OK"){
#echo "Unknown HTTP status code: $temp<br>";
echo "未知状态码 $temp<br/>";
flush();
die();
} else {
#echo "set_bar_len30?";
}
}

while ($temp != "\r\n"){
$temp = fgets($ssl_conn,1024);
if (substr($temp,0,19)=="Authentication-Info"){
$auth_info = $temp;
$temp = fgets($ssl_conn,1024);
if (substr($temp,0,14)!="Content-Length"){
$auth_info.= fgets($ssl_conn,1024);
}
break;
}
}
@fclose($ssl_conn);

$temp_array = explode("'",$auth_info);
flush();

data_out("USR $trid TWN S {$temp_array[1]}");
flush();

$temp=data_in();

flush();
$time_since_initmsg = time();
while(!strstr($temp,"ABCHMigrated") && is_string(trim($temp))){
if (substr($temp,0,3)=="sid"){
$sid = trim(substr($temp,5));
}
if (substr($temp,0,2)=="kv"){
$kv = trim(substr($temp,4));
}
if (substr($temp,0,7)=="MSPAuth"){
$mspauth = trim(substr($temp,9));
flush();
}
$temp = data_in();
}
$temp = data_in();
#echo "authenticated<br />";
echo "验证通过!<br/>";
flush();

#data_out("LST 9 RL");
#data_in();

data_out("SYN $trid 0 0");
#echo "retreiving_contact_list<br />";
echo "正在获取好友列表……<br/><br/>";
flush();
stream_set_timeout($sbconn,0,125000);

/* a lazy man doing this :D */
for($i=0;$i<160;$i++) # some say max is 150
{
$temp = data_in();
switch (substr($temp, 0, 3))
{
case "LST":
$temp_array = explode(" ",$temp);
$un = substr($temp_array[1], 2);
$nn = substr($temp_array[2], 2);
$nn1 = substr($temp_array[2], 0, 1);
if($nn1 == "F")
{
echo "<a href=\"mailto:$un\">$nn</a><br/>";
}
else
{
echo "曾经的好友: $un<br/>";
}
#echo $temp."<br/>";
break;
default:
# no nothing
break;
}
}
echo "列表结束";
@fclose($sbconn);

# end here

# functions

function data_out($data){
global $sbconn,$debug,$trid;
fputs($sbconn,$data."\r\n");
$trid++;
if ($debug && !empty($data)){ echo "> ".$data."<br>\r\n";}
}

function data_in(){
global $sbconn,$debug;
$temp = fgets($sbconn,256);
if ($debug && !empty($temp)){echo "< ".$temp."<br>\r\n";}
return $temp;
}
?>

</div>
</body>
</html>

有需要的朋友可以参考下,大约要延迟几秒。

(0)

相关推荐

  • PHP获取MSN好友列表类的实现代码

    复制代码 代码如下: <?phperror_reporting(7);class msn{    private $startcomm = 0;    private $username = '';    private $password = '';    private $commend = '';    private $domain = '';    private $socket = '';    private $challenge = '';    private $status

  • PHP 获取MSN好友列表的代码(2009-05-14测试通过)

    复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh&qu

  • python 获取微信好友列表的方法(微信web)

    如下所示: import urllib import urllib2 import os import time import re import cookielib import xml.dom.minidom import json tip = 0 uuid = '' successUrl = '' skey = '' wxsid = '' wxuin = '' pass_ticket = '' deviceId = 'e000000000000000' imagesPath = os.ge

  • 用asp获取微软安全更新列表的代码 小偷程序

    复制代码 代码如下: <% Function Bytes2bStr(vin,cSet) Dim BytesStream,StringReturn Set BytesStream = Server.CreateObject("ADODB.Stream") BytesStream.Type = 2 BytesStream.Open BytesStream.WriteText vin BytesStream.Position = 0 BytesStream.CharSet = cSet

  • php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)

    CURL技术说白了就是模拟浏览器的动作实现页面抓取或表单提交,通过此技术可以实现许多有去的功能. 复制代码 代码如下: <?php error_reporting(0); //邮箱用户名(不带@163.com后缀的) $user = 'papatata_test'; //邮箱密码 $pass = '000000'; //目标邮箱 //$mail_addr = uenucom@163.com'; //登陆 $url = 'http://reg.163.com/logins.jsp?type=1&

  • 基于Python的微信机器人开发 微信登录和获取好友列表实现解析

    首先需要安装itchat库,可以pip install itchat安装,也可以在pycharm里安装 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import itchat def get_friends(): friends = itchat.get_friends(update=True) #获取微信好友列表,如果设置update=True将从服务器刷新列表 for i in friends: print(i) def m

  • 使用qt quick-ListView仿微信好友列表和聊天列表的示例代码

    1.视图模型介绍 在Qml中.常见的View视图有: ListView: 列表视图,视图中数据来自ListModel.XmlListModel或c++中继承自QAbstractItemModel或QAbstractListModel的自定义模型类 TableView: 和excel类似的视图 GridView: 网格视图,类似于home菜单那样,排列着一个个app小图标 PathView: 路径视图,可以根据用户自定义的path路径来显示不一样的视图效果 SwipeView: 滑动视图,使用一组

  • 使用UItableview在iOS应用开发中实现好友列表功能

    基本实现 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController 复制代码 代码如下: //  YYViewController.h //  02-QQ好友列表(基本数据的加载) // //  Created by apple on 14-5-31. //  Copyright (c) 2014年 itcase. All rights reserved. // #import <UIKit/UIKit.h> @interface YY

  • 微信小程序开发之好友列表字母列表跳转对应位置

    微信小程序开发之好友列表字母列表跳转对应位置 前言: 在小程序里实现微信好友列表点击右侧字母列表跳转对应位置效果.写了个demo,核心部分很简单,所以没多少注释,如果遇到问题就加群问我吧. 核心技术点: 1.小程序scroll-view组件的scroll-into-view, scroll-with-animation. scroll-y属性. 2.小程序的touch事件的应用. 3.Js定时器的应用. view页面代码: index.wxml class="container" sc

  • Android中使用listview实现qq/微信好友列表

    首先附上运行结果: 如果你没有学过listview请你先看一看基本知识.不想再说的那么细了 太多了. 首先是listview布局 <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lv_view" android

随机推荐