Skip to content

Commit c35bf24

Browse files
committed
新增企业微信用户ID
1 parent d76b829 commit c35bf24

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ WECHAT_CORP_SECRET=''
8989
# 应用 ID
9090
WECHAT_AGENT_ID=''
9191

92+
# 用户 ID 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。指定为"@all",则向该企业应用的全部成员发送
93+
WECHAT_USER_ID='@all'
94+
9295
# 是否启用企业微信送信功能 1:启用 0:不启用 Whether to enable the enterprise WeChat message push function 1: Enable 0: Do not enable
9396
WECHAT_ENABLE=0
9497
###################### end 企业微信 #########################

config.php

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'corp_id' => env('WECHAT_CORP_ID'), // 企业 ID
5454
'corp_secret' => env('WECHAT_CORP_SECRET'), // 企业微信应用的凭证密钥
5555
'agent_id' => (int)env('WECHAT_AGENT_ID'), // 企业微信应用 ID
56+
'user_id' => env('WECHAT_USER_ID'), // 企业微信用户ID
5657
'enable' => (int)env('WECHAT_ENABLE'), // 是否启用,默认不启用
5758
'not_enabled_tips' => env('WECHAT_CORP_ID') && env('WECHAT_CORP_SECRET') && env('WECHAT_AGENT_ID'), // 提醒未启用
5859
'class' => \Luolongfei\Libs\MessageServices\WeChat::class,

libs/MessageServices/WeChat.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class WeChat extends MessageGateway
3131
*/
3232
protected $agentId;
3333

34+
/**
35+
* @var integer 企业微信用户 ID
36+
*/
37+
protected $userId;
38+
3439
/**
3540
* @var Client
3641
*/
@@ -46,6 +51,7 @@ public function __construct()
4651
$this->corpId = config('message.wechat.corp_id');
4752
$this->corpSecret = config('message.wechat.corp_secret');
4853
$this->agentId = config('message.wechat.agent_id');
54+
$this->userId = config('message.wechat.user_id');
4955

5056
$this->accessTokenFile = DATA_PATH . DS . 'wechat_access_token.txt';
5157

@@ -292,7 +298,7 @@ public function send(string $content, string $subject = '', int $type = 1, array
292298
$accessToken = $this->getAccessToken();
293299

294300
$body = [
295-
'touser' => '@all', // 可直接通过此地址获取 userId,指定接收用户,多个用户用“|”分割 https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&fetch_child=FETCH_CHILD&department_id=1
301+
'touser' => $this->userId, // 可直接通过此地址获取 userId,指定接收用户,多个用户用“|”分割 https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&fetch_child=FETCH_CHILD&department_id=1
296302
'msgtype' => 'text', // 消息类型,text 类型支持 a 标签以及 \n 换行,基本满足需求。由于腾讯要求 markdown 语法必须使用 企业微信APP 才能查看,不想安装,故弃之
297303
'agentid' => $this->agentId, // 企业应用的 ID,整型,可在应用的设置页面查看
298304
'text' => [

0 commit comments

Comments
 (0)