/// <summary> /// 创建菜单 /// </summary> public static void CreateMenuPage() { var posturl = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", PartenerInfo.IsTokenExpired()); var content = PartenerInfo.GetPage(posturl, MyMenu); HttpContext.Current.Response.Write(content); }
/// <summary> /// 删除菜单 /// </summary> public static void DelMenu() { string postUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={0}"; postUrl = string.Format(postUrl, PartenerInfo.IsTokenExpired()); var strJson = PartenerInfo.RequestUrl(postUrl, "GET"); var errmsg = CommonHelper.GetJsonValue(strJson, "errmsg"); HttpContext.Current.Response.Write(errmsg); }
protected void btngo_Click(object sender, EventArgs e) { string res = ""; string access_token = PartenerInfo.IsTokenExpired(); string posturl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + access_token; string postData = "{\"touser\":\"" + UserName.Text + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + txtMsg.Text + "\"}}"; res = PartenerInfo.GetPage(posturl, postData); Response.Write(res); }
/// <summary> /// 处理消息 /// </summary> /// <param name="inputStream"></param> public void ExecuteMessage(Stream inputStream) { Wxmessage wx = GetWxMessage(inputStream); LogHelper.WriteLog(wx.FromUserName);//记录用户的OPENID string res = string.Empty; if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "subscribe") {//刚关注时,用于欢迎词 string content = string.Empty; if (!wx.EventKey.Contains("qrscene_")) { content = "/:rose欢迎xx科技有限公司/:rose\n直接回复“你好”"; res = sendTextMessage(wx, content); } else { content = "二维码参数:\n" + wx.EventKey.Replace("qrscene_", ""); res = sendTextMessage(wx, content); } } else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.ToLower() == "scan") { string str = "二维码参数:\n" + wx.EventKey; res = sendTextMessage(wx, str); } else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "CLICK") { if (wx.EventKey == "V1001_GOOD") { res = sendTextMessage(wx, "你好,谢谢支持,请继续关注我们!"); } if (wx.EventKey == "today") { res = sendPicTextMessage(wx, "瑞典首都一卡车冲撞人群 造成多人死伤", "描述仔细", "http://p3.pstatp.com/origin/1a6b000c52144a2ccf47", "http://www.toutiao.com/a6406254221851787522/#p=1"); } } else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "scancode_waitmsg") { if (wx.EventKey == "rselfmenu_0_0") { res = sendTextMessage(wx, "恭喜,您中了500W大奖!"); } } else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "LOCATION")//获取用户地理位置.. { res = sendTextMessage(wx, "您的位置是经度:" + wx.Latitude + ",维度是:" + wx.Longitude + ",地理经度为:" + wx.Precision); } else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "image")//多媒体 { res = ImageHandler.GetMultimedia(PartenerInfo.IsTokenExpired(), wx.MediaId); } else { if (wx.MsgType == "text" && wx.Content == "你好") { res = sendTextMessage(wx, "你好,欢迎使用xx科技有限公司公共微信平台!"); } else if (wx.MsgType == "text" && wx.Content == "授权") { string MyAppid = CommonHelper.GetAppValue("appID"); string RedirectUri = CommonHelper.GetAppValue("redirectUrl"); string URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + MyAppid + "&redirect_uri=" + RedirectUri + "&response_type=code&scope=snsapi_userinfo&state=a1#wechat_redirect"; string Str = "<a href='" + URL + "'>授权页面</a>"; res = sendTextMessage(wx, Str); } else if (wx.MsgType == "text" && wx.Content == "图文") { res = sendPicTextMessage(wx, "这里是一个标题", "这里是摘要", "http://img.178.com/wow/201703/284669205048/284669235126.jpg", "http://www.163.com"); } else if (wx.MsgType == "voice") //识别消息类型为语音 { res = sendTextMessage(wx, wx.Recognition); //wx.Recognition就是语音识别的结果,我们直接引用,以文本形式反馈就OK了 } else if (wx.MsgType == "location") { res = sendTextMessage(wx, "您发送的位置是:" + wx.Label + ";纬度是:" + wx.Location_X + ";经度是:" + wx.Location_Y + ";缩放比例为:" + wx.Scale); } else { res = sendTextMessage(wx, "你好,未能识别消息!"); } } HttpContext.Current.Response.Write(res); }