sendMessage() публичный Метод

主动发送信息接口
public sendMessage ( array $data ) : boolean | array
$data array 结构体为: array( "touser" => "UserID1|UserID2|UserID3", "toparty" => "PartyID1|PartyID2 ", "totag" => "TagID1|TagID2 ", "safe":"0" //是否为保密消息,对于news无效 "agentid" => "001", //应用id "msgtype" => "text", //根据信息类型,选择下面对应的信息结构体 "text" => array( "content" => "Holiday Request For Pony(http://xxxxx)" ), "image" => array( "media_id" => "MEDIA_ID" ), "voice" => array( "media_id" => "MEDIA_ID" ), " video" => array( "media_id" => "MEDIA_ID", "title" => "Title", "description" => "Description" ), "file" => array( "media_id" => "MEDIA_ID" ), "news" => array( //不支持保密 "articles" => array( //articles 图文消息,一个图文消息支持1到10个图文 array( "title" => "Title", //标题 "description" => "Description", //描述 "url" => "URL", //点击后跳转的链接。可根据url里面带的code参数校验员工的真实身份。 "picurl" => "PIC_URL", //图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320, //小图80*80。如不填,在客户端不显示图片 ), ) ), "mpnews" => array( "articles" => array( //articles 图文消息,一个图文消息支持1到10个图文 array( "title" => "Title", //图文消息的标题 "thumb_media_id" => "id", //图文消息缩略图的media_id "author" => "Author", //图文消息的作者(可空) "content_source_url" => "URL", //图文消息点击“阅读原文”之后的页面链接(可空) "content" => "Content" //图文消息的内容,支持html标签 "digest" => "Digest description", //图文消息的描述 "show_cover_pic" => "0" //是否显示封面,1为显示,0为不显示(可空) ), ) ) ) 请查看官方开发文档中的 发送消息 -> 消息类型及数据格式
Результат boolean | array 如果对应用或收件人、部门、标签任何一个无权限,则本次发送失败; 如果收件人、部门或标签不存在,发送仍然执行,但返回无效的部分。 { "errcode": 0, "errmsg": "ok", "invaliduser": "UserID1", "invalidparty":"PartyID1", "invalidtag":"TagID1" }
Пример #1
0
<?php

include './qy-sdk/qywechat.class.php';
function _log($text)
{
    file_put_contents('/opt/gdsserver/logs/wechat_log.txt', $text . "\r\n\r\n", FILE_APPEND);
}
$message = array("touser" => "@all", "safe" => "0", "agentid" => "3", "msgtype" => "text", "text" => array("content" => "这里是GDS-PE微信号,正在测试中, <a href=\"http://www.gds-services.com\">GDS官网</a>"));
$options = array('token' => 'N6cq3R', 'encodingaeskey' => 'nil3OzTxXoPHx4mvx0GLbyECkPYrfyiB9ca4Iz61ny3', 'appid' => 'wx926454a4965d2b7c', 'appsecret' => 'PsPkG1V74sWm6V2mNN3F2NOHKQT696g1wrmJZhB7WT-8xcLmt-3rez3FfuH3SzCf', 'agentid' => '3', 'debug' => true, 'logcallback' => '_log');
$weObj = new Wechat($options);
$result = $weObj->sendMessage($message, $agentid = '3');
echo var_export($result, true);
Пример #2
0
 public function sendMessage()
 {
     \Wechat::sendMessage('您好', 'oUS_vt5i0R1ODvljFbFfKfPr8BuY');
 }