php实现微信公众号群发消息接口(thinkphp3.2.3)

一、说明

1、可以在前一篇博客基础上添加一个方法即可,方法代码下面讲解

二、实现流程

1、看开发手册:
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1481187827_i0l21
这里写图片描述
这里写图片描述
这里写图片描述
2、代码实现:

//群发接口
    function sendMsgAll(){
        //1、获取全局access_token
        $access_token = $this->getWxAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=".$access_token;
        //2、组装群发接口数据array
        //单文本群发
        $array = array(
            'touser' => '',//微信用户的openid
            'text' =>array(
                'content' => 'imooc',
            ),//文本内容
            'msgtype' =>'text',//消息类型
        );
        //3、将array->json
        $postJson = json_encode($array);
        //4、调用curl
        $res = $this->http_curl($url,'post','json',$postJson);
    }

3、补充说明:
‘touser’ => ’ ‘,//微信用户的openid就是
这里写图片描述

猜你喜欢

转载自blog.csdn.net/john_rush/article/details/80632967