api.php 935 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. require_once("config.php");
  3. $gurl = str_replace("/?id=", "", htmlspecialchars($_SERVER["REQUEST_URI"]));
  4. $psize = 18;
  5. $rpsize = $psize * 2;
  6. $mrpsize = 161;
  7. function get (string $url = "", bool $prx = false, bool $embed = false): stdClass {
  8. $res = [];
  9. $ch = curl_init();
  10. if ($prx) curl_setopt($ch, CURLOPT_URL, "https://".$url);
  11. else curl_setopt($ch, CURLOPT_URL, ($prx ? $url : "https://".($embed ? "embed.pixiv.net" : "www.pixiv.net/ajax")."/".$url));
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  13. "Cookie: PHPSESSID=".SESSION_ID,
  14. "User-Agent: Mozilla/5.0",
  15. ]);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. $res = mb_convert_encoding(curl_exec($ch), "UTF-8", "EUC-JP");
  18. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  19. curl_close($ch);
  20. if (!$res || $httpCode != 200) {
  21. echo "エラー ".$httpCode;
  22. die();
  23. }
  24. return json_decode($res);
  25. }
  26. ?>