Пример #1
0
        public string Excute(WeChatConfig config, WeChatData data)
        {
            //var msg = new
            //{
            //    button = new object[]
            //    {
            //        new {type="click",name="定位监控",key="CLICK_DWJK" },
            //        new {type="click",name="里程报表",key="CLICK_LCBB" },
            //        new
            //        {
            //            name="账号",
            //            sub_button=new object[]
            //            {
            //                new {type="click",name="绑定账号",key="CLICK_BDZH" },
            //                new {type="click",name="取消绑定",key="CLICK_QXBD" }
            //            }
            //        }
            //    }
            //};

            var msg = new
            {
                button = new object[]
                {
                    new
                    {
                        name="查车",
                        sub_button=new object[]
                        {
                              new {type="click",name="定位监控",key="CLICK_DWJK" },
                              new {type="click",name="里程报表",key="CLICK_LCBB" }
                        }
                    },
                    new {type="click",name="设防撤防",key="CLICK_SFCF" },
                    new
                    {
                        name="账号",
                        sub_button=new object[]
                        {
                            new {type="click",name="绑定账号",key="CLICK_BDZH" },
                            new {type="click",name="取消绑定",key="CLICK_QXBD" }
                        }
                    }
                }
            };

            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = string.Format("{0}menu/create?access_token={1}", config.APIUrl, config.AccessToken);
            item.Method = "POST";
            item.Encoding = "utf-8";
            item.ContentType = "application/x-www-form-urlencoded";
            item.Postdata = msg.ToJsonString();
            string result = http.GetHtml(item);
            return result;
        }
Пример #2
0
        /// <summary>
        /// 响应消息
        /// </summary>
        /// <returns></returns>
        public static string Excute(WeChatConfig config, WeChatData data)
        {
            if (!data.MsgType.HasValue()) return string.Empty;

            var cmd = GetCMD(data.MsgType);
            if (cmd != null)
            {
                return cmd.Excute(config, data);
            }
            return string.Empty;
        }
Пример #3
0
        public string Excute(WeChatConfig config, WeChatData data)
        {
            if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName))
            {
                return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!");
            }

            var msg = new WeChatData();
            msg.CreateTime = DateTime.Now.ToFileTime().ToString();
            msg.ToUserName = data.FromUserName;
            msg.FromUserName = data.ToUserName;
            msg.MsgType = "text";
            if (ModelFacade.WeChat.WeChatModel.UnBind(data.FromUserName))
            {
                msg.Content = "取消绑定成功!";
            }
            else
            {
                msg.Content = "取消绑定失败!";
            }
            return msg.ToXml();
        }
Пример #4
0
        public string Excute(WeChatConfig config, WeChatData data)
        {
            if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName))
            {
                return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!");
            }

            var vehicles = ModelFacade.WeChat.WeChatModel.GetDevicesByOpenID(7, data.FromUserName);

            if (vehicles.Count == 0)
            {
                return data.ToQuicklyReplayWeChatData("您还没有关联有车辆!");
            }
            var list = vehicles.Select(p =>
            {

                var isFortify = ModelFacade.WeChat.WeChatModel.CheckDeviceIsFortify(p.VehicleCode);
                var wid = new WeChatItemData()
                {
                    Title = p.LicenceNumber + "(" + (isFortify ? "设防中" : "未设防") + ")",
                    Url = string.Format("{0}WeChat/DeviceFortify?vehicleCode={1}&openID={2}&isFortify={3}", config.Host, p.VehicleCode, data.FromUserName, !isFortify)
                };

                return wid;
            }).ToList();

            list.Add(new WeChatItemData() { Title = "更多车辆", Url = string.Format("{0}WeChat/DeviceMore?openID={1}&type=DeviceFortify", config.Host, data.FromUserName) });
            list.Insert(0, new WeChatItemData() { Title = "设防撤防", PicUrl = string.Format("{0}Content/WeChat/images/fortify.png", config.Host) });
            return data.ToNewsWeChatData(list);
        }
