首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xmpphp XMPP,从php脚本发送消息

xmpphp XMPP,从php脚本发送消息
EN

Stack Overflow用户
提问于 2011-04-16 02:34:30
回答 2查看 8.4K关注 0票数 2

嗨,我有一个jabberserver,我希望能够从一个php脚本推送消息给用户。

F.x。如果我从浏览器调用script.php,它会向用户发送一条消息。我已经尝试了jaxl和xmpphp这两个xmp框架,但是我不能让它工作。不是我自己的服务器,也不是facebook服务器。

我的script.php中有以下内容:

代码语言:javascript
复制
error_reporting(E_ALL);    
include("lib/xmpphp/XMPPHP.php");  
$conn = new XMPP('chat.facebook.dk', 5222, 'username', 'password', '', 'chat.facebook.com', true, XMPPHP_Log::LEVEL_VERBOSE);  
$conn->connect();  
$conn->processUntil('session_start');  
$conn->message('someusername@chat.facebook.com', 'This is a test message!');  
$conn->disconnect();    

但是没有发生任何事情,也没有错误。我按照这个指南设置了一个echobot机器人,它在我的服务器和facebook上都能工作。脚本在这里:http://abhinavsingh.com/blog/2010/02/writing-your-first-facebook-chat-bot-in-php-using-jaxl-library/ <--并在服务器命令行上运行,等待一条消息,然后回复。

我该怎么做呢?

EN

回答 2

Stack Overflow用户

发布于 2015-09-26 18:22:50

代码语言:javascript
复制
<?php 
set_time_limit(0);  // some time connection take while  
require_once 'xmpp-lib/XMPPHP/XMPP.php';  
$host = 'you Host name'; // ex.192.168.2.1  
$port = '5222'; // its defauls xmpp port 
$username = 'name@host' // ex vivek@host 
$pass = 'userpass';  
$conn = new XMPPHP_XMPP(host , $port, $username, $pass, 'xmpphp','yourhost', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);  
try {
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message('anotherusername@host', 'Hello!');
         $conn->disconnect(); 
} catch(XMPPHP_Exception $e) {
         die($e->getMessage()); 
} 
?>
票数 1
EN

Stack Overflow用户

发布于 2020-04-23 19:36:03

代码语言:javascript
复制
<?php

$command = 'send_message';
$requestParams = array('type' => 'chat',
    'to' => '919999999999@127.0.0.0',
    'from' => '919999999991@127.0.0.0',
    'body' => 'Hi vivek patel',
    'subject' => 'test',
);

$request = xmlrpc_encode_request($command, $requestParams, (array('encoding' => 'utf-8')));
$context = stream_context_create(array('http' => array('method' => "POST",
        'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
        "Content-Type: text/xml\r\n" .
        "Content-Length: " . strlen($request),
        'content' => $request
    )
        )
);
try {
    $file = file_get_contents("http://127.0.0.0:4560/RPC2", false, $context);
    $response = xmlrpc_decode($file);
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

if (xmlrpc_is_fault($response)) {
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
}
echo '<pre>';
echo print_r($response);
echo '</pre>';
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5680930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档