Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit b5b72bb

Browse files
committed
fix: auth
1 parent 043e62f commit b5b72bb

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

src/V1.php

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,25 @@ public function clearConversations($account = 0): bool
730730
* @param int $offset
731731
* @param int $limit
732732
* @param string $status
733+
* @param mixed $account
733734
*
734735
* @return array
735736
*/
736-
public function getPlugins(int $offset = 0, int $limit = 250, string $status = 'approved'): array
737+
public function getPlugins(int $offset = 0, int $limit = 250, string $status = 'approved', $account = 0): array
737738
{
739+
try {
740+
$token = $this->accessTokenToJWT($this->accounts[$account]['access_token']);
741+
} catch (Exception $e) {
742+
throw new Exception("Invalid account");
743+
}
744+
738745
try {
739746
$response = $this->http->get('aip/p', [
747+
'headers' => [
748+
'Authorization' => $token,
749+
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
750+
'Referer' => 'https://chat.openai.com/chat',
751+
],
740752
'query' => [
741753
'offset' => $offset,
742754
'limit' => $limit,
@@ -759,13 +771,26 @@ public function getPlugins(int $offset = 0, int $limit = 250, string $status = '
759771
* 安装插件
760772
*
761773
* @param string $pluginId
774+
* @param mixed $account
762775
*
763776
* @return bool
764777
*/
765-
public function installPlugin(string $pluginId): bool
778+
public function installPlugin(string $pluginId, $account = 0): bool
766779
{
767780
try {
768-
$response = $this->http->patch('aip/p/'.$pluginId.'/user-settings')->getBody()->getContents();
781+
$token = $this->accessTokenToJWT($this->accounts[$account]['access_token']);
782+
} catch (Exception $e) {
783+
throw new Exception("Invalid account");
784+
}
785+
786+
try {
787+
$response = $this->http->patch('aip/p/'.$pluginId.'/user-settings', [
788+
'headers' => [
789+
'Authorization' => $token,
790+
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
791+
'Referer' => 'https://chat.openai.com/chat',
792+
],
793+
])->getBody()->getContents();
769794
} catch (GuzzleException $e) {
770795
return false;
771796
}
@@ -782,13 +807,25 @@ public function installPlugin(string $pluginId): bool
782807
* 获取未验证插件
783808
*
784809
* @param string $domain
810+
* @param mixed $account
785811
*
786812
* @return array
787813
*/
788-
public function getUnverifiedPlugins(string $domain = ''): array
814+
public function getUnverifiedPlugins(string $domain = '', $account = 0): array
789815
{
816+
try {
817+
$token = $this->accessTokenToJWT($this->accounts[$account]['access_token']);
818+
} catch (Exception $e) {
819+
throw new Exception("Invalid account");
820+
}
821+
790822
try {
791823
$response = $this->http->get('aip/p/domain', [
824+
'headers' => [
825+
'Authorization' => $token,
826+
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
827+
'Referer' => 'https://chat.openai.com/chat',
828+
],
792829
'query' => [
793830
'domain' => $domain,
794831
],
@@ -809,13 +846,25 @@ public function getUnverifiedPlugins(string $domain = ''): array
809846
* 设置保存聊天记录与训练
810847
*
811848
* @param bool $save
849+
* @param mixed $account
812850
*
813851
* @return bool
814852
*/
815-
public function setChatHistoryAndTraining(bool $save): bool
853+
public function setChatHistoryAndTraining(bool $save, $account = 0): bool
816854
{
855+
try {
856+
$token = $this->accessTokenToJWT($this->accounts[$account]['access_token']);
857+
} catch (Exception $e) {
858+
throw new Exception("Invalid account");
859+
}
860+
817861
try {
818862
$response = $this->http->get('aip/models', [
863+
'headers' => [
864+
'Authorization' => $token,
865+
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
866+
'Referer' => 'https://chat.openai.com/chat',
867+
],
819868
'query' => [
820869
'history_and_training_disabled' => ! $save,
821870
],

tests/V1Test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@
5252
$return = $chatGPT->getPlugins();
5353
$this->assertIsArray($return);
5454
})->group('working');
55+
56+
it('should change history and training status', function () use ($chatGPT) {
57+
$return = $chatGPT->setChatHistoryAndTraining(true);
58+
$this->assertTrue($return);
59+
})->group('working');

0 commit comments

Comments
 (0)