Exemplo n.º 1
0
 protected function doRun()
 {
     $to = $this->getArgument(self::argThreemaId);
     $from = $this->getArgument(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($to, $from, $secret);
     $message = $this->readStdIn();
     if (strlen($message) === 0) {
         throw new \InvalidArgumentException('please define a message');
     }
     $settings = new ConnectionSettings($from, $secret);
     $connector = new Connection($settings, $this->publicKeyStore);
     $receiver = new Receiver($to, Receiver::TYPE_ID);
     $result = $connector->sendSimple($receiver, $message);
     if ($result->isSuccess()) {
         Common::l('Message ID: ' . $result->getMessageId());
     } else {
         Common::l('Error: ' . $result->getErrorMessage());
     }
 }
<?php

use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
use Threema\MsgApi\Receiver;
//include_project
require_once 'bootstrap.php';
//define your connection settings
$settings = new ConnectionSettings('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET');
//public key store file
//best practice: create a publickeystore
//$publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile('keystore.php');
$publicKeyStore = null;
//create a connection
$connector = new Connection($settings, $publicKeyStore);
//create a receiver
$receiver = new Receiver('ECHOECHO', Receiver::TYPE_ID);
$result = $connector->sendSimple($receiver, "This is a Test Message");
if ($result->isSuccess()) {
    echo 'Message ID: ' . $result->getMessageId() . "\n";
} else {
    echo 'Error: ' . $result->getErrorMessage() . "\n";
}