| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace ThirdParty\Urs\Webhook;
- use App\Module\ThirdParty\Models\ThirdPartyService as ServiceModel;
- use App\Module\ThirdParty\Services\WebhookReceiver;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- /**
- * URS余额检查Webhook处理器
- *
- * 专门处理余额检查相关的Webhook通知
- */
- class UrsCheckWebhook extends WebhookReceiver
- {
- /**
- * 构造函数
- *
- * @param string $serviceCode 服务代码
- * @param Request $request 请求对象
- * @param ServiceModel $service 服务配置对象
- */
- public function __construct(string $serviceCode, Request $request, ServiceModel $service)
- {
- parent::__construct($serviceCode, $request, $service);
- }
- /**
- * 处理余额检查通知
- *
- * @param string $action 操作类型(固定为check)
- * @param Request $request 请求对象
- * @return array
- * @throws \Exception
- */
- protected function handler(string $action, Request $request): array
- {
- // 验证操作类型
- if ($action !== 'check') {
- throw new \Exception("此处理器只能处理check操作,当前操作: {$action}");
- }
- // 验证必需字段
- $this->validateCheckRequest($request);
- // 处理余额检查通知
- return $this->processCheck($request);
- }
- /**
- * 验证余额检查请求
- *
- * @param Request $request 请求对象
- * @throws \Exception
- */
- protected function validateCheckRequest(Request $request): void
- {
- $requiredFields = [ 'user_id', 'check_type' ];
- foreach ($requiredFields as $field) {
- if (!$request->has($field)) {
- throw new \Exception("缺少必需字段: {$field}");
- }
- }
- // 验证用户ID
- $userId = $request->input('user_id');
- if (!is_numeric($userId) || $userId <= 0) {
- throw new \Exception('用户ID格式无效');
- }
- // 验证检查类型
- $checkType = $request->input('check_type');
- if (!in_array($checkType, [ 'balance', 'transaction', 'status', 'limit' ])) {
- throw new \Exception('检查类型无效,必须是: balance, transaction, status, limit');
- }
- }
- public function processCheck()
- {
- // 是否允许,钻石余额 ,本金总数,手续费总数,所需总数
- // 调用 充值模块 来完成
- return [
- 'check' => true,
- ];
- }
- }
|