/** * 创建自定义菜单 * token = md5('menu'+inner_weixin_key+'menu') * * @param $token */ public function actionCreatemenu() { $token = $this->get('token'); $innerWeixinKey = WEIXIN_INNER_KEY; $trueToken = md5('menu' . $innerWeixinKey . 'menu'); if ($token != $trueToken) { $this->innerOutput(1, '无法通过请求认证'); } $weixin = new Weixin(); //请注意菜单中的中文一定要采用某种方编码 $menu = array('button' => array(array('name' => $this->encodeZH('菜单一'), 'sub_button' => array(array('type' => 'view', 'name' => $this->encodeZH('子菜单一'), 'key' => 'MENU_GENE_INDEX', 'url' => 'http://mp.weixin.qq.com/'), array('type' => 'view', 'name' => $this->encodeZH('趣味文章'), 'key' => 'MENU_ARTICLE', 'url' => 'http://mp.weixin.qq.com'), array('type' => 'view', 'name' => $this->encodeZH('产品预告'), 'key' => 'MENU_PRODUCT', 'url' => 'http://mp.weixin.qq.com/'))), array('name' => $this->encodeZH('产品流程'), 'sub_button' => array(array('type' => 'view', 'name' => $this->encodeZH('武松打虎'), 'key' => 'MENU_GAME', 'url' => 'xxxx'), array('type' => 'view', 'name' => $this->encodeZH('产品详情'), 'key' => 'MENU_PRODUCT_DETAIL', 'url' => 'http://mp.weixin.qq.com/'))))); $menuMsg = $this->decodeZHMsg(json_encode($menu)); $accessMongo = new WeixinAccessToken(); $access_token = $accessMongo->getAccessToken(); if (!$access_token) { $this->innerOutput(2, '无法获取access_token'); } $weixin = new Weixin(); $res = $weixin->customMenu($menuMsg, $access_token); if (!$res) { $this->innerOutput(3, '菜单创建失败'); } $this->innerOutput(0, '菜单创建成功'); }