jxzsxsp/wechat_robot

企业微信群聊机器人。

1.0.0 2021-07-10 07:52 UTC

This package is not auto-updated.

Last update: 2024-05-26 19:37:58 UTC


README

一、发送文本消息

$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();
}

二、发送图片消息

$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消息

$key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381';

sendMarkdownMessage($key);
sendMarkdownContent($key);

function sendMarkdownMessage($key)
{
    $msg = new \Jxzsxsp\WechatRobot\Markdown\MarkdownMessage($key);

    $msg->content = "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。 \n >类型:<font color=\"comment\">用户反馈</font> \n >普通用户反馈:<font color=\"comment\">117例</font> \n >VIP用户反馈:<font color=\"comment\">15例</font>";

    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();
}

四、发送图文消息

$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();
}

五、发送文件消息

$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();
}