Files
nl-admin-api/app/Http/Controllers/Api/WechatAccountController.php
李琦 6e2769c528
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
优化部分代码,增加微信公众号模板
2026-08-13 19:02:05 +08:00

63 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Api;
use App\BaseApp\BaseController;
use App\Service\WechatAccountService;
use Illuminate\Http\JsonResponse;
/**
* 公众号账号配置控制器:CRUD(Secret 加密入库)/ 默认账号切换 / 连通性测试
* list/option/detail 走基类(Service 内已做脱敏),create/update 覆盖走加密逻辑
*/
class WechatAccountController extends BaseController
{
public function __construct()
{
parent::__construct();
$this->service = WechatAccountService::getInstance();
}
/**
* 新增账号(覆盖基类:Secret 加密、AppID 查重在 Service 内处理)
* @Method POST
*/
public function create(): JsonResponse
{
return jok($this->service->create(request()->post()), '创建成功');
}
/**
* 更新账号(app_secret 传空 = 不修改密钥)
* @Method POST
*/
public function update(): JsonResponse
{
$params = request()->post();
$id = (int) ($params['id'] ?? 0);
if ($id <= 0) {
return jerr('参数错误');
}
unset($params['id']);
return jok($this->service->update($id, $params), '更新成功');
}
/**
* 设为默认发布账号
* @Method POST
*/
public function setDefault(): JsonResponse
{
return jok($this->service->setDefault(request()->post()), '设置成功');
}
/**
* 测试连通性(appid+secret 直连微信换 token 验证)
* @Method POST
*/
public function testConnection(): JsonResponse
{
return jok($this->service->testConnection(request()->post()), '连接成功,凭据有效');
}
}