parse($response); } private function parse($response) { $data = null; if (is_array($response)) { Log::write('RESPONSE_ARRAY: ' . json_encode($response)); $data = $response; } else { Log::write('RESPONSE_STR: ' . $response); $data = json_decode($response, true); } if (!$data) { $data = [ 'code' => -998, 'msg' => '数据异常', 'sign' => '', 'sign_type' => 'MD5', 'result' => json_encode([]), ]; } $this->data = $data; $result = $data['result'] ? json_decode($data['result'], true) : []; $this->result = $result; $this->code = $data['code']; $this->msg = $data['msg']; $this->sign = $data['sign']; $this->signType = $data['sign_type']; } public function isSuccess() { return !($this->code < 0); } public function getCode() { return $this->code; } public function getMsg() { return $this->msg; } public function getResult($key = null) { if ($key) { return $this->result[$key] ?: null; } return $this->result; } public function getSign() { return $this->sign; } public function getSignType() { return $this->signType; } public function verify() { return Sign::verify($this->data, Config::get('secret_key')); } }