· last year · Oct 04, 2024, 11:05 AM
1<?php
2
3class Fungsi{
4
5 const API = 'AIzaSyAgqCwCMZve3yn0g-0NzIb-asjHstT_5mw';
6 const VERSION = 1;
7
8 public static function curl($headers, $url, $head = null, $data = null){
9
10 $ch = curl_init();
11 curl_setopt($ch, CURLOPT_URL, $url);
12 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
13 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
14 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
15 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
16 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
17 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
18 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
19 curl_setopt($ch, CURLOPT_ENCODING, "gzip");
20 if ($data){
21 curl_setopt($ch, CURLOPT_POST, 1);
22 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
23 }
24 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
25 curl_setopt($ch, CURLOPT_HEADER, true);
26
27 $response = curl_exec($ch);
28 //echo $response;
29 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
30 $header = substr($response, 0, $header_size);
31 $body = substr($response, $header_size);
32 curl_close($ch);
33 if($head){
34 return $header;
35 }
36 return $body;
37 }
38
39 public static function randomUserAgent() {
40 $platforms = [
41 'Windows NT 10.0', 'Windows NT 6.1', 'Windows NT 6.3', 'Macintosh; Intel Mac OS X 10_15_7',
42 'X11; Ubuntu; Linux x86_64', 'X11; Fedora; Linux x86_64', 'Linux; Android 10', 'iPhone; CPU iPhone OS 14_6 like Mac OS X'
43 ];
44 $browsers = [
45 'Chrome' => 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/',
46 'Firefox' => 'Gecko/20100101 Firefox/',
47 'Safari' => 'AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/',
48 'Edge' => 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Edg/',
49 'Opera' => 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ OPR/'
50 ];
51 $platform = $platforms[array_rand($platforms)];
52 $browser = array_rand($browsers);
53 $engine = $browsers[$browser];
54 $browserVersion = rand(60, 99) . '.0.' . rand(1000, 4999) . '.' . rand(50, 150);
55
56 if ($browser == 'Opera') {
57 $browserVersion .= ' OPR/' . rand(60, 90) . '.0.' . rand(1000, 4999);
58 } elseif ($browser == 'Edge') {
59 $browserVersion .= ' Edg/' . rand(60, 90) . '.0.' . rand(1000, 4999);
60 }
61
62 $userAgent = "Mozilla/5.0 ($platform) $engine$browserVersion";
63
64 return $userAgent;
65 }
66
67
68
69 public static function random($n, $includeUppercase = false) {
70 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
71
72 if ($includeUppercase) {
73 $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
74 }
75
76 $randomString = '';
77 for ($i = 0; $i < $n; $i++) {
78 $index = rand(0, strlen($characters) - 1);
79 $randomString .= $characters[$index];
80 }
81
82 return $randomString;
83 }
84
85
86 public static function gpt($teks){
87 $url = "https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=" . self::API;
88
89 while(true){
90 $data = ["contents" => [["role" => "user","parts" => [["text" => $teks]]]]];
91 $payload = json_encode($data);
92 $response = fungsi::curl(['Content-Type: application/json'],$url,false,$payload);
93
94 $pesan = json_decode($response,true)['candidates'][0]['content']['parts'][0]['text'];
95 if($pesan == null){
96 echo "\rAi tidak merespon -> mengulang permintaan\r";
97 continue;
98 }else{
99 break;
100 }
101 }
102 return $pesan;
103 }
104 public static function sendlog($pesan){
105 return file_get_contents("https://officialtokomajor.my.id/bot/sendlog.php?pesan=".urlencode($pesan));
106 }
107 public static function parse($var){
108 return json_decode($var,true);
109 }
110 public static function pretty(){
111 return json_encode($var,JSON_PRETTY_PRINT);
112 }
113 public static function explo($str1, $str2, $var, $num = null){
114 $key = $num ?? 1;
115 $var1 = explode($str1,$var);
116 $var2 = explode($str2,$var1[$key]);
117
118 return $var2[0];
119 }
120 public static function timer($seconds) {
121 $endTime = time() + $seconds;
122
123 while (($remainingTime = $endTime - time()) > 0) {
124 echo "\r\033[K";
125 echo "\033[0;33mTunggu \033[1;37m" . gmdate('i:s', $remainingTime);
126 flush();
127 sleep(1);
128 }
129 echo "\r\033[K";
130 }
131
132
133}