微信公众号菜单

html

<?php if(!defined(‘PIGCMS_PATH‘)) exit(‘deny access!‘);?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>首页 - <?php echo $store_session[‘name‘]; ?> | <?php if (empty($_SESSION[‘sync_store‘])) { ?><?php echo $config[‘site_name‘];?><?php } else { ?>微店系统<?php } ?></title>
        <meta name="copyright" content="<?php echo $config[‘site_url‘];?>"/>
        <link href="<?php echo TPL_URL;?>css/base.css" type="text/css" rel="stylesheet"/>
        <link href="<?php echo TPL_URL;?>css/store.css" type="text/css" rel="stylesheet"/>
        <link href="<?php echo TPL_URL;?>css/wx_menu.css?r=<?php echo time();?>" type="text/css" rel="stylesheet"/>
        <link href="<?php echo STATIC_URL;?>css/jquery.ui.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="<?php echo STATIC_URL;?>js/jquery.min.js"></script>
    </head>
    <body class="font14 usercenter">
        <?php include display(‘public:header‘);?>
        <div class="wrap_1000 clearfix container">
            <?php if (!empty($_SESSION[‘drp_diy_store‘])) { ?>
            <?php include display(‘sidebar‘);?>
            <?php } ?>
            <div class="app" <?php if (empty($_SESSION[‘drp_diy_store‘])) { ?>style="width: 100%;"<?php } ?>>
                <div class="app-inner clearfix">
                    <div class="app-init-container">
                        <div class="nav-wrapper--app"></div>
                        <div class="app__content page-showcase-dashboard" <?php if (empty($_SESSION[‘drp_diy_store‘])) { ?>style="width: 100%;"<?php } ?>>

                            <div class="widget-app-board ui-box member_degree" style="border: none;">
                                <div class="widget-app-board-info">
                                    <h3>温馨提示:</h3>
                                    <div>
                                        <p>如果您输入的字数超过规定的字数,提交到微信服务器审核,会报错或审核不通过,请到pc端设置公众号菜单。</p>
                                    </div>
                                </div>
                            </div>

                            <div class="msg_menu">
                                <div class="msg_menu_bord">
                                    <div class="msg_menu_left">
                                        <div class="msg_menu_top"></div>
                                        <div class="msg_menu_two">
                                            <?php foreach($menu as $k => $v){?>
                                            <div class="msg_menu_chlid" style="width: <?php echo ((-(count($menu)>2?2:count($menu)) + 3) * 32.55)?>%;">
                                                <div class="msg_menu_add_chlid" data-ac="add" data-pid="<?php echo $v[‘id‘]?>" data-pname="<?php echo $v[‘title‘]?>">+</div>
                                                <?php if(isset($menuChlid)) foreach($menuChlid as $kk =>$vv){?>  <?php if($vv[‘pid‘] == $v[‘id‘]){?>
                                                    <div class="msg_menu_add_chlid">
                                                        <a href="javascript:;" data-id="<?php echo $vv[‘id‘];?>" data-ac="edit" class="edit_menu"><?php echo $vv[‘title‘]?></a>

                                                        </div>
                                                    <?php }?>
                                                <?php }?>
                                            </div>
                                            <?php }?>
                                        </div>
                                        <div class="msg_menu_three">
                                            <?php foreach($menu as $v){?>
                                            <div class="msg_menu_fa " style="width: <?php echo ((-(count($menu)>2?2:count($menu)) + 3) * 32.9)?>%;" ><a href="javascript
                                                :;" data-id="<?php echo $v[‘id‘];?>" data-ac="edit" class="edit_menu"><?php echo $v[‘title‘];?></a></div>
                                            <?php }?>
                                            <?php if(count($menu) < 3){?>
                                            <div class="msg_menu_fa add-menu" <?php if(count($menu) == 0) echo ‘style="width:99.7%"‘;?> data-ac="add" data-pid="0" data-pname="选择父级菜单">+</div>
                                            <?php }?>
                                        </div>
                                    </div>
                                </div>
                                <!-- 左面s -->
                                <div class="msg_menu_bord">
                                    <div class="msg_menu_bord_border">

                                    </div>

                                </div>
                                <!-- end -->

                                <div class="msg_menu_butt"> <a href="javascript:;" class="btn btn-add-wx-menu">一键生成菜单</a></div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php include display(‘public:footer‘);?>
        <div id="nprogress"><div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div></div>
    </body>