Пример #5
0
        public string Excute(WeChatConfig config, WeChatData data)
        {
            if (!ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName))
            {
                return data.ToQuicklyReplayWeChatData("您还没有绑定魔方账号,请您先绑定账号!");
            }

            var vehicles = ModelFacade.WeChat.WeChatModel.GetDevicesByOpenID(7, data.FromUserName);

            if (vehicles.Count == 0)
            {
                return data.ToQuicklyReplayWeChatData("您还没有关联有车辆!");
            }
            var list = vehicles.Select(p => new WeChatItemData() { Title = p.LicenceNumber, Url = string.Format("{0}WeChat/DeviceReport?vehicleCode={1}&openID={2}", config.Host, p.VehicleCode, data.FromUserName) }).ToList();
            list.Add(new WeChatItemData() { Title = "更多车辆", Url = string.Format("{0}WeChat/DeviceMore?openID={1}&type=DeviceReport", config.Host, data.FromUserName) });
            list.Insert(0, new WeChatItemData() { Title = "查看车辆里程报表", PicUrl = string.Format("{0}Content/WeChat/images/report.png", config.Host) });
            return data.ToNewsWeChatData(list);
        }
Пример #6
0
 public string Excute(WeChatConfig config, WeChatData data)
 {
     if (ModelFacade.WeChat.WeChatModel.CheckIsBind(data.FromUserName))
     {
         return data.ToQuicklyReplayWeChatData("您已经绑定过了!");
     }
     else
     {
         var list = new List<WeChatItemData>()
         {
             new WeChatItemData()
             {
                  Title="绑定帐号(魔方)",
                  Url=string.Format("{0}WeChat/DeviceBind?openID={1}", config.Host, data.FromUserName),
                  PicUrl= string.Format( "{0}Content/WeChat/images/bind.png",config.Host),
                  Description="点击我绑定"
             }
         };
         return data.ToNewsWeChatData(list);
     }
 }
Пример #7
0
        public string Excute(WeChatConfig config, WeChatData data)
        {

            if (!data.Event.HasValue()) return string.Empty;
            switch (data.Event)
            {
                case "subscribe":
                    //关注事件

                    return data.ToQuicklyReplayWeChatData("您已经成功关注魔方(MOVO)平台!");
                case "unsubscribe":
                    //取消关注事件
                    ModelFacade.WeChat.WeChatModel.UnBind(data.FromUserName);
                    break;
                case "SCAN":
                    //扫描带参数二维码事件
                    return data.ToQuicklyReplayWeChatData("您已经成功关注魔方(MOVO)平台!");
                case "LOCATION":
                    //上报地理位置事件
                    break;
                case "VIEW":
                    //点击菜单跳转链接时的事件推送 
                    break;
                case "CLICK":
                    //点击菜单拉取消息时的事件推送
                    if (data.EventKey.HasValue())
                    {
                        var cmd = CMDManage.GetCMD("On" + data.EventKey.Replace("_", ""));
                        if (cmd != null)
                        {
                            return cmd.Excute(config, data);
                        }
                        else
                        {
                            return string.Empty;
                        }
                    }
                    break;
                default:
                    break;
            }
            return string.Empty;
        }
Пример #8
0
 public string Excute(WeChatConfig config, WeChatData data)
 {
     return string.Empty;
 }
Пример #9
0
 public string Excute(WeChatConfig config, WeChatData data)
 {
     HttpHelper http = new HttpHelper();
     HttpItem item = new HttpItem();
     item.URL = string.Format("{0}menu/get?access_token={1}", config.APIUrl, config.AccessToken);
     item.Method = "GET";
     item.ContentType = "application/x-www-form-urlencoded";
     string result = http.GetHtml(item);
     return result;
 }
Пример #10
0
 public string Excute(WeChatConfig config, WeChatData data)
 {
     HttpHelper http = new HttpHelper();
     HttpItem item = new HttpItem();
     item.URL = string.Format("{0}menu/delete?access_token={1}", config.APIUrl, config.AccessToken);
     item.Method = "GET";
     string result = http.GetHtml(item);
     return result;
 }