68 行
2.4 KiB
PHP
68 行
2.4 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\shopro_huifu;
|
|
|
|
use app\common\controller\Backend;
|
|
use think\Db;
|
|
|
|
class Config extends Backend
|
|
{
|
|
protected $noNeedRight = [];
|
|
|
|
public function index()
|
|
{
|
|
if ($this->request->isAjax()) {
|
|
$list = Db::name('shopro_huifu_config')->select();
|
|
$data = [];
|
|
foreach ($list as $item) {
|
|
$value = $item['value'];
|
|
if (in_array($item['name'], ['merchant_private_key', 'huifu_public_key']) && $value) {
|
|
$value = substr($value, 0, 8) . '******';
|
|
}
|
|
$data[$item['name']] = $value;
|
|
}
|
|
$cfg = \addons\shopro_huifu\library\HuifuConfig::getInstance();
|
|
$data['notify_url'] = $cfg->getNotifyUrl('pay');
|
|
$data['refund_notify_url_display'] = $cfg->getNotifyUrl('refund');
|
|
$data['site_base_url'] = $cfg->get('site_base_url') ?: $cfg->getSiteBaseUrl();
|
|
$mini = Db::name('shopro_config')->where('name', 'wxMiniProgram')->value('value');
|
|
$mini = json_decode($mini, true);
|
|
$data['mini_program_app_id'] = $mini['app_id'] ?? '';
|
|
$data['onboard_notify_url'] = rtrim($cfg->getSiteBaseUrl(), '/') . '/addons/shopro_huifu/onboard/notify';
|
|
return $this->success('操作成功', null, $data);
|
|
}
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$params = $this->request->post('row/a');
|
|
if (!$params) {
|
|
$this->error('参数错误');
|
|
}
|
|
|
|
if (($params['miniprogram_channel'] ?? '') === 'huifu') {
|
|
if (empty($params['huifu_id']) || empty($params['sys_id']) || empty($params['product_id'])) {
|
|
$this->error('汇付通道需填写商户号、系统号、产品号');
|
|
}
|
|
}
|
|
|
|
foreach ($params as $name => $value) {
|
|
if (strpos($value, '******') !== false) {
|
|
continue;
|
|
}
|
|
Db::name('shopro_huifu_config')->where('name', $name)->update(['value' => $value]);
|
|
}
|
|
|
|
if (($params['miniprogram_channel'] ?? '') === 'huifu') {
|
|
try {
|
|
\addons\shopro_huifu\library\HuifuConfig::reload()->validateKeys();
|
|
} catch (\Exception $e) {
|
|
$this->error('密钥校验失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$this->success('保存成功');
|
|
}
|
|
}
|