コード例 #1
0
 public function getClient($host, $username = null, $password = null)
 {
     $address = "tcp://{$host}:5222";
     $options = new Options($address);
     if ($this->logger) {
         $options->setLogger($this->logger);
     }
     if ($username && $password) {
         $this->log("Logging with {$username} | {$password}");
         $options->setUsername($username)->setPassword($password);
         $options->setImplementation(new AuthenticatedImplementation());
     } else {
         $options->setImplementation(new AnonymousImplementation());
         $options->setAuthenticationClasses([]);
     }
     $client = new Client($options);
     $client->connect();
     return $client;
 }
コード例 #2
0
ファイル: xmpp.inc.php プロジェクト: Natolumin/observium
    // Default to port to 5222 unless specified by endpoint data
    $port = $endpoint['port'] ? $endpoint['port'] : 5222;
    list($username, $xmppdomain) = explode('@', $endpoint['username']);
    // Username is only the part before @
    $password = $endpoint['password'];
    $options = new Options("tcp://{$hostname}:{$port}");
    $options->setUsername($username);
    $options->setPassword($password);
    list($rusername, $rxmppdomain) = explode('@', $endpoint['recipient']);
    if ($rxmppdomain != '') {
        $options->setTo($rxmppdomain);
    }
    // Set destination domain to the recipient's part after the @
    $client = new Client($options);
    try {
        $client->connect();
        $xmessage = new Message();
        $xmessage->setMessage($message);
        $xmessage->setTo($endpoint['recipient']);
        $client->send($xmessage);
        $client->disconnect();
        $notify_status['success'] = TRUE;
    } catch (\Exception $e) {
        // reason:  $e->getMessage()
        $notify_status['success'] = FALSE;
    }
} else {
    // reason: Could not determine server hostname!
    $notify_status['success'] = FALSE;
}
unset($message);