where(['order_id' => $this->orderId])->value('details'); if ($delivery) { return json_decode($delivery, true); } if (($data = \services\CacheServices::get(md5($this->orderId . $this->number))) === false || empty($data)) { $param = array( 'com' => $this->code, //快递公司编码 'num' => $this->number, //快递单号 'phone' => '', //手机号 'from' => '', //出发地城市 'to' => '', //目的地城市 'resultv2' => '1' //开启行政区域解析 ); //请求参数 $post_data = array(); $post_data["customer"] = $this->customer; $post_data["param"] = json_encode($param); $sign = md5($post_data["param"] . $this->key . $post_data["customer"]); $post_data["sign"] = strtoupper($sign); $params = ""; foreach ($post_data as $k => $v) { $params .= "$k=" . urlencode($v) . "&"; //默认UTF-8编码格式 } $post_data = substr($params, 0, -1); //发送post请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); $data = json_decode($result, true)['data']; if (empty($data)) { return []; } if ($data[0]['status'] == '签收') { $delivery = Db::name('shop_order_done_delivery')->where(['order_id' => $this->orderId])->value('id'); if (empty($delivery)) { Db::name('shop_order_done_delivery')->insert(['order_id' => $this->orderId, 'code' => $this->code, 'number' => $this->number, 'details' => json_encode($data, JSON_UNESCAPED_UNICODE)]); } else { Db::name('shop_order_done_delivery')->where(['id' => $delivery])->update(['order_id' => $this->orderId, 'code' => $this->code, 'number' => $this->number, 'details' => json_encode($data, JSON_UNESCAPED_UNICODE)]); } } \services\CacheServices::set(md5($this->orderId . $this->number), $data, $this->expire); } return $data; } catch (\Exception $e) { return false; } } /** * 魔术方法 * @param $name * @param $arguments * @return $this */ public function __call ($name, $arguments) { // TODO: Implement __call() method. if ($name == 'data') { $this->{$name} = $arguments[0]; } else { $this->{$name} = $arguments[0]; } return $this; } }