- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试连接到 Yahoo Messenger 帐户并使用 PHP 或 CURL 发送 PM。我从 phpclasses.org 下载了以下类,它连接到 eBuddy Web Messenger(http://www.ebuddy.com/)以将消息发送到所需的 IM原来的代码不行,所以我做了一些修改(原来的语句被注释掉了),还是不行。
如果有人能帮我弄清楚我哪里出了问题,我将不胜感激。
谢谢。
<?php
class My_Yahoo_Messenger {
/**
* Server host
* @access private
*/
var $serverHost = 'denver.ebuddy.com';
/**
* Login user name
* @access private
*/
var $username = null;
/**
* Login session
* @access private
*/
var $_cookie = null;
/**
*Connection handle
* @access private
*/
var $fp_handle = null;
/**
* Construct
*@params:
* username: String Yahoo account user name
* password: String Yahoo account password
* login status: Boolean true from visible
* @access public
*/
function __construct($username, $password, $inv = false)
{
$this->login($username, $password, $inv);
}
/**
* Construct PHP 4
*@params:
* username: String Yahoo account user name
* password: String Yahoo account password
* login status: Boolean true from visible
* @access public
*/
function My_Yahoo_Messenger($username, $password, $inv = false)
{
$this->__construct($username, $password, $inv);
}
/**
* Function provide login to yahoo account
*@params:
* username: String Yahoo account user name
* password: String Yahoo account password
* login status: Boolean true from visible
*@return: String cookie data
* @access public
*/
function login($username, $password, $inv = false)
{
$inv = $inv === false ? 'FALSE' : 'TRUE';
$username = urlencode($username);
$password = urlencode($password);
$content = "password=$password&network=yahoo&initial=FALSE&login_network=yahoo&username=$username&pwd=&init_status=$inv";
//$this->_createConnection('POST', '/vo074922/login.jsp', 'http://www.ebuddy.com/?web_messenger', "yahoo_uname=$username; Emessenger=yahoo; network=YAHOO;", $content, false);
$this->_createConnection('POST', '/vo7.3.11/start.html', 'http://www.ebuddy.com/?web_messenger', "yahoo_uname=$username; Emessenger=yahoo; network=YAHOO;", $content, false);
$headers = array();
$content = '';
$atStart = true;
$atHeader= true;
while (!feof($this->fp_handle)) {
$line = fgets($this->fp_handle, 4096);
if($atStart) {
$atStart = false;
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
break;
}
}
if ($atHeader) {
if (trim($line) == '') {
$atHeader = false;
continue;
}
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
continue;
}
$key = strtolower(trim($m[1]));
$val = trim($m[2]);
if (isset($headers[$key])) {
if (is_array($headers[$key])) {
$headers[$key][] = $val;
} else {
$headers[$key] = array($headers[$key], $val);
}
} else {
$headers[$key] = $val;
}
continue;
}
$content .= $line;
}
foreach ($headers as $name=>$header)
{
switch (true) {
case strpos($name, 'location') !== false :
if(preg_match('@time\s*=\s*([0-9]+)@i', $header, $m)) {
$this->time = $m[1];
}
if(preg_match('@hash\s*=\s*([a-z0-9]+)@i', $header, $m)) {
$this->hash = $m[1];
}
break;
case strpos($name, 'set-cookie') !== false :
if(is_array($header)) $header = implode(';', $header);
$this->_cookie = $header;
break;
}
}
@fclose ($this->fp_handle);
$this->username = $username;
return $this->_cookie;
}
/**
* Function for send message to fav. yahoo account
*@params:
* to: String Yahoo account
* message: String Your message
* @access public
*/
function sendMessage($to, $message)
{
$message = urlencode($message);
$message = preg_replace( '!<br.*>!iU', "\n", $message );
$hash = isset($this->hash) ? $this->hash : '';
$time = isset($this->time) ? $this->time : time();
$content = "e_hash=$hash&e_action=send_message&e_user=$to&e_message=$message&e_format=FN%3DVerdana%3B%20EF%3D%3B%20CO%3D000000%3B%20CS%3D0%3B%20PF%3D00%3B%20RL%3D0&e_network=YAHOO&_=";
//$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo074922/main.jsp?hash=$hash&u=$this->username&network=YAHOO&time=$time", $this->_cookie, $content, false);
$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo7.3.11/main.html?hash=$hash&u=$this->username&network=YAHOO&time=$time", $this->_cookie, $content, false);
}
/**
* Function for get unread message from yahoo account
*@return : Array From:Message
* @access public
*/
function getMessage()
{
$content = "e_format=short&e_action=poll&e_time=0&e_timeout=10000&e_max=100&_=";
$hash = isset($this->hash) ? $this->hash : '';
$time = isset($this->time) ? $this->time : time();
//$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo074922/main.jsp?hash=$hash&u=$this->username&network=YAHOO&time=$time", null, $content, false);
$this->_createConnection('POST', '/dispatch', "http://".$this->serverHost."/vo7.3.11/main.html?hash=$hash&u=$this->username&network=YAHOO&time=$time", null, $content, false);
$reciveMessage = array();
$atStart = true;
$atHeader= true;
while (!feof($this->fp_handle)) {
$line = fgets($this->fp_handle, 4096);
if($atStart) {
$atStart = false;
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
break;
}
}
if ($atHeader) {
if (trim($line) == '') {
$atHeader = false;
continue;
}
if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
continue;
}
continue;
}
if(strpos($line, 'from') !== false) {
$from = null; $message = null;
if(preg_match('@from\s*=\s*([^;]*);?@i', $line, $m)) {
$from = $m[1];
}
if(preg_match('@msg\s*=\s*([^;]*);?@i', $line, $m)) {
$message = $m[1];
}
if(!empty($message)) {
$reciveMessage[ ] = array($from, $message);
}
}
}
return $reciveMessage;
}
/**
* Function for create connection
*@params:
* method: String Request method
* file: String Request file
* referer: String Referer
* cookie: String cookie for send by request
* content: String data content to post to server
* close: Boolean False for keep connection handle and not close it
* @access public
*/
function _createConnection($method = 'GET', $file = '/', $referer = null,
$cookie = null, $content = null, $close = true)
{
$this->fp_handle = @fsockopen ($this->serverHost, 80, $errno, $errstr, 100);
if(!$this->fp_handle) {
exit("can not connect to $this->serverHost");
}
$method = strtoupper($method);
if(!in_array($method, array('GET', 'POST')) || is_null($content)) {
$method = 'GET';
}
if(is_null($referer)) {
$referer = $this->serverHost;
}
if(is_null($cookie)) {
$cookie = $this->_cookie;
}
$data = "$method $file HTTP/1.1\n";
$data.= "Accept: */*\n";
$data.= "Accept-Language: fa\n";
$data.= "Referer: $referer/\n";
$data.= "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\n";
$data.= "Accept-Encoding: gzip, deflate\n";
$data.= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com]; .NET CLR 1.1.4322)\n";
$data.= "Host: $this->serverHost\n";
$data.= "Connection: Keep-Alive\n";
$data.= "Cache-Control: no-cache\n";
$data.= "Cookie: $cookie\n";
if($method == 'POST') {
$length = strlen($content);
$data.= "Content-Length: $length\n\n";
$data.= $content;
} else {
$data.= "\n";
}
@fputs ($this->fp_handle, $data);
if($close) @fclose($this->fp_handle);
}
}
?>
最佳答案
可能是你忘记了 var $password = '', var $to = '',我不确定,因为我不是 PHP 专家...
关于php - 使用 PHP 向 Yahoo IM 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/815680/
我正在使用 voip 推送通知制作 ios 应用程序。 我想从 Node js 发送 voip 推送通知,但不是很好。 我阅读了本教程 CallKit iOS Swift Tutorial for V
我编写了一个服务器,当浏览器尝试连接到某些站点时,它会检查黑名单并发回 404,但是当我调用 send() 时没有错误,但消息不会出现在网络上浏览器,除非我关闭连接? 有什么建议吗? 接受来自浏览器的
#include int main() { char c = getchar(); //EOF (ctrl + d ) while( ( c = getchar() ) != '?'
我正在尝试使用MailMessage对象通过PowerShell发送电子邮件。该脚本使用Import-CSV来使用文件,然后在电子邮件正文中使用ConvertTo-HTML。由于我要发送的电子邮件客户
我需要创建一个脚本,每 30 秒对网络流量进行一次采样并存储发送/接收的字节。该数据随后用于绘制图形。我编写了一个在 Windows 2012 上完美运行的程序,但我意识到某些 cmdlet 在以前的
我正在运行“autoit3.chm”文件。当它运行时,我想发送一个向下键箭头,但它不起作用: $file = FileGetShortName("C:\Users\PHSD100-SIC\Deskto
当我使用网络浏览器测试我的程序时,我可以很好地写入套接字/FD,所以我决定循环它并在连接中途切断连接,我发现了一个问题。 send() 能够在套接字不可用时关闭整个程序。我认为问题在于该程序陷入了第
我正在运行“autoit3.chm”文件。当它运行时,我想发送一个向下键箭头,但它不起作用: $file = FileGetShortName("C:\Users\PHSD100-SIC\Deskto
所以我试图向自己发送数据并接收数据然后打印它,现在我已经测试了一段时间,我注意到它没有发送任何东西,事实上,也许它是,但我没有正确接收它,我需要这方面的帮助。 这就是我用来发送数据的
问题:开发人员创建自己的序列化格式有多常见?具体来说,我使用 java 本质上将对象作为一个巨大的字符串发送,并用标记来分隔变量。 我的逻辑:我选择这个是因为它几乎消除了语言依赖性(忽略java的修改
我必须在 Linux 上编写一个应用程序,该应用程序需要与具有自定义以太网类型的设备进行通信。甚至在如何编写这样的应用程序中也有很多解决方案。一个缺点是需要 root 访问权限(AFAIK)。之后释放
我有一个包含三个单选按钮选项的表单。我需要将表单数据提交到另一个文件,但由于某种原因,发送的数据包含所选单选按钮的值“on”,而不是 value 属性的值。 我尝试通过 post() 函数手动操作和发
基本上我想实现这样的目标: Process 1 Thread 1 Receive X from process 2 Thread 2 Receive Y from proces
我目前正在 Google App Engine 上开发一个系统,对它还很陌生,我正在使用 Java 平台进行开发。我在 servlet 之间发送 session 对象时遇到问题。我已经在 appeng
当我尝试将“this”(触发的元素)作为参数发送给函数时,函数收到“Object[Document build.php]”作为参数,而不是触发的元素。请让我知道我的错误: function set(a
我正在寻找让我的应用响应联系人 > 发送的魔法咒语。我希望能够接收联系人的 URI 以便检索联系人。谁有 list 过滤器/代码 fragment 吗? 最佳答案 我没有睾丸,但您可以尝试基于 ACT
关于我心爱的套接字的另一个问题。我先解释一下我的情况。之后我会告诉你是什么困扰着我。 我有一个客户端和一个服务器。这两个应用程序都是用 C++ 编写的,实现了 winsock2。连接通过 TCP 和
我看到了这篇文章 http://www.eskimo.com/~scs/cclass/int/sx5.html 但这部分让我感到困惑:如果我们已经使用 send_array 或 send_array_
我对这行代码有疑问。我必须将一个数据包带到一个端口并重新发送到接口(interface)(例如:eth0)。我的程序成功地从端口获取数据包,但是当我重新发送(使用 send())到接口(interfa
我正在尝试编写一个 X11 输入驱动程序,它可以使用我的 Android 手机上的触摸屏来移动和单击鼠标。我可以正常移动鼠标,但我无法让应用程序正确识别点击。我当前的代码位于 https://gist
我是一名优秀的程序员,十分优秀!