Beispiel #1
0
        private void Send(HttpContext context)
        {
            var userid = context.Request["userid"] ?? "";
            var Id = context.Request["Id"] ?? "";
            var Title = context.Request["title"] ?? "";
            var messageDescription = context.Request["MessageDescription"] ?? "";
            var key = context.Request["key"] ?? "";
            if (string.IsNullOrEmpty(userid) || string.IsNullOrEmpty(Id) || string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(messageDescription))
            {
                context.Response.Write("{\"error\":true,\"msg\":\"信息不完整。\"}");
                return;
            }

            var hashTable = new Hashtable();
            var listnews = new List<object>();
            var accessToken = new AccessToken();
            var sendDataToUser = new SendDataToWeChat();

            try
            {
                listnews.Add(new
                    {
                        title = Title,
                        description = messageDescription,
                        url = "http://218.22.27.236/views/messagelist/messagedetail_fxgz.htm?id=" + Id + "&wxid=" + userid + "&state=2",
                        picurl = "http://218.22.27.236/tl/UploadImages/" + key + ".jpg"
                    });

                hashTable["touser"] = userid;
                hashTable["msgtype"] = "news";
                hashTable["news"] = new
                {
                    articles = listnews
                };
                var json = _jss.Serialize(hashTable);
                json = json.Replace("\\u0026", "&");
                var token = accessToken.GetExistAccessToken();
                var back = sendDataToUser.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + token, json);
                var backData = JsonConvert.DeserializeObject<WeChatBackData>(back);
                if (backData.errcode != 0)
                {
                    context.Response.Write("{\"error\":true,\"msg\":\"" + backData.errmsg + "\"}");
                }
                else
                {
                    context.Response.Write("{\"error\":false}");
                }
                var infoReleaseDetailsModel = new InfoReleaseDetailsModel();
                if (backData.errcode == 0 && backData.errmsg == "ok")
                {
                    infoReleaseDetailsModel.State = "2";//待确认
                }
                var infoReleaseDetailsDal = new InfoReleaseDetailsDal();
                infoReleaseDetailsModel.Id = Id;
                infoReleaseDetailsDal.Modify(infoReleaseDetailsModel);
                Log.Debug("调试信息:" + back);
            }
            catch (Exception e)
            {
                context.Response.Write("{\"error\":true,\"msg\":\"" + e.Message + "\"}");
                Log.Error(e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 添加用户到信息发布表
        /// </summary>
        /// <param name="context"></param>
        public void AddPersonToInfoRelease(HttpContext context)
        {
            var hashTable = new Hashtable();
            var weChatData = new Hashtable();

            var infoReleaseDal = new InfoReleaseDal();
            var infoReleaseDetailsDal = new InfoReleaseDetailsDal();
            var accessToken = new AccessToken();
            var sendDataToUser = new SendDataToWeChat();

            var id = context.Request.Params["id"];
            var ppid = context.Request.Params["ppid"];
            var key = context.Request.Params["key"];
            var title = context.Request.Params["title"];
            var ms = context.Request.Params["ms"];
            try
            {
                infoReleaseDal.Modify(new InfoRelease()
                {
                    Id = id,
                    FlagRelease = "1",
                    SendPerson = ppid
                });
                var tmp = JsonConvert.DeserializeObject<List<Tmp>>(ppid);
                if (tmp.Count > 0)
                {
                    infoReleaseDetailsDal.Del(new InfoReleaseDetailsModel() { InfoReleaseId = id });
                    foreach (var t in tmp)
                    {
                        var weChatDataList = new List<object>();
                        weChatDataList.Add(new
                        {
                            title,
                            description = ms,
                            url = "http://218.22.27.236/views/messagelist/messagedetail_fxgz.htm?id=" + id + "&wxid=" + t.wxid,
                            picurl = "http://218.22.27.236/tl/UploadImages/" + key + ".jpg"
                        });
                        weChatData["touser"] = t.wxid;
                        weChatData["msgtype"] = "news";
                        weChatData["news"] = new
                        {
                            articles = weChatDataList
                        };
                        var json = _jss.Serialize(weChatData);
                        json = json.Replace("\\u0026", "&");
                        var token = accessToken.GetExistAccessToken();
                        var back = sendDataToUser.GetPage("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + token, json);
                        var backData = JsonConvert.DeserializeObject<WeChatBackData>(back);
                        var infoReleaseDetailsModel = new InfoReleaseDetailsModel();
                        if (backData.errcode == 0 && backData.errmsg == "ok")
                        {
                            infoReleaseDetailsModel.State = "2";//待确认
                        }
                        else
                        {
                            infoReleaseDetailsModel.State = "1";//待推送
                        }
                        infoReleaseDetailsModel.Id = Guid.NewGuid().ToString();
                        infoReleaseDetailsModel.OpenId = t.wxid;
                        infoReleaseDetailsModel.NickName = t.nickname;
                        infoReleaseDetailsModel.RNumber = t.ywh;
                        infoReleaseDetailsModel.InfoReleaseId = id;

                        infoReleaseDetailsDal.Add(infoReleaseDetailsModel);
                    }
                }

                hashTable["isSuccess"] = true;
                hashTable["jsMethod"] = "ajax_AddPersonToInfoRelease";
                var json2 = _jss.Serialize(hashTable);
                context.Response.Write(json2);
            }
            catch (Exception e)
            {
                Log.Debug("出错信息:" + e.Message);
            }
        }