Пример #1
0
        /// <summary>
        /// 自动回复消息
        /// </summary>
        /// <param name="xmlMsg"></param>
        private string GetTextMsg(XmlElement Xml)
        {
            //自动回复消息
            StringBuilder Content = new StringBuilder();

            Content.Append("您好,我是小怪机器人!");
            //获取事件Model

            XmlElementText   TextModel = GetXmlElementText.GetExmlModel(Xml);
            ObjectTypeHelper obj       = new ObjectTypeHelper();
            int           NowTime      = obj.ConvertDateTimeInt(DateTime.Now);
            StringBuilder TextXml      = new StringBuilder();

            TextXml.Append("<xml>");
            TextXml.Append("<ToUserName><![CDATA[" + TextModel.FromUserName + "]]></ToUserName>");
            TextXml.Append("<FromUserName><![CDATA[" + TextModel.ToUserName + "]]></FromUserName>");
            TextXml.Append("<CreateTime>" + NowTime + "</CreateTime>");
            TextXml.Append("<MsgType><![CDATA[text]]></MsgType>");
            TextXml.Append("<Content><![CDATA[" + Content.ToString() + "]]></Content>");
            TextXml.Append("<MsgId>" + TextModel.MsgId + "</MsgId>");
            TextXml.Append("</xml>");

            LogTextHelper.Log(TextXml.ToString());
            return(TextXml.ToString());
        }
