修复短网址失效
将网址缩短接口替换为 eps.gs,修复无法生成短网址的问题
This commit is contained in:
12
README.md
12
README.md
@@ -1,5 +1,7 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
|
<a href="http://lab.mkblog.cn/lmbtfy/" target="_blank">
|
||||||
<img src="https://user-images.githubusercontent.com/16880885/56845297-9c49cc80-68f1-11e9-94f5-cae16c730fe5.png" alt="让我帮你百度一下">
|
<img src="https://user-images.githubusercontent.com/16880885/56845297-9c49cc80-68f1-11e9-94f5-cae16c730fe5.png" alt="让我帮你百度一下">
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 align="center"> 「Let Me Baidu That For You」</h3>
|
<h3 align="center"> 「Let Me Baidu That For You」</h3>
|
||||||
@@ -28,9 +30,19 @@
|
|||||||
|
|
||||||
[http://lab.mkblog.cn/lmbtfy/](http://lab.mkblog.cn/lmbtfy/)
|
[http://lab.mkblog.cn/lmbtfy/](http://lab.mkblog.cn/lmbtfy/)
|
||||||
|
|
||||||
|
|
||||||
|
### 相关项目
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Let Me Google That For You https://github.com/xb2016/lmgtfy
|
||||||
|
- Let Me Baidu That For You 原版 https://github.com/bangbang93/lmbtfy.cn
|
||||||
|
|
||||||
### 更新日志
|
### 更新日志
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
#### 2019/10/8
|
||||||
|
- 将网址缩短接口替换为 eps.gs,修复无法生成短网址的问题
|
||||||
|
|
||||||
#### 2019/4/27
|
#### 2019/4/27
|
||||||
- 修复因 CDN 失效导致无法使用的问题
|
- 修复因 CDN 失效导致无法使用的问题
|
||||||
- 重构部分代码,界面更美观
|
- 重构部分代码,界面更美观
|
||||||
|
|||||||
22
api.php
22
api.php
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* 短网址 api,基于微博接口
|
* 短网址 API
|
||||||
* 编写:mengkun(https://mkblog.cn)
|
* 编写:mengkun(https://mkblog.cn)
|
||||||
|
* 感谢 https://dwz.gg 提供的接口
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(isset($_GET['url']) && $_GET['url']) {
|
if(isset($_GET['url']) && $_GET['url']) {
|
||||||
@@ -20,19 +21,16 @@ if(isset($_GET['url']) && $_GET['url']) {
|
|||||||
die(json_encode($result));
|
die(json_encode($result));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短网址生成函数
|
* 短网址生成函数 https://likinming.com/post-2554.html
|
||||||
* @param $longUrl 原始网址
|
* @param $longUrl 原始网址
|
||||||
* @return 缩短后的网址
|
* @return 缩短后的网址
|
||||||
*/
|
*/
|
||||||
function shortUrl($longUrl) {
|
function shortUrl($longUrl) {
|
||||||
$url = 'http://api.weibo.com/2/short_url/shorten.json?source=2849184197&url_long=' . $longUrl;
|
$result = file_get_contents('https://eps.gs/api/make.php?url='.$longUrl);
|
||||||
$ch = curl_init($url); // 初始化
|
$result = json_decode($result, true);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl请求有返回的值
|
if(isset($result['url_short'])) {
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
return $result['url_short'];
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
} else {
|
||||||
$output = curl_exec($ch);
|
return $longUrl;
|
||||||
curl_close($ch);
|
}
|
||||||
$obj = json_decode($output);
|
|
||||||
$output = isset($obj->urls[0]->url_short)? $obj->urls[0]->url_short: ''; // 取出短网址的值
|
|
||||||
return $output? $output: $longUrl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user