企业微信群机器人webhook PHP示例

1,556次阅读
23 条评论

共计 997 个字符,预计需要花费 3 分钟才能阅读完成。

<?php
/**
 * PHP cURL 企业微信群机器人推送消息
 * @$key: 群机器人 key
 * @$content: 推送内容
 */
function qyWxBot($key,$content){
    // 机器人 key
    $webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=".$key;
    // 初始化
    $curl = curl_init();
    // 设置抓取的 url
    curl_setopt($curl, CURLOPT_URL, $webhook);
    // 设置头文件的信息作为数据流输出
    curl_setopt($curl, CURLOPT_HEADER, 1);
    // 设置获取的信息以文件流的形式返回,而不是直接输出。curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    // 设置 post 方式提交
    curl_setopt($curl, CURLOPT_POST, 1);
    // 设置 post 数据
    // $post_data = '{"msgtype":"text","text":{"content":"hello","mentioned_list":"@all"}}'; // @群里所有人
    $post_data = '{"msgtype":"markdown","markdown":{"content":"'.$content.'"}';// 直接发送消息
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
    // 执行命令
    $data = curl_exec($curl);
    // 关闭 URL 请求
    curl_close($curl);
    // 显示获得的数据
    // print_r($data);
    return $data;
}
// 执行推送
$data = qyWxBot('key 值',"今日 ** 新增用户 ** 反馈 <font color='warning'>132 例 </font>,请相关同事注意。n
         > 类型:<font color='comment'> 用户反馈 </font>
         > 普通用户反馈:<font color='comment'>117 例 </font>
         >VIP 用户反馈:<font color='comment'>15 例 </font>
         ");
print_r($data);

企业微信群机器人配置说明: 群机器人配置说明 – 文档 – 企业微信开发者中心 (qq.com)

正文完
关注 “浮沉博客” 微信公众号获取更多内容
post-qrcode
 1
浮沉
版权声明:本站原创文章,由 浮沉 于2023-03-30发表,共计997字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(23 条评论)
토토 꽁머니 评论达人 LV.1
2024-04-26 05:10:24 回复

Ive read several just right stuff here Certainly price bookmarking for revisiting I wonder how a lot effort you place to create this kind of great informative website

     韩国首尔首尔
Rachael Mitchell 评论达人 LV.1
2024-05-09 15:41:29 回复

Thank you for the auspicious writeup It in fact was a amusement account it Look advanced to far added agreeable from you However how can we communicate

     土耳其
Carroll Stokes 评论达人 LV.1
2024-05-09 15:45:15 回复

Attractive section of content I just stumbled upon your blog and in accession capital to assert that I get actually enjoyed account your blog posts Anyway I will be subscribing to your augment and even I achievement you access consistently fast

     土耳其
Lucius Cole 评论达人 LV.1
2024-05-11 16:50:26 回复

Your writing is a true testament to your expertise and dedication to your craft. I’m continually impressed by the depth of your knowledge and the clarity of your explanations. Keep up the phenomenal work!

     土耳其
Howell McKenzie 评论达人 LV.1
2024-05-12 04:06:09 回复

Hello Neat post Theres an issue together with your site in internet explorer would check this IE still is the marketplace chief and a large element of other folks will leave out your magnificent writing due to this problem

     土耳其
Horacio Schaden 评论达人 LV.1
2024-05-12 04:48:52 回复

Just wish to say your article is as surprising The clearness in your post is just cool and i could assume youre an expert on this subject Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post Thanks a million and please keep up the enjoyable work

     土耳其
Lexus Beer 评论达人 LV.1
2024-05-12 13:12:14 回复

Simply desire to say your article is as surprising The clearness in your post is simply excellent and i could assume you are an expert on this subject Fine with your permission let me to grab your feed to keep up to date with forthcoming post Thanks a million and please carry on the gratifying work

     土耳其
Maxie Luettgen 评论达人 LV.1
2024-05-18 04:59:36 回复

Ive read several just right stuff here Certainly price bookmarking for revisiting I wonder how a lot effort you place to create this kind of great informative website

     土耳其
Edward Steuber 评论达人 LV.1
2024-05-18 09:03:59 回复

Your blog is a breath of fresh air in the often stagnant world of online content. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for sharing your wisdom with us.

     土耳其
Chelsea Nikolaus 评论达人 LV.1
2024-05-18 09:04:14 回复

I do agree with all the ideas you have introduced on your post They are very convincing and will definitely work Still the posts are very short for newbies May just you please prolong them a little from subsequent time Thank you for the post

     土耳其
Chris Bogan 评论达人 LV.1
2024-05-18 16:12:41 回复

Your blog is a constant source of inspiration for me. Your passion for your subject matter shines through in every post, and it’s clear that you genuinely care about making a positive impact on your readers.

     土耳其
Vickie Bosco 评论达人 LV.1
2024-05-19 01:19:57 回复

Your blog is a breath of fresh air in the often stagnant world of online content. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for sharing your wisdom with us.

     土耳其
Marlen Robel 评论达人 LV.1
2024-05-19 01:45:39 回复

I do not even know how I ended up here but I thought this post was great I do not know who you are but certainly youre going to a famous blogger if you are not already Cheers

     土耳其
William Wiza 评论达人 LV.1
2024-05-19 02:44:27 回复

Its like you read my mind You appear to know so much about this like you wrote the book in it or something I think that you can do with a few pics to drive the message home a little bit but other than that this is fantastic blog A great read Ill certainly be back

     土耳其
Axel Bernhard 评论达人 LV.1
2024-05-19 03:06:50 回复

My brother recommended I might like this web site He was totally right This post actually made my day You cannt imagine just how much time I had spent for this information Thanks

     土耳其
Guadalupe Lynch 评论达人 LV.1
2024-05-19 03:08:03 回复

Hello my loved one I want to say that this post is amazing great written and include almost all significant infos I would like to look extra posts like this

     土耳其
Arlie Erdman 评论达人 LV.1
2024-05-19 04:17:58 回复

Hey there You have done a fantastic job I will certainly digg it and personally recommend to my friends Im confident theyll be benefited from this site

     土耳其
Idella Wiza 评论达人 LV.1
2024-05-19 04:26:58 回复

Your blog is like a beacon of light in the vast expanse of the internet. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Thank you for all that you do.

     土耳其
Ayana Borer 评论达人 LV.1
2024-05-19 04:44:01 回复

Hello my loved one I want to say that this post is amazing great written and include almost all significant infos I would like to look extra posts like this

     土耳其
Jaydon Conroy 评论达人 LV.1
2024-05-19 05:28:59 回复

I loved as much as youll receive carried out right here The sketch is attractive your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike

     土耳其
Ned Sauer 评论达人 LV.1
2024-05-19 05:49:25 回复

I was suggested this web site by my cousin Im not sure whether this post is written by him as no one else know such detailed about my trouble You are incredible Thanks

     土耳其
Norris Heathcote 评论达人 LV.1
2024-05-19 06:33:51 回复

I do not even know how I ended up here but I thought this post was great I dont know who you are but definitely youre going to a famous blogger if you arent already Cheers

     土耳其
Cara Daftar Rajaspin 评论达人 LV.1
2024-05-24 14:00:16 回复

This article provides a fresh perspective on a topic that’s often discussed.

     日本软银