PHPackages                             tinymeng/openai-chatgpt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. tinymeng/openai-chatgpt

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

tinymeng/openai-chatgpt
=======================

wechat sina qq alipay twitter google line facebook oauth

12PHP

Since Feb 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/majiameng/openai-chatgpt)[ Packagist](https://packagist.org/packages/tinymeng/openai-chatgpt)[ RSS](/packages/tinymeng-openai-chatgpt/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

tinymeng/ChatGPT
================

[](#tinymengchatgpt)

php实现调用ChatGPT，参考TS版本 [idootop/chatgpt-bot](https://github.com/idootop/chatgpt-bot) 编写，感谢作者。部分代码由 ChatGPT 转译。

[![](./screenshots/conch.jpeg)](./screenshots/conch.jpeg)[![](./screenshots/demo.png)](./screenshots/demo.png)

Installing
==========

[](#installing)

```
composer require tinymeng/openai-chatgpt
```

Usage
=====

[](#usage)

```
$chatGPT=new \tinymeng\ChatGpt\ChatGpt($yourSessionToken, $yourAuthorization, $userAgent, $cfClearance); // 前两者二选一填写，获取方法见下方。后两者必填。

// 简单使用
var_dump($chatGPT->ask('你好'));

// 设置代理
\tinymeng\ChatGpt\Di::set('proxy', 'http://127.0.0.1:8899');

// 设置谈话参数（继续会话）
$chatGpt->setConversation($yourConversationID, $yourParentMessageID);
```

⚡️ Getting Started
==================

[](#️-getting-started)

**Step 1. 克隆本项目到本地**

```
git@github.com:majiameng/openai-chatgpt.git
```

**Step 2. 配置你的环境变量**

首先，将 `start.php` 文件中的 `$sessionToken` and `$authorization` 字段替换成你自己的 OpenAI 账号参数

> 你可以在这里找到这两个参数值 👉 [教程](#%E5%85%B6%E4%BB%96)

```
# start.php

$sessionToken="Your-Authorization"
$authorization="Your-SessionToken"

// 过了cloudflare的验证后，填写这两者，都必填
$cfClearance = 'Your-cfClearance';// 有效期2小时，过期要换，在Cookie里可以获取
$userAgent = 'Your-userAgent';// 就是你浏览器UA标识，在header里可以获取
```

**Step 3. Hello world!**

首先，你的电脑必须有 PHP 环境，然后在项目根目录下执行以下命令

```
composer install --no-dev
```

```
php start.php
```

就酱，准备好起飞 🚀

更新日志
====

[](#更新日志)

1.0.5 2022-12-13

- 修复cloudflare拦截问题，需补全验证信息

1.0.3 2022-12-09

- cookie交给CookieJar维护
- 优化Di管理方式
- 返回谈话ID
- 支持设置谈话参数（继续会话）
- 支持设置代理

1.0.1 2022-12-07

- 初版

其他
==

[](#其他)

**How to get the `kAuthorization` and `kSessionToken`?**

首先，在你的电脑浏览器上登录 [OpenAI](https://chat.openai.com/chat)

> OpenAI 账号注册教程 👉 [请戳这里](https://juejin.cn/post/7173447848292253704)

[![](./screenshots/logined.png)](./screenshots/logined.png)

登录成功之后，按 `F12` 快捷键，打开浏览器开发者面板

[![](./screenshots/auth.png)](./screenshots/auth.png)

在开发者面板中找到并打开 `网络` 这一栏，然后给 ChatGPT 随便发条消息。 这时候开发者面板里能够看到有许多网络请求，随便选择一个，然后从请求头中找到 `Authorization`，将它的值复制替换掉 `start.php`里的 `kAuthorization`。

[![](./screenshots/session.png)](./screenshots/session.png)

最后，打开 `存储` 这一栏，然后找到名为 `__Secure-next-auth.session-token` 的 Cookie，复制它的值替换掉 `kSessionToken` 即可

以上。

> *PS: `kAuthorization` 和 `kSessionToken` 二选一即可，然后在 `start.php` 里删掉另一个的值*

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f00d0a29ab429fef8e40769a695213a7adcaff7cb9ba6dc1eb77e0d9655e0618?d=identicon)[tinymeng](/maintainers/tinymeng)

---

Top Contributors

[![majiameng](https://avatars.githubusercontent.com/u/24783993?v=4)](https://github.com/majiameng "majiameng (6 commits)")

### Embed Badge

![Health badge](/badges/tinymeng-openai-chatgpt/health.svg)

```
[![Health](https://phpackages.com/badges/tinymeng-openai-chatgpt/health.svg)](https://phpackages.com/packages/tinymeng-openai-chatgpt)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
