Пример #1
0
 public function releaseMenuHandle()
 {
     $token = $this->getAppToken(session('ecid'));
     //如果接口信息不完整,直接返回
     if ($token['weixin_AppId'] == '' || $token['weixin_AppSecret'] == '') {
         $this->ajaxReturn(Error::ERROR_MENU_TOKEN_EMPTY, Error::getErrMsg(Error::ERROR_MENU_TOKEN_EMPTY), 0);
     }
     $menu = $this->getMenuSet(session('ecid'));
     $menu_weixin = array('button' => '');
     for ($i = 0; $i < count($menu); $i++) {
         $menu_weixin['button'][$i] = $this->changeWeixinArray($menu[$i], $token);
         if ($menu[$i]['hasSub'] == 1) {
             for ($j = 0; $j < count($menu[$i]['subitem']); $j++) {
                 if (($menu[$i]['subitem'][$j]['responseType'] == null || $menu[$i]['subitem'][$j]['responseType'] == "text") && $menu[$i]['subitem'][$j]['responseText'] == "") {
                     $data['data'] = ERROR::ERROR_MENU_REPLY_EMPTY;
                     $data['info'] = $menu[$i]['subitem'][$j]['name'] . ":" . Error::getErrMsg(Error::ERROR_MENU_REPLY_EMPTY);
                     $this->ajaxReturn($data, "JSON");
                 }
             }
         } else {
             if (($menu[$i]['responseType'] == "text" || $menu[$i]['responseType'] == null) && $menu[$i]['responseText'] == "") {
                 $data['data'] = ERROR::ERROR_MENU_REPLY_EMPTY;
                 $data['info'] = $menu[$i]['name'] . ":" . Error::getErrMsg(Error::ERROR_MENU_REPLY_EMPTY);
                 $this->ajaxReturn($data, "JSON");
             }
         }
     }
     $weObj = new \Org\Weixin\Wechat();
     if ($weObj->checkAuth($token['weixin_AppId'], $token['weixin_AppSecret'])) {
         if ($tmp = $weObj->createMenu($menu_weixin)) {
             $data['data'] = Error::SUCCESS_OK;
             $data['info'] = Error::getErrMsg(Error::SUCCESS_OK);
             $this->ajaxReturn($data, 'JSON');
         }
     }
 }