Micro-channel custom menus and messages and event notification

1. If you turn on micro-channel messages and event notification service so (including menus) will go to the server URL micro-channel public number of background configuration.

Micro-channel reference request message structure:

<xml>
  <ToUserName><![CDATA[toUser]]></ToUserName>//开发者微信号
  <FromUserName><![CDATA[fromUser]]></FromUserName>//发送者的openid
  <CreateTime>1348831860</CreateTime>//消息创建时间 (整型)
  <MsgType><![CDATA[text]]></MsgType>//什么类型的消息或通知
  <Content><![CDATA[this is a test]]></Content>
  <MsgId>1234567890123456</MsgId>
</xml>

Interface documentation on events and news

LINK: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013

Test Interface:

LINK: https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95&form=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E5%88%9B%E5%BB%BA%E6%8E%A5%E5%8F%A3%20/menu/creat

 

2. Authorized access_token and web-based access_token difference:

Access_token is a one-time authorization page, the foundation supports access_token there is a time limit: 7200s.

Specific reference

LINK: https://www.cnblogs.com/wellsoho/p/5089409.html

 

3. The micro-channel upload pictures to the Library - other file types refer to this same

    function upload_image($access_token, $src)
    {
        $imgUrl = ROOTPATH.'images/poster/' . $src;
        $TOKEN=$access_token;
        $URL ='https://api.weixin.qq.com/cgi-bin/material/add_material?access_token='.$TOKEN.'&type=image';//上传临时文件
        $data = array('media'=>"@".$imgUrl);
        $result = $this->http_post($URL,$data);
        $res = @json_decode($result,true);
        if(isset($res['media_id'])){//判断media_id是否有值
            $res['state'] = 'success';
        }else {
            $res['state'] = 'error';
        }
        return $res;
    }


    function http_post($url, $data = null)
    {
        //创建一个新cURL资源
        $curl = curl_init();
        //设置URL和相应的选项
        curl_setopt($curl, CURLOPT_URL, $url);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //执行curl,抓取URL并把它传递给浏览器
        $output = curl_exec($curl);
        //关闭cURL资源,并且释放系统资源
        curl_close($curl);
        return $output;
    }

 

Published 70 original articles · won praise 18 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_40325734/article/details/87897555