refactor(classes): organize inc/classes into domain folders
Move ~94 root class shells and root *-traits into domain directories (core, auth, user, credits, content, payment/gateways, forum, shop, sms, ai, messages, extensions, widgets, settings, admin). Update bootstrap require paths, co-locate traits with owners, fix forum/user relative requires, drop duplicate shop controller requires, and wire home-modules load. Path-only; class names and init order unchanged.
This commit is contained in:
1 parent
2a8fe68048
commit
ce1c13b947
115 files changed
+171
-224
No files matched your search
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* AKSRT SMS Provider — 华为云短信
|
||||
*
|
||||
* 通过华为云短信 API 发送验证码。
|
||||
* 使用 HMAC-SHA256 签名 (AK/SK Auth),不引入重量级 SDK。
|
||||
*
|
||||
* @package AKSRT
|
||||
* @link https://support.huaweicloud.com/api-msgsms/sms_05_0001.html
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_SMS_Provider_Huawei implements AKSRT_SMS_Provider {
|
||||
|
||||
public function get_key(): string {
|
||||
return 'huawei';
|
||||
}
|
||||
|
||||
public function get_label(): string {
|
||||
return __('华为云短信', 'aksrt');
|
||||
}
|
||||
|
||||
public function validate_config(array $config): array {
|
||||
$missing = [];
|
||||
if (empty($config['sms_access_key'])) $missing[] = 'sms_access_key';
|
||||
if (empty($config['sms_access_secret'])) $missing[] = 'sms_access_secret';
|
||||
if (empty($config['sms_huawei_sender'])) $missing[] = 'sms_huawei_sender';
|
||||
if (empty($config['sms_template_code'])) $missing[] = 'sms_template_code';
|
||||
if (empty($config['sms_huawei_signature'])) $missing[] = 'sms_huawei_signature';
|
||||
return $missing;
|
||||
}
|
||||
|
||||
public function send_code(string $phone, string $code, array $config): array {
|
||||
$app_key = (string) ($config['sms_access_key'] ?? '');
|
||||
$app_secret = (string) ($config['sms_access_secret'] ?? '');
|
||||
$sender = (string) ($config['sms_huawei_sender'] ?? '');
|
||||
$template_id = (string) ($config['sms_template_code'] ?? '');
|
||||
$signature = (string) ($config['sms_huawei_signature'] ?? '');
|
||||
$endpoint = (string) ($config['sms_huawei_endpoint'] ?? 'https://smsapi.ap-southeast-1.myhuaweicloud.com');
|
||||
|
||||
$result = $this->request($app_key, $app_secret, $sender, $template_id, $signature, $endpoint, $phone, $code);
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
$this->log('error', $phone, $result->get_error_message());
|
||||
return ['success' => false, 'message' => $result->get_error_message(), 'transport' => 'hw_http'];
|
||||
}
|
||||
|
||||
$body = json_decode(wp_remote_retrieve_body($result), true);
|
||||
$code_field = $body['code'] ?? '';
|
||||
|
||||
if ($code_field === '000000') {
|
||||
$this->log('sent', $phone, '000000');
|
||||
return ['success' => true, 'message' => __('验证码已发送', 'aksrt'), 'transport' => 'hw_http'];
|
||||
}
|
||||
|
||||
$err_msg = $body['description'] ?? $body['code'] ?? __('未知错误', 'aksrt');
|
||||
$this->log('error', $phone, "{$code_field}: {$err_msg}");
|
||||
return ['success' => false, 'message' => sprintf('华为云: %s', $err_msg), 'transport' => 'hw_http'];
|
||||
}
|
||||
|
||||
public function get_status(array $config): array {
|
||||
$missing = $this->validate_config($config);
|
||||
return [
|
||||
'provider' => $this->get_key(),
|
||||
'configured' => empty($missing),
|
||||
'available' => !empty($config['sms_enabled']) && empty($missing),
|
||||
'verified' => !empty($config['sms_huawei_verified']),
|
||||
'transport' => 'hw_http',
|
||||
'missing_fields' => $missing,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 华为云 AK/SK 签名请求
|
||||
*/
|
||||
private function request(string $app_key, string $app_secret, string $sender, string $template_id, string $signature, string $endpoint, string $phone, string $code) {
|
||||
$endpoint = rtrim($endpoint, '/');
|
||||
$url = "{$endpoint}/sms/batchSendSms";
|
||||
|
||||
$body = wp_json_encode([
|
||||
'from' => $sender,
|
||||
'to' => [$phone],
|
||||
'templateId' => $template_id,
|
||||
'templateParas' => [$code],
|
||||
'signature' => $signature,
|
||||
]);
|
||||
|
||||
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$nonce = wp_generate_uuid4();
|
||||
|
||||
// 简化签名:使用 X-Sms-AppKey 鉴权方式
|
||||
return wp_remote_post($url, [
|
||||
'timeout' => 10,
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Sms-AppKey' => $app_key,
|
||||
'X-Sms-AppSecret' => $app_secret,
|
||||
],
|
||||
'body' => $body,
|
||||
]);
|
||||
}
|
||||
|
||||
private function log(string $level, string $phone, string $message): void {
|
||||
if (!defined('WP_DEBUG') || !WP_DEBUG) return;
|
||||
$masked = substr($phone, 0, 3) . '****' . substr($phone, -4);
|
||||
error_log(sprintf('[AKSRT SMS] [huawei] [%s] Phone: %s — %s', $level, $masked, $message));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user