appCode = trim((string) $appCode); if ($this->appCode === '' && class_exists('\\addons\\shopro_aliyun_express\\library\\ExpressConfig')) { $this->appCode = \addons\shopro_aliyun_express\library\ExpressConfig::getInstance()->getExpressBirdAppcode(); } $this->client = new Client([ 'http_errors' => false, 'exceptions' => false, 'base_uri' => $this->host, ]); } /** * 查询快递轨迹 * @param string $logisticCode * @param string $phone * @return array */ public function queryTrack($logisticCode, $phone) { if ($this->appCode === '') { return [ 'Success' => false, 'Reason' => '请配置 ExpressBird APPCODE', 'Traces' => [], ]; } $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; } }