url = $url; } function request() { try { if (empty(self::$client_id) or empty(self::$client_secret)) { throw new Exception(""); } $post_data['grant_type'] = 'client_credentials'; $post_data['client_id'] = self::$client_id; $post_data['client_secret'] = self::$client_secret; $o = ""; foreach ($post_data as $k => $v) { $o .= "$k=" . urlencode($v) . "&"; } $param = substr($o, 0, -1); if (empty($this->url) || empty($param)) { return false; } return $this->request_with_param($param); } catch (Exception $e) { $GLOBALS["default_log"]->error($e); return <<url);//初始化curl curl_setopt($curl, CURLOPT_HEADER, 0);//设置header curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, 1);//post提交方式 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); $data = curl_exec($curl);//运行curl curl_close($curl); $json_res = json_decode($data, true); info("接口响应结果:" . $data); if (array_key_exists("error", $json_res)) { throw new Exception("请求异常"); } else { $token = new ApiToken($json_res["refresh_token"], $json_res["expires_in"], $json_res["session_key"], $json_res["access_token"], $json_res["scope"], $json_res["session_secret"]); DbUtil::insert("insert into api_token (refresh_token, expires_in, end_time, scope, session_key, access_token, session_secret) values (?,?,?,?,?,?,?)", "sisssss", $token->getRefreshToken(), $token->getExpiresIn(), $token->getEndTime(), $token->getScope(), $token->getSessionKey(), $token->getAccessToken(), $token->getSessionSecret()); info("token保存成功"); return $token; } } catch (Exception $e) { error($e); return <<request();