Exemplo n.º 1
0
 function updatewxmenu()
 {
     //更新菜单到服务器
     $this->checkadminlogin();
     $info = $this->mysql->getarr("select * from   " . Mysite::$app->config['tablepre'] . "wxmenu   order by sort desc");
     $tempinfo = array();
     foreach ($info as $key => $value) {
         if ($value['parent_id'] == 0) {
             $value['sub_button'] = array();
             foreach ($info as $k => $val) {
                 if ($value['id'] == $val['parent_id']) {
                     $value['sub_button'][] = $val;
                 }
             }
             $tempinfo[] = $value;
         }
     }
     /*转换为菜单*/
     $menuinfo = array();
     //$stringarr = '{"button":[';
     foreach ($tempinfo as $key => $value) {
         if (count($value['sub_button']) > 0) {
             $temhuan = array();
             $temhuan['name'] = urlencode($value['name']);
             //	$neicontent = '{"name":"'.$value['name'].'","sub_button":[';
             foreach ($value['sub_button'] as $k => $v) {
                 $temsub = array();
                 $temsub['name'] = urlencode($v['name']);
                 $temsub['type'] = $v['type'];
                 if ($v['type'] == 'view') {
                     $link = unserialize($value['values']);
                     $temhuan['url'] = urlencode($link['lj_link']);
                 } else {
                     $temsub['key'] = $v['code'];
                 }
                 $temhuan['sub_button'][] = $temsub;
             }
             $menuinfo['button'][] = $temhuan;
             //$neicontent .= ']},';
             //	$stringarr .= $neicontent;
         } else {
             //$stringarr .=  '{"name":"'.$value['name'].'","key":"'.$value['code'].'","type":"click"},';
             $temhuan = array();
             $temhuan['name'] = urlencode($value['name']);
             if ($value['type'] == 'view') {
                 $link = unserialize($value['values']);
                 $temhuan['url'] = urlencode($link['lj_link']);
             } else {
                 $temhuan['key'] = $value['code'];
             }
             $temhuan['type'] = $value['type'];
             $menuinfo['button'][] = $temhuan;
         }
     }
     //$stringarr .= ']}';
     $testinfo = urldecode(json_encode($menuinfo));
     $wx_s = new wx_s();
     if ($wx_s->savemenu($testinfo)) {
         $this->success('操作成功');
     } else {
         $this->message($wx_s->err());
     }
 }
Exemplo n.º 2
0
 public function updatewxmenu()
 {
     //更新菜单到服务器
     $this->checkshoplogin();
     $shopid = ICookie::get('adminshopid');
     if ($shopid <= 0) {
         $this->message('操作失败');
     }
     $info = $this->mysql->getarr("select * from   " . Mysite::$app->config['tablepre'] . "shop_wxmenu where shopid={$shopid} order by sort desc");
     $tempinfo = array();
     foreach ($info as $key => $value) {
         if ($value['parent_id'] == 0) {
             $value['sub_button'] = array();
             foreach ($info as $k => $val) {
                 if ($value['id'] == $val['parent_id']) {
                     $value['sub_button'][] = $val;
                 }
             }
             $tempinfo[] = $value;
         }
     }
     $menuinfo = array();
     foreach ($tempinfo as $key => $value) {
         if (0 < count($value['sub_button'])) {
             $temhuan = array();
             $temhuan['name'] = urlencode($value['name']);
             foreach ($value['sub_button'] as $k => $v) {
                 $temsub = array();
                 $temsub['name'] = urlencode($v['name']);
                 if ($v['type'] == 'view') {
                     $link = unserialize($v['values']);
                     $temsub['url'] = urlencode($link['lj_link']);
                     $temsub['type'] = "view";
                 } else {
                     $temsub['type'] = "click";
                     $temsub['key'] = $v['code'];
                 }
                 $temhuan['sub_button'][] = $temsub;
             }
             $menuinfo['button'][] = $temhuan;
         } else {
             $temhuan = array();
             $temhuan['name'] = urlencode($value['name']);
             $temhuan['key'] = $value['code'];
             if ($value['type'] == 'view') {
                 $link = unserialize($value['values']);
                 $temhuan['url'] = urlencode($link['lj_link']);
                 $temhuan['type'] = "view";
             } else {
                 $temhuan['key'] = $value['code'];
                 $temhuan['type'] = "click";
             }
             $menuinfo['button'][] = $temhuan;
         }
     }
     $testinfo = urldecode(json_encode($menuinfo));
     $wechat = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "shop_wechat where shopid={$shopid}");
     if (empty($wechat)) {
         $this->message('未设置微信基本信息');
     }
     //print_r($wechat);exit;
     $wx_s = new wx_s($wechat['token'], $wechat['appid'], $wechat['secret'], $shopid);
     if ($wx_s->savemenu($testinfo)) {
         $this->success('操作成功');
     } else {
         $this->message($wx_s->err());
     }
 }