You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

2 days ago
<?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'];
1 day ago
$this->line('完整请求入参(不含 authKey):');
$this->line(json_encode($repository->lastRequest, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
2 days ago
$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;
}
}