|
[ 本帖最后由 SirW 于 2024-4-6 18:50 编辑 ]\n\n随便写了下,拿去用吧。做图床用的?
- $type ,
- "timestamp" => $timestamp,
- "source" => "h5",
- "key" => "1F2F58F2220096D7E209224F826B6D67"
- );
- $j = json_encode($json);
- $sign = md5(strtoupper($j));
- $h = array(
- "accept: application/json, text/javascript, */*; q=0.01",
- "Channel:",
- "Method:GET",
- "Referer:",
- "Branchid:1002",
- "Sign:".$sign,
- "Source:h5",
- "Tenantid:3",
- "Timestamp:".$timestamp,
- "User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
- );
- if($token != ""){
- $h[] = "Token:".$token;
- }
- return $h;
- }
- function upload($filePath){
- $url = "/api/front/user/h5Login";//带上域名,回帖发不了
- $type = "GET";
- $timestamp = (string)(time()*1000+rand(100,999));
- $randToken = uuid();
- $headers = getHeaders($type, $timestamp, $randToken);
- //register Token
- $content = POST($url, "", $headers);
- $d = json_decode($content, true);
- $token = $d["data"]["token"];
-
- //upload
- $type2 = "POST";
- $url2 = "/api/front/upload/img";//带上域名,回帖发不了
- $timestamp = (string)(time()*1000+rand(100,999));
- $headers2 = getHeaders($type2, $timestamp, $token);
- $headers2[] = "Content-Type:multipart/form-data";
- $postData = array(
- 'file' => new CURLFile($filePath),
- );
- $c = POST($url2, $postData, $headers2);
- $d = json_decode($c,true);
- return $d["data"];
- }
- function POST($url,$post,$headers){
- $c = curl_init();
- curl_setopt($c, CURLOPT_URL, $url);
- curl_setopt($c, CURLOPT_HEADER, 0);
- curl_setopt($c, CURLOPT_NOBODY, 0);
- if($post) {
- curl_setopt($c, CURLOPT_POST, 2);
- curl_setopt($c, CURLOPT_POSTFIELDS, $post);
- }
- if(stripos($url, 'https://') > -1){
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE);
- }
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 12);
- curl_setopt($c, CURLOPT_TIMEOUT,12);
- curl_setopt($c, CURLOPT_ENCODING ,'gzip, deflate');
- if(!$ip) {
- $ip_long = array(
- array('607649792', '608174079'), //36.56.0.0-36.63.255.255
- array('1038614528', '1039007743'), //61.232.0.0-61.237.255.255
- array('1783627776', '1784676351'), //106.80.0.0-106.95.255.255
- array('2035023872', '2035154943'), //121.76.0.0-121.77.255.255
- array('2078801920', '2079064063'), //123.232.0.0-123.235.255.255
- array('-1950089216', '-1948778497'), //139.196.0.0-139.215.255.255
- array('-1425539072', '-1425014785'), //171.8.0.0-171.15.255.255
- array('-1236271104', '-1235419137'), //182.80.0.0-182.92.255.255
- array('-770113536', '-768606209'), //210.25.0.0-210.47.255.255
- array('-569376768', '-564133889'), //222.16.0.0-222.95.255.255
- );
- $rand_key = mt_rand(0, 9);
- $ip= long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
- }
-
- $headers[] = 'X-Forwarded-For:'.$ip;
- $headers[] = 'x-real-ip:'.$ip;
- $headers[] = 'CLIENT_IP:'.$ip;
- curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
- // curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
- $content = curl_exec($c);
- curl_close($c);
- return $content;
- }
- function uuid() {
- $data = openssl_random_pseudo_bytes(16);
- assert(strlen($data) == 16);
-
- // Set version to 0100
- $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
- // Set bits 6-7 to 10
- $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
-
- return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
- }
复制代码 |
|