zoukankan      html  css  js  c++  java
  • 微信开发笔记

    用户登录微信客户端,向公众号发消息——>微信服务器——>我的服务器。

    1、用户发送给公众号的消息,还有订阅、取消订阅、位置等信息,通过微信服务器,转发给我的服务器。那么就需要在微信服务器上配置我的服务器地址,登陆微信公众平台——>开发者中心——>服务器配置。

    2、公众号给微信用户展现的界面菜单在微信服务器配置,可以使用微信公众平台的自定义菜单,也可以用程序修改。

    程序创建菜单的例子如下,PHP 代码,通过 curl_exec 函数调用微信提供的创建菜单接口。把该代码放到 web 服务器的文件中,然后通过浏览器访问该文件就可以创建微信公众号的菜单,当然也可以自己写个程序,模拟浏览器访问 https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN 也行。

    <?php
    
    header('Content-Type: text/html; charset=UTF-8');
    
    //更换成自己的APPID和APPSECRET
    $APPID="123456555";
    $APPSECRET="dfdsfsdfdsfs";
    
    $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
    
    $json=file_get_contents($TOKEN_URL);
    $result=json_decode($json);
    
    $ACC_TOKEN=$result->access_token;
    
    $data='{
             "button":[
             {
                   "name":"球场管理",
                   "sub_button":[
                    {
                       "type":"click",
                       "name":"时段管理",
                       "key":"tianQi"
                    },
                    {
                       "type":"click",
                       "name":"预约管理",
                       "key":"gongJiao"
                    },
                    {
                       "type":"click",
                       "name":"发布公告",
                       "key":"fanYi"
                    }]
              },
              {
                   "name":"球场查询",
                   "sub_button":[
                    {
                       "type":"view",
                       "name":"时段查询",
                       "url":"http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NDM0NTEyMg==&appmsgid=10000005&itemidx=1&sign=136d2f76ede1b6661fd7dc08011889d7#wechat_redirect"
                    },
                    {
                       "type":"click",
                       "name":"位置查询",
                       "key":"suzhouScenic"
                    },
                    {
                       "type":"click",
                       "name":"预约管理",
                       "key":"suzhouFood"
                    },
                    {
                       "type":"click",
                       "name":"球友交流",
                       "key":"liveSuzhou"
                    }]
               },
               {
                   "type":"view",
                   "name":"联系我们",
                   "url":"http://www.baidu.com"
               }]
           }';
    
    $MENU_URL="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$ACC_TOKEN;
    
    $ch = curl_init($MENU_URL);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
    $info = curl_exec($ch);
    $menu = json_decode($info);
    print_r($info);        //创建成功返回:{"errcode":0,"errmsg":"ok"}
    
    if($menu->errcode == "0"){
        echo "菜单创建成功";
    }else{
        echo "菜单创建失败";
    }
    ?>
    View Code

    获取微信公众号菜单的 PHP 代码如下:

    <?php
    
    header('Content-Type: text/html; charset=UTF-8');
    
    $APPID="";
    $APPSECRET="";
    
    $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
    
    $json=file_get_contents($TOKEN_URL);
    $result=json_decode($json);
    
    $ACC_TOKEN=$result->access_token;
    
    $MENU_URL="https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".$ACC_TOKEN;
    
    $cu = curl_init();
    curl_setopt($cu, CURLOPT_URL, $MENU_URL);
    curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
    $menu_json = curl_exec($cu);
    $menu = json_decode($menu_json);
    curl_close($cu);
    
    echo $menu_json;
    
    ?>
    View Code

    删除微信公众号菜单的 PHP 代码如下:

    <?php
    
    header('Content-Type: text/html; charset=UTF-8');
    
    $APPID="";
    $APPSECRET="";
    
    $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
    
    $json=file_get_contents($TOKEN_URL);
    $result=json_decode($json);
    
    $ACC_TOKEN=$result->access_token;
    
    $MENU_URL="https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".$ACC_TOKEN;
    
    $cu = curl_init();
    curl_setopt($cu, CURLOPT_URL, $MENU_URL);
    curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
    $info = curl_exec($cu);
    $res = json_decode($info);
    curl_close($cu);
    
    if($res->errcode == "0"){
        echo "菜单删除成功";
    }else{
        echo "菜单删除失败";
    }
    
    ?>
    View Code

    3、用户点击公众号界面菜单显示的内容由我的服务器提供。

    持续……

  • 相关阅读:
    x5开源库后续知识点
    仿抖音上下滑动分页视频
    Sp效率分析和理解
    ARCGIS 数据格式
    arcEngine开发之activeView.PartialRefresh(译)
    arcEngine开发之查询的相关接口
    arcEngine开发之查看属性表
    arcEngine开发之根据点坐标创建Shp图层
    arcEngine开发之加载栅格数据
    arcEngine开发之IMap、ILayer、IFeatureLayer和IFeatureClass关系
  • 原文地址:https://www.cnblogs.com/NaughtyBaby/p/4776164.html
Copyright © 2011-2022 走看看