zoukankan      html  css  js  c++  java
  • 微信响应文本消息

    using System;
    using System.Collections.Generic;
    using System.Web;
    using YTO.WeiXin.BLL;
    using YTO.WeiXin.BLL.Interface;
    using YTO.WeiXin.Core;
    using YTO.WeiXin.Model;
    
    
    namespace YTO.WeiXin.Process
    {
        public class TextProcess : IProcess
        {
            IAuthorizationBiz AuthorizationBiz { get; set; }
            IContactBiz ContactBiz { get; set; }
            public void Process()
            {
                HttpContext context = HttpContext.Current;
                string paramXML = context.Items["XML"].ToString();
                //Logger.Write("paramXML:" + paramXML);
                TextInfo Info = XmlHelper.XmlDeserialize<TextInfo>(paramXML);
    
                AuthorizationInfo authInfo = new AuthorizationInfo { OpenId = Info.FromUserName };
                IList<AuthorizationInfo> authList = AuthorizationBiz.Query(authInfo);
                string reccontent = Info.Content;
                string[] str = reccontent.Split(' ');
                TextSendInfo SendInfo = new TextSendInfo();
                SendInfo.ToUserName = Info.FromUserName;
                SendInfo.FromUserName = Info.ToUserName;
                SendInfo.CreateTime = DateTime.Now.ToString();
                SendInfo.MsgType = MsgTypeEnum.text.ToString();
                if (authList.Count > 0 && authList[0].Status == "已授权")
                {
                    if (str.Length > 1 && !string.IsNullOrEmpty(str[1]))//如果格式正确
                    {
                        //Logger.Write("str[1]:" + str[1]);
                        ContactInfo contactInfo = new ContactInfo { CenterName = str[1].Trim() };
                        IList<ContactInfo> list = ContactBiz.Query(contactInfo);
                        if (list.Count > 0)//数据库中有相关信息
                        {
                            string content = string.Format(JobBase.GetConfParamValue(ParamEnum.CenterQueryResponse), list[0].CenterName, list[0].Name, list[0].PhoneNumber, list[0].Address);
                            SendInfo.Content = content;
                        }
                        else//未查询到相关信息
                        {
                            SendInfo.Content = JobBase.GetConfParamValue(ParamEnum.CenterNotExist);//"该中心不存在,请重新输入。如有问题,请联系021-69777911";
                        }
                    }
                    else//格式不正确
                    {
                        SendInfo.Content = JobBase.GetConfParamValue(ParamEnum.CenterFormatError);//"请确认输入信息格式正确后,重新输入。如有问题,请联系021-69777911";
                    }
                }
                else
                {
                    SendInfo.Content = JobBase.GetConfParamValue(ParamEnum.AuthWarning);//"请先在授权页面申请授权,再使用该功能!";
                }
                string xml = XmlHelper.CustomXMLSerialize<TextSendInfo>(SendInfo, string.Empty);
                //Logger.Write("xml:" + xml);
                ResponseHelper.Success(xml);
            }
        }
    }
  • 相关阅读:
    工具类
    开发中用到的工具
    项目中另外添加有用的文件:404
    如何组织项目结构:约定优于配置
    媒体查询
    响应式网站开发需要掌握的技术及国内外主流浏览器
    响应式网站概念
    sql存储过程,raisError后要return错误代码,过程最后要return 0
    delphi用TAdoStoredProc调用存储过程,兼容sql2005、2008、2014的远程事务问题
    网页视频下载牛逼工具,支持各种格式转换,比如腾讯视频格式qlv转mp4
  • 原文地址:https://www.cnblogs.com/slu182/p/4257784.html
Copyright © 2011-2022 走看看