gistfile1.txt
· 851 B · Text
Неформатований
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://v2.api-m.com/api/heisi",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
if(curl_errno($curl)){
echo 'Request Error:' . curl_error($curl);
}
curl_close($curl);
$json = $response;
$data = json_decode($json, true);
if ($data && isset($data['data']) && filter_var($data['data'], FILTER_VALIDATE_URL)) {
$imageUrl = $data['data'];
$html = <<<HTML
<script>
window.location.href = "$imageUrl";
</script>
HTML;
echo $html;
} else {
echo "无法解析数据或数据字段不存在。";
}
?>
1 | <?php |
2 | $curl = curl_init(); |
3 | curl_setopt_array($curl, array( |
4 | CURLOPT_URL => "https://v2.api-m.com/api/heisi", |
5 | CURLOPT_RETURNTRANSFER => true, |
6 | CURLOPT_ENCODING => '', |
7 | CURLOPT_MAXREDIRS => 10, |
8 | CURLOPT_TIMEOUT => 30, |
9 | CURLOPT_FOLLOWLOCATION => true, |
10 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
11 | CURLOPT_CUSTOMREQUEST => 'GET', |
12 | )); |
13 | $response = curl_exec($curl); |
14 | if(curl_errno($curl)){ |
15 | echo 'Request Error:' . curl_error($curl); |
16 | } |
17 | curl_close($curl); |
18 | $json = $response; |
19 | $data = json_decode($json, true); |
20 | if ($data && isset($data['data']) && filter_var($data['data'], FILTER_VALIDATE_URL)) { |
21 | $imageUrl = $data['data']; |
22 | $html = <<<HTML |
23 | <script> |
24 | window.location.href = "$imageUrl"; |
25 | </script> |
26 | HTML; |
27 | echo $html; |
28 | } else { |
29 | echo "无法解析数据或数据字段不存在。"; |
30 | } |
31 | ?> |