88 行
2.5 KiB
PHP
88 行
2.5 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_huifu\library\onboard;
|
||
|
||
use addons\shopro_huifu\library\HuifuClient;
|
||
use addons\shopro_huifu\library\HuifuConfig;
|
||
use addons\shopro_huifu\library\SdkLoader;
|
||
|
||
class HuifuOnboardSdk
|
||
{
|
||
protected $client;
|
||
protected $config;
|
||
|
||
public function __construct()
|
||
{
|
||
$this->config = HuifuConfig::getInstance();
|
||
SdkLoader::boot();
|
||
$this->reinitSkillSource();
|
||
$this->client = new HuifuClient();
|
||
}
|
||
|
||
protected function reinitSkillSource()
|
||
{
|
||
$skill = $this->config->get('onboard_skill_source', 'hfps/1.3.5;hfms/1.0.2');
|
||
\BsPaySdk\core\BsPay::init([
|
||
'sys_id' => $this->config->get('sys_id'),
|
||
'product_id' => $this->config->get('product_id'),
|
||
'rsa_merch_private_key' => $this->config->getPrivateKey(),
|
||
'rsa_huifu_public_key' => $this->config->getPublicKey(),
|
||
'skill_source' => $skill,
|
||
], true);
|
||
}
|
||
|
||
public function getClient()
|
||
{
|
||
return $this->client;
|
||
}
|
||
|
||
public function newReqMeta()
|
||
{
|
||
return [
|
||
'req_date' => date('Ymd'),
|
||
'req_seq_id' => 'HFOB' . date('YmdHis') . mt_rand(1000, 9999),
|
||
];
|
||
}
|
||
|
||
public function getUpperHuifuId()
|
||
{
|
||
$upper = trim((string) $this->config->get('upper_huifu_id'));
|
||
if ($upper !== '') {
|
||
return $upper;
|
||
}
|
||
return trim((string) $this->config->get('sys_id'));
|
||
}
|
||
|
||
/**
|
||
* 为 SDK skill 请求头补齐 huifu_id(extendInfo 合并进 params 后供 jpt-x-skill-huifu_id 使用)
|
||
*/
|
||
public function mergeSkillHuifuId(array $extend = [])
|
||
{
|
||
if (empty($extend['huifu_id'])) {
|
||
$extend['huifu_id'] = $this->getPictureMerchantHuifuId();
|
||
}
|
||
return $extend;
|
||
}
|
||
|
||
/**
|
||
* 进件图片上传用的商户号(个人用户尚未开户前,传平台/渠道商户 huifu_id)
|
||
*/
|
||
public function getPictureMerchantHuifuId()
|
||
{
|
||
$huifuId = trim((string) $this->config->get('huifu_id'));
|
||
if ($huifuId !== '') {
|
||
return $huifuId;
|
||
}
|
||
$upper = $this->getUpperHuifuId();
|
||
if ($upper !== '') {
|
||
return $upper;
|
||
}
|
||
throw new \RuntimeException('插件未配置 huifu_id 或 upper_huifu_id,无法上传进件图片');
|
||
}
|
||
|
||
public function getOnboardNotifyUrl()
|
||
{
|
||
return rtrim($this->config->getSiteBaseUrl(), '/') . '/addons/shopro_huifu/onboard/notify';
|
||
}
|
||
}
|