任务时间: 2025年06月16日 10:29 - 10:30
任务类型: Bug修复
模块: ThirdParty/Urs
修复UrsGetUserLevelCountRequest和UrsGetUserTeamRequest两个Request类的继承和配置获取问题,使其与UrsGetUserInfoRequest保持一致的实现方式。
App\Module\ThirdParty\Services\BaseRequest,应该继承ThirdParty\Urs\Request\BaseRequestgetConfig()方法获取配置,应该使用getUrsCredential()和getService()方法参考UrsGetUserInfoRequest.php的正确实现方式:
ThirdParty\Urs\Request\BaseRequestgetUrsCredential()获取认证凭证getService()->base_url获取API地址$c->getApiKey()和$c->getEcologyId()获取配置修复前问题:
use App\Module\ThirdParty\Services\BaseRequest; // 错误的继承
class UrsGetUserLevelCountRequest extends BaseRequest
{
public function __construct() // 不必要的构造函数
{
parent::__construct('urs');
}
// 错误的配置获取方式
$config = $this->getConfig();
$apiUrl = $config['api_url'] ?? '';
$appKey = $config['app_key'] ?? '';
$ecologyId = $config['ecology_id'] ?? 1;
}
修复后:
use ThirdParty\Urs\Util\CryptoService; // 只需要导入CryptoService
class UrsGetUserLevelCountRequest extends BaseRequest // 正确继承
{
// 移除构造函数,使用基类构造函数
// 正确的配置获取方式
$c = $this->getUrsCredential();
$apiUrl = $this->getService()->base_url;
$appKey = $c->getApiKey();
$ecologyId = $c->getEcologyId();
}
修复内容: 与UrsGetUserLevelCountRequest相同的修复方式
ThirdParty\Urs\Request\BaseRequest<?php
namespace ThirdParty\Urs\Request;
use ThirdParty\Urs\Util\CryptoService;
class UrsXxxRequest extends BaseRequest
{
protected function handler(array $params = []): array
{
// 1. 参数验证
if (empty($params['requiredParam'])) {
throw new \Exception('参数验证错误');
}
// 2. 获取配置(标准方式)
$c = $this->getUrsCredential();
$apiUrl = $this->getService()->base_url;
$appKey = $c->getApiKey();
$ecologyId = $c->getEcologyId();
// 3. 构建请求数据
$requestData = [
'param' => $params['param']
];
// 4. 加密和发送请求
$cryptoService = new CryptoService($appKey);
$encryptedData = $cryptoService->encrypt($requestData);
$fullUrl = rtrim($apiUrl, '/') . "/api/ecology/{$ecologyId}/endpoint";
$response = $this->sendHttpRequest($fullUrl, $encryptedData);
// 5. 解密和返回结果
if (isset($response['data'], $response['iv'], $response['timestamp'], $response['sign'])) {
$decryptedResponse = $cryptoService->decrypt($response);
return [
'success' => true,
'message' => '操作成功',
'data' => $decryptedResponse,
];
}
return [
'success' => false,
'message' => '响应格式错误',
'data' => $response,
];
}
}
本次修复解决了URS模块中Request类的架构不一致问题,通过统一继承关系和配置获取方式,提高了代码的一致性和可维护性。修复后的代码更加简洁,遵循了ThirdParty模块的设计规范。
提交信息: 修复URS Request类继承和配置获取问题
Git Hash: d840dd10