Browse Source

feat():授权

geek 4 years ago
parent
commit
c3dbf7ed87
1 changed files with 53 additions and 18 deletions
  1. 53 18
      application/common/service/SettingService.php

+ 53 - 18
application/common/service/SettingService.php

@@ -16,19 +16,42 @@ class SettingService {
 
     const TOKEN = 'Bearer a1aw1av25bk1usqjv7r84mw9knpv3sma';
 
-    const BASE_URL = 'http://api.webcasting.bizconfstreaming.com/';
+    const BASE_URL = 'http://api.mudu.tv/';
 
     public function verifyChannelName(int $channelId, string $channelName) {
-        $client = new Client();
-        $res = $client->request('GET', self::BASE_URL . 'v1/activities/' . $channelId, [
-            'headers' => [
-                'Authorization' => self::TOKEN
-            ]
+//        $client = new Client();
+//        $res = $client->request('GET', 'http://api.mudu.tv/v1/activities/' . $channelId, [
+//            'headers' => [
+//                'Authorization' => self::TOKEN
+//            ]
+//        ]);
+
+        $curl = curl_init();
+
+        curl_setopt_array($curl, [
+            CURLOPT_URL            => 'http://api.mudu.tv/v1/activities/'.$channelId,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_ENCODING       => '',
+            CURLOPT_MAXREDIRS      => 10,
+            CURLOPT_TIMEOUT        => 0,
+            CURLOPT_FOLLOWLOCATION => true,
+            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
+            CURLOPT_CUSTOMREQUEST  => 'GET',
+            CURLOPT_HTTPHEADER     => [
+                'Authorization: '.self::TOKEN,
+                'Content-Type: application/json'
+            ],
         ]);
-        $info = json_decode((string)$res->getBody(), true);
+
+        $response = curl_exec($curl);
+
+        curl_close($curl);
+        $info = json_decode($response, true);
         if ($channelName !== $info['name']) {
             throw new ApiException("频道名称不一致,频道{$channelId}名称为 " . $info['name']);
         }
+
+
     }
 
     public function setAuthUrl(int $channelId, string $redirectUrl) {
@@ -47,12 +70,7 @@ class SettingService {
             'method'       => 'CUSTOM_VERIFY',
             'redirect_url' => $redirectUrl
         ];
-        $headers = [
-            'Authorization' => self::TOKEN,
-            'Content-Type'  => 'application/json'
-        ];
         $data = json_encode($data);
-        $headers = json_encode($headers);
         curl_setopt_array($curl, [
             CURLOPT_URL            => 'http://api.mudu.tv/v1/activities/' . $channelId . '/setAuth',
             CURLOPT_RETURNTRANSFER => true,
@@ -80,13 +98,30 @@ class SettingService {
     }
 
     public function getAuthCode(int $channelId) {
-        $client = new Client();
-        $res = $client->request('Post', self::BASE_URL . 'v1/activities/' . $channelId . '/getAuthKey', [
-            'headers' => [
-                'Authorization' => self::TOKEN
-            ]
+//        $client = new Client();
+//        $res = $client->request('Post', self::BASE_URL . 'v1/activities/' . $channelId . '/getAuthKey', [
+//            'headers' => [
+//                'Authorization' => self::TOKEN
+//            ]
+//        ]);
+
+        $curl = curl_init();
+        curl_setopt_array($curl, [
+            CURLOPT_URL            => 'http://api.mudu.tv/v1/activities/' . $channelId . '/getAuthKey',
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_ENCODING       => '',
+            CURLOPT_MAXREDIRS      => 10,
+            CURLOPT_TIMEOUT        => 0,
+            CURLOPT_FOLLOWLOCATION => true,
+            CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
+            CURLOPT_CUSTOMREQUEST  => 'POST',
+            CURLOPT_HTTPHEADER     => [
+                'Authorization: '.self::TOKEN
+            ],
         ]);
-        $info = json_decode((string)$res->getBody(), true);
+        $response = curl_exec($curl);
+        curl_close($curl);
+        $info = json_decode((string)$response, true);
         if (empty($info)) {
             throw new ApiException($info['message']);
         }