Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义菜单 - 创建接口 #27

Open
Tracked by #28
drodata opened this issue Mar 19, 2016 · 0 comments
Open
Tracked by #28

自定义菜单 - 创建接口 #27

drodata opened this issue Mar 19, 2016 · 0 comments

Comments

@drodata
Copy link
Owner

drodata commented Mar 19, 2016

📖 http://mp.weixin.qq.com/wiki/10/0234e39a2025342c17a7d23595c6b40a.html

Example:

$token = 'your-token';
$url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $token;

$menu = ['button' => [
    [
        'type' => 'click',
        "name" => "订单查询",
        'key' => 'key01',
    ],
    [
        'name' => '自助服务',
        'sub_button' => [
            [
                'type' => 'view',
                'name' => '订单系统',
                'url' => 'http://i.a.com/',
            ],
            [
                'type' => 'click',
                'name' => '点赞',
                'key' => 'key02',
            ],
        ],
    ],
]];

// json_encode 第2个参数确保中文能正确显示
$postFieldsData = json_encode($menu, JSON_UNESCAPED_UNICODE);

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFieldsData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$info = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Errno'.curl_error($ch);
}

curl_close($ch);

var_dump($info);

修改自定义菜单

同样调用上面的 munu/create api, 只是讲 menu 内容修改即可。 🔔 修改后的菜单不会立即同步到微信客户端, 有一定时间延迟。

@drodata drodata mentioned this issue Mar 19, 2016
12 tasks
@drodata drodata changed the title 自定义菜单创建接口 自定义菜单 - 创建接口 Mar 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant