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
| <?php $appid = "your appid"; $appsecret = "your appsecret "; $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"]; $jsonmenu = { "button": [{ "name": "微信导览", "sub_button": [{ "type": "click", "name": "迎福纳祥", "key": "迎福纳祥" }, { "type": "click", "name": "破茧成蝶", "key": "破茧成蝶" }, { "type": "click", "name": "成丁人间", "key": "成丁人间" }, { "type": "click", "name": "安宅立业", "key": "安宅立业" }, { "type": "click", "name": "福寿永存", "key": "福寿永存" } ]
}, { "name": "展讯活动", "sub_button": [{ "type": "click", "name": "馆藏精品", "key": "馆藏精品" }, { "type": "click", "name": "讲座活动", "key": "讲座活动" }, { "type": "click", "name": "工作坊", "key": "工作坊" } ]
}, { "name": "帮助", "sub_button": [{ "type": "click", "name": "导览说明", "key": "导览说明" }, { "type": "click", "name": "服务指引", "key": "服务指引" } ]
} ] }; $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token; $result = https_request($url, $jsonmenu); 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); curl_close($curl); return $output; } ?>
|