diff --git a/src/Work/Message/Client.php b/src/Work/Message/Client.php index 8cd250183..bf70b5a7c 100644 --- a/src/Work/Message/Client.php +++ b/src/Work/Message/Client.php @@ -73,4 +73,33 @@ public function updateTaskcard(array $userids, int $agentId, string $taskId, str return $this->httpPostJson('cgi-bin/message/update_taskcard', $params); } + + /** + * * 更新模版卡片消息状态 + * + * @see https://developer.work.weixin.qq.com/document/path/94888 + * + * @param array $userids + * @param int $agentId + * @param string $responseCode + * @param string $replaceName + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function updateTemplateCard(array $userids, int $agentId, string $responseCode, string $replaceName = '已收到') + { + $params = [ + 'userids' => $userids, + 'agentid' => $agentId, + 'response_code' => $responseCode, + 'button' => [ + 'replace_name' => $replaceName + ] + ]; + + return $this->httpPostJson('cgi-bin/message/update_template_card', $params); + } } diff --git a/tests/Work/Message/ClientTest.php b/tests/Work/Message/ClientTest.php index fd344edf0..6c44cc7cf 100644 --- a/tests/Work/Message/ClientTest.php +++ b/tests/Work/Message/ClientTest.php @@ -48,4 +48,22 @@ public function testUpdateTaskcard() $this->assertSame('mock-result', $client->updateTaskcard(['userid1','userid2'], 1, 'taskid1', '已收到')); } + + public function testTemplateCard() + { + $client = $this->mockApiClient(Client::class); + + $params = [ + 'userids' => ['userid1','userid2'], + 'agentid' => 1, + 'response_code' => 'testcode', + 'button' => [ + 'replace_name' => '已收到' + ] + ]; + + $client->expects()->httpPostJson('cgi-bin/message/update_template_card', $params)->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->updateTemplateCard(['userid1','userid2'], 1, 'testcode', '已收到')); + } }