liufumingren c35ac184ae feat: WMS 开放接口签名 & 消息转发模块
- 新增 extra/wms.php 统一配置(app_key/app_secret/base_url)
- 新增 WmsSign.php 签名工具(canonicalQuery + bodySign + stableStringify)
- 新增 WmsVerify.php 验签工具(恒定时间比较防时序攻击)
- 新增 func/ 目录与远端 API 对应(Index.ping / Store.list / Inbox.push)
- 重构 Forward.php 使用 Inbox.push 转发群聊消息到 WMS 站内信
- Chat.php processMessage 接入 Forward 转发,异常不阻塞原有流程
- 删除冗余 WmsSignConfig.php,配置统一从 config('wms') 读取
- 修复 deploy.js chown/chmod .user.ini 报错
2026-08-06 22:46:30 +08:00

84 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\index\library\new_wms\func;
/**
* 站内信模块 — inbox
*
* 外部系统将消息推入仓库站内信。
* warehouse_id 由验签后上下文注入,禁止外部传入。
* ext_id = api:{appKey}:{requestId},幂等去重。
*
* 使用示例:
* $inbox = new Inbox();
* $result = $inbox->push(['requestId' => 'REQ20240806001']);
*
* // 带完整参数
* $result = $inbox->push([
* 'requestId' => 'REQ20240806001',
* 'content' => '入库订单 SO001 已完成',
* 'groupId' => 'GRP001',
* 'groupName' => '仓储业务群',
* 'userId' => 'U001',
* 'userName' => '张三',
* 'parentId' => 0,
* 'sourceType' => 'api',
* 'targetType' => 'im',
* 'extData' => ['orderNo' => 'SO001'],
* 'flags' => new \stdClass(),
* ]);
*/
class Inbox extends Base
{
/**
* {@inheritDoc}
*/
protected function moduleName()
{
return 'inbox';
}
// ==================== API 方法 ====================
/**
* inbox.push — 推送站内信
*
* 外部系统将消息推入仓库站内信。
* 注意:warehouse_id 由验签后上下文注入,禁止外部传入。
*
* @param array $params 推送参数(共 11 个字段)
* - requestId string 必填 来源请求唯一 ID,与 appKey 组合为 ext_id(api:{appKey}:{requestId}),用于幂等去重
* - content string 可选 消息正文/摘要
* - groupId string 可选 外部群 ID,用于关联群及自动查询货主路由
* - groupName string 可选 群名称(展示用)
* - userId string 可选 外部用户 ID
* - userName string 可选 用户名称(展示用)
* - parentId number 可选 关联消息 ID(回信时指向原消息,形成对话链)
* - sourceType string 可选 来源类型:im / api / system,默认 api
* - targetType string 可选 目标类型:im / api / webhook,默认 im
* - extData object 可选 外部透传数据,任意 JSON,WMS 不解析,回信时原样返回
* - flags object 可选 处理标记(预留,当前未消费)
* @return array ['code' => int, 'msg' => string, 'data' => ['ok' => bool, 'id' => int, 'ext_id' => string]]
*/
public function push(array $params)
{
$body = array_merge([
'requestId' => '',
'content' => '',
'groupId' => '',
'groupName' => '',
'userId' => '',
'userName' => '',
'parentId' => 0,
'sourceType' => 'api',
'targetType' => 'im',
'extData' => new \stdClass(),
'flags' => new \stdClass(),
], $params);
return $this->call('push', $body);
}
}