PHP code example of xx19941215 / dingtalk-stream-sdk-php

1. Go to this page and download the library: Download xx19941215/dingtalk-stream-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xx19941215 / dingtalk-stream-sdk-php example snippets


use Xx19941215\DingTalkStream\DingTalkStreamClient;
use GuzzleHttp\Client as HttpClient;
use Psr\Log\NullLogger;

$config = [
    'clientId' => '你的AppKey',
    'clientSecret' => '你的AppSecret',
    'subscriptions' => [
        ['type' => 'EVENT', 'topic' => '*'],
        ['type' => 'CALLBACK', 'topic' => '*'],
    ],
    'ua' => 'your-app/1.0.0',
    'localIp' => '10.0.0.1',
    'debug' => true,
];

$http = new HttpClient(['timeout' => 10]);
$logger = new NullLogger();

$client = new DingTalkStreamClient($config, $http, $logger);

// 注册事件处理器(EVENT)
$client->registerHandler('EVENT', function(array $message) {
    // 解析 $message['data'],执行业务逻辑
    return ['status' => 'handled'];
});

// 注册卡片/回调处理器(CALLBACK)
$client->registerHandler('CALLBACK', function(array $message) {
    // 处理卡片交互
    return ['ack' => true];
});

// 建立连接并开始监听
$client->connect();
bash
composer update xx19941215/dingtalk-stream-sdk-php