WeChat development news template push + php WeChat development generates QR code, scan the code to follow the public number PHP

Official WeChat development document  https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5

How to get the template is very clear, I use the test number, so I will not talk about the process of getting the template_id, just say how to push.

PHP code

public  function pushmsg () { // Instant WeChat
         operation class 
        $ wx = new Wechat (); 
        
        $ token = $ wx- > getAccessToken (); 
        
        // Push data array 
        $ data = [
             "touser" => "oTwTywxibPkyhkZFkDJ9CKy7tW0k",         // Receiver's openid 
            "template_id" => "szXdvDcezI8Z2mgdd-otK4NTAB8WrEtowC3vQPD5sqE",         // Applied message template id 
            "url" => "XXXX",     // If you click on the jump link in the push message, it will not jump Turn 
            "data" => array (
                 "name"=> array("value"=>"测试用户","color"=>"#173177"),
                "time" => array("value"=>date('Y-m-d H:i:s',time()),"color"=>"#173177")
            )
        ];
        
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=$token";
        
        // 发送模板消息
        $res = $wx->http_curl($url, 'post', 'json', json_encode($data));
        echo "<pre>";
        print_r($res);
    }

 

effect:

 

 

 Wechat class is my own package, such as access_token, ticket, curl request these, the code can see the previous text  WeChat development generated QR code, scan the code to follow the public number PHP

Guess you like

Origin www.cnblogs.com/zxf100/p/12750122.html