SettingService.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.'/setAuth', [
  29. 'headers' => [
  30. 'Authorization' => self::TOKEN
  31. ],
  32. 'json' => [
  33. 'method' => 'CUSTOM_VERIFY',
  34. 'redirect_url' => $redirectUrl
  35. ]
  36. ]);
  37. $info = json_decode((string)$res->getBody(),true);
  38. if ($info['status'] !== 'y') {
  39. throw new ApiException("设置自定义授权url失败--".(string)$res->getBody());
  40. }
  41. }
  42. public function getAuthCode(int $channelId) {
  43. $client = new Client();
  44. $res =$client->request('Post', self::BASE_URL.'v1/activities/'.$channelId.'/getAuthKey', [
  45. 'headers' => [
  46. 'Authorization' => self::TOKEN
  47. ]
  48. ]);
  49. $info = json_decode((string)$res->getBody(),true);
  50. if (empty($info)){
  51. throw new ApiException($info['message']);
  52. }
  53. return $info['authkey'];
  54. }
  55. }