全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
查看: 1494|回复: 13
打印 上一主题 下一主题

通过企业微信发送提醒消息 支持markdown

[复制链接]
跳转到指定楼层
1#
发表于 2020-4-9 22:02:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 师太 于 2020-4-9 22:05 编辑

最近一直在使用方糖推送,看到LOC大佬的企业微信推送感觉NB,隧稍作修改发上来分享给大家食用~
LOC大佬的GITHUB:https://github.com/kaixin1995/InformationPush

大佬的目前仅支持卡片(我知道大佬是懒得写),稍作修改之后目前支持文字推送,卡片推送,和markdown推送(markdown仅支持在企业微信客户端内使用,普通微信仅支持文字和卡片推送)



使用方法:

1、创建一个PHP文件,复制下方代码进去保存,上传至服务器
2、注册一个企业微信,很简单,参考大佬教程 https://github.com/kaixin1995/InformationPush

普通文字:http://域名/index.php?msg=测试提交
卡片消息:http://域名/index.php?type=textcard&msg=测试提交
        (支持自定义卡片URL和btntxt,http://hostloc-workers.ikyomon.com&btntxt=更多)
markdown:http://域名/index.php?type=markdown&msg=markdown内容,需urlencode后提交



  1. <?php
  2. if(!isset($_REQUEST['msg'])) { exit; }

  3. $corpid = ''; // 填写企业ID
  4. $agentid = ''; // 填写应用ID
  5. $corpsecret = ''; // 填写应用Secret

  6. $access_token = json_decode(icurl("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$corpsecret"),true)["access_token"];
  7. $url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=".$access_token;

  8. $msg = urldecode($_REQUEST['msg']);
  9. $type = $_REQUEST['type'];
  10. switch ($type) {
  11.         // 文本卡片消息
  12.         case 'textcard':
  13.                 $data = array(
  14.                         'touser' => '@all',
  15.                     'toparty' => '@all',
  16.                     'totag' => '@all',
  17.                     'msgtype' => 'textcard',
  18.                     'agentid' => $agentid,
  19.                     'textcard' => array(
  20.                         'title' => $_REQUEST['title'] ?? '新提醒',
  21.                             'description' => $msg,
  22.                             'url' => $_REQUEST['url'] ?? 'https://hostloc-workers.ikyomon.com',
  23.                             'btntxt' => $_REQUEST['btntxt'] ?? '详情',
  24.                     ),
  25.                     'enable_id_trans' => 0,
  26.                     'enable_duplicate_check' => 0,
  27.                     'duplicate_check_interval' => 1800,
  28.                 );
  29.                 break;

  30.         // markdown消息,仅企业微信内可以查看
  31.         case 'markdown':
  32.                 $data = array(
  33.                         'touser' => '@all',
  34.                     'toparty' => '@all',
  35.                     'totag' => '@all',
  36.                     'msgtype' => 'markdown',
  37.                     'agentid' => $agentid,
  38.                     'markdown' => array(
  39.                         'content' => $msg,
  40.                     ),
  41.                     'enable_duplicate_check' => 0,
  42.                     'duplicate_check_interval' => 1800,
  43.                 );
  44.                 break;

  45.         // 文本消息
  46.         default:
  47.                 $data = array(
  48.                         'touser' => '@all',
  49.                     'toparty' => '@all',
  50.                     'totag' => '@all',
  51.                     'msgtype' => 'text',
  52.                     'agentid' => $agentid,
  53.                     'text' => array(
  54.                         'content' => $msg,
  55.                     ),
  56.                     'safe' => 0,
  57.                     'enable_id_trans' => 0,
  58.                     'enable_duplicate_check' => 0,
  59.                     'duplicate_check_interval' => 1800,
  60.                 );
  61.                 break;
  62. }

  63. $res = json_decode(icurl($url,json_encode($data)));

  64. if ( $res->errcode == 0 ) { echo "Success"; } else { echo "Error:".$res->errmsg; }

  65. function icurl($url, $data = null)
  66. {
  67.     $curl = curl_init();
  68.     curl_setopt($curl, CURLOPT_URL, $url);
  69.     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  70.     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  71.     if (!empty($data)) {
  72.         curl_setopt($curl, CURLOPT_POST, 1);
  73.         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  74.     }
  75.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  76.     $res = curl_exec($curl);
  77.     curl_close($curl);
  78.     return $res;
  79. }
复制代码
cherbim 该用户已被删除
2#
发表于 2020-4-9 22:07:06 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
3#
发表于 2020-4-9 22:09:50 | 只看该作者
一个论坛都能玩出花来的都是大佬
5#
 楼主| 发表于 2020-4-9 22:12:26 | 只看该作者
cherbim 发表于 2020-4-9 22:07
不如看看我的.....

可以搭配LOC帖子监控然后实时推送到微信的啊哈哈哈
6#
发表于 2020-4-9 22:13:04 | 只看该作者
感谢分享  
7#
发表于 2020-4-9 22:16:09 来自手机 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
8#
发表于 2020-4-9 23:52:35 | 只看该作者
这个有啥用啊大佬
9#
发表于 2020-4-10 01:17:14 | 只看该作者
不错,支持一下
10#
发表于 2020-4-10 02:45:12 | 只看该作者
大佬都玩出花来了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-15 01:26 , Processed in 0.067275 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表