<?php
/**
 * 短网址生成API - API
 *
 * @Author:张张的碎碎念
 * @Date: 2020-05-14 18:00:00 
 * @Link  https://jizhi6.cn/
 */
ini_set("display_errors", "Off");
error_reporting(E_ALL^E_NOTICE^E_WARNING);
header("content-type:application/json");
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

if(key_list() == false){ 
	get_json('KEY不正确,请联系管理员获取Key',null);
}
function key_list() {
    $Array = array(
        '23AE9F3572B7FA8A6DA239577E53141B',//定义你的KEY 一行一个
        'dec842cded8f32368555af834366da8f',//定义你的KEY 一行一个
        'NDc2NjY2CiA=',//定义你的KEY 一行一个
    );
    return in_array($_GET['key'], $Array);
}

$uomg_key = "8c946904615c160e8b951f3030abc5b8";   //优启梦后台KEY
$sourl_key = "00bf9a6b31aeb60700416a618478868e";  //sourl.cn后台KEY
$suo_key = "5ebcdbeab1b63c2029716e83@e3c4c3d8c34b414b4f52443c98a11d70";  //suo.im后台KEY
$mrw_key = "5ebcdc9944bb357e0483be36@2639ba41892f80f625fbdd1afb02296a";  //mrw.so后台KEY
$suo7_Key = "1177426511871906093@f0f24d18e9774e2d9fd705cdef88861e";  //suo7.com后台KEY
$suoyx_Key = "1177426511871905824@e4bbc1f7aaa440d186b9b4e608937f8b";  //suoyx.com后台KEY

$expireDate = "2029-01-01";  //suowo.cn的到期时间

$domain_suo = "0";  //suowo.cn的域名类型:suo.im
$domain_mrw = "1";  //suowo.cn的域名类型:mrw.so
$domain_m6z = "2";  //suowo.cn的域名类型:m6z.cn
$domain_i7q = "3";  //suowo.cn的域名类型:i7q.cn
$domainId_vw2 = "7";  //suo7.com的域名类型:vw2.cn
$domainId_vw3 = "8";  //suo7.com的域名类型:vw3.cn
$domainId_vw4 = "9";  //suo7.com的域名类型:vw4.cn
$domainId_vt5 = "4";  //suoyx.com的域名类型:vt5.cn
$domainId_vt6 = "3";  //suoyx.com的域名类型:vt6.cn
$domainId_vt7 = "2";  //suoyx.com的域名类型:vt7.cn
$domainId_i8n = "6";  //suo7.com的域名类型:i8n
$domainId_suo2 = "5";  //suoyx.com的域名类型:suo2.cn

global $url;
$url = $_GET['url'];
$type = $_GET['type'];

