微信根据openid给用户发送图文消息

 

 

先在微信公众号后台素材库中创建图文

然后获取该公众号图文消息的media_id

$data = ['type' => 'news','offset' => 0,'count' => 20];
            $str = json_encode($data);
            $access_token = $wechat_C->token();
            $rt = curl_do('https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$access_token,$str,'POST');

 

根据用户openid和media_id,发送

$media_id = $res['item'][0]['media_id'];
                $message = [];
                $message['touser'] = $openid2[0];
                $message['msgtype'] = 'mpnews';
                $message['mpnews'] = ['media_id' => $media_id];
                $message2 = json_encode($message);

                $api_url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;

                $rts = curl_do($api_url,$message2,'POST');

 

posted @ 2018-09-28 18:24  白尼玛砸缸  阅读(475)  评论(0编辑  收藏  举报