</html>
<script type="text/javascript" src="<?php echo STATIC_URL;?>js/layer/layer.min.js"></script>
<script type="text/javascript" src="<?php echo TPL_URL;?>js/base.js"></script>
<script type="text/javascript" src="<?php echo TPL_URL;?>js/wx_menu.js?r=<?php echo time();?>"></script>
<script type="text/javascript">
    $(function(){
        $(‘.msg_menu_add_chlid,.add-menu,.edit_menu‘).click(function(){
            var finfo = {}
            finfo.ac =  $(this).data(‘ac‘);
            if(finfo.ac == ‘add‘){
                finfo.pid =  $(this).data(‘pid‘);
                finfo.pname =  $(this).data(‘pname‘);
                commWxMenu(12,finfo);
            }else if(finfo.ac == ‘edit‘){
                $.post(‘?c=bonus&a=wx_find‘, {id: $(this).data(‘id‘)}, function(re) {
                    re.msg.ac = finfo.ac;
                    commWxMenu(re.f_menu,re.msg);
                },‘json‘);
                //console.log(finfo.pid);
            }

        });

        $(‘.btn-add-wx-menu‘).click(function(){

            if (confirm(‘你确定要生成吗!‘)) {
                $.post(‘?c=bonus&a=add_wx_menu‘, {admin:‘yepai‘},function(re){
                    console.log(re);
                    if(re.error == 0){
                        alert(re.msg);
                    }else{
                        alert(re.msg);
                    }

                },‘json‘);
            }

        });
    });
lk.auto();
function commWxMenu(f,finfo){
    lk.wx_add_menu(f,finfo,function(data){
        console.log(data);
        if(data.type == 1){
            $.post(‘?c=bonus&a=wx_creat‘, data, function(re) {
                if(re.error == 0){
                    alert(re.msg);
                    lk.rel(1000);
                }else{
                    alert(re.msg);
                }

            },‘json‘);
        }else if(data.type == 2){

            if (confirm(‘你确定要删除吗!‘)) {
                $.post(‘?c=bonus&a=del_ment‘, data, function(re) {
                    if(re.error == 0){
                        alert(re.msg);
                        lk.rel(1000);
                    }else{
                        alert(re.msg);
                    }

                },‘json‘);
            }
        }
    });    

}
</script>

css

            .msg_menu{
                border: 1px solid #f4f5f9;
                width: 100%;
                height: 676px;
                background: #fff;
            }
            .msg_menu_butt{
                border-top: 1px solid #f4f5f9;
                width: 100%;
                clear: both;
                height: 74.1px;
                line-height: 74.1px;
                text-align: center;
            }
            .btn-add-wx-menu{
                /* margin-left: 50%; */
            }
            .msg_menu_left{
                clear: both;
                border: 1px solid #2f4050;
                width:78%;
                height:525px;
                margin:10px auto;
                background: #dfdfdf;
            }
            .msg_menu_top{
                width: 100%;
                height: 60px;
                background: url(‘/static/images/img_card_control.png?r=23‘);
                background-size: 100% 60px;
            }
            .msg_menu_two{
                border-bottom: 1px solid #2f4050;
                border-right: 1px solid #2f4050;
                width:100%;
                height:407px;
                background: #fff;
            }
            .msg_menu_three{
                width:100%;
                min-height:57px;
                padding-right: 30px: 

            }
            .msg_menu_chlid,.msg_menu_fa{
                border-left:1px solid #2f4050;
                width:32.88%;
                float: left;
                background:#fff;
                text-align: center;        

            }
            .msg_menu_chlid{
                border-right:1px solid #fff;
                border-left:1px solid #fff;
                min-height: 300px;
                margin-top: 105px;
            }
            .msg_menu_add_chlid{
                border: 1px solid #000;
                width: 95%;
                margin: 0px auto;
            }
            .msg_menu_add_chlid,.msg_menu_fa{
                min-height:57px;
                line-height: 57px;
                color: #000;
            }
            a {
                color:#000;
            }
            .msg_menu_bord{
                border: 1px solid #f4f5f9;
                width: 49.70%;
                height: 560px;
                float: left;
            }
            .msg_menu_bord_border{
                border: 1px solid #000;
                width: 90%;
                height: 500px;
                margin:40px auto 0px;
                clear: both;                     

            }
            .msg_menu_bord_border_tops{
                width: 90%;
                height:60px;
                margin:10px auto;
                line-height: 60px;
            }
            .msg_menu_bord_border_top{
                border-bottom: 1px solid #000;

            }

            .form-control, .single-line {
                margin-left: 32px;
                height: 32px;
            }
            .btn-wx{
                width: 68px;
                height: 30px;
                line-height: 30px;
                margin-left: 56px;
            }
            .msg_menu_del{
                float: right;
            }

