1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| $appid = "xxxxxxx"; $appsecret = "xxxxxxxxxxx"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $host = "http://xxxxxx.com"; $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"];
header("Content-type: text/html; charset=utf-8");
function createMenu($data, $access_token){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $tmpInfo; } function getMenu(){ return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN); }
function deleteMenu(){ return file_get_contents("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".ACCESS_TOKEN); }
$data = array( "button" => array( array( "name"=>urlencode("推广赚钱"), "sub_button"=>array( array( "type"=>"view", "name"=>urlencode("首页"), "url"=>$host."/default/index?needLogin=1&agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("做任务"), "url"=>$host."/proxy/taskHall?agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("提商机"), "url"=>$host."/business/add?agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("推广爆品"), "url"=>$host."/proxy/home?agent_r=agent_wx" ),array( "type"=>"view", "name"=>urlencode("推广店铺"), "url"=>$host."/rebateshop/index?agent_r=agent_wx" ) ) ), array( "name"=>urlencode("发展下级"), "sub_button"=>array( array( "type"=>"view", "name"=>urlencode("发展下级"), "url"=>$host."/invite/newinviteentershow?agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("管理下级"), "url"=>$host."/partner/mypartner?agent_r=agent_wx" ) ) ), array( "name"=>urlencode("我的"), "sub_button"=>array( array( "type"=>"view", "name"=>urlencode("收益"), "url"=>$host."/earnings/BalanceCommission?agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("我的店铺"), "url"=>$host."/shop/detail?agent_r=agent_wx" ), array( "type"=>"view", "name"=>urlencode("个人中心"), "url"=>$host."/home/ucenter?agent_r=agent_wx" )
) ) ) ); $data = json_encode($data); $data = urldecode($data); echo $data;echo "<br>\n"; echo createMenu($data, $access_token);echo "\n";
|