Blogger Information
Blog 30
fans 1
comment 0
visits 23197
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP实现腾讯短网址生成api接口实例
P粉896289085
Original
1203 people have browsed it

腾讯短网址(url.cn短链接)生成api接口是腾讯官方对外公开的短网址生成接口,可以将一个冗长的链接缩短成10个字符以内的短链接,需要的朋友跟随小编一起看看吧

1.简要描述
腾讯短网址(url.cn短链接)生成api接口是腾讯官方对外公开的短网址生成接口,可以将一个冗长的链接缩短成10个字符以内的短链接。
2.应用场景
腾讯短网址的应用场景很广,譬如短信营销、邮件推广、微信营销、QQ营销、自媒体推广、渠道推广等都会用到短网址。究其原因是在于短网址可以降低推广成本、用户记忆成本,提高用户点击率;在特定的场景下推广还能规避关键词,防止域名被拦截,隐藏真实地址等。
3.使用说明
接口地址:http://api.monkeyapi.com
请求方式:http get/post
返回格式:json

4.示例

  1. $url = "http://api.monkeyapi.com";
  2. $params = array(
  3. 'appkey' =>'appkey',//您申请的APPKEY
  4. 'url' =>'www.monkeyapi.com',//需要查询的网站
  5. );
  6. $paramstring = http_build_query($params);
  7. $content = Curl($url, $paramstring);
  8. $result = json_decode($content, true);
  9. if($result) {
  10. var_dump($result);
  11. }else {
  12. //请求异常
  13. }
  14. /**
  15. * 请求接口返回内容
  16. * @param string $url [请求的URL地址]
  17. * @param string $params [请求的参数]
  18. * @param int $ipost [是否采用POST形式]
  19. * @return string
  20. */
  21. function Curl($url, $params = false, $ispost = 0)
  22. {
  23. $httpInfo = array();
  24. $ch = curl_init();
  25. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  26. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
  27. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  28. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  29. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  30. if ($ispost) {
  31. curl_setopt($ch, CURLOPT_POST, true);
  32. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  33. curl_setopt($ch, CURLOPT_URL, $url);
  34. }else {
  35. if ($params) {
  36. curl_setopt($ch, CURLOPT_URL, $url.'?'.$params);
  37. } else {
  38. curl_setopt($ch, CURLOPT_URL, $url);
  39. }
  40. }
  41. $response = curl_exec($ch);
  42. if ($response === FALSE) {
  43. //echo "cURL Error: " . curl_error($ch);
  44. return false;
  45. }
  46. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  47. $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
  48. curl_close($ch);
  49. return $response;
  50. }

到此这篇关于PHP实现腾讯短网址生成api接口实例的文章就介绍到这了。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post