sendError('文件不存在', 404); } $real_path = new \CURLFile($path); $data = [ 'appid' => $this->config->getAppid(), 'media' => $real_path, 'form-data[filename]' => $path, 'form-data[content-type]' => $real_path->getMimeType() ]; $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'multipart/form-data']); $client->upload($path, $data); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { return new Result(code: 505, message: $client->getBody()); } $body = json_decode($client->getBody(), true); if (isset($body['errCode']) && $body['errCode'] != 0) { return new Result(code: $body['errCode'], message: $body['errMsg']); } else { return new Result(code: 0, data: $body); } } /** * @param string $content * @return Result */ public function text(string $content): Result { if (empty($content)) { return $this->sendError('文件不存在', 404); } $url = '/' . ltrim($this->_url, '/') . $this->config->getAccessToken(); $client = new Client('api.q.qq.com', 443, true); $client->withHeader(['Content-Type' => 'application/json']); $client->post($url, ['appid' => $this->config->getAppid(), 'content' => $content]); $client->close(); if (!in_array($client->getStatusCode(), [101, 200, 201])) { return new Result(code: 505, message: $client->getBody()); } $body = json_decode($client->getBody(), true); if (isset($body['errCode']) && $body['errCode'] != 0) { return new Result(code: $body['errCode'], message: $body['errMsg']); } else { return new Result(code: 0, data: $body); } } }