fix(admin): restore WeChat template message REST callbacks
/wechat/status 与 /wechat/settings 自引入起只注册了路由、从未实现回调方法,后台「微信模板消息」页调用即 500。 按既定设计补齐:状态读取委托 WeChatNotify::get_status()(其既定用途即 REST 与 AJAX 复用),写入委托 Settings::update_wechat_settings() 并由 Integration 收敛键白名单;前端空密钥下发掩码 *** 时保留已存密钥,避免把密钥写成字面量。 新增 PHP harness 驱动真实 UserController + Integration + WeChatNotify 验证状态形状、掩码保留、缺省沿用、未知键丢弃与输入消毒。
This commit is contained in:
@@ -325,6 +325,54 @@ class UserController extends ControllerBase {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GET /wechat/status — 微信模板消息配置状态。
|
||||
*
|
||||
* 状态形状与 WeChatNotify::get_status() 对齐(该方法的既定用途即 REST 与 AJAX 复用)。
|
||||
*/
|
||||
public function get_wechat_status(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\WeChatNotify')) {
|
||||
return $this->error(__('微信通知组件未加载', 'aksrt'), 500);
|
||||
}
|
||||
|
||||
return $this->success(['data' => \AKSRT\Payment\WeChatNotify::get_instance()->get_status()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /wechat/settings — 更新微信模板消息配置。
|
||||
*
|
||||
* 前端在密钥留空且已配置时发送掩码 ***,此时保留已存密钥;
|
||||
* 未提供的字段沿用当前值。键白名单由 Integration::update_wechat_settings() 收敛。
|
||||
*/
|
||||
public function update_wechat_settings(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$params = $this->get_json_params($request);
|
||||
$current = \AKSRT\Settings\Settings::get_wechat_settings();
|
||||
|
||||
$enabled = array_key_exists('enabled', $params) ? !empty($params['enabled']) : !empty($current['enabled']);
|
||||
$app_id = array_key_exists('app_id', $params)
|
||||
? sanitize_text_field((string) $params['app_id'])
|
||||
: (string) ($current['app_id'] ?? '');
|
||||
$template_id = array_key_exists('template_id', $params)
|
||||
? sanitize_text_field((string) $params['template_id'])
|
||||
: (string) ($current['template_id'] ?? '');
|
||||
|
||||
// 掩码 *** 表示「不修改密钥」;仅在显式传入其他值时才覆盖。
|
||||
if (array_key_exists('app_secret', $params) && (string) $params['app_secret'] !== '***') {
|
||||
$app_secret = sanitize_text_field((string) $params['app_secret']);
|
||||
} else {
|
||||
$app_secret = (string) ($current['app_secret'] ?? '');
|
||||
}
|
||||
|
||||
\AKSRT\Settings\Settings::update_wechat_settings([
|
||||
'enabled' => $enabled,
|
||||
'app_id' => $app_id,
|
||||
'app_secret' => $app_secret,
|
||||
'template_id' => $template_id,
|
||||
]);
|
||||
|
||||
return $this->success(['message' => __('微信通知配置已保存', 'aksrt')]);
|
||||
}
|
||||
|
||||
public function rest_handle_credit_settings(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if ($request->get_method() === 'GET') {
|
||||
$config = \AKSRT\Settings\CreditsRuntime::get_credit_settings();
|
||||
|
||||
Reference in New Issue
Block a user