Skip to content

Commit

Permalink
新增企业微信用户ID
Browse files Browse the repository at this point in the history
  • Loading branch information
abwuge committed Mar 6, 2023
1 parent d76b829 commit c35bf24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ WECHAT_CORP_SECRET=''
# 应用 ID
WECHAT_AGENT_ID=''

# 用户 ID 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。指定为"@all",则向该企业应用的全部成员发送
WECHAT_USER_ID='@all'

# 是否启用企业微信送信功能 1:启用 0:不启用 Whether to enable the enterprise WeChat message push function 1: Enable 0: Do not enable
WECHAT_ENABLE=0
###################### end 企业微信 #########################
Expand Down
1 change: 1 addition & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'corp_id' => env('WECHAT_CORP_ID'), // 企业 ID
'corp_secret' => env('WECHAT_CORP_SECRET'), // 企业微信应用的凭证密钥
'agent_id' => (int)env('WECHAT_AGENT_ID'), // 企业微信应用 ID
'user_id' => env('WECHAT_USER_ID'), // 企业微信用户ID
'enable' => (int)env('WECHAT_ENABLE'), // 是否启用,默认不启用
'not_enabled_tips' => env('WECHAT_CORP_ID') && env('WECHAT_CORP_SECRET') && env('WECHAT_AGENT_ID'), // 提醒未启用
'class' => \Luolongfei\Libs\MessageServices\WeChat::class,
Expand Down
8 changes: 7 additions & 1 deletion libs/MessageServices/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class WeChat extends MessageGateway
*/
protected $agentId;

/**
* @var integer 企业微信用户 ID
*/
protected $userId;

/**
* @var Client
*/
Expand All @@ -46,6 +51,7 @@ public function __construct()
$this->corpId = config('message.wechat.corp_id');
$this->corpSecret = config('message.wechat.corp_secret');
$this->agentId = config('message.wechat.agent_id');
$this->userId = config('message.wechat.user_id');

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

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

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

0 comments on commit c35bf24

Please sign in to comment.