/** * Returns the short user-friendly hash of the public key. * * This is the way the key is also displayed in the Threema app. For example * there ECHOECHO is shown as `d30f795a904a213578baecc62c8611b5`. However the * full public key of it is: * `4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b` * * @param $publicKey The public key to format. * * @return string 32 hex characters */ function KeyGetUserDisplay($publicKey) { //force key to be binary if (ctype_alnum($publicKey)) { $publicKey = KeyHexToBin($publicKey); } //create short hash $shortHash = substr(hash('sha256', $publicKey), 0, 32); return $shortHash; }
/** * Send a message to a Threema ID. * * @param Threema\MsgApi\Connection $connector connector * @param string $threemaId The id where the message should be send to * @param string $message The message to send (max 3500 characters) * * @throws Exception * @return int */ function SendMessage(Threema\MsgApi\Connection $connector, $threemaId, $message) { $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector); $result = $e2eHelper->sendTextMessage($threemaId, $message); if (true === $result->isSuccess()) { return $result->getMessageId(); } else { throw new Exception($result->getErrorMessage()); } }