PHP微信公共号自定义菜单。

Posted on   jiaoqing。  阅读(465)  评论(0编辑  收藏  举报

/**微信生成菜单

     * [addMennu description]

     */

    public function addMennu(){

        $token = $this->getToken();

        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$token;

        $SERVER_NAME = "http://".$_SERVER['SERVER_NAME'];/*域名*/

        $zhifu = $this->url."index.php?r=pay/index";

        $fu = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode($zhifu)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";

        $data = '{

            "button": [

                {

                    "name": "海宇", 

                    "sub_button": [

                        {

                            "type":"view",

                            "name":"支付",

                            "url":"'.$fu.'"

                        }

                    ]

                }

                

            ]

        }';

        return $this->sendCurl($url,$data);

    }

 

    public function sendCurl($url1,$data){

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url1);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //绕过安全证书

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //绕过安全证书

        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        $output = curl_exec($ch);

        curl_close($ch);

        return $output;

    }

 

print_r($this->addMennu());

/**微信生成菜单     * [addMennu description]     */    public function addMennu(){        $token = $this->getToken();        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$token;        $SERVER_NAME = "http://".$_SERVER['SERVER_NAME'];/*域名*/        $huoqu = $this->url."indexs.php?r=agent/code";        $qianyue = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode($huoqu)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";        $wdht = $this->url."indexs.php?r=mycontrct/code";        $myqy = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode($wdht)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";        $zhifu = $this->url."index.php?r=pay/index";        $fu = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode($zhifu)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";        $a =  $this->url."index.php?r=agent/code";        $agent = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$this->appid."&redirect_uri=".urlencode($a)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";        $data = '{            "button": [                {                    "name": "海宇",                     "sub_button": [                        {                            "type": "view",                            "name": "租赁豪宅",                             "url": "http://m.haiyufc.com/rent/rentAll"                        },                         {                            "type": "view",                            "name": "委托",                             "url": "http://m.haiyufc.com"                        },                         {                            "type":"view",                            "name":"支付",                            "url":"'.$fu.'"                        }                    ]                },                 {                    "name": "合同",                     "sub_button": [                        {                            "type": "miniprogram",                             "name": "租赁签约",                            "url":"'.$qianyue.'",                            "appid":"wx935e38107163e960",                            "pagepath":"pages/index/index?typeid=1"                         },                        {                            "type":"miniprogram",                            "name":"经纪人登陆",                            "url":"'.$agent.'",                            "appid":"wx935e38107163e960",                            "pagepath":"pages/index/index?typeid=2"                        }                    ]                },                 {                    "name": "关于海宇",                     "sub_button": [                        {                           "type":"view",                           "name":"税费计算器",                           "url":"http://m.haiyufc.com/Mortgage/sm.html"                         },                         {                           "type":"view",                           "name":"房贷计算器",                           "url":"http://m.haiyufc.com/Mortgage/Dksl.html"                        },                        {                            "type":"view",                            "name":"招贤纳士",                            "url":"http://m.eqxiu.com/s/BJUmXHfy?from=singlemessage&isappinstalled=0&share_level=1&from_user=85c218ad-ec68-4329-93d2-b8fef280ef07&from_id=26875fa5-55e2-4b93-8f1b-06988424d127&share_time=1526789738908",                        },                         {                            "type":"click",                            "name":"权证知识",                            "key":"V1001_GOOD"                        }                    ]                }            ]        }';        return $this->sendCurl($url,$data);    }

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?

随笔 - 287, 文章 - 0, 评论 - 3, 阅读 - 42万

Copyright © 2025 jiaoqing。
Powered by .NET 9.0 on Kubernetes

点击右上角即可分享
微信分享提示