feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_aliyun_express\library;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class ExpressConfig
|
||||
{
|
||||
protected static $instance;
|
||||
protected $values = [];
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function reload()
|
||||
{
|
||||
self::$instance = null;
|
||||
return self::getInstance();
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
try {
|
||||
$rows = Db::name('shopro_aliyun_express_config')->select();
|
||||
foreach ($rows as $row) {
|
||||
$this->values[$row['name']] = $row['value'];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->values = [];
|
||||
}
|
||||
}
|
||||
|
||||
public function get($name, $default = '')
|
||||
{
|
||||
return array_key_exists($name, $this->values) ? $this->values[$name] : $default;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
if ($this->get('express_enable', '1') !== '1') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 已写入插件配置表则视为可用(避免 info.ini state=0 时业务 API 与后台测试行为不一致)
|
||||
try {
|
||||
if (\think\Db::name('shopro_aliyun_express_config')->count() > 0) {
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
if (!function_exists('get_addon_info')) {
|
||||
return false;
|
||||
}
|
||||
$info = get_addon_info('shopro_aliyun_express');
|
||||
return $info && intval($info['state'] ?? 0) === 1;
|
||||
}
|
||||
|
||||
public function getProvider()
|
||||
{
|
||||
$provider = strtolower(trim($this->get('express_provider', 'aliyun')));
|
||||
if (!in_array($provider, ['aliyun', 'kdniao', 'expressbird'], true)) {
|
||||
return 'aliyun';
|
||||
}
|
||||
return $provider;
|
||||
}
|
||||
|
||||
public function getCacheTtl()
|
||||
{
|
||||
$ttl = intval($this->get('cache_ttl', 300));
|
||||
return $ttl > 0 ? $ttl : 300;
|
||||
}
|
||||
|
||||
public function getAliyunAppcode()
|
||||
{
|
||||
return trim($this->get('aliyun_appcode', ''));
|
||||
}
|
||||
|
||||
public function getAliyunApiUrl()
|
||||
{
|
||||
$url = trim($this->get('aliyun_api_url', ''));
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getAliyunApiMode()
|
||||
{
|
||||
$mode = strtolower(trim($this->get('aliyun_api_mode', 'auto')));
|
||||
$allowed = ['auto', 'expr_post', 'expr_get', 'wuliu_kdi', 'kzexpress'];
|
||||
return in_array($mode, $allowed, true) ? $mode : 'auto';
|
||||
}
|
||||
|
||||
public function getAliyunHttpMethod()
|
||||
{
|
||||
$method = strtolower(trim($this->get('aliyun_http_method', 'auto')));
|
||||
return in_array($method, ['auto', 'get', 'post'], true) ? $method : 'auto';
|
||||
}
|
||||
|
||||
public function getExpressBirdAppcode()
|
||||
{
|
||||
return trim($this->get('expressbird_appcode', ''));
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户