以下是php代码:
//构建菜单,这个菜单直接复制了百度例子
$menues='{
    "button": [
        {
            "type": "click",
            "name": "点击示例",
            "msg": {
                "text": "回复文本",
                "type": "view_text"
            },
            "key": "test"
        },
        {
            "name": "菜单列表",
            "sub_button": [
                {
                    "type": "click",
                    "name": "素材回复",
                    "msg": {
                        "text": "素材名称",
                        "type": "view_limited",
                        "materialId": "1504611015245"
                    },
                    "key": "test"
                },
                {
                    "type": "view",
                    "name": "跳转链接",
                    "url": "https://www.baidu.com"
                },
                {
                    "type": "click",
                    "name": "文字回复",
                    "msg": {
                        "text": "文字回复内容",
                        "type": "view_text"
                    },
                    "key": "test"
                }
            ]
        }
    ]
}';
//$access_token 已经正确获取到了.
$MENU_URL="https://openapi.baidu.com/rest/2.0/cambrian/menu/create?access_token=".$access_token;
$result = https_request($MENU_URL, $menues);var_dump($result);function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
//print_r($data);
    curl_close($curl);
    return $output;
}运行出错:string(66) "{"error_code":306255,"error_msg":"\u65e0\u83dc\u5355\u6570\u636e"}"
把\u65e0\u83dc\u5355\u6570\u636e转成中文是:菜单数组为空.
请问这是什么原因?熊掌号就用api建菜单,搞了一天也没有搞成功.请高手帮忙看看.

解决方案 »

  1.   

    检查一下 $menues 的字符集
      

  2.   

    这个怎么检查啊?我把中文换成英文,或用php数组,再json_encode成json格式,也不行。
    $postArr = array(
               'button' => array(
               array(
                    'type'=>'click',
                    'name'=>"menu1",
    'msg' =>array('text'=>'回复文本','type'=>'view_text'),
                    'key' => 'item1'
                )
              )
            );
          $menues = json_encode($postArr);
    这样转换也不行。
      

  3.   

    $menues = json_encode($postArr); 后,看 $menues 的内容
      

  4.   

    json数据都是正确的, 然后创建的时间就是说菜单数据为空
      

  5.   

    我解决了 mlpy  坑死人啊  $menues = 'menues=' . json_encode($menu_list);  这样子才行