赞
踩
目录
- // 文本消息类型
- {
- "msgtype": "text",
- "text": {
- "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
- "mentioned_list":["wangqing","@all"],
- "mentioned_mobile_list":["13800001111","@all"]
- }
- }
-
- // markdown消息类型
- {
- "msgtype": "markdown",
- "markdown": {
- "content": "实时新增用户反馈<font color="warning">132例</font>,请相关同事注意。\n
- >类型:<font color="comment">用户反馈</font>
- >普通用户反馈:<font color="comment">117例</font>
- >VIP用户反馈:<font color="comment">15例</font>"
- }
- }
-
- // 图片消息类型
- {
- "msgtype": "image",
- "image": {
- "base64": "DATA",
- "md5": "MD5"
- }
- }
-
- // 图文消息类型
- {
- "msgtype": "news",
- "news": {
- "articles" : [
- {
- "title" : "中秋节礼品领取",
- "description" : "今年中秋节公司有豪礼相送",
- "url" : "www.qq.com",
- "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"
- }
- ]
- }
- }

- <?php
- /**
- * Created by PhpStorm.
- * User: autofelix
- * Date: 2021/5/18
- * Time: 22:00
- * Desc: 机器人实例.
- */
-
- class robot
- {
- //你的机器人webhook地址
- const ROBOT_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
-
- //日志上报
- public function report($content, $list = ['@all'])
- {
- $data = [
- 'msgtype' => 'text',
- 'text' => [
- 'content' => $content,
- 'mentioned_list' => $list,
- 'mentioned_mobile_list' => $list
- ]
- ];
-
- $result = $this->post_curl(self::ROBOT_URL, json_encode($data));
-
- $result = json_decode($result, true);
-
- if ($result['errcode'] == 0) {
- //上报成功之后的逻辑
- echo '上报结果:' . $result['errmsg'];
- } else {
- //上报失败之后的逻辑
- echo '上报错误:' . $result['errmsg'];
- }
- }
-
- //请求
- protected function post_curl($url, $post_data, $header = [], $timeout = 5)
- {
- $ch = curl_init(); //初始化curl
- curl_setopt($ch, CURLOPT_URL, $url); //抓取指定网页
- if ($header) {
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //设置header
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置不输出直接返回字符串
- curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- $result = curl_exec($ch); //运行curl
- curl_close($ch);
-
- return $result;
- }
- }
-
- (new robot())->report('上报错误日志');

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。