群发

微信的群发消息接口有各种乱七八糟的注意事项及限制,具体请阅读微信官方文档:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html

获取实例

  1. <?php
  2. use EasyWeChat\Foundation\Application;
  3. // ...
  4. $app = new Application($options);
  5. $broadcast = $app->broadcast;

API

注意:

  1. 下面提到的 `$messageType` `$message` 可以是:
  2. - `$messageType = Broadcast::MSG_TYPE_NEWS;` 图文消息类型,所对应的 `$message` media_id
  3. - `$messageType = Broadcast::MSG_TYPE_TEXT;` 文本消息类型,所对应的 `$message` 为一个文本字符串
  4. - `$messageType = Broadcast::MSG_TYPE_VOICE;` 语音消息类型,所对应的 `$message` media_id
  5. - `$messageType = Broadcast::MSG_TYPE_IMAGE;` 图片消息类型,所对应的 `$message` media_id
  6. - `$messageType = Broadcast::MSG_TYPE_CARD;` 卡券消息类型,所对应的 `$message` card_id
  7. - `$messageType = Broadcast::MSG_TYPE_VIDEO;` 视频消息为两种情况:
  8. - 视频消息类型,群发视频消息给**组或预览群发视频消息**给用户时所对应的 `$message` `media_id`
  9. - 群发视频消息**给指定用户**时所对应的 `$message` 为一个数组 `['MEDIA_ID', 'TITLE', 'DESCRIPTION']`

群发消息给所有粉丝

  1. $broadcast->send($messageType, $message);
  2. // 别名方式
  3. $broadcast->sendText("大家好!欢迎使用 EasyWeChat。");
  4. $broadcast->sendNews($mediaId);
  5. $broadcast->sendVoice($mediaId);
  6. $broadcast->sendImage($mediaId);
  7. //视频:
  8. // - 群发给组用户,或者预览群发视频时 $message 为 media_id
  9. // - 群发给指定用户时为数组:[$media_Id, $title, $description]
  10. $broadcast->sendVideo($message);
  11. $broadcast->sendCard($cardId);

群发消息给指定组

  1. $broadcast->send($messageType, $message, $groupId);
  2. // 别名方式
  3. $broadcast->sendText($text, $groupId);
  4. $broadcast->sendNews($mediaId, $groupId);
  5. $broadcast->sendVoice($mediaId, $groupId);
  6. $broadcast->sendImage($mediaId, $groupId);
  7. $broadcast->sendVideo($message, $groupId);
  8. $broadcast->sendCard($cardId, $groupId);

群发消息给指定用户

至少两个用户的openid,必须是数组。

  1. $broadcast->send($messageType, $message, [$openId1, $openId2]);
  2. // 别名方式
  3. $broadcast->sendText($text, [$openId1, $openId2]);
  4. $broadcast->sendNews($mediaId, [$openId1, $openId2]);
  5. $broadcast->sendVoice($mediaId, [$openId1, $openId2]);
  6. $broadcast->sendImage($mediaId, [$openId1, $openId2]);
  7. $broadcast->sendVideo($message, [$openId1, $openId2]);
  8. $broadcast->sendCard($cardId, [$openId1, $openId2]);

发送预览群发消息给指定的 openId 用户

  1. $broadcast->preview($messageType, $message, $openId);
  2. // 别名方式
  3. $broadcast->previewText($text, $openId);
  4. $broadcast->previewNews($mediaId, $openId);
  5. $broadcast->previewVoice($mediaId, $openId);
  6. $broadcast->previewImage($mediaId, $openId);
  7. $broadcast->previewVideo($message, $openId);
  8. $broadcast->previewCard($cardId, $openId);

发送预览群发消息给指定的微信号用户

  1. $broadcast->previewByName($messageType, $message, $wxname);
  2. // 别名方式
  3. $broadcast->previewTextByName($text, $wxname);
  4. $broadcast->previewNewsByName($mediaId, $wxname);
  5. $broadcast->previewVoiceByName($mediaId, $wxname);
  6. $broadcast->previewImageByName($mediaId, $wxname);
  7. $broadcast->previewVideoByName($message, $wxname);
  8. $broadcast->previewCardByName($cardId, $wxname);

删除群发消息

  1. $broadcast->delete($msgId);

查询群发消息发送状态

  1. $broadcast->status($msgId);

有关群发信息的更多细节请参考微信官方文档:http://mp.weixin.qq.com/wiki/