if (!empty($url)) {
    if (strpos($url, "http") === false) {
        get_json('缩短的链接有误,URL参数不正确,需要加HTTP',null);
    }
    if ($type == "hydwz") {
        $headers = get_headers($url, true);
        $GET = $headers['Location'];
        get_json('还原短网址成功',$GET);

    } else {
        if ($type == "mcn") {
            $str = curl_get('https://4m.cn/api/?key=Vz9E1889zMa5GG3&url='.$url);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "jqz") {
            $str = curl_get('http://api.m.urlfh.com/dwz.php?dwzapi=jqzcn&type=qq&longurl='.$url);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["longurl"]);
        }
        if ($type == "l5o") {
            $str = curl_get('http://api.wx.urlfh.com/dwz.php?dwzapi=l5ocn&type=qq&longurl='.$url);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "zz3") {
            $str = curl_get('http://api.wx.urlfh.com/dwz.php?dwzapi=zz3cn&type=qq&longurl='.$url);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "url") {
            $str = curl_get('http://check.uomg.com/api/dwz/urlcn?longurl='.$url.'&format=json&token='.$uomg_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "wurl") {
            $str = curl_get('http://check.uomg.com/api/dwz/wurlcn?longurl='.$url.'&format=json&token='.$uomg_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "sl") {
            $str = curl_get('http://check.uomg.com/api/dwz/slink?longurl='.$url.'&format=json&token='.$uomg_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "git") {
            $str = curl_get('http://check.uomg.com/api/dwz/gitio?longurl='.$url.'&format=json&token='.$uomg_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["ae_url"]);
        }
        if ($type == "unu") {
            $str = curl_get('https://u.nu/api.php?action=shorturl&format=json&url='.$url);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["shorturl"]);
        }
		if ($type == "mrw") {
            $str = curl_get('http://mrw.so/api.php?format=json&url='.$url.'&key='.$mrw_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["url"]);
        }
        if ($type == "suo") {
            $str = curl_get('http://suo.im/api.htm?url='.$url.'&format=json&key='.$suo_key);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["url"]);
        }
        if (empty($type) or $type == "ss6") {
            $str = curl_get('https://ss6.co/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "c34") {
            $str = curl_get('https://hsuo.cn/api/?key=uINeQXKUolus&url='.$url.'&format=json');
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "m6z") {
            $str = curl_get('http://api.suowo.cn/api.htm?format=json&url='.$url.'&key='.$suo_key.'&expireDate='.$expireDate.'&domain='.$domain_m6z);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["url"]);
        }
        if ($type == "i7q") {
            $str = curl_get('http://api.suowo.cn/api.htm?format=json&url='.$url.'&key='.$suo_key.'&expireDate='.$expireDate.'&domain='.$domain_i7q);
			$arr = json_decode($str,true);
            get_json('生成短网址成功',$arr["url"]);
        }
        if ($type == "dwz") {
            $str = curl_get('https://dwz.lc/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "q6p") {
            $str = curl_get('https://q6p.cn/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "ecx") {
            $str = curl_get('https://ecx.cx/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "ons") {
            $str = curl_get('https://ons.red/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "urlc") {
            $str = curl_get('https://urlc.cn/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "soso") {
            $str = curl_get('https://soso.bz/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "8f") {
            $str = curl_get('https://8f.ink/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "suokim") {
            $str = curl_get('https://suo.kim/api?key=WyJTupRSzTXB&url='.$url.'&format=json');
            $arr = json_decode($str, true);
            get_json('生成短网址成功',$arr["short"]);
        }
        if ($type == "surlcn") {
            $str = curl_get('https://surl.cn/index/api/create?url='.$url);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> short);
        }
        if ($type == "i8n") {
            $str = curl_get('http://suo7.com/api.htm?url='.$url.'&formatResult=json&key='.$suo7_Key.'&domainId='.$domainId_i8n);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vw2") {
            $str = curl_get('http://suo7.com/api.htm?url='.$url.'&formatResult=json&key='.$suo7_Key.'&domainId='.$domainId_vw2);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vw3") {
            $str = curl_get('http://suo7.com/api.htm?url='.$url.'&formatResult=json&key='.$suo7_Key.'&domainId='.$domainId_vw3);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vw4") {
            $str = curl_get('http://suo7.com/api.htm?url='.$url.'&formatResult=json&key='.$suo7_Key.'&domainId='.$domainId_vw4);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "suo2") {
            $str = curl_get('http://suoyx.com/api.htm?url='.$url.'&formatResult=json&key='.$suoyx_Key.'&domainId='.$domainId_suo2);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vt5") {
            $str = curl_get('http://suoyx.com/api.htm?url='.$url.'&formatResult=json&key='.$suoyx_Key.'&domainId='.$domainId_vt5);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vt6") {
            $str = curl_get('http://suoyx.com/api.htm?url='.$url.'&formatResult=json&key='.$suoyx_Key.'&domainId='.$domainId_vt6);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == "vt7") {
            $str = curl_get('http://suoyx.com/api.htm?url='.$url.'&formatResult=json&key='.$suoyx_Key.'&domainId='.$domainId_vt7);
            $arr = json_decode($str);
            get_json('生成短网址成功', $arr -> data -> shortUrl);
        }
        if ($type == 'tim') {
            $str = curl_get("http://t.im/?url={$url}&keyword=&title=&expiration=365");
            preg_match("/success\">(.*)<\/span>/", $str, $mat);
            $short = $mat[1];
            if ($short) {
                echo(json_encode(['code' => 'ok', 'url' => $url, 'short_url' => $short], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
            } else {
                exit(json_encode(['code' => 'error', 'msg' => '生成短网址失败'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
            }
        }
    }

} else {
    //header("content-type:text/html");
    //require_once("help.htm");
    get_json('缩短或还原的链接有误,URL参数不正确,还原缩短的URL就加个参数type=hydwz',null);
}
//  get_json($msg,$str) 函数说明:输出json数据,$msg为json的msg说明,str是生成的短网址

function get_json($msg,$str){
    if(empty($str)){
        exit(json_encode(['code' => 'error','msg'=> $msg],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
    }else{
        file_put_contents("data.txt", $GLOBALS["url"]." => ".$str."\n", FILE_APPEND);
        exit(json_encode(['code' => 'ok', 'msg'=> $msg,'url' => $GLOBALS["url"] , 'short_url' => $str],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
    }
    
}

//公共curl函数
function curl_get($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36');
    $headers = array("Content-Type: application/x-www-form-urlencoded");
    curl_setopt($curl, CURLOPT_REFERER, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注