发送网络/sdn-php-sdk

用于与发送网络交互的PHP SDK

v0.2.0 2023-08-21 11:32 UTC

This package is not auto-updated.

Last update: 2024-09-30 16:59:04 UTC


README

Software License Software Version Software License

发送网络的PHP SDK。

安装

composer require sending-network/sdn-php-sdk

使用方法

准备配置文件

在文件bot.creds.json中提供服务器节点URL、钱包地址、私钥和开发者密钥

{
    "nodeUrl": "https://example.com",
    "walletAddress": "<WALLET_ADDRESS>",
    "privateKey": "<PRIVATE_KEY>",
    "developerKey": "<DEVELOPER_KEY>"
}

创建一个SDNClient实例

require('vendor/autoload.php');
use SdnSdk\SDNClient;

$json_data = file_get_contents("bot.creds.json");
$config = json_decode($json_data,true);
$client = new SDNClient($config['nodeUrl']);

// login
$token = $client->login($config['walletAddress'], $config['privateKey'], $config['developerKey']);

// add listener for events
$client->addListener(function ($event) {
    // process room event here
    print_r($event);
}, "m.room.message");

// start listen
$client->listenForever();

调用API函数

// create new room
$client->createRoom("room name");

// invite user
$client->getRoom($roomId)->inviteUser($userId);

// send message
$client->getRoom($roomId)->sendText("hello");

示例

examples目录中查看更多使用案例。

许可证

MIT许可证.