token = TokenModel::getToken(config('miniprogram.public_id')); $this->guzzleHttpClient = new Client(); } public function imgSecCheck($imageUrl) { $filename = storage_path() . '/app/' . uniqid() . '.png'; File::put($filename, Curl::to($imageUrl)->get()); $resource = fopen($filename, 'r'); File::delete($filename); $response = $this->guzzleHttpClient->request('post', self::IMG_API_URL, [ 'query' => [ 'access_token' => $this->token, ], 'multipart' => [ [ 'name' => 'media', 'contents' => $resource, ], ], ]); $response = json_decode($response->getBody()->getContents(), true); return $response; } public function msgSecCheck($content) { $response = $this->guzzleHttpClient->request('post', self::MSG_API_URL, [ 'query' => [ 'access_token' => $this->token, ], 'body' => json_encode([ 'content' => $content, ], JSON_UNESCAPED_UNICODE), ]); $response = json_decode($response->getBody()->getContents(), true); return $response; } }