Пример #2
0
        /// <summary>
        /// 服务器响应微信请求
        /// </summary>
        /// <param name="WeChatXml"></param>
        public string ResponseMsg(string WeChatXml)
        {
            //定义消息管理
            string ManagerMsg = "";

            try
            {
                XmlDocument doc = new XmlDocument();
                //读取xml字符串
                doc.LoadXml(WeChatXml);
                XmlElement Xml = doc.DocumentElement;
                //获取收到的消息类型。文本(text),图片(image),语音等
                XmlMsgType xmlModel = GetXmlMsgType.GetExmlModel(Xml);
                switch (xmlModel.MsgType)
                {
                //当消息为文本时
                case "text":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                //关注与取消关注
                case "event":
                    ManagerMsg = GetEvenMsg(Xml);
                    break;

                case "image":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                case "voice":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                case "vedio":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                case "location":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                case "link":
                    ManagerMsg = GetServicesMsg(Xml);
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                LogTextHelper.Log("异常消息:" + e.Message);
            }
            return(ManagerMsg);
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            TemplatePurchaseNotice notice = new TemplatePurchaseNotice();
            string openid           = context.Request["openid"].ToString();
            string cDingDanHao      = context.Request["cDingDanHao"].ToString();
            string cGongDiMingCheng = context.Request["cGongDiMingCheng"].ToString();
            string cTuWeiMingCheng  = context.Request["cTuWeiMingCheng"].ToString();
            var    Msg = notice.TemplateSendMsg(GetJsonString(openid, cDingDanHao, cGongDiMingCheng, cTuWeiMingCheng));

            LogTextHelper.Log("消息推送返回码:" + Msg.errcode);
            context.Response.Write(Msg.errcode);
        }
Пример #4
0
 public void ProcessRequest(HttpContext context)
 {
     //POST为微信发出消息
     if (context.Request.HttpMethod == "POST")
     {
         WeChatToKenApi api       = new WeChatToKenApi();
         string         WeChatXml = api.PostRequestString();
         LogTextHelper.Log(WeChatXml);
         context.Response.Write(ResponseMsg(WeChatXml));
     }
     else
     {
         WeChatSignature.Auth(WeChatConfig.Token);
     }
 }
Пример #5
0
        private static void SDK_Config(HttpContext context)
        {
            JS_SDKModel model = new JS_SDKModel();

            try
            {
                var windowurl = context.Request["windowurl"];
                var action    = context.Request["action"];
                LogTextHelper.Log("action:" + action + " windowurl_1:" + windowurl);
                WxPayData jsApiParam = new WxPayData();
                model.appId     = WeChatConfig.AppId;
                model.timeStamp = WxPayApi.GenerateTimeStamp();
                model.nonceStr  = WxPayApi.GenerateNonceStr();
                model.ticket    = string.Empty;
                //获取jsapi_ticket
                if (HttpRuntime.Cache["JsApiTicket"] == null)
                {
                    model.ticket = WxPayApi.initJSAPITicket();
                }
                model.ticket = HttpRuntime.Cache["JsApiTicket"] as string;
                if (string.IsNullOrEmpty(model.ticket))
                {
                    model.ticket = WxPayApi.initJSAPITicket();
                }
                //构造需要用SHA1算法加密的数据
                WxPayData signData = new WxPayData();
                signData.SetValue("noncestr", model.nonceStr);
                signData.SetValue("jsapi_ticket", model.ticket);
                signData.SetValue("timestamp", model.timeStamp);
                signData.SetValue("url", windowurl);
                string param = signData.ToUrl();
                model.signature = FormsAuthentication.HashPasswordForStoringInConfigFile(param, "SHA1");
            }
            catch (Exception ex)
            {
                model.status = 0;
                model.msg    = ex.Message;
                LogTextHelper.Log(ex.ToString());
            }
            context.Response.Write(JsonConvert.SerializeObject(model));
        }
Пример #6
0
        public ResponseMessageResult Get(int iBangDingLeiXing, string cChePaiHao = null, string cShangBanBianMa = null, string cDiZhi = null, string cGongDiBianMa = null)
        {
            string openid = HttpContext.Current.Request.Headers.GetValues("openid").First().ToString();

            if (!string.IsNullOrEmpty(openid))
            {
                //查询现在车辆绑定记录
                var up_jilu = db.BangDingJiLu.Where(o => o.cChePaiHao == cChePaiHao).OrderByDescending(o => o.AutoID).First();
                if (up_jilu != null)
                {
                    BangDingJiLu ad_jilu = new BangDingJiLu();
                    ad_jilu.iBangDingLeiXing = 0;
                    ad_jilu.openid           = up_jilu.openid;
                    ad_jilu.iFangShi         = 0;
                    ad_jilu.cChePaiHao       = cChePaiHao;
                    ad_jilu.cDiZhi           = cDiZhi;
                    ad_jilu.cGongDiBianMa    = cGongDiBianMa;
                    ad_jilu.cShangBanBianMa  = null;
                    ad_jilu.dShiJian         = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    db.BangDingJiLu.Add(ad_jilu);
                    var user = db.wechatUser.Where(o => o.openid == up_jilu.openid).FirstOrDefault();
                    user.status = 0;
                }

                BangDingJiLu jilu = new BangDingJiLu();
                jilu.iBangDingLeiXing = iBangDingLeiXing;
                jilu.openid           = openid;
                jilu.iFangShi         = 0;
                jilu.cChePaiHao       = cChePaiHao;
                jilu.cDiZhi           = cDiZhi;
                jilu.cGongDiBianMa    = cGongDiBianMa;
                jilu.cShangBanBianMa  = iBangDingLeiXing == 1 ? cShangBanBianMa : null;
                jilu.dShiJian         = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                db.BangDingJiLu.Add(jilu);
                var wechat = db.wechatUser.Where(o => o.openid == openid).FirstOrDefault();
                wechat.status = iBangDingLeiXing;
                LogTextHelper.Log("openid:" + openid + ";车牌号:" + cChePaiHao);
                //判断是否下班 车牌号为空时
                if (iBangDingLeiXing == 0 && string.IsNullOrEmpty(cChePaiHao))
                {
                    var driver_list = db.CheLiangInfo.Where(o => o.openid == openid).ToList();
                    driver_list.ForEach(o =>
                    {
                        o.openid = null;
                    });
                }
                if (!string.IsNullOrEmpty(cChePaiHao))
                {
                    var driver = db.CheLiangInfo.Where(o => o.cChePaiHao == cChePaiHao).FirstOrDefault();
                    if (driver != null)
                    {
                        if (iBangDingLeiXing == 1)
                        {
                            driver.openid = openid;
                        }
                        else
                        {
                            driver.openid = null;
                        }
                        driver.cShangBanBianMa = iBangDingLeiXing == 1 ? cShangBanBianMa : null;;
                    }
                }
                try
                {
                    db.SaveChanges();
                    model.message     = "新增成功";
                    model.status_code = 200;
                }
                catch (Exception ex)
                {
                    model.message     = ex.Message;
                    model.status_code = 401;
                }
            }
            else
            {
                model.message     = "微信授权失败";
                model.status_code = 401;
            }
            return(new ResponseMessageResult(Request.CreateResponse((HttpStatusCode)model.status_code, model)));
        }