# wechat_robot **Repository Path**: jxzsxsp/wechat_robot ## Basic Information - **Project Name**: wechat_robot - **Description**: 企业微信群聊机器人。 - **Primary Language**: PHP - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 1 - **Created**: 2021-07-09 - **Last Updated**: 2022-11-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 一、发送文本消息 ```injectablephp $key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381'; sendTextMessage($key); function sendTextMessage($key) { $msg = new \Jxzsxsp\WechatRobot\Text\TextMessage($key); $msg->content = '测试消息'; $msg->mentioned_mobile_list = ['13387057301', '@all']; return $msg->send(); } ``` ### 二、发送图片消息 ```injectablephp $key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381'; sendImageMessage($key); function sendImageMessage($key) { $msg = new \Jxzsxsp\WechatRobot\Image\ImageMessage($key); $msg->base64 = base64_encode(file_get_contents('test_pic_msg1.png')); $msg->md5 = md5_file('test_pic_msg1.png'); return $msg->send(); } ``` ### 三、发送markdown消息 ```injectablephp $key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381'; sendMarkdownMessage($key); sendMarkdownContent($key); function sendMarkdownMessage($key) { $msg = new \Jxzsxsp\WechatRobot\Markdown\MarkdownMessage($key); $msg->content = "实时新增用户反馈132例,请相关同事注意。 \n >类型:用户反馈 \n >普通用户反馈:117例 \n >VIP用户反馈:15例"; return $msg->send(); } function sendMarkdownContent($key) { $msg = new \Jxzsxsp\WechatRobot\Markdown\MarkdownMessage($key); $msg->appendTitle('这是标题'); $msg->append('实时新增用户反馈'); $msg->appendColor('132例', 'warning'); $msg->append(',请相关同事注意。'); $msg->appendReference('类型:'); $msg->appendColor('用户反馈', 'comment'); $msg->appendReference('普通用户反馈:'); $msg->appendColor('117例', 'comment'); $msg->appendReference('VIP用户反馈:'); $msg->appendColor('15例', 'comment'); $msg->appendEnter(2); $msg->appendLink('www.qq.com', '点击链接查看详情'); $msg->appendEnter(); $msg->appendBold('代码:'); $msg->appendCode('c = a + b;'); return $msg->send(); } ``` ### 四、发送图文消息 ```injectablephp $key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381'; sendNewsMessage($key); function sendNewsMessage($key) { $msg = new \Jxzsxsp\WechatRobot\News\NewsMessage($key); $article = new \Jxzsxsp\WechatRobot\News\Article(); $article->title = '中秋节礼品领取'; $article->description = '今年中秋节公司有豪礼相送'; $article->url = 'www.qq.com'; $article->picurl = 'http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png'; $articles[] = $article; $msg->articles = $articles; return $msg->send(); } ``` ### 五、发送文件消息 ```injectablephp $key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381'; sendFileMessage($key); function sendFileMessage($key) { $filepath = realpath('testfile.txt'); $upload = new \Jxzsxsp\WechatRobot\File\Upload($key, $filepath); $res = $upload->upload(); $msg = new \Jxzsxsp\WechatRobot\File\FileMessage($key); $msg->media_id = $res['media_id']; return $msg->send(); } ```