106 lines
3.4 KiB
PHP
106 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Admin;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
trait UserControllerVerifyIntegrations {
|
|
|
|
/**
|
|
* GET /sms/status — SMS provider connection status.
|
|
*/
|
|
public function get_sms_status(): \WP_REST_Response {
|
|
if (class_exists('\AKSRT\Sms\SMS')) {
|
|
return $this->success(['data' => \AKSRT\Sms\SMS::get_instance()->get_provider_status()]);
|
|
}
|
|
|
|
return $this->success([
|
|
'data' => [
|
|
'enabled' => false,
|
|
'provider' => 'none',
|
|
'configured' => false,
|
|
'available' => false,
|
|
'verified' => false,
|
|
'transport' => '',
|
|
'missing_fields' => [],
|
|
'code_length' => 6,
|
|
'code_expire' => 300,
|
|
'rate_limit' => 60,
|
|
'daily_limit' => 10,
|
|
'notify_bind' => true,
|
|
'notify_login' => false,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* POST /sms/test — Send a test SMS to verify provider configuration.
|
|
*/
|
|
public function test_sms_send(\WP_REST_Request $request): \WP_REST_Response {
|
|
if (!class_exists('\AKSRT\Sms\SMS')) {
|
|
return $this->error('短信服务不可用');
|
|
}
|
|
|
|
$params = $this->get_json_params($request);
|
|
$phone = sanitize_text_field((string) ($params['phone'] ?? ''));
|
|
|
|
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
|
return $this->error('手机号格式不正确');
|
|
}
|
|
|
|
$result = \AKSRT\Sms\SMS::get_instance()->test_provider($phone);
|
|
|
|
if (!empty($result['success'])) {
|
|
return $this->success(['message' => $result['message'] ?? '发送成功']);
|
|
}
|
|
|
|
return $this->error($result['message'] ?? '发送失败');
|
|
}
|
|
|
|
/**
|
|
* GET /wechat/status — WeChat notification service status.
|
|
*/
|
|
public function get_wechat_status(): \WP_REST_Response {
|
|
if (class_exists('\AKSRT\Payment\WeChatNotify')) {
|
|
return $this->success(['data' => \AKSRT\Payment\WeChatNotify::get_instance()->get_status()]);
|
|
}
|
|
|
|
return $this->success([
|
|
'data' => [
|
|
'appid' => '',
|
|
'configured' => false,
|
|
'has_token' => false,
|
|
'available' => false,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* POST /wechat/settings — 更新微信通知设置
|
|
*/
|
|
public function update_wechat_settings(\WP_REST_Request $request): \WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
|
|
$settings = [
|
|
'enabled' => !empty($params['enabled']),
|
|
'app_id' => sanitize_text_field((string) ($params['app_id'] ?? '')),
|
|
'app_secret' => sanitize_text_field((string) ($params['app_secret'] ?? '')),
|
|
'template_id' => sanitize_text_field((string) ($params['template_id'] ?? '')),
|
|
];
|
|
|
|
$existing = \AKSRT\Settings\Settings::get_wechat_settings();
|
|
if ($settings['app_secret'] === '***') {
|
|
$settings['app_secret'] = $existing['app_secret'] ?? '';
|
|
}
|
|
|
|
$merged = array_merge($existing, $settings);
|
|
\AKSRT\Settings\Settings::update_wechat_settings($merged);
|
|
delete_transient('aksrt_wechat_token');
|
|
|
|
return $this->success(['message' => __('微信设置已保存', 'aksrt')]);
|
|
}
|
|
}
|