微信开发(五)发送模板消息

http请求方式: POST
https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN

主要的是url,openid和模板id
参数按照文档里的写就行了

 /*
     * 发送模板消息
     */
    public function send_template_message(){
        $openid='oJMd0weUXJppG4bt4GaqSKRw9Ct4';
        $url='https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$this->tools->get_access_token();
        $data=[
            'touser'=>$openid,
            'template_id'=>'gDsIyl1h_elVHIzk_V2txsZhno_jspfhZwISvAbukEY',
            'url'=>'www.laravel.com',
            'data'=>[
                'first'=>[
                    'value'=>'阿伟',
                    'color'=>''
                ],
                'keyword1'=>[
                    'value'=>'阿伟啊'
                ],
                'keyword2'=>[
                    'value'=>'你不操蛋了'
                ],
                'remark'=>[
                    'value'=>'假期快乐',
                    'color'=>''
                ]
            ]
        ];
        $re=$this->tools->curl_post($url,json_encode($data,JSON_UNESCAPED_UNICODE));
        $result=json_decode($re,1);
        dd($result);
    }

模板id
在这里插入图片描述


版权声明:本文为zhanghongjie_du原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。