增加钉钉消息推动
Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
parent
5c2a0e04fc
commit
a6c0b15738
@ -162,6 +162,14 @@ function isOpenNoticePush()
|
|||||||
{
|
{
|
||||||
return config('config.notice_push');
|
return config('config.notice_push');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 是否开启钉钉消息推送
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function isOpenDingTalkNoticePush()
|
||||||
|
{
|
||||||
|
return config('config.dingtalk_push');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日期格式标准输出
|
* 日期格式标准输出
|
||||||
|
@ -134,6 +134,7 @@ class Member extends CommonModel
|
|||||||
'dingtalk_openid' => $openid,
|
'dingtalk_openid' => $openid,
|
||||||
'dingtalk_unionid' => $unionid,
|
'dingtalk_unionid' => $unionid,
|
||||||
'name' => $userInfo['nick'],
|
'name' => $userInfo['nick'],
|
||||||
|
'dingtalk_userid' => isset($userInfo['userId']) ? $userInfo['userId'] : '',
|
||||||
'avatar' => isset($userInfo['avatar']) ? $userInfo['avatar'] : '',
|
'avatar' => isset($userInfo['avatar']) ? $userInfo['avatar'] : '',
|
||||||
'mobile' => isset($userInfo['mobile']) ? $userInfo['mobile'] : '',
|
'mobile' => isset($userInfo['mobile']) ? $userInfo['mobile'] : '',
|
||||||
'email' => isset($userInfo['email']) ? $userInfo['email'] : '',
|
'email' => isset($userInfo['email']) ? $userInfo['email'] : '',
|
||||||
|
@ -24,6 +24,21 @@ class Oauth extends BasicApi
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$app = new Application(config('dingtalk.'));
|
$app = new Application(config('dingtalk.'));
|
||||||
|
$msg = [
|
||||||
|
'msgtype' => "oa",
|
||||||
|
'oa' => [
|
||||||
|
'message_url' => 'http://dingtalk.com',
|
||||||
|
'head' => ['bgcolor' => 'FFBBBBBB', 'title' => '消息通知'],
|
||||||
|
'body' => ['title' => '888', 'content' => '666'],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$params = [
|
||||||
|
'agent_id'=> '271863764',
|
||||||
|
'userid_list' => 'manager9168',
|
||||||
|
'msg'=> json_encode($msg)
|
||||||
|
];
|
||||||
|
$res = $app->conversation->sendCorporationMessage($params);
|
||||||
|
echo json_encode($res);die;
|
||||||
$userId = $app->user->getUseridByUnionid('3CnKFHEE7mX1hayPIHvpCwiEiE');
|
$userId = $app->user->getUseridByUnionid('3CnKFHEE7mX1hayPIHvpCwiEiE');
|
||||||
// echo json_encode($userId);die;
|
// echo json_encode($userId);die;
|
||||||
$userId = $userId['userid'];
|
$userId = $userId['userid'];
|
||||||
@ -36,6 +51,7 @@ class Oauth extends BasicApi
|
|||||||
$currentMember = getCurrentMember();
|
$currentMember = getCurrentMember();
|
||||||
if (!$currentMember) {
|
if (!$currentMember) {
|
||||||
$app = new Application(config('dingtalk.'));
|
$app = new Application(config('dingtalk.'));
|
||||||
|
// $response = $app->oauth->use('app-01')->redirect();
|
||||||
$response = $app->oauth->use('app-01')->withQrConnect()->redirect();
|
$response = $app->oauth->use('app-01')->withQrConnect()->redirect();
|
||||||
$redirect = $response->getTargetUrl();
|
$redirect = $response->getTargetUrl();
|
||||||
if ($redirect) {
|
if ($redirect) {
|
||||||
@ -77,6 +93,7 @@ class Oauth extends BasicApi
|
|||||||
$user['user_info']['avatar'] = $userInfo['avatar'];
|
$user['user_info']['avatar'] = $userInfo['avatar'];
|
||||||
$user['user_info']['mobile'] = $userInfo['mobile'];
|
$user['user_info']['mobile'] = $userInfo['mobile'];
|
||||||
$user['user_info']['email'] = $userInfo['email'];
|
$user['user_info']['email'] = $userInfo['email'];
|
||||||
|
$user['user_info']['userId'] = $userId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Member::dingtalkLogin($user['user_info']);
|
Member::dingtalkLogin($user['user_info']);
|
||||||
|
@ -11,11 +11,16 @@ namespace app\project\behavior;
|
|||||||
|
|
||||||
use app\common\Model\CommonModel;
|
use app\common\Model\CommonModel;
|
||||||
use app\common\Model\Member;
|
use app\common\Model\Member;
|
||||||
|
use app\common\Model\Notify;
|
||||||
use app\common\Model\ProjectLog;
|
use app\common\Model\ProjectLog;
|
||||||
use app\common\Model\ProjectVersion;
|
use app\common\Model\ProjectVersion;
|
||||||
use app\common\Model\TaskMember;
|
use app\common\Model\TaskMember;
|
||||||
use app\common\Model\TaskStages;
|
use app\common\Model\TaskStages;
|
||||||
|
use message\DingTalk;
|
||||||
use service\MessageService;
|
use service\MessageService;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
use think\exception\DbException;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
|
|
||||||
class Task
|
class Task
|
||||||
@ -23,9 +28,9 @@ class Task
|
|||||||
/**
|
/**
|
||||||
* 任务操作钩子
|
* 任务操作钩子
|
||||||
* @param $data
|
* @param $data
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws DataNotFoundException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
* @throws \think\exception\DbException
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function run($data)
|
public function run($data)
|
||||||
{
|
{
|
||||||
@ -178,7 +183,7 @@ class Task
|
|||||||
$notifyActions = ['done', 'redo', 'assign'];
|
$notifyActions = ['done', 'redo', 'assign'];
|
||||||
if (in_array($data['type'], $notifyActions)) {
|
if (in_array($data['type'], $notifyActions)) {
|
||||||
//todo 短信,消息推送
|
//todo 短信,消息推送
|
||||||
$notifyModel = new \app\common\Model\Notify();
|
$notifyModel = new Notify();
|
||||||
$member = Member::where(['code' => $data['memberCode']])->find();
|
$member = Member::where(['code' => $data['memberCode']])->find();
|
||||||
$notifyData['title'] = $member['name'] . ' ' . $remark;
|
$notifyData['title'] = $member['name'] . ' ' . $remark;
|
||||||
$notifyData['content'] = $task['name'];
|
$notifyData['content'] = $task['name'];
|
||||||
@ -186,11 +191,26 @@ class Task
|
|||||||
$taskMembers = TaskMember::where(['task_code' => $task['code']])->select()->toArray();
|
$taskMembers = TaskMember::where(['task_code' => $task['code']])->select()->toArray();
|
||||||
if ($taskMembers) {
|
if ($taskMembers) {
|
||||||
$messageService = new MessageService();
|
$messageService = new MessageService();
|
||||||
|
$messageDingTalk = new DingTalk();
|
||||||
foreach ($taskMembers as $taskMember) {
|
foreach ($taskMembers as $taskMember) {
|
||||||
if ($taskMember['member_code'] == $data['memberCode']) {
|
if ($taskMember['member_code'] == $data['memberCode']) {
|
||||||
continue;//跳过产生者
|
continue;//跳过产生者
|
||||||
}
|
}
|
||||||
|
$member = Member::where(['code' => $taskMember['member_code']])->find();
|
||||||
$result = $notifyModel->add($notifyData['title'], $notifyData['content'], $notifyData['type'], $data['memberCode'], $taskMember['member_code'], $notifyData['action'], json_encode($task), $notifyData['terminal'], $notifyData['avatar']);
|
$result = $notifyModel->add($notifyData['title'], $notifyData['content'], $notifyData['type'], $data['memberCode'], $taskMember['member_code'], $notifyData['action'], json_encode($task), $notifyData['terminal'], $notifyData['avatar']);
|
||||||
|
if (isOpenDingTalkNoticePush()) {
|
||||||
|
if ($member['dingtalk_userid']) {
|
||||||
|
$params = [
|
||||||
|
'msgtype' => "oa",
|
||||||
|
'oa' => [
|
||||||
|
'message_url' => 'http://dingtalk.com',
|
||||||
|
'head' => ['bgcolor' => 'FFBBBBBB', 'text' => '任务动态'],
|
||||||
|
'body' => ['title' => $notifyData['title'], 'content' => $notifyData['content']],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$messageDingTalk->sendCorporationMessage($member['dingtalk_userid'], $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isOpenNoticePush()) {
|
if (isOpenNoticePush()) {
|
||||||
$messageService->sendToUid($taskMember['member_code'], ['content' => $notifyData['content'], 'title' => $notifyData['title'], 'data' => ['organizationCode' => getCurrentOrganizationCode()], 'notify' => $result], $notifyData['action']);
|
$messageService->sendToUid($taskMember['member_code'], ['content' => $notifyData['content'], 'title' => $notifyData['title'], 'data' => ['organizationCode' => getCurrentOrganizationCode()], 'notify' => $result], $notifyData['action']);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'notice_push' => true, //是否开启websocket消息推送
|
'notice_push' => false, //是否开启websocket消息推送
|
||||||
|
'dingtalk_push' => false, //是否开启钉钉消息推送
|
||||||
];
|
];
|
||||||
|
@ -6,21 +6,29 @@ return [
|
|||||||
| 【必填】企业 corpId
|
| 【必填】企业 corpId
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
'corp_id' => 'ccc',
|
'corp_id' => 'aa',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
| 【必填】应用 AppKey
|
| 【必填】应用 AppKey
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
'app_key' => 'bbb',
|
'app_key' => 'bb',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
| 【必填】应用 AppSecret
|
| 【必填】应用 AppSecret
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
'app_secret' => 'aaa',
|
'app_secret' => 'cc',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|-----------------------------------------------------------
|
||||||
|
| 【选填】应用agent_id
|
||||||
|
|-----------------------------------------------------------
|
||||||
|
| 如果你用到消息推送,需要配置该项
|
||||||
|
*/
|
||||||
|
'agent_id' => 'dd',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|-----------------------------------------------------------
|
|-----------------------------------------------------------
|
||||||
@ -61,10 +69,10 @@ return [
|
|||||||
| `redirect` 为回调地址
|
| `redirect` 为回调地址
|
||||||
*/
|
*/
|
||||||
'app-01' => [
|
'app-01' => [
|
||||||
'client_id' => 'aaa',
|
'client_id' => 'ee',
|
||||||
'client_secret' => 'bbb-Tu2CsUZN-ZlQXWQ',
|
'client_secret' => 'ff',
|
||||||
'scope' => 'snsapi_login',
|
'scope' => 'snsapi_login',
|
||||||
'redirect' => 'https://example.com',
|
'redirect' => 'https://gg.com',
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
|-------------------------------------------
|
|-------------------------------------------
|
||||||
|
41
extend/message/DingTalk.php
Normal file
41
extend/message/DingTalk.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace message;
|
||||||
|
|
||||||
|
|
||||||
|
use EasyDingTalk\Application;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息推送服务
|
||||||
|
* Class MessageService
|
||||||
|
* @package service
|
||||||
|
*/
|
||||||
|
class DingTalk
|
||||||
|
{
|
||||||
|
public $app;
|
||||||
|
public $agentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessageService constructor.
|
||||||
|
* @param $agentId
|
||||||
|
* @param $userIdList
|
||||||
|
* @param $msg
|
||||||
|
*/
|
||||||
|
public function __construct($agentId = '')
|
||||||
|
{
|
||||||
|
$app = new Application(config('dingtalk.'));
|
||||||
|
$this->app = $app;
|
||||||
|
$this->agentId = $agentId ? $agentId : config('dingtalk.agent_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendCorporationMessage($userIdList, $msg, $agentId = '')
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'agent_id' => $agentId ? $agentId : $this->agentId,
|
||||||
|
'userid_list' => $userIdList,
|
||||||
|
'msg' => is_array($msg) ? json_encode($msg) : $msg
|
||||||
|
];
|
||||||
|
return $this->app->conversation->sendCorporationMessage($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user