像推送通知(下游消息),我想在我的Android设备上实现上传消息到我的app服务器.
我正在使用Github的这个XMPPHP库将我的应用服务器连接到GCM的CCS.但是当我尝试执行以下代码来连接GCM的CCS时:
include 'XMPPHP/XMPP.php';
$conn = new XMPPHP_XMPP('gcm-preprod.googleapis.com', 5236, '<myProjectId>@gcm.googleapis.com', '<myApiKey>', 'xmpphp', 'http://myserverdomain', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
$conn->autoSubscribe();
$vcard_request = array();
try {
$conn->connect();
...
Run Code Online (Sandbox Code Playgroud)
我收到了以下错误.
1455354076 [INFO]: Connecting to tls://gcm-preprod.googleapis.com:5236 1455354106 [ERROR]: Could not connect. Could not connect before timeout.
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用XMPPHP获取我的在线状态,我似乎无法获得具有我的状态的任何东西$conn
.这是我的代码片段:
require_once('XMPPHP/XMPP.php');
$conn = new XMPPHP_XMPP('talk.google.com', 5222, 'xxxx@gmail.com', 'xxxxx', 'xmpphp', 'gmail.com', $printlog = false, $loglevel = XMPPHP_Log::LEVEL_INFO);
$conn->connect();
$conn->processUntil('session_start');
$conn->presence($status='Controller available.');
var_dump($conn); // this gives me a long output but nothing about status. ex: http://pastebin.com/yfs1V5Jb
Run Code Online (Sandbox Code Playgroud)
我也试图getRoster()
看到我朋友的信息列表(虽然我只对我感兴趣)但没有运气.
有什么建议我可以让它工作?谢谢.
也许你已经听过了.它可能是在一个月前在Google IO上宣布的.Google Cloud Messaging只是下游(服务器 - >手机),但现在通过增强型CCS(云连接服务器),您可以通过XMPP协议通过持久TCP连接向上游发送消息.我已经设计了一个适用于GCM和HTTP的应用程序.它使用gcm库和那里打包的类(如GCMRegistrar).现在不推荐使用此类,Google建议使用GoogleCloudMessaging API.
现在一切都有点不同了.您有Google文档,他们会解释非常好,您可以如何设计Android应用程序.但是我的服务器有问题,因为我之前从未使用过XMPP.他们在这里给出了一个Python代码:http: //developer.android.com/google/gcm/gs.html 但我不知道Python.所以我调查了然后我找到了XMPPHP库.然后,您可以使用PHP并使用该库连接XMPP并发送/接收消息.
我没有使用它的经验,它对我不起作用.如何打开与Google XMPP服务器的XMPP连接?
我发现这种方式打开一个连接(这里你使用库):
$conn = new XMPPHP_XMPP($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
Run Code Online (Sandbox Code Playgroud)
有谁知道我必须通过哪些参数才能与谷歌CCS连接?
我也想知道:
我如何通过XMPP向设备发送消息?如何从设备接收消息?
我有使用jaxl库的xmpp事务库:
class xmpp{
public function register_user($username, $password){
require_once 'JAXL/jaxl.php';
$this->client = new JAXL(array(
'jid' => 'localhost',
'log_level' => JAXL_ERROR
));
$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];
if($stanza->name == 'iq') {
if($stanza->attrs['type'] == 'result') {
echo "registration successful".PHP_EOL."shutting down...".PHP_EOL;
$this->client->end_stream();
return …
Run Code Online (Sandbox Code Playgroud)