client = new Client([ // 关闭错误异常 'http_errors' => false, // 关闭所有异常 'exceptions' => false, // 接口域名 'base_uri' => $this->host, ]); } /** * 查询快递轨迹 * @param $logisticCode * @param int $phone * @return mixed|string * @throws \GuzzleHttp\Exception\GuzzleException */ public function queryTrack($logisticCode, $phone) { $uri = '/api/track/8002'; // 请求参数 $data = [ 'CustomInfo' => 0000, 'LogisticCode' => $logisticCode ]; // 如果是顺丰需要加入尾号参数 if (strpos($logisticCode, 'SF') !== false) { // 获取尾号 $lastNumber = substr($phone, 7, 4); $data['CustomerName'] = $lastNumber; } $res = $this->client->request('POST', $uri, [ 'headers' => [ 'Authorization' => 'APPCODE ' . $this->appCode, 'Content-Type' => 'application/json; charset=UTF-8' ], 'json' => $data ])->getBody()->getContents(); $res = json_decode($res, true); if (!empty($res['Reason'])) { $res['Traces'] = []; } return $res; } }