ejabberd 或 openfire 等 xmpp 服务端 注册新用户的问题 最近需要用PHP 实现 向ejabberd 和openfire 服务端注册新用户,php方面 尝试了 jaxl 和xmpPHP ,都没有实现,相关文档非常少,基本上只有 如何发送信息,用代码注册新用户 的资料非常少,在这里向各位同学求助,还请不吝赐教,万分感谢。目前问题:无法实现 新用户的注册。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我贴下我的代码吧。我是在本地测试的,xmpp 服务端用的是openfire网上看到有篇 jaxl 注册 openfire 用户的blog然后跟着改了下代码//引入核心文件require_once './jaxl/jaxl.php';error_reporting(E_ALL);//初始化配置$client = new JAXL(array( "jid" => "reg", "host" => "127.0.0.1", "port" => "5222", "log_level" => JAXL_DEBUG ));var_dump($client);$client->require_xep(array('0077'));$form = array();function wait_for_register_response($event, $args) { global $client, $form; if ($event == 'stanza_cb') { $stanza = $args[0]; if ($stanza->name == 'iq') { $form['type'] = $stanza->attrs['type']; if ($stanza->attrs['type'] == 'result') { echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL; $client->send_end_stream(); return "logged_out"; } else if ($stanza->attrs['type'] == 'error') { $error = $stanza->exists('error'); echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL; echo "error text: " . $error->exists('text')->text . PHP_EOL; echo "shutting down..." . PHP_EOL; $client->send_end_stream(); return "logged_out"; } else { echo "Error"; } } } else { _notice("unhandled event $event rcvd"); }}function wait_for_register_form($event, $args) { global $client, $form, $regdata; // reg data 為需求資料陣列 $stanza = $args[0]; $query = $stanza->exists('query', NS_INBAND_REGISTER); if ($query) { $instructions = $query->exists('instructions'); if ($instructions) { echo $instructions->text . PHP_EOL; } foreach ($query->childrens as $k => $child) { if ($child->name != 'instructions') { // 原始 example 的 readline 改寫 $form[$child->name] = $regdata[$child->name]; } } // 移除無用欄位 unset($form["x"], $form["name"]); $client->xeps['0077']->set_form($stanza->attrs['from'], $form); return "wait_for_register_response"; } else { $$client->send_end_stream(); return "logged_out"; }}// 取得註冊表單$client->add_cb('on_stream_features', function($stanza) { global $client, $domain; // $domain 請自行設定全域變數 $client->xeps['0077']->get_form($domain); return "wait_for_register_form";});$client->start();echo 'OK';然后他说这个 相当于一直接受用户注册,往这个页面 提交 信息即可,但是不能以表单形式提交过来,要以ajax 提交,这个就搞不明白了。他要提交的东西 是个数组一个数组你怎么用ajax提交,没搞懂,他最关键的部分 没有写出来。但是他后面又确实在openfire 里面注册成功了,所以没办法来请教大家了,我又找了另一个 博客代码是这样的class xmpp { public function register_user($username, $password) { require_once './jaxl/jaxl.php'; $this->client = new JAXL(array( 'jid' => 'reg', 'host' => '127.0.0.1', 'port' => '5222', 'log_level' => JAXL_DEBUG ));// var_dump($this->client); $this->username = $username; $this->password = $password; $this->client->require_xep(array( '0077' // InBand Registration )); $thisClassObject = & $this; $this->client->add_cb('on_stream_features', function($stanza) use(&$thisClassObject) { $thisClassObject->client->xeps['0077']->get_form('localhost'); return array($thisClassObject, 'wait_for_register_form'); }); $this->client->start(); return; } public function wait_for_register_response($event, $args) { if ($event == 'end_stream') { return; } else if ($event == 'stanza_cb') { $stanza = $args[0]; echo '<pre>'; print_r($stanza); if ($stanza->name == 'iq') { if ($stanza->attrs['type'] == 'result') { echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL; $client->send_end_stream(); return 'logged_out'; } else if ($stanza->attrs['type'] == 'error') { $error = $stanza->exists('error'); echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL; echo "error text: " . $error->exists('text')->text . PHP_EOL; echo "shutting down..." . PHP_EOL; $client->send_end_stream(); return "logged_out"; } } } } public function wait_for_register_form($event, $args) { $stanza = $args[0]; $query = $stanza->exists('query', NS_INBAND_REGISTER); if ($query) { $form = array(); $instructions = $query->exists('instructions'); if ($instructions) { echo $instructions->text . PHP_EOL; } $this->client->xeps['0077']->set_form($stanza->attrs['from'], array('username' => $this->username, 'password' => $this->password)); return array($this, "wait_for_register_response"); } else { $client->send_end_stream(); return "logged_out"; } }}$xmppObj = new xmpp();var_dump($xmppObj->register_user('user', 'password'));这个也无法实现注册。只有一个程序打印的错误信息registration failed with error code: 400 and type: modify 风靡全球的社交网站程序 介绍几个知识管理系统,要php的 各位帮我看下这是什么问题。谢谢! 有关WP调用文章的图片,标题,内容,却不破坏CSS。 2个开源软件 pligg wordpress mysql left join 的问题 有朋友用过WordPress吗? lnmp面板,AMH3.2 已发布 关于mysql的default 急!!!服务器响应速度过慢,求大神指导!! 求助:PHPExcel无法加入图片 如何查看每个网站页面的源代码
我是在本地测试的,xmpp 服务端用的是openfire
网上看到有篇 jaxl 注册 openfire 用户的blog
然后跟着改了下代码
//引入核心文件
require_once './jaxl/jaxl.php';
error_reporting(E_ALL);
//初始化配置$client = new JAXL(array(
"jid" => "reg",
"host" => "127.0.0.1",
"port" => "5222",
"log_level" => JAXL_DEBUG
));
var_dump($client);$client->require_xep(array('0077'));$form = array();function wait_for_register_response($event, $args) {
global $client, $form; if ($event == 'stanza_cb') {
$stanza = $args[0];
if ($stanza->name == 'iq') {
$form['type'] = $stanza->attrs['type'];
if ($stanza->attrs['type'] == 'result') {
echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL;
$client->send_end_stream();
return "logged_out";
} else if ($stanza->attrs['type'] == 'error') {
$error = $stanza->exists('error');
echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL;
echo "error text: " . $error->exists('text')->text . PHP_EOL;
echo "shutting down..." . PHP_EOL;
$client->send_end_stream();
return "logged_out";
} else {
echo "Error";
}
}
} else {
_notice("unhandled event $event rcvd");
}
}function wait_for_register_form($event, $args) {
global $client, $form, $regdata; // reg data 為需求資料陣列
$stanza = $args[0];
$query = $stanza->exists('query', NS_INBAND_REGISTER); if ($query) { $instructions = $query->exists('instructions');
if ($instructions) {
echo $instructions->text . PHP_EOL;
}
foreach ($query->childrens as $k => $child) {
if ($child->name != 'instructions') {
// 原始 example 的 readline 改寫
$form[$child->name] = $regdata[$child->name];
}
}
// 移除無用欄位
unset($form["x"], $form["name"]); $client->xeps['0077']->set_form($stanza->attrs['from'], $form);
return "wait_for_register_response";
} else {
$$client->send_end_stream();
return "logged_out";
}
}// 取得註冊表單
$client->add_cb('on_stream_features', function($stanza) {
global $client, $domain; // $domain 請自行設定全域變數
$client->xeps['0077']->get_form($domain);
return "wait_for_register_form";
});$client->start();
echo 'OK';
然后他说这个 相当于一直接受用户注册,往这个页面 提交 信息即可,但是不能以表单形式提交过来,要以ajax 提交,这个就搞不明白了。他要提交的东西 是个数组
一个数组你怎么用ajax提交,没搞懂,他最关键的部分 没有写出来。
但是他后面又确实在openfire 里面注册成功了,所以没办法来请教大家了,
我又找了另一个 博客代码是这样的class xmpp { public function register_user($username, $password) {
require_once './jaxl/jaxl.php'; $this->client = new JAXL(array(
'jid' => 'reg',
'host' => '127.0.0.1',
'port' => '5222',
'log_level' => JAXL_DEBUG
));// var_dump($this->client);
$this->username = $username; $this->password = $password; $this->client->require_xep(array(
'0077' // InBand Registration
));
$thisClassObject = & $this; $this->client->add_cb('on_stream_features', function($stanza) use(&$thisClassObject) {
$thisClassObject->client->xeps['0077']->get_form('localhost');
return array($thisClassObject, 'wait_for_register_form');
}); $this->client->start(); return;
} public function wait_for_register_response($event, $args) { if ($event == 'end_stream') {
return;
} else if ($event == 'stanza_cb') {
$stanza = $args[0];
echo '<pre>';
print_r($stanza);
if ($stanza->name == 'iq') {
if ($stanza->attrs['type'] == 'result') {
echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL;
$client->send_end_stream();
return 'logged_out';
} else if ($stanza->attrs['type'] == 'error') {
$error = $stanza->exists('error');
echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL;
echo "error text: " . $error->exists('text')->text . PHP_EOL;
echo "shutting down..." . PHP_EOL;
$client->send_end_stream();
return "logged_out";
}
}
}
} public function wait_for_register_form($event, $args) { $stanza = $args[0];
$query = $stanza->exists('query', NS_INBAND_REGISTER);
if ($query) {
$form = array();
$instructions = $query->exists('instructions');
if ($instructions) {
echo $instructions->text . PHP_EOL;
} $this->client->xeps['0077']->set_form($stanza->attrs['from'], array('username' => $this->username, 'password' => $this->password));
return array($this, "wait_for_register_response");
} else {
$client->send_end_stream();
return "logged_out";
}
}}$xmppObj = new xmpp();
var_dump($xmppObj->register_user('user', 'password'));
这个也无法实现注册。只有一个程序打印的错误信息
registration failed with error code: 400 and type: modify