Thinkphp 中 distinct 的用法解析
668
2024-01-18
本文實例講述了PHP實現微信公眾號企業號自定義菜單接口。分享給大家供大家參考,具體如下:
define(AppId, "wx666cae44xxxxxx2");//定義AppId,需要在微信公眾平臺申請自定義菜單后會得到 define(AppSecret, "d77026a714d443a01d0229xxxxxxxx");//定義AppSecret,需要在微信公眾平臺申請自定義菜單后會得到 include("menu.php");//引入微信類 $wechatObj = new Wechat();//實例化微信類 $creatMenu = $wechatObj->creatMenu();//創建菜單
微信類(menu.php)代碼
<? class Wechat { private function getAccessToken() //獲取access_token { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".AppId."&secret=".AppSecret; $data = getCurl($url);//通過自定義函數getCurl得到https的內容 $resultArr = json_decode($data, true);//轉為數組 return $resultArr["access_token"];//獲取access_token } public function creatMenu()//創建菜單 { $accessToken = $this->getAccessToken();//獲取access_token $menuPostString = '{//構造POST給微信服務器的菜單結構體 "button":[ { "name":"產品介紹", "sub_button":[ { "type":"view", "name":"分銷A型", "url":"http://www.yourwebname.com/fenxiao/jianjie/soft.html" }, { "type":"view", "name":"分銷B型", "url":"http://www.yourwebname.com/fenxiaob/jianjie/soft.html" },{ "type":"view", "name":"地接批發", "url":"http://www.yourwebname.com/dijie/jianjie/soft.html" },{ "type":"view", "name":"精簡組團", "url":"http://www.yourwebname.com/zutuan/jianjie/soft.html" },{ "type":"view", "name":"直客網站", "url":"http://www.yourwebname.com/tripal/jianjie/soft.html" }] }, { "name":"申請試用", "sub_button":[ { "type":"click", "name":"分銷A型", "key":"fxa" }, { "type":"click", "name":"分銷B型", "key":"fxb" }, { "type":"click", "name":"地接批發", "key":"dj" }, { "type":"click", "name":"精簡組團", "key":"zutuan" }, { "type":"click", "name":"直客網站", "key":"zhike" } ] }, { "name":"博縱在線", "sub_button":[ { "type":"view", "name":"企業介紹", "url":"http://www.yourwebname.com/about.html" }, { "type":"view", "name":"公司新聞", "url":"http://www.yourwebname.com/news/company/" }, { "type":"view", "name":"聯系我們", "url":"http://www.yourwebname.com/contact.html" } ] } ] }'; $menuPostUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$accessToken;//POST的url $menu = dataPost($menuPostString, $menuPostUrl);//將菜單結構體POST給微信服務器 } } function getCurl($url){//get https的內容 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不輸出內容 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($ch); curl_close ($ch); return $result; } function dataPost($post_string, $url) {//POST方式提交數據 $context = array ('http' => array ('method' => "POST", 'header' => "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) rn Accept: */*", 'content' => $post_string ) ); $stream_context = stream_context_create ( $context ); $data = file_get_contents ( $url, FALSE, $stream_context ); return $data; } ?>
更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP微信開發技巧匯總》、《PHP編碼與轉碼操作技巧匯總》、《PHP網絡編程技巧總結》、《php字符串(string)用法總結》、《PHP中json格式數據操作技巧匯總》及《PHP針對XML文件操作技巧總結》
希望本文所述對大家PHP程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!