PHPackages                             xin6841414/work-wechat-robot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xin6841414/work-wechat-robot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xin6841414/work-wechat-robot
============================

一个企业微信群机器人通知的laravel扩展

1.2.1(5y ago)21.1kMITPHPPHP ^7.2.5 || ^8.0

Since Oct 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/xin6841414/work-wechat-robot)[ Packagist](https://packagist.org/packages/xin6841414/work-wechat-robot)[ RSS](/packages/xin6841414-work-wechat-robot/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

 企业微信群机器人\_Laravel
===================

[](#-企业微信群机器人_laravel-)

 企业微信群机器人通知的 laravel扩展

[![Build Status](https://camo.githubusercontent.com/c98e4d7558bf7067f10804dcf359e599798293becc91928f31ca24771b5ed15d/68747470733a2f2f7472617669732d63692e6f72672f78696e363834313431342f776f726b2d7765636861742d726f626f742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/xin6841414/work-wechat-robot)[![Total Downloads](https://camo.githubusercontent.com/edc0c325cb759aee55c3788f0123be14762e464b26c78a0a8e866f6bcabc2e10/68747470733a2f2f706f7365722e707567782e6f72672f78696e363834313431342f776f726b2d7765636861742d726f626f742f646f776e6c6f616473)](https://packagist.org/packages/xin6841414/work-wechat-robot)[![License](https://camo.githubusercontent.com/edc738445672675304809b4a1d696e5a5d40c8041c612c78ce01b82b02c6d289/68747470733a2f2f706f7365722e707567782e6f72672f78696e3638343134312f776f726b2d7765636861742d726f626f742f6c6963656e7365)](//packagist.org/packages/xin6841414/work-wechat-robot)[![Latest Stable Version](https://camo.githubusercontent.com/9e6e411867bacec23d25da56f576ac1a26f0deb8bcba3a39af792e4026c6b838/68747470733a2f2f706f7365722e707567782e6f72672f78696e363834313431342f776f726b2d7765636861742d726f626f742f76)](//packagist.org/packages/xin6841414/work-wechat-robot)[![Latest Unstable Version](https://camo.githubusercontent.com/2f0ee50e15e5c9e2996d42408c19658a329929284368c591bba17a9d3ec6b3d0/68747470733a2f2f706f7365722e707567782e6f72672f78696e363834313431342f776f726b2d7765636861742d726f626f742f762f756e737461626c65)](//packagist.org/packages/xin6841414/work-wechat-robot)[![StyleCI build status](https://camo.githubusercontent.com/035a731f86c0d49a8d0e6a0da1783fe36825c1dd875ae87d17fe1ed3063ad605/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3330373931323638332f736869656c64)](https://camo.githubusercontent.com/035a731f86c0d49a8d0e6a0da1783fe36825c1dd875ae87d17fe1ed3063ad605/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3330373931323638332f736869656c64)

安装
--

[](#安装)

```
$ composer require xin6841414/work-wechat-robot -vvv
```

配置
--

[](#配置)

```
    php artisan vendor:publish --provider="Xin6841414\WorkWechatRobot\ServiceProvider"
    //或者
    php aritsan vendor:publish 选择相应数字序号

```

### 修改配置文件

[](#修改配置文件)

- 在生成的`config/workwechatrobot.php`配置文件中结合env添加机器人配置，每个机器人项支持配置多个，所以env文件配置num数要和key数量对应
- 最简配置 `.env` 文件

```
    WORK_WECHAT_GROUP_ROBOT_DEFAULT_NUM=1
    WORK_WECHAT_GROUP_ROBOT_DEFAULT_KEY_1=151de1af-f525****f5ea2186d4a0 //你的机器人key
```

- 每个key消息频率20次每分钟，消息量大的话尽量多配制几个，防止消息遗漏
- 支持自定义机器人项，现有 `default`和 `other` 两项，可根据自己业务自由加项，切换机器人使用`with($robot)`切换

使用
--

[](#使用)

```
use Xin6841414\WorkWechatRobot\Robot;

$robot = app('workwechatrobot');
//或者
$robot = app(Robot::class);
```

### 切换机器人

[](#切换机器人)

```
    $robot->with('other');
```

1、Text文本
--------

[](#1text文本)

```
$response = $robot->text('测试消息');
//response
[
    'errcode' => 0，
    'errmsg' => 'ok',
]
```

### 1.1、text文本添加@某人

[](#11text文本添加某人)

#### 1.1.1 mentioned模式

[](#111-mentioned模式)

- 在 config/workwechatrobot的配置文件的响应的机器人子项（默认default）配置
    - `notify_user_ids`支持用户id，企业内唯一，可通过企业微信管理后台-通讯录查看，一般为姓名拼音大驼峰，如张三：ZhangSan,多个成员用`,`隔开
    - `notify_mobiles`支持手机号，多个用`,`隔开
- 调用`atUserId`方法或者`atMobiles` 与配置文件不冲突会合并
- 调用 `mentionedAtUserIds`和 `mentionedAtMobile`方法必须在`text`方法之后，`send`方法之前

```
    $user = [
        'ZhangSan',
        'LiSi'
    ];
    $atAll = false ; //使用@all通知@所有人
    $robot->text('今天天气真好')->mentionedAtUserId($user, $atAll)->send();
```

```
    $mobile = [
    '13800138000',
    '13900139000'
    ];
    $atAll = false;
    $robot->text('今天天气真好')->mentionedAtMobile($mobile, $atAll)->send();
```

#### 1.1.2 contentAt模式

[](#112-contentat模式)

- text文本支持&lt;@userid&gt; 语法，不支持手机号，

```
    $user = [
        'ZhangSan',
        'LiSi'
    ];
    //或
    $user = 'ZhangSan';
    $robot->text('今天天气真好')->contentAt($user)->send();
    //或自行拼接
    $robot->text('今天天气真好')->send();
```

2. markdown类型
-------------

[](#2-markdown类型)

### 2.1 获取markdown消息实例

[](#21--获取markdown消息实例)

```
    $markdown = $robot->setMessage('markdown')->getMessage();
```

### 2.2 消息内容

[](#22-消息内容)

#### 2.2.1 无格式的直接调用

[](#221-无格式的直接调用)

```
    $robot->markdown('我是内容')->send();
```

#### 2.2.2 内容的特殊格式

[](#222-内容的特殊格式)

```
    $title = $markdown->setTitleContent('这是标题', 2)
    //参数2表示标题级别，支持1-6，默认1
    $bold = $markdown->setBoldContent('此处加粗');
    $wrap = $markdown->addWrap(); //换行符 \n
    $url = $markdown->setUrlContent('百度', 'https://baidu.com'); //超链接
    $code = $markdown->setOneLineCodeContent('我是一行代码'); //仅支持单行代码，不支持跨行代码段
    $quote = $markdown->setQuoteContent('这是引用文字'); //转引用
    $color = $mardown->setTextColor('我是绿色的字', 1); //这是字体颜色，仅支持仅支持绿(1),灰(2),橙红(3)
```

### 2.3 发送消息

[](#23-发送消息)

```
    //内容可随意拼接,不同格式间需要用换行符隔离，防止格式粘连
    $result = $robot->markdown($title.$wrap.'我只是一行内容'.$wrap.$bold.$wrap.$url)->send();
```

### 2.4 markdown支持contentAt语法，不支持手机号

[](#24-markdown支持contentat语法不支持手机号)

```
 $user = [
        'ZhangSan',
        'LiSi'
    ];
 //或
    $user = 'ZhangSan';
    $robot->markdown($title.$warp.$ulr)->contentAt($user)->send();
```

3 图片消息
------

[](#3-图片消息)

### 3.1 处理图片转base64，

[](#31-处理图片转base64)

```

    $base64_data = base64_encode(file_get_contents($file)); //base64头可带可不带；
```

### 3.2 文件md5

[](#32-文件md5)

```
   $md5 = md5_file($file); //md5值必须是转base64之前的图片计算得来
```

### 3.3 发送

[](#33-发送)

```
    $result = $robot->image($base64_data, $md5)->send();
```

4 news消息
--------

[](#4-news消息)

### 4.1 添加一条图文消息

[](#41-添加一条图文消息)

```
    $title = "中秋节礼品领取";
    $description = '今年中秋节公司有豪礼相送';
    $url = 'www.qq.com';
    $picUrl = 'http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png';
     $news = $robot->addNew($title,  $url, $description = '', $picUrl = '');

```

### 4.2 发送

[](#42-发送)

```
    $news->send();
    //支持多条图文
    $robot->addNew($title1, $url1)->addNew($title2, $url2)->send();
    //最大支持添加8条图文， 大于一条的图文展示效果类似公众号消息

```

5 文件类型
------

[](#5-文件类型)

### 5.1 文件上传

[](#51-文件上传)

```
- 文件素材需要提前上传，上传得到media_id,media_id三天有效
- media_id在同一企业内应用之间可以共享

```

```
    $media_id = '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0';
    $robot->file($media_id)->send();
```

### 5.2 文件上传接口

[](#52-文件上传接口)

```
请求方式：POST（HTTPS）
请求地址：https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=KEY&type=TYPE

使用multipart/form-data POST上传文件， 文件标识名为”media”
参数说明：

参数	必须	说明
key	是	调用接口凭证, 机器人webhookurl中的key参数
type	是	固定传file
POST的请求包中，form-data中媒体文件标识，应包含有 filename、filelength、content-type等信息

filename标识文件展示的名称。比如，使用该media_id发消息时，展示的文件名由该字段控制

```

- 要求文件大小在5B~20M之间

### 6 参考文档

[](#6-参考文档)

[企业微信群机器人配置说明](https://work.weixin.qq.com/api/doc/90000/90136/91770)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/xin6841414/work-wechat-robot/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/xin6841414/work-wechat-robot/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

2012d ago

PHP version history (2 changes)1.1.1PHP &gt;=7.0

1.2.1PHP ^7.2.5 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20766942?v=4)[xin6841414](/maintainers/xin6841414)[@xin6841414](https://github.com/xin6841414)

---

Top Contributors

[![xin6841414](https://avatars.githubusercontent.com/u/20766942?v=4)](https://github.com/xin6841414 "xin6841414 (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xin6841414-work-wechat-robot/health.svg)

```
[![Health](https://phpackages.com/badges/xin6841414-work-wechat-robot/health.svg)](https://phpackages.com/packages/xin6841414-work-wechat-robot)
```

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
