<?php
header("Content-type: text/html; charset=utf-8");

$APPID="";
$APPSECRET="";

function gbk_to_utf8($str){
    return mb_convert_encoding($str, 'utf-8', 'gbk');
}


  $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$output = curl_exec($ch);
	curl_close($ch);
	$jsoninfo = json_decode($output, true);
	$access_token = $jsoninfo["access_token"];
	
	//$access_token ="23_oSwx5G1s1Ek9999999999999999999999RbABASVC";
    
    $data = '{
			"button":[
							{
							"name":"常见问题",
								 "sub_button":[
								 
								{	
							   "type":"click",
							   "name":"交易费率",
							   "key":"z001"
								},
								{
							   "type":"click",
							   "name":"结算与到账",
							   "key":"z002"
								}
							
								
								]
							},
							
							
							{
							"name":"交易查询",
								 "sub_button":[
								 
								{
							   "type":"click",
							   "name":"商家-今日销量",
							   "key":"u002"
								},
								{	
							   "type":"click",
							   "name":"商家-10笔成功订单",
							   "key":"a001"
								},
								{
							   "type":"click",
							   "name":"买家-订单查询",
							   "key":"a003"
								}
								
								]
							},
							
							
							{
							"name":"我的账号",
								 "sub_button":[
								 
								{	
							   "type":"click",
							   "name":"账号余额",
							   "key":"u001"
								},
								{	
							   "type":"click",
							   "name":"普通提现",
							   "key":"u003"
								},
								{
							   "type":"click",
							   "name":"加急提现",
							   "key":"u005"
								},
								{
							   "type":"view",
							   "name":"商家绑定",
							   "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxx&redirect_uri=https://wap.xxxx.cn/weixin/namebd.asp&host=v1&response_type=code&scope=snsapi_base&state=bd#wechat_redirect"
								}
								
								
								]
							}

					]
 			}';
 
  
 
 
    $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
	
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, gbk_to_utf8($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
	
	echo $result;

?>
