PHP订阅号(认证)微信自定义菜单开发
https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
https://mp.weixin.qq.com/debug?token=140733899&lang=zh_CN
https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Global_Return_Code.html
<?php /** * 插件名称: 微信公众号自定义菜单 * 插件描述: 微信公众号自定义菜单 * 作者:赤域吧 * 插件官网: https://chiyuba.com */ namespace app\common\lib; namespace addons\wxAutoReply\controller; class WeChatMenu { public $APPID = "xx"; // 替换此处 public $APPSECRET = "xx"; // 替换此处 private function getCurl($url) { $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); return $output; } //请求接口方法 private function postcurl($url, $data = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)) { curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); return $output = json_decode($output, true); } //获取access_token public function index() { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->APPID . "&secret=" . $this->APPSECRET; $date = $this->postcurl($url); $access_token = $date['access_token']; return $access_token; } //拼接参数,带着access_token请求创建菜单的接口 public function createMenu() { header("content-type:text/html;charset=utf-8"); $data = array( 'button' => array( array( 'name' => urlencode('文章'), 'sub_button' => array( array( 'type' => 'click', 'name' => urlencode('电影'), 'key' => 'item1_1' ), array( 'type' => 'click', 'name' => urlencode('小说'), 'key' => 'item1_2' ), array( 'type' => 'click', 'name' => urlencode('工具'), 'key' => 'item1_3' ) ) ), array( 'name' => urlencode('黑科技'), 'sub_button' => array( array( 'type' => 'miniprogram', 'name' => urlencode('赤域吧'), 'url' => urlencode('http://mp.weixin.qq.com'), 'appid' => urlencode('wx131ed77e55c0e850'), 'pagepath' => urlencode('pages/index/index') ), array( "type" => "miniprogram", "name" => urlencode("聊天有术"), "url" => urlencode("http://mp.weixin.qq.com"), "appid" => urlencode("wx9d909157711bbb4d"), "pagepath" => "pages/home/home" ) ) ), array( 'name' => urlencode('合作'), 'sub_button' => array( array( 'type' => 'click', 'name' => urlencode('官方群'), 'key' => 'item2_1' ), array( 'type' => 'view', 'name' => urlencode('官方微信'), 'url' => urlencode('https://chiyuba.com') ), array( 'type' => 'view', 'name' => urlencode('官方网址'), 'url' => urlencode('https://chiyuba.com') ) ) ) ) ); $access_token = $this->index(); var_dump($access_token); $data_json = urldecode(json_encode($data)); $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token; // $result = $this->postcurl($url, $data_json); // echo $result; } }
版权声明:
作者:小何
链接:https://ligo100.cn/houduanjishu/php/359.html
来源:小何博客
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
打赏
文章目录
关闭
共有 0 条评论