weizong song 2 days ago
parent 8b2ec8a590
commit c631b328a2

@ -0,0 +1,62 @@
<?php
namespace App\Console\Commands;
use App\Repositories\YuanheRepository;
use Illuminate\Console\Command;
use Throwable;
class VerifyYuanheEnterpriseSearch extends Command
{
protected $signature = 'yuanhe:verify-enterprise-search
{keyword : 企业名称关键词}
{--raw : 输出元禾完整原始响应}';
protected $description = '测试小程序注册页使用的元禾企业搜索接口,不会变更任何本地数据或企业户状态';
public function handle(): int
{
$keyword = trim((string) $this->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;
}
}

@ -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(),
];
}
/**
* 查询企业户聚合信息。
*

Loading…
Cancel
Save