Example #1
0
        public string HandleAndGetResponse(BaseMessage message)
        {
            string response = "";
            TextMessage textMsg = message as TextMessage;

            string content = textMsg.Content.Trim();

            if (string.IsNullOrEmpty(content))
            {
                response = "您什么都没输入,没法帮您啊,%>_<%。";
            }
            //else if (SessionUtility.Contains(textMsg.FromUserName))
            //{
            //    response = AuthUtility.GetAuthResult(textMsg);
            //}
            else
            {
                if (content.Contains("图文"))
                {
                    return GetTuwenResponse(textMsg);
                }
                response = HandleOtherString(content);
            }

            TextMessage tm = new TextMessage();
            tm.ToUserName = message.FromUserName;
            tm.FromUserName = message.ToUserName;
            tm.CreateTime = WeiXinHelper.GetNowTime();
            tm.Content = response;

            string returnValue = tm.GetResponseString();
            return returnValue;
        }
        //protected IUserRepository<UserDTO> userRepository = RepositoryFactory.GetInstance().GetUserRepository();
        //protected IAuthProfileRepository<AuthProfileDTO> authProfileRepository = RepositoryFactory.GetInstance().GetAuthProfileRepository();
        public string Handle_LocationEventMessage(LocationMessage message)
        {
            //回复欢迎消息
            TextMessage tm = new TextMessage();
            tm.ToUserName = message.FromUserName;
            tm.FromUserName = message.ToUserName;
            tm.CreateTime = WeiXinHelper.GetNowTime();
            //tm.Content = string.Format("您当前的经度:{0}, 纬度{1}",message.Longitude, message.Latitude);

            string url = string.Format("http://lbs.juhe.cn/api/getaddressbylngb?lngx={0}&lngy={1}", message.Longitude, message.Latitude);
            string content = HttpUtility.SendGetHttpRequest(url, "text/json");
            //Log4netHelper.Write("content from web: " + content);

            JsonTextReader tr = new JsonTextReader(new StringReader(content));
            JsonSerializer jSerializer = new JsonSerializer();
            LocationSearchResult rObj = jSerializer.Deserialize<LocationSearchResult>(tr);

            //Log4netHelper.Write("resultinfo: " + rObj.resultinfo);
            //Log4netHelper.Write("formatted_address: " + rObj.row.result.formatted_address);

            //Log4netHelper.Write("Handle_LocationEventMessage content: " + content);
            tm.Content = string.Format("您当前的位置为:{0}", rObj.row.result.formatted_address);
            string returnValue = tm.GetResponseString();
            return returnValue;
        }
 protected string HandleSubscribeAndGetResponse(EventMessage message)
 {
     //回复欢迎消息
     TextMessage tm = new TextMessage();
     tm.ToUserName = message.FromUserName;
     tm.FromUserName = message.ToUserName;
     tm.CreateTime = WeiXinHelper.GetNowTime();
     tm.Content = "欢迎您关注交大红娘-小鹿心动,我是服务小二,有事就请问我,呵呵!\n\n";
     string returnValue = tm.GetResponseString();
     return returnValue;
 }