<?php
require_once('msnpauth.php');
define('ERR_AUTHENTICATION_FAILED', 911);
define('ERR_SERVER_UNAVAILABLE', 600);
define('ERR_USER_OFFLINE', 217);
define('ERR_TOO_MANY_SESSIONS', 800);
define('OK', 1);
class sendMsg
{
var $_passport;
var $_password;
var $_account;
var $_sockets;
var $_msg;
var $result;
var $error;
function simpleSend($passport, $password, $recipient, $message)
{
$this->login($passport, $password);
if ($this->result > 1)
{
return;
}
$this->createSession($recipient);
$this->sendMessage($message);
}
function login($passport, $password)
{
$this->_passport = $passport;
$this->_password = $password;
$this->_connect('NS');
$this->_send_data('NS', 'VER 0 MSNP8');
$this->_read();
}
function createSession($account)
{
// Stop if login failed.
if ($this->result > 1)
{
return;
}
$this->_account = $account;
$this->_send_data('NS', 'XFR 5 SB');
$this->_read();
}
function sendMessage($message, $font = NULL, $color = NULL)
{
// Stop if login failed.
if ($this->result > 1)
{
return;
}
$head = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n";
if (isset($font))
{
$font = rawurlencode($font);
$head .= "X-MMS-IM-Format: FN=$font; EF=; CO=$color; CS=0; PF=22\r\n";
}
$head .= "\r\n";
$len = strlen($head.$message);
$this->_send_data('SB', "MSG 3 U $len\r\n$head$message");
$this->result = OK;
}
function _connect($socket, $server = 'messenger.hotmail.com')
{
// This part does a DNS lookup on the server, and fails with error if it is not found.
// fsockopen doesn't return an error on DNS lookup failures, instead it outputs a warning (which we want to suppress).
if ((gethostbyname($server) == $server) && !is_numeric(str_replace('.', '', $server)))
{
$this->result = ERR_SERVER_UNAVAILABLE;
$this->error = 'Host not found'.$server;
return false;
}
ini_set('default_socket_timeout', 2);
$this->_sockets[$socket] = @fsockopen($server, 1863, $errno, $errstr, 2);
if ($this->_sockets[$socket] == false)
{
$this->result = $errno;
$this->error = $errstr;
return false;
}
return true;
}
function _read($socket = 'NS')
{
$r = false;
while ($this->_sockets[$socket] && !feof($this->_sockets[$socket]) && !$r)
{
$data = fgets($this->_sockets[$socket], 1024);
if (!$data)
{
continue;
}
$data = substr($data, 0, -2);
$r = $this->_process_data($data);
if ($r)
{
return;
}
}
}
function _send_data($socket, $data)
{
if (substr($data, 0, 3) == 'MSG')
{
// Don't send appending new line if it's a payload command. (MSG)
fputs($this->_sockets[$socket], $data);
}
else
{
fputs($this->_sockets[$socket], "$data\r\n");
}
}
function _process_data($data)
{
$params = explode(' ', $data);
switch ($params[0])
{
case 'VER':
$this->_send_data('NS', 'CVR 1 0x0409 winnt 5.1 i386 MSNMSGR 6.0.0254 MSMSGS '.$this->_passport);
break;
case 'CVR':
$this->_send_data('NS', 'USR 2 TWN I '.$this->_passport);
break;
case 'XFR':
$subParams = explode(':', $params[3]);
$r = $this->_connect($params[2], $subParams[0]);
if (!$r)
{
return true;
}
if ($params[2] == 'NS')
{
$this->_send_data('NS', 'VER 0 MSNP8');
}
elseif ($params[2] == 'SB')
{
$this->_send_data('SB', 'USR 1 '.$this->_passport.' '.$params[5]);
}
$this->_read($params[2]);
return true;
break;
case 'USR':
if ($params[2] == 'TWN')
{
$msnpauth = new MSNPAuth($this->_passport, $this->_password, $params[4]);
$hash = $msnpauth->getKey();
if (!$hash)
{
$this->result = ERR_AUTHENTICATION_FAILED;
$this->_send_data('NS', 'OUT');
return false;
}
$this->_send_data('NS', 'USR 3 TWN S '.$hash);
}
elseif ($params[2] == 'OK')
{
if (count($params) == 7)
{
$this->_send_data('NS', 'CHG 4 NLN');
return true;
}
else
{
$this->_send_data('SB', 'CAL 0 '.$this->_account);
}
}
break;
case 'JOI':
return true;
break;
// Error code handling
case '500':
case '600':
case '601':
case '910':
case '911':
case '921':
case '928':
$this->result = ERR_SERVER_UNAVAILABLE;
return true;
break;
case '800':
$this->result = ERR_TOO_MANY_SESSIONS;
return true;
break;
case '217':
$this->result = ERR_USER_OFFLINE;
return true;
break;
}
return false;
}
}
?>
CrMylive.
- 粉丝: 1w+
- 资源: 4万+
最新资源
- 负荷需求响应模型matlab 通过分时电价方式下的负荷需求响应模型得到负荷响应前后变化情况,可以看到明显呈现削峰填谷的作用
- SXU-python实验报告及笔记
- Halcon安全环检测例程资源包
- 六轴EtherCAT总线伺服涂布收卷机程序,采用六个伺服+变频器+编码器,动态测量频率,计算转速,再算频率,用变频器同步伺服电机速度,进行通讯控制,具备一定参考价值
- 社会事件检测任务数据集 14个SocialED python库相关的数据集
- MMCM Dynamic Reconfig Source
- 基于HSV颜色的保险丝分类的完整Halcon例程代码和示例图像文件
- 基于springboot的冬奥会科普平台源码(java毕业设计完整源码+LW).zip
- 三菱R系列PLC案例程序 三菱R系列ST、RD77MS定位以及三菱触摸屏配方功能,此案例还提供两个触摸屏实现异地操作,使操作更加方便快捷 此案例还通过CClink远程连接远程IO站以及机器人,将机器
- 高噪声环境下形状匹配的完整Halcon例程代码、示例图像以及相关配套文件
- SXU-大数据开源框架实验报告
- SocialED:一个社会事件检测任务的python库
- a6efce1b9d16fdfae3915991f36fde5995ee7b39.jpeg
- 基于springboot的社区医院管理服务系统源码(java毕业设计完整源码+LW).zip
- 台达DVP PLC与3台西门子V20变频器通讯程序 台达PLC与3台西门子变频器通讯,可靠稳定,同时解决西门子变频器断电重启后,自准备工作,无需人为准备 器件:台达DVP 14es PLC,昆仑通态
- 基于形状匹配与OCR的多图像处理Halcon例程代码及示例图像文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