PHPackages                             rugk/threema-msgapi-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. rugk/threema-msgapi-sdk-php

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

rugk/threema-msgapi-sdk-php
===========================

Threema PHP-SDK to integrate Threema Gateway in your environment. This SDK allows you to send end-to-end-encrypted messages to Threema users using the Threema Gateway.

1.2.0(9y ago)131055[10 issues](https://github.com/rugk/threema-msgapi-sdk-php/issues)MITPHPPHP &gt;=5.4.0

Since Mar 22Pushed 7y ago7 watchersCompare

[ Source](https://github.com/rugk/threema-msgapi-sdk-php)[ Packagist](https://packagist.org/packages/rugk/threema-msgapi-sdk-php)[ Docs](https://gateway.threema.ch/en/developer/sdk-php)[ RSS](/packages/rugk-threema-msgapi-sdk-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)DependenciesVersions (3)Used By (0)

[Threema Gateway](https://gateway.threema.ch/) PHP SDK
======================================================

[](#threema-gateway-php-sdk)

Version: [1.2.0](https://github.com/rugk/threema-msgapi-sdk-php/releases/tag/v1.2.0)

[![Build Status](https://camo.githubusercontent.com/fa8d42525a738576dc545994df5878c5618da9029b7e4fa5f0a6adbea2facd8c/68747470733a2f2f7472617669732d63692e6f72672f7275676b2f74687265656d612d6d73676170692d73646b2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rugk/threema-msgapi-sdk-php)[![Code Climate](https://camo.githubusercontent.com/3fb44bf49130bd12493631226be8496eb82b8828ce9cdb5e466e2b9821d36bb1/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f7275676b2f74687265656d612d6d73676170692d73646b2d7068702f6261646765732f6770612e737667)](https://codeclimate.com/github/rugk/threema-msgapi-sdk-php)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/76dca358a31c6a2944ee4d5cd69929b55daab91355f8b774706a49d009765b21/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7275676b2f74687265656d612d6d73676170692d73646b2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rugk/threema-msgapi-sdk-php/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/06f467c835549aae4f7e4090d58f959accbf51b53639a3b5fb578edd4f89851c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62326433333261652d343130302d343265302d616264612d3963633936613739623138612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/b2d332ae-4100-42e0-abda-9cc96a79b18a)[![Codacy Badge](https://camo.githubusercontent.com/17b1632d18d63cc33273b06e1633d25c030fd5cc89a6515a70113841a0722dd9/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f67726164652f3238613836646532663734613432316239386563623264646464343335356636)](https://www.codacy.com/app/rugk/threema-msgapi-sdk-php)

Notes about this version
------------------------

[](#notes-about-this-version)

This is a fork of the [original repo](https://github.com/threema-ch/threema-msgapi-sdk-php) after it was announced that the GitHub-version is no longer maintained by Threema. As this is the community version of the Threema Gateway PHP SDK it may contain additional changes which are not yet included in the official downloadable version on the Threema website. If you are looking for a simple mirror of the downloadable Threema version you can switch to the branch [`official`](https://github.com/rugk/threema-msgapi-sdk-php/tree/official).
More information is avaliable in [the wiki](https://github.com/rugk/threema-msgapi-sdk-php/wiki/Branches-and-releases).

An automatically created documentation of this SDK can be found [on GitHub Pages](https://rugk.github.io/threema-msgapi-sdk-php/).

The contributors of this repository are not affiliated with Threema or the Threema GmbH.

Installation
------------

[](#installation)

- Install PHP 5.4 or later:
- For better encryption performance, install the [libsodium PHP extension](https://github.com/jedisct1/libsodium-php).

    This step is optional; if the libsodium PHP extension is not available, the SDK will automatically fall back to (slower) pure PHP code for ECC encryption (file and image sending not supported).

    A 64bit version of PHP is required for pure PHP encryption.

    To install the libsodium PHP extension:

    ```
    pecl install libsodium
    ```

    Then add the following line to your php.ini file:

    ```
    extension=libsodium.so
    ```

If you want to check whether your server meets the requirements and everything is configured properly you can execute `threema-msgapi-tool.php` without any parameters on the console or point your browser to the location where it is saved on your server.

If you want to use this library in your own product it is recommend to use [Composer](https://getcomposer.org/) and require [`rugk/threema-msgapi-sdk-php`](https://packagist.org/packages/rugk/threema-msgapi-sdk-php).

SDK usage
---------

[](#sdk-usage)

### Creating a connection

[](#creating-a-connection)

```
use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
use Threema\MsgApi\Receiver;

require_once('lib/bootstrap.php');

//define your connection settings
$settings = new ConnectionSettings(
    '*THREEMA',
    'THISISMYSECRET'
);

//simple php file to store the public keys (this file must already exist)
$publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile('/path/to/my/keystore.php');

//create a connection
$connector = new Connection($settings, $publicKeyStore);
```

### Creating a connection with advanced options

[](#creating-a-connection-with-advanced-options)

**Attention:** These settings change internal values of the TLS connection. Choosing wrong settings can weaken the TLS connection or prevent a successful connection to the server. Use them with care!

Each of the additional options shown below is optional. You can leave it out or use `null` to use the default value determinated by cURL for this option.

```
use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
use Threema\MsgApi\Receiver;

require_once('lib/bootstrap.php');

//define your connection settings
$settings = new ConnectionSettings(
    '*THREEMA',
    'THISISMYSECRET',
    null, //the host to be used, set to null to use the default (recommend)
    [
        'forceHttps' => true, //set to true to force HTTPS, default: false
        'tlsVersion' => '1.2', //set the version of TLS to be used, default: null
        'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384' //choose a cipher or a list of ciphers, default: null
        'pinnedKey' => 'sha256//8SLubAXo6MrrGziVya6HjCS/Cuc7eqtzw1v6AfIW57c=;sha256//8kTK9HP1KHIP0sn6T2AFH3Bq+qq3wn2i/OJSMjewpFw=' // the hashes to pin, the default is shown here, it is NOT recommend to change this value!
    ]
);

//simple php file to store the public keys (this file must already exist)
$publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile('/path/to/my/keystore.php');

//create a connection
$connector = new Connection($settings, $publicKeyStore);
```

If you want to get a list of all ciphers you can use have a look at the [SSLLabs scan](https://www.ssllabs.com/ssltest/analyze.html?d=msgapi.threema.ch&latest), at the list of all available [OpenSSL ciphers](https://www.openssl.org/docs/manmaster/apps/ciphers.html) and the [comparison table by Mozilla](https://wiki.mozilla.org/Security/Server_Side_TLS#Cipher_names_correspondence_table) which also has some suggestions for good ciphers you should use.

**Note:** For `pinnedKey` to work you must install cURL 7.39 or higher. It is also recommend to use PHP 7.0.7 or higher if you want to support this feature, but it is not required. You can test whether it works by specifying an invalid pin.

### Sending a text message to a Threema ID (Simple Mode)

[](#sending-a-text-message-to-a-threema-id-simple-mode)

```
//create the connection
//(...)
//create a receiver
$receiver = new Receiver('ABCD1234', Receiver::TYPE_ID);

$result = $connector->sendSimple($receiver, "This is a Test Message");
if($result->isSuccess()) {
    echo 'new id created '.$result->getMessageId();
}
else {
    echo 'error '.$result->getErrorMessage();
}
```

### Sending a text message to a Threema ID (E2E Mode)

[](#sending-a-text-message-to-a-threema-id-e2e-mode)

```
//create the connection
//(...)

$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey,$connector);
$result = $e2eHelper->sendTextMessage("TEST1234", "This is an end-to-end encrypted message");

if(true === $result->isSuccess()) {
    echo 'Message ID: '.$result->getMessageId() . "\n";
}
else {
    echo 'Error: '.$result->getErrorMessage() . "\n";
}
```

### Sending a file message to a Threema ID (E2E Mode)

[](#sending-a-file-message-to-a-threema-id-e2e-mode)

```
//create the connection
//(...)

$senderPrivateKey = "MY_PUBLIC_KEY_IN_BIN";
$filePath = "/path/to/my/file.pdf";

$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($senderPrivateKey,$connector);
$result = $e2eHelper->sendFileMessage("TEST1234", $filePath);

if(true === $result->isSuccess()) {
    echo 'File Message ID: '.$result->getMessageId() . "\n";
}
else {
    echo 'Error: '.$result->getErrorMessage() . "\n";
}
```

Console client usage
--------------------

[](#console-client-usage)

### Local operations (no network communication)

[](#local-operations-no-network-communication)

#### Encrypt

[](#encrypt)

```
threema-msgapi-tool.php -e
```

Encrypt standard input using the given sender private key and recipient public key. Two lines to standard output: first the nonce (hex), and then the box (hex).

#### Decrypt

[](#decrypt)

```
threema-msgapi-tool.php -D
```

Decrypt standard input using the given recipient private key and sender public key. The nonce must be given on the command line, and the box (hex) on standard input. Prints the decrypted message to standard output.

#### Hash Email Address

[](#hash-email-address)

```
threema-msgapi-tool.php -h -e
```

Hash an email address for identity lookup. Prints the hash in hex.

#### Hash Phone Number

[](#hash-phone-number)

```
threema-msgapi-tool.php -h -p
```

Hash a phone number for identity lookup. Prints the hash in hex.

#### Generate Key Pair

[](#generate-key-pair)

```
threema-msgapi-tool.php -g
```

Generate a new key pair and write the private and public keys to the respective files (in hex).

#### Derive Public Key

[](#derive-public-key)

```
threema-msgapi-tool.php -d
```

Derive the public key that corresponds with the given private key.

### Network operations

[](#network-operations)

#### Send Simple Message

[](#send-simple-message)

```
threema-msgapi-tool.php -s
```

Send a message from standard input with server-side encryption to the given ID. `` is the API identity and `` is the API secret. the message ID on success.

#### Send End-to-End Encrypted Text Message

[](#send-end-to-end-encrypted-text-message)

```
threema-msgapi-tool.php -S
```

Encrypt standard input and send the text message to the given ID. `` is the API identity and `` is the API secret. Prints the message ID on success.

#### Send a End-to-End Encrypted Image Message

[](#send-a-end-to-end-encrypted-image-message)

```
threema-msgapi-tool.php -S -i
```

Encrypt the image file and send the message to the given ID. `` is the API identity and `` is the API secret. Prints the message ID on success.

#### Send a End-to-End Encrypted File Message

[](#send-a-end-to-end-encrypted-file-message)

```
threema-msgapi-tool.php -S -f
```

Encrypt the file (and thumbnail if given) and send the message to the given ID. `` is the API identity and `` is the API secret. Prints the message ID on success.

#### ID-Lookup By Email Address

[](#id-lookup-by-email-address)

```
threema-msgapi-tool.php -l -e
```

Lookup the ID linked to the given email address (will be hashed locally).

#### ID-Lookup By Phone Number

[](#id-lookup-by-phone-number)

```
threema-msgapi-tool.php -l -p
```

Lookup the ID linked to the given phone number (will be hashed locally).

#### Fetch Public Key

[](#fetch-public-key)

```
threema-msgapi-tool.php -l -k
```

Lookup the public key for the given ID.

#### Fetch Capability

[](#fetch-capability)

```
threema-msgapi-tool.php -c
```

Fetch the capabilities of a Threema ID.

#### Decrypt a Message and download the Files

[](#decrypt-a-message-and-download-the-files)

```
threema-msgapi-tool.php -r
```

Decrypt a box (must be provided on stdin) message and download (if the message is an image or file message) the file(s) to the given `` folder.

#### Remaining credits

[](#remaining-credits)

```
threema-msgapi-tool.php -C
```

Fetch remaining credits.

Contributing
------------

[](#contributing)

Nice to see you want to contribute. We may periodically send patches to Threema to make it possible for them to implement them in the official SDK version.
You can find more information [in our wiki](https://github.com/rugk/threema-msgapi-sdk-php/wiki/Contributing).

Implementations
---------------

[](#implementations)

Looking for some implementations? Have a look at [the wiki](https://github.com/rugk/threema-msgapi-sdk-php/wiki/Implementations).

Other platforms (Java and Python)
---------------------------------

[](#other-platforms-java-and-python)

All repositories on GitHub are no longer maintained by the Threema GmbH. However, the community has forked the repositories of all platforms and they are now maintained unofficially.

You can find the Java repository at [simmac/threema-msgapi-sdk-java](https://github.com/simmac/threema-msgapi-sdk-java)
and the Python repository at [lgrahl/threema-msgapi-sdk-python](https://github.com/lgrahl/threema-msgapi-sdk-python).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance5

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~323 days

Total

2

Last Release

3420d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/776b2f29b28be5a208d3a10bf5fea63ebcbccecd79d91f8eb60efd168abfdee8?d=identicon)[rugk](/maintainers/rugk)

---

Top Contributors

[![rugk](https://avatars.githubusercontent.com/u/11966684?v=4)](https://github.com/rugk "rugk (236 commits)")[![mrthreema](https://avatars.githubusercontent.com/u/25795074?v=4)](https://github.com/mrthreema "mrthreema (11 commits)")[![medienverbinder](https://avatars.githubusercontent.com/u/4519686?v=4)](https://github.com/medienverbinder "medienverbinder (2 commits)")[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (1 commits)")

---

Tags

cryptographycurve25519encryptencryptedencryptiongatewaylibsodiummessagemessengermobilenaclnotificationnotificationsphp-sdksdksecuritysmsswitzerlandthreemathreema-gatewaymessagesecurityencryptionnotificationnotificationslibsodiumCurve25519mobilegatewayMessengersms-gatewayswitzerlandencryptednaclThreema

### Embed Badge

![Health badge](/badges/rugk-threema-msgapi-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/rugk-threema-msgapi-sdk-php/health.svg)](https://phpackages.com/packages/rugk-threema-msgapi-sdk-php)
```

###  Alternatives

[mouse0270/bootstrap-growl

This is a simple pluging that turns standard Bootstrap alerts into "Growl-like" notifications.

2.2k126.5k](/packages/mouse0270-bootstrap-growl)[sly/notification-pusher

Standalone PHP library for easy devices notifications push.

1.2k2.8M16](/packages/sly-notification-pusher)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4432.4M16](/packages/spatie-url-signer)[liran-co/laravel-notification-subscriptions

Notification subscription management.

128247.2k1](/packages/liran-co-laravel-notification-subscriptions)[bentools/webpush-bundle

Send push notifications through Web Push Protocol to your Symfony users.

72285.7k](/packages/bentools-webpush-bundle)[gr8shivam/laravel-sms-api

A modern, flexible Laravel package for integrating any SMS gateway with REST API support

10139.9k](/packages/gr8shivam-laravel-sms-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
