900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 调用百度api 生成短网址

调用百度api 生成短网址

时间:2024-03-31 01:45:13

相关推荐

调用百度api 生成短网址

功能描述:

自己有一个长网址,调用API直接做成一个短的,就不用去百度的短网址链接了。

function send_post($url, $post_data) {$postdata = http_build_query($post_data); $options = array( //必要的http请求信息'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 // 超时时间(单位:s) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } //使用方法 $post_data = array( 'url' => 'URL'); $json_data = send_post('/create.php', $post_data); $arr=json_decode($json_data,true);//由于返回的数据是json,需要解码一下echo $arr['tinyurl'];//输出短网址字段即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。