js

var lk = {
        a:1,
        arrs:function(a){
              var arrs = [a[0],a[1]];
                return arrs;
        },
        id:function(e){
            return  document.getElementById(e);
        },
        die:function(e){
            alert(e);
        },
        isUrl:function(url){
            var re =/^((https|http|ftp|rtsp|mms)?:\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\‘:+!]*([^<>\"\"])*$/;
            if (re.test(url)) {
                return true;
            }else{
                return false;
            }
        },
        rel:function(e){
            setTimeout(function(){
                window.location.reload();
            },e)

        },
        auto:function(){
                var menu_chlid = document.getElementsByClassName(‘msg_menu_chlid‘);
                for (var i = 0; i< menu_chlid.length; i++) {
                    var sum_height = 0;
                    for(var j = 0; j <menu_chlid[i].children.length;j++ ){
                        sum_height += menu_chlid[i].children[j].offsetHeight;
                    }
                    var sum = menu_chlid[i].offsetHeight - sum_height;
                    if(j < 6){
                        menu_chlid[i].children[0].style.marginTop = sum+"px";
                    }else if(j == 6){
                        menu_chlid[i].children[0].remove();
                        menu_chlid[i].children[0].style.marginTop = "4.2px";
                    }
            }
        }

    };

(function($,window){
    $.wx_add_menu = function(f_menu,inputdata,backfun){
        var CLASS_MSG = ‘msg_menu_bord_border_tops‘;
        var title = ‘‘;
        var keyword = ‘‘;
        var url = ‘‘;
        var sort = ‘‘;
        if(inputdata.ac == ‘edit‘){
            title = inputdata.title;
            keyword = inputdata.keyword;
            url = inputdata.url;
            sort = inputdata.sort;
        }
        var msg_menu = document.getElementsByClassName(‘msg_menu_bord_border‘);

        var html = ‘<div class="‘+CLASS_MSG+‘ msg_menu_bord_border_top"><span style="font-size:18px">菜单信息</span>‘;
        if(inputdata.ac == ‘edit‘){
            html+=‘<span class="msg_menu_del"><a href="javascript:;" id="del" data-id="‘+inputdata.id+‘">X</a></span>‘
        }
        html+=‘</div><div class="‘+CLASS_MSG+‘">菜单名称:<input type="text" id="title"value="‘+title+‘"class="form-control"placeholder="输入菜单名"/></div><div class="‘+CLASS_MSG+‘">*父级菜单:<select class="form-control"id="pid">‘;
        if(inputdata.ac == ‘add‘){
            html+=‘<option value="‘+inputdata.pid+‘">‘+inputdata.pname+‘</option>‘;
        }else if(inputdata.ac == ‘edit‘){
            var ps  = inputdata.pid == 0?‘selected = "selected"‘:‘‘;
            html+=‘<option value="0" ‘+ps+‘>选择父类菜单</option>‘;
            for(var o in f_menu){
                var p_ss  = inputdata.pid == f_menu[o].id?‘selected = "selected"‘:‘‘;
                html+=‘<option value="‘+f_menu[o].id+‘" ‘+p_ss+‘>‘+f_menu[o].title+‘</option>‘;
            }

        }
        html+=‘</select></div><div class="‘+CLASS_MSG+‘">*菜单类型:<select class="form-control"id="menu_type">‘;
        if(inputdata.ac == ‘add‘){
            html+=‘<option value="0">关键词回复菜单</option><option value="1">url链接菜单</option>‘;
        }else if(inputdata.ac == ‘edit‘){
            var bs_u = inputdata.url?‘selected = "selected"‘:‘‘;
            var bs_k  = inputdata.keyword?‘selected = "selected"‘:‘‘;
            html+=‘<option value="0" ‘+bs_k+‘>关键词回复菜单</option><option value="1" ‘+bs_u+‘>url链接菜单</option>‘;

        }

        html+=‘</select></div><div class="‘+CLASS_MSG+‘" id="keyword">关联关键词:<input type="text"id="keywords"value="‘+keyword+‘"class="form-control"placeholder="请输入关键词"/></div>‘;
        html+=‘<div class="‘+CLASS_MSG+‘"style="display: none;" id="url_css">*外链接url:<input type="text" id="url"value="‘+url+‘"class="form-control"placeholder="输入url"/></div><div class="‘+CLASS_MSG+‘">*菜单排序:<input type="text"id="sort"value="‘+sort+‘"class="form-control"placeholder="输入序号"/></div><div class="‘+CLASS_MSG+‘"><a href="javascript:;"class="btn btn-wx">取消</a><a href="javascript:;"class="btn btn-wx">确定</a></div>‘;
        msg_menu[0].innerHTML = html;

        if(inputdata.ac == ‘edit‘){
            if(inputdata.url){
                $.id(‘url_css‘).style.display = ‘block‘;
                $.id(‘keyword‘).style.display = ‘none‘;
            }else{
                $.id(‘url_css‘).style.display = ‘none‘;
                $.id(‘keyword‘).style.display = ‘block‘;
            }            

        }
        var removePopupElement = function() {
             while(msg_menu[0].hasChildNodes()) //当div下还存在子节点时 循环继续
            {
                msg_menu[0].removeChild(msg_menu[0].firstChild);
            }
        };
        var popup = {
                close: function(index) {
                        var data = {type:index};
                        if(index == 1){
                            data.title = $.id(‘title‘).value;
                            if(data.title.length < 1){
                                $.die(‘菜单信息不能为空‘);return false;
                            }
                            data.pid = $.id(‘pid‘).value;
                            data.menu_type = $.id(‘menu_type‘).value;
                            if($.id(‘menu_type‘).value == 0){
                                data.keyword = $.id(‘keywords‘).value;
                                data.url = ‘‘;
                                if(data.keyword.length < 1){
                                    $.die(‘关联关键词不能为空‘);return false;
                                }
                            }else{
                                data.keyword = ‘‘;
                                data.url = $.id(‘url‘).value;
                                console.log($.id(‘url‘).value);
                                if(!$.isUrl(data.url)){
                                    $.die(‘url格式不对‘);return false;
                                }    

                            }
                            data.sort = $.id(‘sort‘).value;
                            if(inputdata.id){
                                data.id = inputdata.id;
                            }
                        }
                          backfun(data);
                        removePopupElement();
                }
            };
        var btn =  document.getElementsByClassName(‘btn-wx‘);
        var handleEvent = function(e){
            popup.close($.arrs(btn).indexOf(e.target));
        }
        var menuType = function(){
            var a = this.value;
            var keyword = $.id(‘keyword‘);
            var url = $.id(‘url_css‘);
            if(a == 0 ){
                keyword.style.display = ‘block‘;
                url.style.display = ‘none‘;
            }else{
                keyword.style.display = ‘none‘;
                url.style.display = ‘block‘;
            }
        }
        var menuDel = function(){
            var data = {type:2,id:inputdata.id};
            backfun(data);
            removePopupElement();
        }
        for (i=0; i<btn.length; i++) {
            var re_obj =  btn[i].addEventListener(‘click‘, handleEvent);
        }
        $.id(‘menu_type‘).addEventListener(‘click‘, menuType);
        $.id(‘del‘).addEventListener(‘click‘, menuDel);
    }

})(lk,window);

php

    /**
     * 微信公众号菜单展示
     */
    public function wx_creat()
    {
        if (IS_POST) {
            $data = $this->clear_html($_POST);
            unset($data[‘type‘],$data[‘menu_type‘]);
            if(!$data[‘id‘]){
                $data[‘mid‘] = $this->mid;
                $data[‘is_show‘] = 1;
                //D(‘Aaep_wxmenu‘)->data($data)->add();
                if(D(‘Aaep_wxmenu‘)->data($data)->add()){
                    $this->dexit(array(‘error‘=>0,‘msg‘=>‘添加成功‘));
                }else{
                    $this->dexit(array(‘error‘=>1,‘msg‘=>‘添加失败‘));
                }
            }else{
                $menu = D(‘Aaep_wxmenu‘)->where(array(‘id‘=>$data[‘id‘]))->find();
                //检查子父类的修改
                if($data[‘pid‘] != $menu[‘pid‘]){
                    $count = D(‘Aaep_wxmenu‘)->where(array(‘pid‘=>$data[‘pid‘],‘mid‘=>$this->mid))->count(‘*‘);
                    if($count == 5 ){
                        $this->dexit(array(‘error‘=>1,‘msg‘=>‘子类菜单不能多于5个‘));
                    }

                    if($data[‘pid‘] == 0 && $count == 3){
                        $this->dexit(array(‘error‘=>1,‘msg‘=>‘父类菜单不能多于3个‘));
                    }

                }
                //检查父类
                if($menu[‘pid‘] == 0){
                    $counts = D(‘Aaep_wxmenu‘)->where(array(‘pid‘=>$menu[‘id‘],‘mid‘=>$this->mid))->count(‘*‘);
                    if($counts != 0){
                        $this->dexit(array(‘error‘=>1,‘msg‘=>‘还有子类不能修改!‘));
                    }

                }
                $id = $data[‘id‘];unset($data[‘id‘]);
                if (D(‘Aaep_wxmenu‘)->data($data)->where(array(‘mid‘=>$this->mid,‘id‘=>$id))->save()) {
                    $this->dexit(array(‘error‘=>0,‘msg‘=>‘修改成功‘));
                }else{
                    $this->dexit(array(‘error‘=>1,‘msg‘=>‘修改失败‘));
                }

            }
        }
        $menu = D(‘Aaep_wxmenu‘)->field(‘id,title‘)->where(array(‘mid‘=>$this->mid,‘pid‘=>0))->order(‘sort‘)->select();
        $menuChlid = D(‘Aaep_wxmenu‘)->field(‘id,pid,title‘)->where(array(‘mid‘=>$this->mid,‘pid‘=>array(‘<>‘,0)))->order(‘sort‘)->select();
        //dump($menuChlid);

        $this->assign(array(‘menu‘=>$menu,‘menuChlid‘=>$menuChlid));
        $this->display();
    }

    /**
     * 查询一个菜单
     */
    public function wx_find()
    {
        $id = $this->clear_html($_POST[‘id‘]);
        $menu = D(‘Aaep_wxmenu‘)->where(array(‘id‘=>$id))->find();
        $f_menu = D(‘Aaep_wxmenu‘)->field(‘id,title‘)->where(array(‘mid‘=>$this->mid,‘pid‘=>0))->select();
        $this->dexit(array(‘error‘=>0,‘msg‘=>$menu,‘f_menu‘=>$f_menu));

    }
    /**
     * 删除菜单
     */

    public function del_ment()
    {
        $id = $this->clear_html($_POST[‘id‘]);
        $menu = D(‘Aaep_wxmenu‘)->where(array(‘id‘=>$id))->find();
        if($menu[‘pid‘] == 0){
            $conut = D(‘Aaep_wxmenu‘)->where(array(‘pid‘=>$id,‘mid‘=>$this->mid))->count(‘*‘);
            if($conut != 0){
                 $this->dexit(array(‘error‘=>1,‘msg‘=>‘还有子类菜单不能删除!‘));
            }
        }
        if(D(‘Aaep_wxmenu‘)->where(array(‘id‘=>$id))->delete()){
            $this->dexit(array(‘error‘=>0,‘msg‘=>‘删除成功‘));
        }else{
            $this->dexit(array(‘error‘=>1,‘msg‘=>‘删除失败‘));
        }

    }

    /**
     *  一键生成微信菜单
     *  admin:方法条件
     */
    public function add_wx_menu()
    {
        if(IS_POST){
            if ($this->clear_html($_POST[‘admin‘]) == ‘yepai‘) {
                $re = $this->createmenu();
                if($re == 1){

                    $this->dexit(array(‘error‘=>0,‘msg‘=>‘微信公众号菜单生成成功‘));
                }else{
                    $this->dexit(array(‘error‘=>1,‘msg‘=>‘微信公众号菜单生成失败‘.$re));
                }

            }
        }
    }

      //创建菜单操作
    public function createmenu()
    {
        $url = ‘https://api.weixin.qq.com/cgi-bin/menu/create?access_token=‘.$this->getAccessToken();

        $where1 = array(‘pid‘=>0,‘mid‘=>$this->mid);
        $wxmenu_model = D(‘Aaep_wxmenu‘);
        $class = $wxmenu_model->where($where1)->order(‘sort‘)->limit(‘3‘)->select();
        $kcount =$wxmenu_model->where($where1)->count(‘*‘);
        $data = ‘{"button":[‘;
        foreach($class as $key=>$vo){
            $data.=‘{"name":"‘.$vo[‘title‘].‘",‘;
            $where2 = array(‘pid‘=>$vo[‘id‘],‘mid‘=>$this->mid);
            $c = $wxmenu_model->where($where2)->order(‘sort‘)->select();
            $count = $wxmenu_model->where($where2)->count(‘*‘);
            if($c!=false){
                $data.=‘"sub_button":[‘;
            }else{
                if($vo[‘keyword‘]){
                    $data.=‘"type":"click","key":"‘.$vo[‘keyword‘].‘"‘;
                }else if($vo[‘url‘]){
                    $data.=‘"type":"view","url":"‘.htmlspecialchars_decode($vo[‘url‘]).‘"‘;
                }else if($vo[‘wxsys‘]){
                    $data.=‘"type":"‘.$this->_get_sys(‘send‘,$vo[‘wxsys‘]).‘","key":"‘.$vo[‘wxsys‘].‘"‘;
                }
            }
            $i=1;
            foreach($c as $voo){
                if($i==$count){
                    if($voo[‘keyword‘]){
                        $data.=‘{"type":"click","name":"‘.$voo[‘title‘].‘","key":"‘.$voo[‘keyword‘].‘"}‘;
                    }else if($voo[‘url‘]){
                        $data.=‘{"type":"view","name":"‘.$voo[‘title‘].‘","url":"‘.htmlspecialchars_decode($voo[‘url‘]).‘"}‘;
                    }else if($voo[‘wxsys‘]){
                        $data.=‘{"type":"‘.$this->_get_sys(‘send‘,$voo[‘wxsys‘]).‘","name":"‘.$voo[‘title‘].‘","key":"‘.$voo[‘wxsys‘].‘"}‘;
                    }
                }else{
                    if($voo[‘keyword‘]){
                        $data.=‘{"type":"click","name":"‘.$voo[‘title‘].‘","key":"‘.$voo[‘keyword‘].‘"},‘;
                    }else if($voo[‘url‘]){
                        $data.=‘{"type":"view","name":"‘.$voo[‘title‘].‘","url":"‘.htmlspecialchars_decode($voo[‘url‘]).‘"},‘;
                    }else if($voo[‘wxsys‘]){
                        $data.=‘{"type":"‘.$this->_get_sys(‘send‘,$voo[‘wxsys‘]).‘","name":"‘.$voo[‘title‘].‘","key":"‘.$voo[‘wxsys‘].‘"},‘;
                    }
                }
                $i++;
            }
            if($c!=false){
                $data.=‘]‘;
            }
            if($k==$kcount){
                $data.=‘}‘;
            }else{
                $data.=‘},‘;
            }
            $k++;
        }
      $data.=‘]}‘;
  //==========================================
    //3.发送请求
    $content = $this->request($url,true,‘post‘,$data);
    //4.处理返回值
    $content = json_decode($content);
    if($content->errmsg == ‘ok‘){
      return 1;
    }else{
      //echo ‘创建菜单不成功!‘.‘<br />‘;
     return $content->errcode;
    }
  }

  private function _get_sys($type=‘‘,$key=‘‘)
  {
    $wxsys  = array(
        ‘扫码带提示‘,
        ‘扫码推事件‘,
        ‘系统拍照发图‘,
        ‘拍照或者相册发图‘,
        ‘微信相册发图‘,
        ‘发送位置‘,
    );

    if($type == ‘send‘){
      $wxsys  = array(
          ‘扫码带提示‘=>‘scancode_waitmsg‘,
          ‘扫码推事件‘=>‘scancode_push‘,
          ‘系统拍照发图‘=>‘pic_sysphoto‘,
          ‘拍照或者相册发图‘=>‘pic_photo_or_album‘,
          ‘微信相册发图‘=>‘pic_weixin‘,
          ‘发送位置‘=>‘location_select‘,
      );
      return $wxsys[$key];
      exit;
    }
    return $wxsys;
  }

    public function getAccessToken()
    {
        $filename = ‘./cache/token/accesstoken‘.$this->mid;
        if(!file_exists($filename) || (file_exists($filename) && (time()-filemtime($filename)) > 4000)){
            $url = ‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=‘.$this->appid.‘&secret=‘.$this->appsecret;
            $content = $this->request($url);
            $content = json_decode($content);
            $access_token = $content->access_token;
            file_put_contents($filename, $access_token);
        }else{
            $access_token = file_get_contents($filename);
        }
            return $access_token;
    }

    public function request($url,$https=true,$method=‘get‘,$data=null)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if($https === true){
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if($method == ‘post‘){
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        $str = curl_exec($ch);
        curl_close($ch);
        return $str;
    }
    

mysql

CREATE TABLE IF NOT EXISTS `ep_aaep_wxmenu` (
  `id` int(11) NOT NULL,
  `mer_id` int(11) NOT NULL,
  `pid` int(11) NOT NULL,
  `title` varchar(30) NOT NULL,
  `keyword` varchar(30) NOT NULL,
  `is_show` tinyint(1) NOT NULL,
  `sort` tinyint(3) NOT NULL,
  `url` char(255) NOT NULL,
  `wxsys` int(11) NOT NULL,
  `mid` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4;

ALTER TABLE `ep_aaep_wxmenu`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `ep_aaep_wxmenu`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=19;
时间: 2024-10-14 00:46:56

微信公众号菜单的相关文章

微信公众号菜单openid 点击菜单即可打开并登录微站

现在大部分微站都通过用户的微信openid来实现自动登录.在我之前的开发中,用户通过点击一个菜单,公众号返回一个图文,用户点击这个图文才可以自动登录微站.但是如果你拥有高级接口,就可以实现点击菜单,打开网页就能获取这个openid,实现自动登录. 这里已经提到,必须要拥有高级接口的权限(服务号.企业号),开启了开发者模式. 1.设置回调地址 在微信公众平台后台“开发者中心”中找到“高级接口”下的“OAuth2.0网页授权”,后面有一个“修改”,点击之后就会弹出填写回调地址的对话框.具体如何授权,

微信公众号菜单添加小程序,miniprogram,pagepath参数详解,php开发公众号

随着微信小程序功能的开发, 已经可以跟公众号打通了, 主要有两种方式: 1) 在公众号文章中插入小程序 2) 在公众号菜单中添加小程序 第一种方式, 子恒老师在前面的课程已经详细介绍过, 今天来讲第二种方法, 怎么通过开发的方式实现. 一. 公众号菜单添加小程序请求的微信地址 https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN 其中 ACCESS_TOKEN 需要替换成你自己的 access token,

unigui不是单个网页相应的链接,而是整体Web Application,如何把webApp的子功能映射到微信公众号菜单?

只需要用UniApplication.Parameters.Values['xxx']读取url的参数然后调用就可以 例如:要打开公众号菜单的取样送检指南查询模块,在自定义菜单设定:http://www.xxxxx.com/m?app=qyzn procedure TMainmForm.UnimFormCreate(Sender: TObject); var app:string; begin app := UniApplication.Parameters.Values['app']; if

微信公众号菜单进入的页面切换第二次失效

现象: 近期在微信中开发了一个电商的平台,一切接口页面处理完成后,正式布置到公众号,在公众号上自定义菜单进行平台时(如:.../index.html),发现了一个很有意思的问题:哪个页面是从公众号里点击进入的平台的,当切换一两次页面时,.../index.html这个页面就切换不进了. 解决过程: 1.测试了在“微信web开发者工具”里点到哭也点不出问题来,初步确定页面没有问题: 2.测试了在公众号中哪个页面进入平台就会出现哪个页面切换不过去,初步确定入口处有问题: 3.测试利用中间页面进行引导

微信公众号菜单开发以及授权详细说明

主代码请参考:http://www.cnblogs.com/hopelooking/p/7463934.html 难点解析: 在微信创建菜单的时候我们惯用的是curl,但是菜单中难免是要有中文的,如果你的php版本是5.4版本的话,那么一定会报错的,主要错误原因是对象或者字符串之间的错误,那么我们在使用json_encode的时候就不能单纯的只是json一下了,应该json_encode($data,JSON_UNESCAPED_UNICODE) 例子: public function acti

微信公众号开发之院校行业应用

本方案适用于大学院系,职业学院等官方公众号建设,院校公众号,采用微信服务号定制开发,面向学生,以微信互动为主,让学生通过微信公众号认识了解同学,了解院校.帮助院校了解学生需求,建立一种新的院校与学生的沟通方式. 院校微信公众号需求模型 微信公众号功能模块 1.微社区 学生可以在微社区各个板块发言跟帖,并分享到朋友圈 2.校园生活 以图文,或视频的形式发布关系校园的趣事,新闻等. 3.院校工作 院校的微官网,院校介绍,公告通知消息等查询,办公室联系人等 4.个人主页 学生的个人微信主页,可以互动留

Vue仿微信公众号配置页面

一.需求: 1.刚好公司需要自定义微信公众号菜单配置,在vue的后台管理系统写一个页面,进行菜单配置. 二.页面图片:(menu对象值那个地方只是打印出来看而已,自行去掉) 三.demo链接 https://summer-lin.github.io/vue-wechat-menu-demo/#/ 四.框架 vue + elementUI + mockjs 因为公司是基于vue和elementUI,如果想改其他UI框架,则将el-开头的组件都换了就行了. 五.注意事项: 1.data里面有个men

微信公众号开发-配置开发环境02

1.前言 经过前面的配置,基本完成了一些基础配置.后面接下来就是一些开发流程了. 2.配置pom.xml 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi

微信公众号如何设置“粉丝海报裂变”使用步骤:

微信公众号作为企业重要的宣传渠道,阅读量和粉丝数成了公众号的关键数据,其中吸引用户关注是最难的,除去从内容方面提升之外,还可以借用一些微信公众号吸粉工具,比如通过粉丝海报来进行粉丝裂变吸粉. 微信公众号粉丝海报使用步骤: 首先你需要设计一个海报,推荐尺寸为750×1334,然后结合自身服务或产品抛出一个诱惑,引起大家的关注,同时要让人一眼看过去就有分享的愿望. 注意:海报上要预留二维码位置 然后登陆进入鱼塘互动平台,在上方菜单中找到活动-超级粉丝海报-新建海报-自定义粉丝海报即可进入粉丝海报功能