對上級項目中的wenxin.php頁面更改,頁面展示
~~~
<?php
function http_curl($url,$data=null){
//1.初始化,創建一個新cURL資源
$ch = curl_init();
//2.設置URL和相應的選項
curl_setopt($ch, CURLOPT_URL, $url);
//下面兩個是php5.6版本需加上才能實現
curl_setopt($ch,CURLOPT_SAFE_UPLOAD, FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
//curl_setopt($ch, CURLOPT_HEADER, 0);
if(!empty($data)){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//測試號寫上這個是跳過SSL證書檢查,返回結果才不會null;
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//禁止curl資源直接輸出
//3.抓取URL并把它傳遞給瀏覽器
$opt=curl_exec($ch);
//4.關閉cURL資源,并且釋放系統資源
curl_close($ch);
return $opt;
}
function get_token(){
$appid="wx165112bf167af76c";
$secret="c65b22bfcf03fdd98504eac299701b03";
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$json=http_curl($url);
$result=json_decode($json);
return $result->access_token;
}
$token=get_token();
//var_dump($_POST);
if(isset($_POST['do_submit'])){
for($i=0;$i<3;$i++){
//指定下標
$button="menu{$i}";//一級菜單的名字
$type="menu{$i}_box";//一級菜單的類型
$key="menu{$i}_{$i}";//一級菜單的值
$sub_submit="menu{$i}_menu0";//二級菜單的名字
//如果有子菜單
if(trim($_POST[$sub_submit]) !=""){
//組裝二級菜單
for($j=0;$j<=4;$j++){
$sub_submit="menu{$i}_menu{$j}";//二級菜單名字
$sub_type="menu{$i}_menu0_box{$j}";//二級菜單類型
$sub_key="menu{$i}_menu0_name{$j}";//二級菜單的值
if(trim($_POST[$sub_submit] !="")){
$menuarr['button'][$i]['name']=$_POST[$button];//一級菜單名字
if($_POST[$sub_type]=="click"){
$menuarr['button'][$i]['sub_button'][$j]['type']="click";
$menuarr['button'][$i]['sub_button'][$j]['name']=$_POST[$sub_submit];
$menuarr['button'][$i]['sub_button'][$j]['key']=$_POST[$sub_key];
}else if($_POST[$sub_type]=="view"){
$menuarr['button'][$i]['sub_button'][$j]['type']="view";
$menuarr['button'][$i]['sub_button'][$j]['name']=$_POST[$sub_submit];
$menuarr['button'][$i]['sub_button'][$j]['url']=$_POST[$sub_key];
}
}
}
}else{
//組裝一級菜單
if(trim($_POST[$button] !="")){
if($_POST[$type]=="click"){
$menuarr['button'][$i]['type']="click";
$menuarr['button'][$i]['name']=$_POST[$button];
$menuarr['button'][$i]['key']=$_POST[$key];
}else if($_POST[$type]=="view"){
$menuarr['button'][$i]['type']="view";
$menuarr['button'][$i]['name']=$_POST[$button];
$menuarr['button'][$i]['url']=$_POST[$key];
}
}
}
}
}
echo "<pre>";
print_r($menuarr);
echo "<pre>";
?>
~~~
提交結果為

該章節源碼獲取(獲取密碼:wfg7)
[源碼下載](https://pan.baidu.com/s/17Wg25MUf6nr4KM9Nx8Hb0g)