From 853e0772e6aa53a71edf1b5d251c7ff1e6b2a2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=B9=E5=92=8C=E5=A5=B9=E7=9A=84=E7=8C=AB?= Date: Thu, 28 Nov 2019 00:38:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=B6=88=E6=81=AF=E6=A8=A1=E6=9D=BF=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=94=AF=E6=8C=81=20(#1745)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加小程序订阅消息模板相关支持 * 添加小程序订阅消息模板单元测试 * Delete extra blank lines * Fix styleci errors --- src/MiniProgram/SubscribeMessage/Client.php | 96 +++++++++++++++++++ .../SubscribeMessage/ClientTest.php | 66 +++++++++++++ 2 files changed, 162 insertions(+) diff --git a/src/MiniProgram/SubscribeMessage/Client.php b/src/MiniProgram/SubscribeMessage/Client.php index 8669614f8..a9a7dfeb0 100644 --- a/src/MiniProgram/SubscribeMessage/Client.php +++ b/src/MiniProgram/SubscribeMessage/Client.php @@ -109,4 +109,100 @@ protected function restoreMessage() { $this->message = (new ReflectionClass(static::class))->getDefaultProperties()['message']; } + + /** + * Combine templates and add them to your personal template library under your account. + * + * @param string $tid + * @param array $kidList + * @param string|null $sceneDesc + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function addTemplate(string $tid, array $kidList, string $sceneDesc = null) + { + $sceneDesc = $sceneDesc ?? ''; + $data = \compact('tid', 'kidList', 'sceneDesc'); + + return $this->httpPost('wxaapi/newtmpl/addtemplate', $data); + } + + /** + * Delete personal template under account. + * + * @param string $id + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function deleteTemplate(string $id) + { + return $this->httpPost('wxaapi/newtmpl/deltemplate', ['priTmplId' => $id]); + } + + /** + * Get keyword list under template title. + * + * @param string $tid + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getTemplateKeywords(string $tid) + { + return $this->httpGet('wxaapi/newtmpl/getpubtemplatekeywords', compact('tid')); + } + + /** + * Get the title of the public template under the category to which the account belongs. + * + * @param array $ids + * @param int $start + * @param int $limit + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getTemplateTitles(array $ids, int $start = 0, int $limit = 30) + { + $ids = \implode(',', $ids); + $query = \compact('ids', 'start', 'limit'); + + return $this->httpGet('wxaapi/newtmpl/getpubtemplatetitles', $query); + } + + /** + * Get list of personal templates under the current account. + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getTemplates() + { + return $this->httpGet('wxaapi/newtmpl/gettemplate'); + } + + /** + * Get the category of the applet account. + * + * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string + * + * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function getCategory() + { + return $this->httpGet('wxaapi/newtmpl/getcategory'); + } } diff --git a/tests/MiniProgram/SubscribeMessage/ClientTest.php b/tests/MiniProgram/SubscribeMessage/ClientTest.php index fcf8e55cf..941e77d19 100644 --- a/tests/MiniProgram/SubscribeMessage/ClientTest.php +++ b/tests/MiniProgram/SubscribeMessage/ClientTest.php @@ -114,4 +114,70 @@ public function testSend() ])->andReturn('mock-result'); $this->assertSame('mock-result', $client->send(['touser' => 'mock-openid', 'template_id' => 'mock-template_id', 'data' => ['thing1' => 'thing1.DATA']])); } + + public function testAddTemplate() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpPost('wxaapi/newtmpl/addtemplate', [ + 'tid' => 'mock-tid', + 'kidList' => ['mock-kid'], + 'sceneDesc' => 'mock-scene', + ])->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->addTemplate('mock-tid', ['mock-kid'], 'mock-scene')); + } + + public function testDeleteTemplate() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpPost('wxaapi/newtmpl/deltemplate', [ + 'priTmplId' => 'mock-template-id', + ])->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->deleteTemplate('mock-template-id')); + } + + public function testGetTemplateKeywords() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpGet('wxaapi/newtmpl/getpubtemplatekeywords', [ + 'tid' => 'mock-tid', + ])->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getTemplateKeywords('mock-tid')); + } + + public function testGetTemplateTitles() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpGet('wxaapi/newtmpl/getpubtemplatetitles', [ + 'ids' => 'mock-tid1,mock-tid2', + 'start' => 0, + 'limit' => 30, + ])->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getTemplateTitles(['mock-tid1', 'mock-tid2'])); + } + + public function testGetTemplates() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpGet('wxaapi/newtmpl/gettemplate')->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getTemplates()); + } + + public function testGetCategory() + { + $client = $this->mockApiClient(Client::class)->makePartial(); + + $client->expects()->httpGet('wxaapi/newtmpl/getcategory')->andReturn('mock-result'); + + $this->assertSame('mock-result', $client->getCategory()); + } }