发布于 2015-10-18 04:57:41 | 186 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

微信 即时通讯软件

微信(英文名:wechat)是腾讯公司于2011年1月21日推出的一个为智能终端提供即时通讯服务的免费应用程序,微信支持跨通信运营商、跨操作系统平台通过网络快速发送免费语音短信、视频、图片和文字,同时,也可以使用通过共享流媒体内容的资料和基于位置的社交插件“摇一摇”、“漂流瓶”、“朋友圈”、”公众平台“、”语音记事本“等服务插件。


在微信5.0以前,自定义菜单是作为一种内测资格使用的,只有少数公众帐号拥有菜单,因此出现很多企业为了弄到菜单不惜重金求购。现如今,一大批帐号从订阅号转为服务号,很多都是奔着自定义菜单去的。今天我们就来简单研究下微信自定义菜单的处理。

自定义菜单的创建

<?php

define("APPID", "您的appid");
define("APPSECRET", "您的appsecret ");

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;
$res = file_get_contents($token_access_url);  //获取文件内容或获取网络请求的内容
//echo $res;
$result = json_decode($res, true);  //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result['access_token'];

define("ACCESS_TOKEN", $access_token);  //将access_token定义为常量,便于使用.

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

$menuData = ' {
   "button":[
   {
     "type":"click",
     "name":"今日歌曲",
     "key":"V1001_TODAY_MUSIC"
   },
   {
      "name":"菜单",
      "sub_button":[
      {
        "type":"view",
        "name":"搜索",
        "url":"http://www.soso.com/"
      },
      {
        "type":"view",
        "name":"视频",
        "url":"http://v.qq.com/"
      },
      {
        "type":"click",
        "name":"赞一下我们",
        "key":"V1001_GOOD"
      }]
    }]
 }';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $make_menu_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $menuData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$info = curl_exec($ch);

//判读执行过程中是否有错误,有则发送数据错误报告.
if (curl_errno($ch)) {
  echo 'Error' . curl_error($ch); //用户检查php运行环境中的curl模块开启情况.
}

curl_close($ch);
print_r($info); //查看post提交到微信服务器后,返回的数据.

自定义菜单的获取

<?php

define("APPID", "您的appid");
define("APPSECRET", "您的appsecret ");

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;
$res = file_get_contents($token_access_url);  //获取文件内容或获取网络请求的内容
$result = json_decode($res, true);  //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result['access_token'];

$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token;

$menu_json = file_get_contents($make_menu_url);

echo $menu_json;

自定义菜单的删除

<?php

define("APPID", "您的appid");
define("APPSECRET", "您的appsecret ");

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;
$res = file_get_contents($token_access_url);  //获取文件内容或获取网络请求的内容
$result = json_decode($res, true);  //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
$access_token = $result['access_token'];

$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token;

$menu_json = file_get_contents($make_menu_url);

echo $menu_json;

以上所述就是本文的全部内容了,希望对大家做微信开发有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务