非常好
<?php function output() { $Token = "这里是填写秘钥"; $array = array("vid"=>9872); $api = PostCurl("接口地址", $array,$Token); $data = json_decode($api, true); return $data; } /** * @param {接口地址} $url * @param {请求参数} $data * @param {秘钥} $Token */ function PostCurl($url, $data,$Token) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Token:'.$Token)); curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $content = curl_exec($ch); curl_close($ch); return $content; } echo json_encode(output());
<?php function output() { $verify_Token = !empty($_SERVER['HTTP_TOKEN']) ? $_SERVER['HTTP_TOKEN'] : false; $vid = isset($_POST["vid"]) ? $_POST["vid"] : ""; if (empty($verify_Token)) { exit(json_encode(Json_msg(201, "秘钥不能为空"))); } if ($verify_Token == "ace888" && $vid == "9872") { $msg = Json_msg(200, "正常了"); } else { $msg = Json_msg(202, "验证失败"); } return $msg; } /** * @param {状态码} $code * @param {消息} $msg */ function Json_msg($code, $msg){ return array("code"=>$code,"msg"=>$msg); } echo json_encode(output());