Files
lgp-admin-plus-api/app/Http/Controllers/Api/WechatAccountController.php

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;
/**
* 公众号账号配置控制器CRUDSecret 加密入库)/ 默认账号切换 / 连通性测试
* 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()), '连接成功,凭据有效');
}
}