1.新增游戏管理接口和菜单

2.创建对接第三方文档
This commit is contained in:
2026-04-22 18:44:55 +08:00
parent d3ee3faec4
commit 40277e677d
14 changed files with 1373 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ namespace app\api\controller\v1;
use app\api\logic\UserLogic;
use app\api\util\ReturnCode;
use app\dice\model\game\DiceGame;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser;
use app\dice\model\play_record\DicePlayRecord;
@@ -22,6 +23,53 @@ use app\api\cache\UserCache;
*/
class GameController extends BaseController
{
private const GAME_PUBLIC_FIELDS = [
'provider',
'provider_code',
'game_code',
'game_key',
'game_type',
'logo',
'game_url',
'hall_url',
'status',
'sort',
];
/**
* 获取游戏列表
* POST 参数lang可选zh/en默认 zh
* 当前返回启用中的游戏列表
*/
public function getGameList(Request $request): Response
{
$lang = $this->resolveLang($request->post('lang', 'zh'));
$games = $this->buildPublicGameList($lang);
return $this->success([
'game_list' => $games,
]);
}
/**
* 获取游戏大厅信息(脱敏)
* POST 参数lang可选zh/en默认 zh
*/
public function getGameHall(Request $request): Response
{
$lang = $this->resolveLang($request->post('lang', 'zh'));
$games = $this->buildPublicGameList($lang);
$hallUrl = '';
if (!empty($games)) {
$hallUrl = $games[0]['hall_url'] ?? '';
}
return $this->success([
'provider' => 'Dicey Fun',
'provider_code' => 'DF',
'hall_url' => $hallUrl,
'game_list' => $games,
]);
}
/**
* 获取游戏地址
* 根据 username 创建登录 tokenJWT拼接游戏地址返回
@@ -310,4 +358,41 @@ class GameController extends BaseController
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
return $this->success($recordArr);
}
private function resolveLang($lang): string
{
if (!is_string($lang)) {
return 'zh';
}
$langValue = strtolower(trim($lang));
if (!in_array($langValue, ['zh', 'en'], true)) {
return 'zh';
}
return $langValue;
}
private function buildPublicGameList(string $lang): array
{
$rows = DiceGame::where('status', 1)
->orderBy('sort', 'asc')
->orderBy('id', 'asc')
->select(array_merge(self::GAME_PUBLIC_FIELDS, ['game_name', 'game_name_en']))
->get()
->toArray();
if (empty($rows)) {
return [];
}
$games = [];
foreach ($rows as $row) {
$game = [];
foreach (self::GAME_PUBLIC_FIELDS as $fieldName) {
$game[$fieldName] = $row[$fieldName] ?? '';
}
$gameNameEn = $row['game_name_en'] ?? '';
$game['game_name'] = $lang === 'en' && $gameNameEn !== '' ? $gameNameEn : ($row['game_name'] ?? '');
$games[] = $game;
}
return $games;
}
}

View File

@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\controller\game;
use app\dice\logic\game\DiceGameLogic;
use app\dice\validate\game\DiceGameValidate;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 游戏管理控制器
*/
class DiceGameController extends BaseController
{
public function __construct()
{
$this->logic = new DiceGameLogic();
$this->validate = new DiceGameValidate();
parent::__construct();
}
#[Permission('游戏管理列表', 'dice:game:index:index')]
public function index(Request $request): Response
{
$where = $request->more([
['provider_code', ''],
['game_code', ''],
['game_type', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
return $this->success($data);
}
#[Permission('游戏管理读取', 'dice:game:index:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
if (!$model) {
return $this->fail('not found');
}
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
}
#[Permission('游戏管理添加', 'dice:game:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
if (!$result) {
return $this->fail('add failed');
}
return $this->success('add success');
}
#[Permission('游戏管理修改', 'dice:game:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if (!$result) {
return $this->fail('update failed');
}
return $this->success('update success');
}
#[Permission('游戏管理删除', 'dice:game:index:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if ($ids === '' || $ids === null) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
if (!$result) {
return $this->fail('delete failed');
}
return $this->success('delete success');
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\logic\game;
use plugin\saiadmin\basic\eloquent\BaseLogic;
use app\dice\model\game\DiceGame;
/**
* 游戏管理逻辑层
*/
class DiceGameLogic extends BaseLogic
{
public function __construct()
{
$this->model = new DiceGame();
}
}

View File

@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\model\game;
use plugin\saiadmin\basic\eloquent\BaseModel;
/**
* 游戏管理模型
*
* dice_game 游戏配置表
*/
class DiceGame extends BaseModel
{
protected $primaryKey = 'id';
protected $table = 'dice_game';
public $timestamps = true;
public function searchProviderCodeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('provider_code', '=', $value);
}
public function searchGameCodeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('game_code', 'like', '%' . $value . '%');
}
public function searchGameTypeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('game_type', '=', $value);
}
public function searchStatusAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('status', '=', $value);
}
}

