|
@@ -26,20 +26,21 @@ class Usps
|
|
|
use ErrorTrait;
|
|
|
|
|
|
// 物流跟踪查询API地址
|
|
|
- const QUERY_URL = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
+ //const QUERY_URL = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
+ const QUERY_URL = 'http://f1.itdida.com/itdida-api/queryTracks?no=';
|
|
|
|
|
|
// 查询轨迹账号
|
|
|
/* @var string $userId */
|
|
|
- private string $userId;
|
|
|
+ private $userId = '';
|
|
|
|
|
|
/**
|
|
|
* 构造方法
|
|
|
* @param $userId
|
|
|
*/
|
|
|
- public function __construct($userId)
|
|
|
- {
|
|
|
- $this->userId = $userId;
|
|
|
- }
|
|
|
+// public function __construct($userId)
|
|
|
+// {
|
|
|
+// $this->userId = $userId;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 执行查询
|
|
@@ -100,4 +101,45 @@ class Usps
|
|
|
curl_close($ch);
|
|
|
return $result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行查询
|
|
|
+ * @param string $expressNo
|
|
|
+ * @return string|bool
|
|
|
+ */
|
|
|
+ public function queryF1(string $expressNo)
|
|
|
+ {
|
|
|
+ // 缓存索引
|
|
|
+ $cacheIndex = 'express_usps_'. $expressNo;
|
|
|
+ if ($cacheData = Cache::get($cacheIndex)) {
|
|
|
+ return $cacheData;
|
|
|
+ }
|
|
|
+ // 请求快递100 api
|
|
|
+ $result = $this->curlGet(self::QUERY_URL.$expressNo);
|
|
|
+
|
|
|
+ $express = helper::jsonDecode($result);
|
|
|
+ // 记录错误信息
|
|
|
+ if (!isset($express['data']) || !empty($express['errorMsg'])) {
|
|
|
+ $this->error = $express['errorMsg'] ?? '查询失败';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 记录缓存, 时效30分钟
|
|
|
+ Cache::set($cacheIndex, $express['data'], 3000);
|
|
|
+ return $express['data'];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function curlGet($url)
|
|
|
+ {
|
|
|
+ $header[] = "Accept: application/json";
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 0);//1:post方式 0:get方式
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ $result = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
}
|