protected function doRun()
 {
     $id = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($id, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->fetchPublicKey($id);
     if ($result->isSuccess()) {
         Common::l(Common::convertPublicKey($result->getPublicKey()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }
示例#2
0
 protected function doRun()
 {
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->credits();
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l("remaining credits: " . $result->getCredits());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 protected function doRun()
 {
     $phoneNo = $this->getArgument(self::argPhoneNo);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($phoneNo, $from, $secret);
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyLookupByPhoneNumber($phoneNo);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l($result->getId());
     } else {
         Common::e($result->getErrorMessage());
     }
 }
 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());
     }
 }
示例#5
0
 /**
  * @param ThreemaMessage $message
  * @param string $blobId blob id as hex
  * @param \Closure|null $downloadMessage
  * @return null|\Threema\MsgApi\Commands\Results\DownloadFileResult
  * @throws Exception
  */
 private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null)
 {
     if (null === $downloadMessage || true === $downloadMessage->__invoke($message, $blobId)) {
         //make a download
         $result = $this->connection->downloadFile($blobId);
         if (null === $result || false === $result->isSuccess()) {
             throw new Exception('could not download the file with blob id ' . $blobId);
         }
         return $result;
     }
     return null;
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($threemaId, $from, $secret);
     if (strlen($threemaId) != 8) {
         throw new Exception('invalid threema id');
     }
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyCapability($threemaId);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l(implode("\n", $result->getCapabilities()));
     } else {
         Common::e($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";
}
<?php

use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
//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);
$result = $connector->keyLookupByPhoneNumber('123456789');
if ($result->isSuccess()) {
    echo 'Threema ID found: ' . $result->getId() . "\n";
} else {
    echo 'Error: ' . $result->getErrorMessage() . "\n";
}
<?php

use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
//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
//Threema\MsgApi\PublicKeyStores\PhpFile::create('keystore.php'); //new keystore
//$publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile('keystore.php'); //reuse keystore
$publicKeyStore = null;
//create a connection
$connector = new Connection($settings, $publicKeyStore);
$result = $connector->fetchPublicKey('ECHOECHO');
if ($result->isSuccess()) {
    echo 'public key ' . $result->getPublicKey() . "\n";
} else {
    echo 'error ' . $result->getErrorMessage() . "\n";
}