63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?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()), '连接成功,凭据有效');
|
||
}
|
||
}
|