From c631b328a223adc2339b547b19c2fd0f7079a80c Mon Sep 17 00:00:00 2001 From: weizong song Date: Thu, 24 Sep 2026 11:58:45 +0800 Subject: [PATCH] up --- .../Commands/VerifyYuanheEnterpriseSearch.php | 62 +++++++++++++++++++ app/Repositories/YuanheRepository.php | 16 +++++ 2 files changed, 78 insertions(+) create mode 100644 app/Console/Commands/VerifyYuanheEnterpriseSearch.php diff --git a/app/Console/Commands/VerifyYuanheEnterpriseSearch.php b/app/Console/Commands/VerifyYuanheEnterpriseSearch.php new file mode 100644 index 0000000..fa2f173 --- /dev/null +++ b/app/Console/Commands/VerifyYuanheEnterpriseSearch.php @@ -0,0 +1,62 @@ +argument('keyword')); + if ($keyword === '') { + $this->error('企业名称关键词不能为空。'); + return self::FAILURE; + } + + $repository = new YuanheRepository(); + $this->info("开始调用注册页企业搜索:{$keyword}"); + + try { + $result = $repository->enterpriseSearchProbe(['keyword' => $keyword]); + } catch (Throwable $exception) { + $this->error($exception->getMessage()); + $this->line('签名 timestamp:' . ($repository->lastRequestTimestamp ?? '(未生成)')); + return self::FAILURE; + } + + $response = $result['response']; + $data = $response['data'] ?? null; + $this->line('签名 timestamp:' . ($repository->lastRequestTimestamp ?? '(未生成)')); + $this->table( + ['元禾 code', '元禾 msg', '元禾 status', '结果数量'], + [[ + $response['code'] ?? '(无业务码)', + $response['msg'] ?? ($result['json_error'] ? '非 JSON:' . $result['json_error'] : ''), + $response['status'] ?? '', + is_array($data) ? count($data) : 0, + ]] + ); + + if ($this->option('raw')) { + $this->line('原始响应:'); + $this->line($result['raw_response']); + } + + if (!is_array($response) || !array_key_exists('code', $response)) { + return self::FAILURE; + } + + return in_array((int) $response['code'], [0, 200], true) + ? self::SUCCESS + : self::FAILURE; + } +} diff --git a/app/Repositories/YuanheRepository.php b/app/Repositories/YuanheRepository.php index 910813d..167a2c5 100755 --- a/app/Repositories/YuanheRepository.php +++ b/app/Repositories/YuanheRepository.php @@ -83,6 +83,22 @@ class YuanheRepository } } + /** + * 诊断用:复用小程序企业搜索的请求方式,但保留元禾完整响应。 + */ + public function enterpriseSearchProbe(array $params): array + { + $url = $this->baseUrl . '/master-service/openapi/businessCollege/enterprise/search'; + $rawResponse = httpCurl($url, 'GET', $params, $this->getHeader()); + $response = json_decode($rawResponse, true); + + return [ + 'raw_response' => $rawResponse, + 'response' => is_array($response) ? $response : null, + 'json_error' => is_array($response) ? null : json_last_error_msg(), + ]; + } + /** * 查询企业户聚合信息。 *