View File

@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\validate\game;
use plugin\saiadmin\basic\BaseValidate;
/**
* 游戏管理验证器
*/
class DiceGameValidate extends BaseValidate
{
protected $rule = [
'provider' => 'require|max:64',
'provider_code' => 'require|max:32',
'game_code' => 'require|max:64',
'game_key' => 'require|max:64',
'game_name' => 'require|max:128',
'game_name_en' => 'max:128',
'game_type' => 'require|max:32',
'status' => 'require|in:0,1',
'sort' => 'number',
];
protected $message = [
'provider' => 'provider 必填',
'provider_code' => 'provider_code 必填',
'game_code' => 'game_code 必填',
'game_key' => 'game_key 必填',
'game_name' => 'game_name 必填',
'game_type' => 'game_type 必填',
'status' => 'status 仅支持 0 或 1',
'sort' => 'sort 必须为数字',
];
protected $scene = [
'save' => [
'provider',
'provider_code',
'game_code',
'game_key',
'game_name',
'game_name_en',
'game_type',
'status',
'sort',
],
'update' => [
'provider',
'provider_code',
'game_code',
'game_key',
'game_name',
'game_name_en',
'game_type',
'status',
'sort',
],
];
}

View File

@@ -23,6 +23,8 @@ Route::group('/api/v1', function () {
// 平台 v1 接口:需在请求头携带 auth-token
Route::group('/api/v1', function () {
Route::any('/getGameList', [app\api\controller\v1\GameController::class, 'getGameList']);
Route::any('/getGameHall', [app\api\controller\v1\GameController::class, 'getGameHall']);
Route::any('/getGameUrl', [app\api\controller\v1\GameController::class, 'getGameUrl']);
Route::any('/getPlayerInfo', [app\api\controller\v1\GameController::class, 'getPlayerInfo']);
Route::any('/getPlayerGameRecord', [app\api\controller\v1\GameController::class, 'getPlayerGameRecord']);

View File

@@ -0,0 +1,535 @@
# Dicey Fun 第三方接入文档(基于现有项目接口)
## 1. 基础信息
- provider: `Dicey Fun`
- provider_code: `DF`
- game_type: `slot`
- game_list: `["dafuwen"]`
- provider_logo: ``
- 获取大厅地址: `https://dice-v3-lobby.yuliao666.top`
- 后台管理地址: `https://dice-v3.yuliao666.top/`
- agent_token: `[我来填]`
- agent_id: `5ef059938ba799aaa845e1c2e8a762bd`
## 2. 接口域名与协议
- 协议: `HTTP/HTTPS`(建议生产使用 `HTTPS`
- Base URL: `https://{your-domain}`(由部署方提供)
- 数据格式: `application/json`
- 字符编码: `UTF-8`
### 2.1 调用规范(建议第三方按此统一实现)
- `/api/v1/authToken` 使用 `GET + Query 参数`
- 其他 `/api/v1/*` 接口使用 `POST + JSON Body`(本项目路由为 `Route::any`,但建议第三方统一按 `POST` 接入)
- 请求头统一:
- `Content-Type: application/json`
- `Accept: application/json`
- `auth-token: {authtoken}`(除 `/api/v1/authToken` 外必传)
- 时间相关参数统一使用 Unix 时间戳(秒)
- 建议所有请求设置超时:连接超时 `3s`,读取超时 `10s`
- 生产环境建议增加调用方 IP 白名单和重试退避机制(避免瞬时重试风暴)
---
## 3. 通用返回格式
所有接口统一返回:
```json
{
"code": 200,
"message": "success",
"data": {}
}
```
说明:
- `code=200` 表示成功
- 失败时通常返回:`400/401/402/403/404/422/500`
常见错误码:
- `400` 参数错误
- `401` 未携带 token
- `402` token 无效或过期
- `403` 签名或鉴权失败
- `404` 资源不存在
- `422` 业务错误(如余额不足)
- `500` 服务端异常
---
## 4. 鉴权流程(平台级)
`/api/v1/*` 接口调用前,先获取 `auth-token`
### 4.1 获取 auth-token
- 路径: `GET /api/v1/authToken`
- 鉴权参数Query
- `agent_id`:代理标识(商户标识)
- `secret`:双方约定密钥
- `time`Unix 时间戳(秒)
- `signature`:签名
签名规则:
```text
signature = md5(agent_id + secret + time)
```
签名示例(原串与结果):
```text
agent_id = 9f86d081884c7d659a2feaa0c55ad015
secret = xF75oK91TQj13s0UmNIr1NBWMWGfflNO
time = 1713753600
sign_src = 9f86d081884c7d659a2feaa0c55ad015xF75oK91TQj13s0UmNIr1NBWMWGfflNO1713753600
signature= md5(sign_src)
```
PHP 生成签名示例:
```php
$agentId = '9f86d081884c7d659a2feaa0c55ad015';
$secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
$time = (string) time();
$signature = md5($agentId . $secret . $time);
```
JavaScript 生成签名示例Node.js
```javascript
const crypto = require('crypto');
const agentId = '9f86d081884c7d659a2feaa0c55ad015';
const secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
const time = Math.floor(Date.now() / 1000).toString();
const signature = crypto.createHash('md5').update(agentId + secret + time).digest('hex');
```
服务端校验逻辑(关键点):
- `agent_id/secret/time/signature` 任一缺失即失败(`400`
- `secret` 不匹配即失败(`403`
- `time` 超出容差窗口即失败(`403`,默认容差 `300s`
- `signature` 校验失败即失败(`403`
- 校验通过后颁发 `authtoken`,后续请求必须放在 Header `auth-token`
防重放与时间同步建议:
- 调用方服务器必须启用 NTP 时间同步
- `time` 使用发起请求时的当前秒级时间戳,不要复用旧值
- 遇到 “Timestamp expired or invalid” 时优先检查服务器时间偏差
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"authtoken": "xxx.yyy.zzz"
}
}
```
后续调用 `/api/v1/*` 时,请在 Header 携带:
```text
auth-token: {authtoken}
```
### 4.2 完整调用链(推荐)
1. 计算 `signature = md5(agent_id + secret + time)`
2. 调用 `GET /api/v1/authToken` 获取 `authtoken`
3. 在 Header 添加 `auth-token: {authtoken}`
4. 调用业务接口(如 `getPlayerInfo``setPlayerWallet``getGameUrl`
5. 若返回 `402`,重新获取 `authtoken` 后重试一次
---
## 5. 游戏相关接口
以下接口均需 Header: `auth-token`
## 5.1 获取游戏列表(已支持)
- 路径: `POST /api/v1/getGameList`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `lang`(可选):`zh`/`en`,默认 `zh`
- 返回说明:
-`dice_game` 表读取启用状态(`status=1`)的游戏
- 当前默认仅返回一个游戏:`dafuwen`
-`lang` 返回中英文 `game_name`
- 已做字段脱敏:不会返回敏感配置(如 `sensitive_config_json`
返回字段(`data.game_list[]`
- `provider`:供应商名称
- `provider_code`:供应商编码
- `game_code`:游戏编号
- `game_key`:游戏唯一值
- `game_type`:游戏类型
- `logo`:游戏 Logo 地址
- `game_url`:游戏地址
- `hall_url`:大厅地址
- `status`:状态(`1` 启用)
- `sort`:排序值
- `game_name`:游戏名称(跟随 `lang` 返回中文或英文)
成功返回示例(`lang=zh`
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.yuliao666.top/",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
成功返回示例(`lang=en`
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.yuliao666.top/",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.2 获取游戏大厅信息(已支持,脱敏)
- 路径: `POST /api/v1/getGameHall`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `lang`(可选):`zh`/`en`,默认 `zh`
- 返回说明:
- 返回大厅地址 `hall_url`
- 返回游戏列表(来自 `dice_game`
- 不返回敏感信息字段
返回字段:
- `data.provider`:供应商名称
- `data.provider_code`:供应商编码
- `data.hall_url`:大厅地址
- `data.game_list`:游戏列表(字段结构同 `/api/v1/getGameList`
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.yuliao666.top/",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
成功返回示例(`lang=en`
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.yuliao666.top/",
"hall_url": "https://dice-v3-game.yuliao666.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.3 获取某个游戏地址(已支持)
- 路径: `POST /api/v1/getGameUrl`
- Body 参数:
- `username`(必填):玩家账号(不存在会自动创建)
- `password`(可选):默认 `123456`
- `time`(可选):不传则服务端取当前时间戳
- `lang`(可选):`zh`/`en`,默认 `zh`
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"url": "https://{game-domain}/?token=...&lang=zh"
}
}
```
### 5.4 获取大厅地址(当前项目建议)
当前项目以 `getGameUrl` 作为主要入场方式,`game_list` 仅有 `dafuwen`
- 若第三方需要独立大厅地址,可使用你方配置值:`[代填]`
- 若第三方可直接跳游戏,可直接调用 `getGameUrl`
### 5.5 获取游戏列表 API当前项目状态
已提供独立接口:`POST /api/v1/getGameList`,支持中英文格式,且数据来自 `dice_game` 表。
---
## 6. 游戏管理后台(新增)
本次已新增游戏管理数据表与菜单,用于统一管理游戏基础信息。
### 6.1 数据表
- 建表 SQL`server/db/dice_game.sql`
- 表名:`dice_game`
- 关键字段:
- `logo`:游戏 logo
- `game_url`:游戏地址
- `hall_url`:大厅地址
- `game_code`:游戏编号
- `game_key`:游戏唯一值
- `status`状态1 启用 / 0 禁用)
- `game_type`:游戏类型
- `merchant_config_json`:商户可见扩展
- `sensitive_config_json`:敏感配置(大厅接口不返回)
### 6.2 菜单与权限
- 菜单 SQL`server/db/dice_game_menu.sql`
- 菜单路径:`/dice/game/index`
- 权限标识:
- `dice:game:index:index`
- `dice:game:index:read`
- `dice:game:index:save`
- `dice:game:index:update`
- `dice:game:index:destroy`
---
## 7. 钱包相关接口
以下接口均需 Header: `auth-token`
### 7.1 查询余额(已支持)
方式 1推荐`POST /api/v1/getPlayerInfo`
- 请求参数:
- `username`(必填)
- 余额字段:
- `data.coin`
### 7.2 额度转入 / 额度转出(已支持)
接口:`POST /api/v1/setPlayerWallet`
- 请求参数:
- `username`(必填)
- `coin`(必填)
- `coin > 0`:额度转入(充值)
- `coin < 0`:额度转出(提现)
- `coin = 0`:非法
成功返回 `wallet record`,包含转账前后余额等信息。
### 7.3 获取大厅地址(钱包侧)
如接入方钱包流程要求“转账后返回大厅地址”,可在完成 `setPlayerWallet` 后再调用:
- `POST /api/v1/getGameUrl`
---
## 8. 商户(代理)可配置字段
建议在对接参数表中配置以下字段:
- `provider``Dicey Fun`
- `provider_code``DF`
- `agent_id``5ef059938ba799aaa845e1c2e8a762bd`
- `secret`:签名密钥(双方约定)
- `agent_token``[我来填]`(如需额外业务层 token
- `game_url`:游戏前端域名/地址
- `lobby_url`:大厅地址(可选)
- `lang`:默认语言(`zh`/`en`
- `callback_url`:业务回调地址(如后续扩展)
- `ip_whitelist`:调用白名单(建议)
---
## 9. 后台管理信息
- 后台管理地址:`https://dice-v3.yuliao666.top/`
- 后台账号:`zhuguan`
- 后台密码:`qwer1234`
---
## 10. 对接时序(建议)
1. 平台分配 `agent_id``secret`
2. 第三方调用 `/api/v1/authToken` 获取 `authtoken`
3. 第三方调用 `/api/v1/getGameHall``/api/v1/getGameList` 获取大厅/游戏信息
4. 第三方调用 `/api/v1/getPlayerInfo`(可选,检查用户与余额)
5. 第三方调用 `/api/v1/setPlayerWallet` 进行额度转入(如有)
6. 第三方调用 `/api/v1/getGameUrl` 获取游戏地址并跳转
7. 结束后调用 `/api/v1/setPlayerWallet` 执行额度转出(如有)
---
## 11. Postman 调用示例
### 11.1 获取 auth-token
```bash
curl --location --request GET 'https://{your-domain}/api/v1/authToken?agent_id={agent_id}&secret={secret}&time={time}&signature={signature}'
```
建议在接入测试时,先本地打印以下值再发请求,便于排查:
- `agent_id`
- `time`
- `sign_src`(拼接前字符串)
- `signature`
- 最终请求 URL
### 11.2 获取游戏地址
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameUrl' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"lang":"zh"
}'
```
### 11.3 获取游戏列表(中文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.4 获取游戏列表(英文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"en"
}'
```
### 11.5 获取游戏大厅(中文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameHall' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.6 额度转入
```bash
curl --location --request POST 'https://{your-domain}/api/v1/setPlayerWallet' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"coin":100
}'
```
### 11.7 查询余额
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerInfo' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001"
}'
```

View File

@@ -117,6 +117,7 @@ Route::group('/core', function () {
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdate', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdate']);
Route::post('/dice/reward_config/DiceRewardConfig/createRewardReference', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'createRewardReference']);
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
fastRoute('dice/game/DiceGame', \app\dice\controller\game\DiceGameController::class);
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getOptions']);

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* 生成 /api/v1/authToken或 /api/v1/authtoken所需 signature
*
* 用法:
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret --time=1713772800
*/
$options = getopt('', ['agent_id:', 'secret:', 'time::']);
$agentId = $options['agent_id'] ?? '';
$secret = $options['secret'] ?? '';
$time = $options['time'] ?? (string) time();
if ($agentId === '' || $secret === '' || $time === '') {
echo "缺少参数。\n";
echo "用法: php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret [--time=unix_timestamp]\n";
exit(1);
}
if (ctype_digit($time) === false) {
echo "time 必须是 unix 时间戳(纯数字字符串)。\n";
exit(1);
}
$signature = md5($agentId . $secret . $time);
$query = http_build_query([
'agent_id' => $agentId,
'secret' => $secret,
'time' => $time,
'signature' => $signature,
]);
echo "agent_id: {$agentId}\n";
echo "secret: {$secret}\n";
echo "time: {$time}\n";
echo "signature: {$signature}\n";
echo "query: {$query}\n";

View File

@@ -43,7 +43,6 @@ $fallbackCn = [
'添加失败' => 'add failed',
'修改失败' => 'update failed',
'删除失败' => 'delete failed',
'请选择要删除的数据' => 'please select data to delete',
'参数错误,请检查' => 'invalid parameters, please check',
'参数错误,请检查参数' => 'invalid parameters, please check',
'操作失败' => 'operation failed',