在微信5.0以前,自訂選單是作為一種內(nèi)測資格使用的,只有少數(shù)公眾帳號擁有選單,因此出現(xiàn)很多企業(yè)為了弄到選單不惜重金求購?,F(xiàn)如今,一大批帳號從訂閱號碼轉(zhuǎn)為服務(wù)號,很多都是奔著自訂選單去的。今天我們就來簡單研究下微信自訂選單的處理。
自訂選單的建立
<?php define("APPID", "您的appid"); define("APPSECRET", "您的appsecret "); $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET; $res = file_get_contents($token_access_url); //獲取文件內(nèi)容或獲取網(wǎng)絡(luò)請求的內(nèi)容 //echo $res; $result = json_decode($res, true); //接受一個 JSON 格式的字符串并且把它轉(zhuǎn)換為 PHP 變量 $access_token = $result['access_token']; define("ACCESS_TOKEN", $access_token); //將access_token定義為常量,便于使用. $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . ACCESS_TOKEN; $menuData = ' { "button":[ { "type":"click", "name":"今日歌曲", "key":"V1001_TODAY_MUSIC" }, { "name":"菜單", "sub_button":[ { "type":"view", "name":"搜索", "url":"http://www.soso.com/" }, { "type":"view", "name":"視頻", "url":"http://v.qq.com/" }, { "type":"click", "name":"贊一下我們", "key":"V1001_GOOD" }] }] }'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $make_menu_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_USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $menuData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $info = curl_exec($ch); //判讀執(zhí)行過程中是否有錯誤,有則發(fā)送數(shù)據(jù)錯誤報告. if (curl_errno($ch)) { echo 'Error' . curl_error($ch); //用戶檢查php運行環(huán)境中的curl模塊開啟情況. } curl_close($ch); print_r($info); //查看post提交到微信服務(wù)器后,返回的數(shù)據(jù).
#自訂選單的取得
<?php define("APPID", "您的appid"); define("APPSECRET", "您的appsecret "); $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET; $res = file_get_contents($token_access_url); //獲取文件內(nèi)容或獲取網(wǎng)絡(luò)請求的內(nèi)容 $result = json_decode($res, true); //接受一個 JSON 格式的字符串并且把它轉(zhuǎn)換為 PHP 變量 $access_token = $result['access_token']; $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token; $menu_json = file_get_contents($make_menu_url); echo $menu_json;
自訂選單的刪除
<?php define("APPID", "您的appid"); define("APPSECRET", "您的appsecret "); $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET; $res = file_get_contents($token_access_url); //獲取文件內(nèi)容或獲取網(wǎng)絡(luò)請求的內(nèi)容 $result = json_decode($res, true); //接受一個 JSON 格式的字符串并且把它轉(zhuǎn)換為 PHP 變量 $access_token = $result['access_token']; $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token; $menu_json = file_get_contents($make_menu_url); echo $menu_json;
以上所述就是本文的全部內(nèi)容了,希望對大家做微信開發(fā)有所幫助。
以上是分享微信開發(fā)自訂選單的處理範(fàn)例程式碼的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!
本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool
免費脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
Grass Wonder Build Guide |烏瑪媽媽漂亮的德比
4 週前
By Jack chen
<??>:在森林裡99夜 - 所有徽章以及如何解鎖
3 週前
By DDD
烏瑪?shù)姆劢z漂亮的德比橫幅日程(2025年7月)
4 週前
By Jack chen
Windows安全是空白或不顯示選項
4 週前
By 下次還敢
Rimworld Odyssey溫度指南和Gravtech
3 週前
By Jack chen

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)