• 微信公众号 菜单


    <?php
    
    class Weixin_menu extends My_Controller
    {
        public function __construct()
        {        
            parent::__construct(); 
        }
    
        public function menu(){
    
            $appid = "wxe0745a5de6f0c3e6";
            $appsecret = "f21999aa967bc522e2d542c2ff0b5e5e";
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
    
            $output = $this->https_request($url);
            $jsoninfo = json_decode($output, true);
    
            $access_token = $jsoninfo["access_token"];
    
            $jsonmenu = '{
                            "button": [
                                {
                                    "name": "逍游中心", 
                                    "sub_button": [
                                        {
                                            "type": "click", 
                                            "name": "1", 
                                            "key": "1"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "2", 
                                            "key": "2"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "3", 
                                            "key": "3"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "4", 
                                            "key": "4"
                                        }, 
                                        {
                                            "type": "view", 
                                            "name": "本地天气", 
                                            "url": "http://m.hao123.com/a/tianqi"
                                        }
                                    ]
                                }, 
                                {
                                    "name": "逍游手游", 
                                    "sub_button": [
                                        {
                                            "type": "click", 
                                            "name": "10", 
                                            "key": "10"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "20", 
                                            "key": "20"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "30", 
                                            "key": "30"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "40", 
                                            "key": "40"
                                        }
                                    ]
                                }, 
                                {
                                    "name": "逍游天下", 
                                    "sub_button": [
                                        {
                                            "type": "click", 
                                            "name": "公司简介", 
                                            "key": "company"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "趣味游戏", 
                                            "key": "game"
                                        }, 
                                        {
                                            "type": "click", 
                                            "name": "领取兑换码", 
                                            "key": "dhm"
                                        }
                                    ]
                                }
                            ]
                        }';
    
            $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
            $result = $this->https_request($url, $jsonmenu);
            //var_dump($result);
        }
    
        public 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;
        }
    }
  • 相关阅读:
    node path.resolve()和path.join()
    完美替代postman的接口测试工具—— apipost
    localforage indexedDB如何使用索引
    ApiPost V5 升级指南
    Chrome升级到91版本以上后Cookies SameSite问题,IdentityServer4登录不上问题?
    React直接调用Bootstrap的方案
    Golang的module模式下项目组织结构
    Linux部署SpringBoot项目jar包,输出日志到文件并追踪
    mybatis plus 查询语句
    springboot 引入AOP 切面 @Aspect 注解使用
  • 原文地址:https://www.cnblogs.com/feiwu123/p/5234024.html
Copyright © 2020-2023  润新知