公众号开发13【生成二维码】

生成临时二维码和永久二维码代码如下:

//生成带参数的临时二维码
   function getTimeQrCode(){
     header('content-type:text/html;charset=utf-8');
     //1.获取ticket票据
     //2.全局票据access_token网页授权access_token 威信js-SDK jsapi_ticket临时的这三个都有过期时间
     $access_token="12_EDjuJXo7AKFzpxOWcgis-F_EaXNT6ITQt6ZBbMgMUhuqySF-5aD5bUv-p1TPT63oTIy3uXSDVMDIbnrcpzdFXgfqxHGZbN2_-lzlZ8MKUQ3dskH3B7wpkr1aQymY459MjXYfioZJJW7FNYnLYMNjAHAIWX";
     $url="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
    $postArr=array(
        'expire_seconds'=>604800,//24*60*60
        'action_name'=>"QR_SCENE",
        'action_info'=>array(
           'scene'=>array('scene_id'=>2000),
        ),
    );
    $postJson=json_encode($postArr);
    $res=$this->http_curl($url,'post','json',$postJson);
    $ticket=$res['ticket'];
    //2.使用ticket获取二维码图片
     $url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
     //上面二维码的地址已经生成了,直接展示
     echo '临时二维码';
     echo "<img src='".$url."'  />";
   }//getQrCode end

   //生成带参数的永久二维码
    function getForeverQrCode(){
       header('content-type:text/html;charset=utf-8');
      //1.获取ticket票据
      //2.全局票据access_token网页授权access_token 微信js-SDK jsapi_ticket临时的这三个都有过期时间
      $access_token="12_EDjuJXo7AKFzpxOWcgis-F_EaXNT6ITQt6ZBbMgMUhuqySF-5aD5bUv-p1TPT63oTIy3uXSDVMDIbnrcpzdFXgfqxHGZbN2_-lzlZ8MKUQ3dskH3B7wpkr1aQymY459MjXYfioZJJW7FNYnLYMNjAHAIWX";
      $url="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
     $postArr=array(
         'action_name'=>"QR_LIMIT_SCENE",
         'action_info'=>array(
            'scene'=>array('scene_id'=>3000),
         ),
     );
     $postJson=json_encode($postArr);
     $res=$this->http_curl($url,'post','json',$postJson);
     $ticket=$res['ticket'];
     //2.使用ticket获取二维码图片
      $url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
      //上面二维码的地址已经生成了,直接展示
      echo '永久二维码';
      echo "<img src='".$url."'  />";
    }//getQrCode end

posted @ 2018-07-31 15:52  L1230205  阅读(177)  评论(0编辑  收藏  举报