金数据表单API php接口文件
<?php
//QQ123691873
$APIKey='xxxxx';
$Secret='xxxxxx';
$url='https://jinshuju.net/api/v1/forms/gslVV1';
$field_1 = test_input($_POST["title"]);
$field_2 = test_input($_POST["tel"]);
$field_3 = test_input($_POST["url"]);
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$jsonStr = json_encode(array('field_1' =>$field_1, 'field_2' =>$field_2, 'field_3' =>$field_3, 'Username' =>$APIKey, 'Password' =>$Secret));
echo post_curls($url,$Secret,$jsonStr);
}
/**
* POST请求https接口返回内容
* @param string $url [请求的URL地址]
* @param string $post [请求的参数]
* @return string
*/
function post_curls($url,$author, $post)
{
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
// 需要通过Authorization验证
if ( !empty($author)) {
$headers[] = 'Origin:https://jinshuju.net';
$headers[] = 'Accept:*/*';
$headers[] = 'Content-type:application/json';
//$headers[] = 'Authorization: Basic ' . $author';'
$headers[] = 'Authorization: Basic Y3dRNFcxOTIycTdHUTc5VUE3emdlZzp5cTVtRndNOGg3Yks1RTk5UHF0bTN3';
//echo base64_encode($author);
//$headers[] = 'Authorization: Basic ' . base64_encode($author);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
/*
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Basic Y3dRNFcxOTIycTdHUTc5VUE3emdlZzp5cTVtRndNOGg3Yks1RTk5UHF0bTN3',
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($post)
)
);
*/
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);// 获取的信息以文件流的形式返回
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
$res = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);//捕抓异常
}
curl_close($curl); // 关闭CURL会话
return $res; // 返回数据,json格式
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询