feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_huifu\library;
|
||||
|
||||
class SdkLoader
|
||||
{
|
||||
protected static $loaded = false;
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
if (self::$loaded) {
|
||||
return self::getSdkRoot();
|
||||
}
|
||||
|
||||
if (defined('HUIFU_DEBUG_BLOCKED')) {
|
||||
throw new \RuntimeException('汇付 SDK 拒绝启动:DEBUG 已启用');
|
||||
}
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
} elseif (DEBUG !== false) {
|
||||
throw new \RuntimeException('汇付 SDK 拒绝启动:DEBUG 必须为 false');
|
||||
}
|
||||
|
||||
$config = HuifuConfig::getInstance();
|
||||
// 必须在 init.php 之前定义,否则 SDK 默认 PROD_MODE=true 永远走生产网关
|
||||
if (!defined('PROD_MODE')) {
|
||||
define('PROD_MODE', $config->get('env', 'prod') !== 'test');
|
||||
}
|
||||
|
||||
$root = self::getSdkRoot();
|
||||
require_once $root . '/init.php';
|
||||
|
||||
$config->validateKeys();
|
||||
\BsPaySdk\core\BsPay::init([
|
||||
'sys_id' => $config->get('sys_id'),
|
||||
'product_id' => $config->get('product_id'),
|
||||
'rsa_merch_private_key' => $config->getPrivateKey(),
|
||||
'rsa_huifu_public_key' => $config->getPublicKey(),
|
||||
'skill_source' => $config->get('skill_source', 'hfps/1.3.5'),
|
||||
], true);
|
||||
|
||||
self::$loaded = true;
|
||||
return $root;
|
||||
}
|
||||
|
||||
public static function getSdkRoot()
|
||||
{
|
||||
$paths = [
|
||||
ROOT_PATH . 'vendor/huifurepo/dg-php-sdk/BsPaySdk',
|
||||
ADDON_PATH . 'shopro_huifu/library/sdk/BsPaySdk',
|
||||
ADDON_PATH . 'shopro_huifu/library/sdk/extracted/huifurepo-bspay-php-sdk-45b895b/BsPaySdk',
|
||||
];
|
||||
foreach ($paths as $path) {
|
||||
if (is_file($path . '/init.php')) {
|
||||
return rtrim($path, '/\\');
|
||||
}
|
||||
}
|
||||
throw new \RuntimeException('未找到汇付 dg-php-sdk,请安装 huifurepo/dg-php-sdk ^2.0.30');
|
||||
}
|
||||
|
||||
public static function requireRequest($relativePath)
|
||||
{
|
||||
$root = self::boot();
|
||||
$file = $root . '/request/' . ltrim(str_replace('\\', '/', $relativePath), '/');
|
||||
if (!is_file($file)) {
|
||||
$file = dirname($root) . '/request/' . ltrim(str_replace('\\', '/', $relativePath), '/');
|
||||
}
|
||||
if (!is_file($file)) {
|
||||
throw new \RuntimeException('SDK request 文件不存在: ' . $relativePath);
|
||||
}
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户