diff --git a/src/OfficialAccount/Material/Client.php b/src/OfficialAccount/Material/Client.php index d02924954..8a56dd8e3 100644 --- a/src/OfficialAccount/Material/Client.php +++ b/src/OfficialAccount/Material/Client.php @@ -157,9 +157,9 @@ public function uploadArticleImage(string $path) */ public function get(string $mediaId) { - $response = $this->requestRaw('cgi-bin/material/get_material', 'GET', ['query' => ['media_id' => $mediaId]]); + $response = $this->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => $mediaId]]); - if (preg_match('/(image|video|audio)/i', $response->getHeaderLine('Content-Type'))) { + if (strpos($response->getHeaderLine('Content-Type'), 'text') === false) { return StreamResponse::buildFromPsrResponse($response); } diff --git a/tests/OfficialAccount/Material/ClientTest.php b/tests/OfficialAccount/Material/ClientTest.php index 0b787af05..a06f3a86e 100644 --- a/tests/OfficialAccount/Material/ClientTest.php +++ b/tests/OfficialAccount/Material/ClientTest.php @@ -157,15 +157,15 @@ public function testGet() $client = $this->mockApiClient(Client::class, [], new ServiceContainer(['response_type' => 'array'])); // stream response - $response = new Response(200, ['Content-Type' => ['image/jpeg']], 'mock-content'); - $client->expects()->requestRaw('cgi-bin/material/get_material', 'GET', ['query' => ['media_id' => 'mock-media-id']]) + $response = new Response(200, [], 'mock-content'); + $client->expects()->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => 'mock-media-id']]) ->andReturn($response)->once(); $this->assertInstanceOf(StreamResponse::class, $client->get('mock-media-id')); // json response - $response = new Response(200, ['Content-Type' => ['application/json']], '{"title": "mock-title"}'); - $client->expects()->requestRaw('cgi-bin/material/get_material', 'GET', ['query' => ['media_id' => 'mock-media-id']]) + $response = new Response(200, ['Content-Type' => ['text/plain']], '{"title": "mock-title"}'); + $client->expects()->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => 'mock-media-id']]) ->andReturn($response)->once(); $result = $client->get('mock-media-id');