feat(shopro_huifu): 完善商户入网状态检查逻辑 - 新增响应码验证机制,支持通过resp_code判断业务状态 - 增加结算配置和现金配置的状态检测功能 - 实现多维度激活状态判断,包括基础状态、结算状态和现金状态 - 添加JSON对象和数组的安全解析方法 - 扩展日志记录,包含更多调试信息用于问题排查 ```
175 行
6.9 KiB
PHP
175 行
6.9 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro_huifu\library\onboard;
|
|
|
|
use addons\shopro_huifu\library\SdkLoader;
|
|
use addons\shopro_huifu\model\Onboard;
|
|
|
|
class HuifuOnboardQuery
|
|
{
|
|
protected $sdk;
|
|
|
|
public function __construct(HuifuOnboardSdk $sdk = null)
|
|
{
|
|
$this->sdk = $sdk ?: new HuifuOnboardSdk();
|
|
}
|
|
|
|
public function pollAndUpdate(Onboard $row)
|
|
{
|
|
\think\Log::error('[shopro_huifu] onboard poll begin file=' . realpath(__FILE__)
|
|
. ' id=' . $row['id']
|
|
. ' huifu_id=' . ($row['huifu_id'] ?? '')
|
|
. ' apply_no=' . ($row['apply_no'] ?? '')
|
|
. ' busi_req_seq_id=' . ($row['busi_req_seq_id'] ?? '')
|
|
. ' status=' . ($row['onboard_status'] ?? ''));
|
|
|
|
if (!$row['huifu_id']) {
|
|
\think\Log::error('[shopro_huifu] onboard poll skipped: missing huifu_id id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
if ($row['onboard_status'] === Onboard::STATUS_APPROVED) {
|
|
\think\Log::error('[shopro_huifu] onboard poll skipped: already approved id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
|
|
$applyNo = $row['apply_no'];
|
|
if ($applyNo) {
|
|
$status = $this->queryApply($row['huifu_id'], $applyNo);
|
|
\think\Log::error('[shopro_huifu] onboard apply query id=' . $row['id']
|
|
. ' apply_no=' . $applyNo
|
|
. ' data=' . json_encode($status, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
$row = $this->applyRemoteStatus($row, $status);
|
|
if ($row['onboard_status'] === Onboard::STATUS_APPROVED) {
|
|
return $row;
|
|
}
|
|
} else {
|
|
\think\Log::error('[shopro_huifu] onboard apply query skipped: empty apply_no id=' . $row['id']);
|
|
}
|
|
|
|
$basic = $this->queryBasic($row['huifu_id']);
|
|
\think\Log::error('[shopro_huifu] onboard basic query id=' . $row['id']
|
|
. ' data=' . json_encode($basic, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
if ($this->isBasicActive($basic)) {
|
|
if (in_array($row['onboard_status'], [Onboard::STATUS_BUSI_PENDING, Onboard::STATUS_BASIC_OK], true)) {
|
|
$row->onboard_status = Onboard::STATUS_APPROVED;
|
|
$row->reject_reason = '';
|
|
$row->resp_snapshot = json_encode($basic, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
HuifuOnboardReceiverSync::sync($row);
|
|
}
|
|
}
|
|
|
|
return $row;
|
|
}
|
|
|
|
public function queryApply($huifuId, $applyNo)
|
|
{
|
|
SdkLoader::requireRequest('V2UserApplyQueryRequest.php');
|
|
$meta = $this->sdk->newReqMeta();
|
|
$request = new \BsPaySdk\request\V2UserApplyQueryRequest();
|
|
$request->setHuifuId($huifuId);
|
|
$request->setReqSeqId($meta['req_seq_id']);
|
|
$request->setReqDate($meta['req_date']);
|
|
$request->setApplyNo($applyNo);
|
|
$result = $this->sdk->getClient()->postRequest($request);
|
|
$safe = $this->sdk->getClient()->safeApiResult($result);
|
|
return $safe['ok'] ? $safe['data'] : [];
|
|
}
|
|
|
|
public function queryBasic($huifuId)
|
|
{
|
|
SdkLoader::requireRequest('V2UserBasicdataQueryRequest.php');
|
|
$meta = $this->sdk->newReqMeta();
|
|
$request = new \BsPaySdk\request\V2UserBasicdataQueryRequest();
|
|
$request->setHuifuId($huifuId);
|
|
$request->setReqSeqId($meta['req_seq_id']);
|
|
$request->setReqDate($meta['req_date']);
|
|
$result = $this->sdk->getClient()->postRequest($request);
|
|
$safe = $this->sdk->getClient()->safeApiResult($result);
|
|
return $safe['ok'] ? $safe['data'] : [];
|
|
}
|
|
|
|
protected function applyRemoteStatus(Onboard $row, array $data)
|
|
{
|
|
if (!$data) {
|
|
\think\Log::error('[shopro_huifu] onboard remote status empty id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
$stat = strtolower((string) ($data['apply_status'] ?? $data['audit_status'] ?? $data['status'] ?? ''));
|
|
$desc = (string) ($data['apply_desc'] ?? $data['resp_desc'] ?? $data['reject_reason'] ?? '');
|
|
|
|
\think\Log::error('[shopro_huifu] onboard remote status parsed id=' . $row['id']
|
|
. ' stat=' . $stat
|
|
. ' desc=' . $desc
|
|
. ' keys=' . implode(',', array_keys($data)));
|
|
|
|
if (in_array($stat, ['s', 'success', 'approved', '1', '02', '2'], true)) {
|
|
$row->onboard_status = Onboard::STATUS_APPROVED;
|
|
$row->reject_reason = '';
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
HuifuOnboardReceiverSync::sync($row);
|
|
return $row;
|
|
}
|
|
if (in_array($stat, ['f', 'fail', 'failed', 'rejected', '3', '03', '-1'], true)) {
|
|
$row->onboard_status = Onboard::STATUS_REJECTED;
|
|
$row->reject_reason = $desc ?: '汇付进件审核驳回';
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
return $row;
|
|
}
|
|
|
|
$row->onboard_status = Onboard::STATUS_BUSI_PENDING;
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
return $row;
|
|
}
|
|
|
|
protected function isBasicActive(array $data)
|
|
{
|
|
if (!$data) {
|
|
\think\Log::error('[shopro_huifu] onboard basic active check: empty response');
|
|
return false;
|
|
}
|
|
$stat = strtolower((string) ($data['user_status'] ?? $data['status'] ?? $data['acct_stat'] ?? ''));
|
|
$respCode = (string) ($data['resp_code'] ?? '');
|
|
$settleConfig = $this->decodeJsonObject($data['settle_config'] ?? null);
|
|
$cashConfigList = $this->decodeJsonList($data['qry_cash_config_list'] ?? null);
|
|
$settleActive = (string) ($settleConfig['settle_status'] ?? '') === '1';
|
|
$cashActive = false;
|
|
foreach ($cashConfigList as $cashConfig) {
|
|
if ((string) ($cashConfig['switch_state'] ?? '') === '1') {
|
|
$cashActive = true;
|
|
break;
|
|
}
|
|
}
|
|
$active = in_array($stat, ['n', 'normal', 's', 'success', '1'], true)
|
|
|| ($respCode === '00000000' && ($settleActive || $cashActive));
|
|
\think\Log::error('[shopro_huifu] onboard basic active check stat=' . $stat
|
|
. ' resp_code=' . $respCode
|
|
. ' settle_active=' . ($settleActive ? '1' : '0')
|
|
. ' cash_active=' . ($cashActive ? '1' : '0')
|
|
. ' active=' . ($active ? '1' : '0')
|
|
. ' keys=' . implode(',', array_keys($data)));
|
|
return $active;
|
|
}
|
|
|
|
protected function decodeJsonObject($value)
|
|
{
|
|
if (is_array($value)) {
|
|
return $value;
|
|
}
|
|
$decoded = json_decode((string) $value, true);
|
|
return is_array($decoded) ? $decoded : [];
|
|
}
|
|
|
|
protected function decodeJsonList($value)
|
|
{
|
|
$decoded = $this->decodeJsonObject($value);
|
|
if (isset($decoded[0]) && is_array($decoded[0])) {
|
|
return $decoded;
|
|
}
|
|
return [];
|
|
}
|
|
}
|