微信自定义菜单
转
private function receiveEvent($object)
{
$contentStr = "";
switch ($object->Event)
{
case "subscribe":
$contentStr[] = array("Title" =>"欢迎关注方倍工作室", "Description" =>"点击图片关注或者微信搜索方倍工作室", "PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"weixin://addfriend/pondbaystudio");
case "unsubscribe":
$contentStr = "";
break;
case "CLICK":
switch ($object->EventKey)
{
case "company":
$contentStr[] = array("Title" =>"公司简介", "Description" =>"方倍工作室提供移动互联网相关的产品及服务,包括新浪微博应用、微信公众平台接口、手机版网站等", "PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"weixin://addfriend/pondbaystudio");
break;
default:
$contentStr[] = array("Title" =>"默认菜单回复", "Description" =>"您正在使用的是方倍工作室的自定义菜单测试接口", "PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg", "Url" =>"weixin://addfriend/pondbaystudio");
break;
}
break;
default:
$contentStr = "receive a new event: ".$object->Event;
break;
}
return $contentStr;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=HI3brcIDTXHIxpDoxJfYSGd9Yx-OgQNlEmJ48I80SV8tD0zpCzA1yZ069E1GTjz6-3aAZHfrYHIZKdgsRvWlyv7OR5PJjrq3Zy-MgSyZ4Xhuvz2qJr3mjGmZ0cjYQ0kh";
string param = "{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜单\",\"sub_button\":[{\"type\":\"click\",\"name\":\"helloword\",\"key\":\"V1001_HELLO_WORLD\"},{\"type\":\"click\",\"name\":\"赞一下我们\",\"key\":\"V1001_GOOD\"}]}]}";
string result = postWebReq(url, param, Encoding.UTF8);
}
static string postWebReq(string postUrl, string paramData, Encoding dataEncode)
{
string ret = string.Empty;
try
{
byte[] byteArray = dataEncode.GetBytes(paramData);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse reponse = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(reponse.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
reponse.Close();
newStream.Close();
}
catch (Exception ex)
{
}
return ret;
}
}
}

浙公网安备 33010602011771号