SettingService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/6 17:25
  5. */
  6. namespace app\common\service;
  7. use app\index\exception\ApiException;
  8. use GuzzleHttp\Client;
  9. use GuzzleHttp\Exception\RequestException;
  10. use think\Exception;
  11. class SettingService {
  12. const TOKEN = 'Bearer a1aw1av25bk1usqjv7r84mw9knpv3sma';
  13. const BASE_URL = 'http://api.webcasting.bizconfstreaming.com/';
  14. public function verifyChannelName(int $channelId,string $channelName) {
  15. $client = new Client();
  16. $res =$client->request('GET', self::BASE_URL.'v1/activities/'.$channelId, [
  17. 'headers' => [
  18. 'Authorization' => self::TOKEN
  19. ]
  20. ]);
  21. $info = json_decode((string)$res->getBody(),true);
  22. if ($channelName !== $info['name']) {
  23. throw new ApiException("频道名称不一致,频道{$channelId}名称为 ".$info['name']);
  24. }
  25. }
  26. public function setAuthUrl(int $channelId, string $redirectUrl) {
  27. $client = new Client();
  28. $res =$client->request('Post', self::BASE_URL.'v1/activities/'.$channelId.'/setAuthUrl', [
  29. 'headers' => [
  30. 'Authorization' => self::TOKEN
  31. ],
  32. 'json' => [
  33. 'redirect_url' => $redirectUrl
  34. ]
  35. ]);
  36. $info = json_decode((string)$res->getBody(),true);
  37. if ($info['status'] !== 'y') {
  38. throw new ApiException("设置自定义授权url失败--".(string)$res->getBody());
  39. }
  40. }
  41. public function getAuthCode(int $channelId) {
  42. $client = new Client();
  43. $res =$client->request('Post', self::BASE_URL.'v1/activities/'.$channelId.'/getAuthKey', [
  44. 'headers' => [
  45. 'Authorization' => self::TOKEN
  46. ]
  47. ]);
  48. $info = json_decode((string)$res->getBody(),true);
  49. if (empty($info)){
  50. throw new ApiException($info['message']);
  51. }
  52. return $info['authkey'];
  53. }
  54. }