anonymous//src/Conversation/Client.php$0   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 39
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\Conversation;
13
14
use EasyDingTalk\Kernel\BaseClient;
15
use function EasyDingTalk\tap;
16
17
class Client extends BaseClient
18
{
19
    /**
20
     * 发送普通消息
21
     *
22
     * @param string $sender
23
     * @param string $cid
24
     * @param array  $message
25
     *
26
     * @return mixed
27
     */
28
    public function sendGeneralMessage($sender, $cid, $message)
29
    {
30
        return $this->client->postJson('message/send_to_conversation', [
31
            'sender' => $sender, 'cid' => $cid, 'msg' => $message,
32
        ]);
33
    }
34
35
    /**
36
     * 发送工作通知消息
37
     *
38
     * @param array $params
39
     *
40
     * @return mixed
41
     */
42
    public function sendCorporationMessage($params)
43
    {
44
        return $this->client->post('topapi/message/corpconversation/asyncsend_v2', $params);
45
    }
46
47
    /**
48
     * @param int $taskId
49
     *
50
     * @return mixed
51
     */
52
    public function corporationMessage($taskId)
53
    {
54
        $client = new class($this->app) extends BaseClient {
55
            /**
56
             * 任务 ID
57
             *
58
             * @var int
59
             */
60
            protected $taskId;
61
62
            /**
63
             * @param int
64
             */
65
            public function setTaskId($taskId)
66
            {
67
                $this->taskId = $taskId;
68
69
                return $this;
70
            }
71
72
            /**
73
             * 查询工作通知消息的发送进度
74
             *
75
             * @return mixed
76
             */
77
            public function progress()
78
            {
79
                return $this->client->postJson('topapi/message/corpconversation/getsendprogress', [
80
                    'agent_id' => $this->app['config']['agent_id'], 'task_id' => $this->taskId,
81
                ]);
82
            }
83
84
            /**
85
             * 查询工作通知消息的发送结果
86
             *
87
             * @return mixed
88
             */
89
            public function result()
90
            {
91
                return $this->client->postJson('topapi/message/corpconversation/getsendresult', [
92
                    'agent_id' => $this->app['config']['agent_id'], 'task_id' => $this->taskId,
93
                ]);
94
            }
95
        };
96
97
        return tap($client, function ($client) use ($taskId) {
98
            $client->setTaskId($taskId);
99
        });
100
    }
101
}
102