ShortUrl.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\admin\library;
  3. use app\common\library\WeChatObject;
  4. use think\Log;
  5. use GuzzleHttp\Client as Http;
  6. class ShortUrl{
  7. /**
  8. * 生成腾讯短连接
  9. * @param $channel_id int 渠道ID
  10. * @param $source_url string 原始链接
  11. * @return bool|string
  12. */
  13. public function tencent($channel_id,$source_url){
  14. return false;
  15. // try{
  16. // $adminConfig = model('AdminConfig')->getAdminInfoAll($channel_id);
  17. // $wechat = new WeChatObject($adminConfig);
  18. // $officialAccount = $wechat->getOfficialAccount();
  19. // $shortUrl = $officialAccount->url->shorten($source_url);
  20. // if (!isset($shortUrl['errcode']) || $shortUrl['errcode'] != 0) {
  21. // return false;
  22. // }
  23. // return $shortUrl['short_url'];
  24. // }catch (\Exception $e){
  25. // Log::notice("腾讯短连接生成失败,SourceURL:{$source_url} Error:".$e->getMessage());
  26. // return false;
  27. // }
  28. }
  29. /**
  30. * 生成sina短链
  31. * @param $source_url string 原始链接
  32. * @return bool|string
  33. */
  34. public function sina($source_url){
  35. return false;
  36. // try{
  37. // $client = new Http;
  38. // $sinaAppIds = ['3167852394', '896597265', '627893179', '2536438578', '2449189067', '1254322903', '1631645512', '539676626', '985865594', '1630884126', '426002535', '36004745', '2869574319', '969499444', '3375473254', '3152384273', '811319594', '2996984438'];
  39. // shuffle($sinaAppIds);
  40. // $sinaAppId = array_pop($sinaAppIds);
  41. // $res = $client->request('GET','https://api.t.sina.com.cn/short_url/shorten.json?source=' . $sinaAppId . '&url_long=' . urlencode($source_url));
  42. // if ($res->getStatusCode() != '200') {
  43. // Log::notice("微博短连接生成失败,SourceURL:{$source_url} Error:API返回状态错误!");
  44. // return false;
  45. // }
  46. // $data = json_decode($res->getBody(), true);
  47. // if (!isset($data[0]['type']) || $data[0]['type'] != 0) {
  48. // Log::notice("微博短连接生成失败,SourceURL:{$source_url} Error:API返回内容错误!");
  49. // return false;
  50. // }else {
  51. // return $data[0]['url_short'];
  52. // }
  53. // }catch (\GuzzleHttp\Exception\GuzzleException $e){
  54. // Log::notice("微博短连接生成失败,SourceURL:{$source_url} Error:".$e->getMessage());
  55. // return false;
  56. // }catch (\Exception $e){
  57. // Log::notice("微博短连接生成失败,SourceURL:{$source_url} Error:".$e->getMessage());
  58. // return false;
  59. // }
  60. }
  61. }