function sinaweibo($xxurl) { function shortenSinaUrl($long_url) { $apiKey = '4098049467'; $apiUrl = 'http://api.t.sina.com.cn/short_url/shorten.json?source=' . $apiKey . '&url_long=' . $long_url; $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, $apiUrl); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); $response = curl_exec($curlObj); curl_close($curlObj); $json = json_decode($response); return $json[0]->url_short; } function expandSinaUrl($short_url) { $apiKey = '4098049467'; $apiUrl = 'http://api.t.sina.com.cn/short_url/expand.json?source=' . $apiKey . '&url_short=' . $short_url; $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, $apiUrl); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); $response = curl_exec($curlObj); curl_close($curlObj); $json = json_decode($response); return $json[0]->url_long; } return shortenSinaUrl($xxurl); }
$curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, $apiUrl); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); $response = curl_exec($curlObj); curl_close($curlObj); $json = json_decode($response); return $json[0]->url_short; } $urlToShortLink = $_POST['url']; if (empty($urlToShortLink)) { return; } $sinaShortUrl = shortenSinaUrl($urlToShortLink); $googleShortUrl = shortenGoogleUrl($urlToShortLink); ?> <html> <head> <meta charset="utf-8"> <title>生成二维码</title> <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.css.map"> </head> <body> <nav class="navbar navbar-default"> <div class="container">