底层微信接口免密登录

This commit is contained in:
Ghost
2025-04-09 14:45:27 +08:00
parent 282a301eeb
commit ecf7024fcb
20 changed files with 158 additions and 103 deletions

View File

@@ -12,12 +12,16 @@ class AccountController extends BaseController
* 获取公司账号列表
* @return \think\response\Json
*/
public function getlist()
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
}else{
return errorJson('缺少授权信息');
}
}
try {
@@ -26,8 +30,8 @@ class AccountController extends BaseController
'showNormalAccount' => $this->request->param('showNormalAccount', ''),
'keyword' => $this->request->param('keyword', ''),
'departmentId' => $this->request->param('companyId', ''),
'pageIndex' => $this->request->param('pageIndex', 0),
'pageSize' => $this->request->param('pageSize', 12)
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize',20)
];
// 设置请求头
@@ -58,7 +62,7 @@ class AccountController extends BaseController
public function createDepartment()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -112,7 +116,7 @@ class AccountController extends BaseController
public function createAccount()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -194,7 +198,7 @@ class AccountController extends BaseController
public function getDepartmentList()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -4,6 +4,7 @@ namespace app\api\controller;
use think\Controller;
use think\facade\Env;
use app\common\service\AuthService;
class BaseController extends Controller {
@@ -17,6 +18,8 @@ class BaseController extends Controller {
protected $baseUrl;
protected $authorization = '';
public function __construct() {
parent::__construct();
$this->baseUrl = Env::get('api.wechat_url');
@@ -24,6 +27,10 @@ class BaseController extends Controller {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
$this->authorization = AuthService::getSystemAuthorization();
}

View File

@@ -14,10 +14,10 @@ class DeviceController extends BaseController
* 获取设备列表
* @return \think\response\Json
*/
public function getlist($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -146,7 +146,7 @@ class DeviceController extends BaseController
public function addDevice($accountId = 0)
{
if (empty($accountId)) {
$accountId = $this->request->param('accountId', 5555);
$accountId = $this->request->param('accountId', '');
}
if (empty($accountId)) {

View File

@@ -11,10 +11,10 @@ class FriendTaskController extends BaseController
* 获取添加好友记录列表
* @return \think\response\Json
*/
public function getlist($pageIndex,$pageSize,$authorization,$isJob = false)
public function getlist($pageIndex,$pageSize,$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -68,7 +68,7 @@ class FriendTaskController extends BaseController
public function addFriendTask()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -12,10 +12,10 @@ class MessageController extends BaseController
* 获取微信好友列表
* @return \think\response\Json
*/
public function getFriendsList($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
public function getFriendsList($pageIndex = '',$pageSize = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -167,10 +167,10 @@ class MessageController extends BaseController
* 获取微信群聊列表
* @return \think\response\Json
*/
public function getChatroomList($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
public function getChatroomList($pageIndex = '',$pageSize = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -363,7 +363,7 @@ class MessageController extends BaseController
public function getMessageList()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -422,7 +422,7 @@ class MessageController extends BaseController
public function getChatroomMessages()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -13,7 +13,7 @@ class MomentsController extends BaseController
public function addJob()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -107,7 +107,7 @@ class MomentsController extends BaseController
public function getList()
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -20,7 +20,7 @@ class StatsController extends BaseController
*/
public function basicData()
{
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -46,7 +46,7 @@ class StatsController extends BaseController
from to 时间 当lidu为 0时2025-03-12 09:54:42 当lidu为 1时2025-03-12 当lidu为 2时2025-03
*/
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
$lidu = trim($this->request->param('lidu', ''));
$from = trim($this->request->param('from', ''));
$to = trim($this->request->param('to', ''));

View File

@@ -105,7 +105,7 @@ class UserController extends BaseController
{
$grant_type = $this->request->param('grant_type', 'refresh_token');
$refresh_token = $this->request->param('refresh_token', '');
$authorization = $this->request->header('authorization', '');
$authorization = $this->request->header('authorization', $this->authorization);
if (empty($grant_type) || empty($authorization)) {
return errorJson('参数错误');
@@ -144,7 +144,7 @@ class UserController extends BaseController
*/
public function getAccountInfo()
{
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -209,7 +209,7 @@ class UserController extends BaseController
return $params;
}
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}
@@ -244,7 +244,7 @@ class UserController extends BaseController
*/
public function logout()
{
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -18,7 +18,7 @@ class WebSocketController extends BaseController
public function __construct()
{
parent::__construct();
$this->authorized = $this->request->header('authorized', '');
$this->authorized = $this->request->header('authorization', $this->authorization);
$this->accountId = $this->request->param('accountId', '');
if (empty($this->authorized) || empty($this->accountId)) {
$data['authorized'] = $this->authorized;
@@ -54,6 +54,109 @@ class WebSocketController extends BaseController
}
/**
* 朋友圈点赞
*/
public function momentInteract()
{
if ($this->request->isPost()) {
$data = $this->request->param();
if (empty($data)) {
$this->error('参数缺失');
}
$dataArray = $data;
if (!is_array($dataArray)) {
$this->error('数据格式错误');
}
//过滤消息
if (empty($dataArray['snsId'])) {
$this->error('snsId不能为空');
}
if (empty($dataArray['wechatAccountId'])) {
$this->error('微信id不能为空');
}
$result = [
"cmdType" => "CmdMomentInteract",
"momentInteractType" => 1,
"seq" => time(),
"snsId" => $dataArray['snsId'],
"wechatAccountId" => $dataArray['wechatAccountId'],
"wechatFriendId" => 0,
];
$result = json_encode($result);
$this->client->send($result);
$message = $this->client->receive();
$message = json_decode($message, 1);
//关闭WS链接
$this->client->close();
//Log::write('WS个人消息发送');
successJson($message, '点赞成功');
} else {
errorJson('非法请求');
}
}
/**
* 朋友圈取消点赞
*/
public function momentCancelInteract()
{
if ($this->request->isPost()) {
$data = $this->request->param();
if (empty($data)) {
$this->error('参数缺失');
}
$dataArray = $data;
if (!is_array($dataArray)) {
$this->error('数据格式错误');
}
//过滤消息
if (empty($dataArray['snsId'])) {
$this->error('snsId不能为空');
}
if (empty($dataArray['wechatAccountId'])) {
$this->error('微信id不能为空');
}
$result = [
"CommentId2" => '',
"CommentTime" => 0,
"cmdType" => "CmdMomentCancelInteract",
"optType" => 1,
"seq" => time(),
"snsId" => $dataArray['snsId'],
"wechatAccountId" => $dataArray['wechatAccountId'],
"wechatFriendId" => 0,
];
$result = json_encode($result);
$this->client->send($result);
$message = $this->client->receive();
$message = json_decode($message, 1);
//关闭WS链接
$this->client->close();
//Log::write('WS个人消息发送');
successJson($message, '取消点赞成功');
} else {
errorJson('非法请求');
}
}
/**
* 个人消息发送
*/

View File

@@ -16,7 +16,7 @@ class WechatChatroomController extends BaseController
public function getlist($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
@@ -123,7 +123,7 @@ class WechatChatroomController extends BaseController
public function listChatroomMember($wechatChatroomId = '')
{
// 获取授权token
$authorization = trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
return errorJson('缺少授权信息');
}

View File

@@ -59,10 +59,10 @@ class WechatController extends BaseController
}
}
public function getlist($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);

View File

@@ -12,10 +12,10 @@ class WechatFriendController extends BaseController
* 获取微信好友列表数据
* @return \think\response\Json
*/
public function getlist($pageIndex = '',$pageSize = '',$preFriendId = '',$authorization = '',$isJob = false)
public function getlist($pageIndex = '',$pageSize = '',$preFriendId = '',$isJob = false)
{
// 获取授权token
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', ''));
$authorization = trim($this->request->header('authorization', $this->authorization));
if (empty($authorization)) {
if($isJob){
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\AccountController;
use app\common\service\AuthService;
class AccountListJob
{
@@ -73,15 +72,8 @@ class AccountListJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用公司账号列表获取方法
$result = $accountController->getlist($pageIndex,$pageSize,$authorization);
$result = $accountController->getlist($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\DeviceController;
use app\common\service\AuthService;
class DeviceListJob
{
@@ -73,15 +72,10 @@ class DeviceListJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用设备列表获取方法
$result = $deviceController->getlist($pageIndex,$pageSize,$authorization,true);
$result = $deviceController->getlist($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\FriendTaskController;
use app\common\service\AuthService;
class FriendTaskJob
{
@@ -72,16 +71,9 @@ class FriendTaskJob
// 设置请求信息
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用添加好友任务获取方法
$result = $friendTaskController->getlist($pageIndex,$pageSize,$authorization,true);
$result = $friendTaskController->getlist($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\MessageController;
use app\common\service\AuthService;
class MessageChatroomListJob
{
@@ -73,15 +72,8 @@ class MessageChatroomListJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用添加好友任务获取方法
$result = $messageController->getChatroomList($pageIndex,$pageSize,$authorization,true);
$result = $messageController->getChatroomList($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\MessageController;
use app\common\service\AuthService;
class MessageFriendsListJob
{
@@ -73,16 +72,10 @@ class MessageFriendsListJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用添加好友任务获取方法
$result = $messageController->getFriendsList($pageIndex,$pageSize,$authorization,true);
$result = $messageController->getFriendsList($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\WechatChatroomController;
use app\common\service\AuthService;
class WechatChatroomJob
{
@@ -73,15 +72,8 @@ class WechatChatroomJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用设备列表获取方法
$result = $wechatChatroomController->getlist($pageIndex,$pageSize,$authorization,true);
$result = $wechatChatroomController->getlist($pageIndex,$pageSize,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\WechatFriendController;
use app\common\service\AuthService;
class WechatFriendJob
{
@@ -75,15 +74,9 @@ class WechatFriendJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用设备列表获取方法
$result = $wechatFriendController->getlist($pageIndex,$pageSize,$preFriendId,$authorization,true);
$result = $wechatFriendController->getlist($pageIndex,$pageSize,$preFriendId,true);
$response = json_decode($result,true);

View File

@@ -7,7 +7,6 @@ use think\facade\Log;
use think\Queue;
use think\facade\Config;
use app\api\controller\WechatController;
use app\common\service\AuthService;
class WechatListJob
{
@@ -73,15 +72,9 @@ class WechatListJob
$request = request();
$request->withGet($params);
// 获取系统授权信息
$authorization = AuthService::getSystemAuthorization();
if (empty($authorization)) {
Log::error('获取系统授权信息失败');
return false;
}
// 调用设备列表获取方法
$result = $wechatController->getlist($pageIndex,$pageSize,$authorization,true);
$result = $wechatController->getlist($pageIndex,$pageSize,true);
$response = json_decode($result,true);