Пример #1
0
        private ReturnValue SendSystemNoticeToPersonals(SystemNotice systemNotice, string personals)
        {
            BLLJIMP.BLLUser              bllUser      = new BLLUser("");
            BLLJIMP.BLLWeixin            bllWeixin    = new BLLWeixin("");
            BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification();
            notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host);
            var accessToken = bllWeixin.GetAccessToken();

            string[] userArray    = personals.Split(',');
            int      successCount = 0;

            foreach (string userId in userArray)
            {
                successCount += SendSystemNoticeToUserId(systemNotice, userId) ? 1 : 0;


                try
                {
                    notificaiton.First    = "您好,您有新系统消息";
                    notificaiton.Keyword1 = systemNotice.Title;
                    notificaiton.Keyword2 = systemNotice.NoticeTypeString;
                    notificaiton.Remark   = "点击查看";
                    bllWeixin.SendTemplateMessage(accessToken, bllUser.GetUserInfo(userId).WXOpenId, notificaiton);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            return(new ReturnValue {
                Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount)
            });
        }
Пример #2
0
        private ReturnValue SendSystemNoticeToAll(SystemNotice systemNotice, string websiteOwner)
        {
            BLLJIMP.BLLWeixin            bllWeixin    = new BLLWeixin("");
            BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification();
            notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host);
            var acctoken = bllWeixin.GetAccessToken();

            List <UserInfo> userList = new List <UserInfo>();

            if (WebsiteOwner.Equals("wubuhui"))
            {
                userList = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}' and Phone is not null and Phone <>''", websiteOwner));
            }
            else
            {
                userList = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}'", websiteOwner));
            }
            int successCount = 0;

            foreach (UserInfo uinfo in userList)
            {
                successCount += SendSystemNoticeToUserId(systemNotice, uinfo.UserID) ? 1 : 0;
                try
                {
                    notificaiton.First    = "您好,您有新系统消息";
                    notificaiton.Keyword1 = systemNotice.Title;
                    notificaiton.Keyword2 = systemNotice.NoticeTypeString;
                    notificaiton.Remark   = "点击查看";
                    bllWeixin.SendTemplateMessage(acctoken, uinfo.WXOpenId, notificaiton);
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return(new ReturnValue {
                Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount)
            });
        }
Пример #3
0
        //给用户增加积分(负值为减积分),同时写入积分历史,返回修改的delta分值,
        //并调用微信模板消息通知用户
        public double UpdateUserScoreWithWXTMNotify(UserScore userScore, string accessToken)
        {
            double deltaScore = UpdateUserScore(userScore);

            if ((int)deltaScore != 0 && accessToken != string.Empty)
            {
                switch (userScore.UserScoreType)
                {
                case UserScoreType.ShareActivityToWXFriendGroup:
                case UserScoreType.ShareArticleToWXFriendGroup:
                case UserScoreType.SharePositionToWXFriendGroup:
                case UserScoreType.ShareTutorToWXFriendGroup:
                case UserScoreType.TutorShareActivityToWXFriendGroup:
                case UserScoreType.TutorShareArticleToWXFriendGroup:
                case UserScoreType.TutorShareTutorToWXFriendGroup:
                case UserScoreType.TutorSharePositionToWXFriendGroup:
                    System.Threading.Thread.Sleep(30 * 1000);
                    break;

                default:
                    break;
                }

                BLLJIMP.BLLWeixin             bllWeixin    = new BLLWeixin("");
                BLLWeixin.TMScoreNotification notificaiton = new BLLWeixin.TMScoreNotification();
                notificaiton.Url          = string.Format("http://{0}/WuBuHui/MyCenter/Index.aspx", System.Web.HttpContext.Current.Request.Url.Host);
                notificaiton.TemplateId   = "8JLCEV3HmIYV3C3bDiGARxRBJqAZosnQEOI4C0d5He4";
                notificaiton.First        = "您有新的积分变化,详情如下";
                notificaiton.Account      = userInfo.WXNickname;
                notificaiton.Time         = DateTime.Now.ToString();
                notificaiton.Type         = userScore.RecordTypeString;
                notificaiton.CreditChange = "变化";
                notificaiton.Number       = userScore.Score.ToString();
                notificaiton.Amount       = userInfo.TotalScore.ToString();
                notificaiton.Remark       = "您可以点击下方菜单进入五步会,赚取更多积分!";
                bllWeixin.SendTemplateMessage(accessToken, userInfo.WXOpenId, notificaiton);
            }
            return(deltaScore);
        }
Пример #4
0
        private ReturnValue SendSystemNoticeToGroups(SystemNotice systemNotice, string groups, string websiteOwner)
        {
            BLLJIMP.BLLWeixin            bllWeixin    = new BLLWeixin("");
            BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification();
            notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host);
            var acctoken = bllWeixin.GetAccessToken();

            string[] groupArray = groups.Split(',');
            string   strWhere   = string.Format("TagName like '%{0}%'", groupArray[0].Trim());

            foreach (string group in groupArray)
            {
                strWhere += string.Format(" or TagName like '%{0}%'", group);
            }
            List <UserInfo> userList     = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}' and ({1})", websiteOwner, strWhere));
            int             successCount = 0;

            foreach (UserInfo uinfo in userList)
            {
                successCount += SendSystemNoticeToUserId(systemNotice, uinfo.UserID) ? 1 : 0;

                try
                {
                    notificaiton.First    = "您好,您有新系统消息";
                    notificaiton.Keyword1 = systemNotice.Title;
                    notificaiton.Keyword2 = systemNotice.NoticeTypeString;
                    notificaiton.Remark   = "点击查看";
                    bllWeixin.SendTemplateMessage(acctoken, uinfo.WXOpenId, notificaiton);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            return(new ReturnValue {
                Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount)
            });
        }
Пример #5
0
        public static string SendTMUserScoreDailyAccountBillNotify(string receiverUserId, string websiteOwner)
        {
            BLLWeixin bllWeixin = new BLLWeixin("");

            BLLWeixin.TMScoreNotification notificaiton = new BLLWeixin.TMScoreNotification();
            notificaiton.Url        = string.Format("http://{0}/WuBuHui/MyCenter/Index.aspx", System.Web.HttpContext.Current.Request.Url.Host);
            notificaiton.TemplateId = "8JLCEV3HmIYV3C3bDiGARxRBJqAZosnQEOI4C0d5He4";
            notificaiton.First      = "您今日的积分对账单,详情如下";
            notificaiton.Account    = "积分账户";
            notificaiton.Time       = DateTime.Now.ToString();
            notificaiton.Type       = "每日积分对账单";
            //notificaiton.CreditChange = "每日积分对账单";
            UserInfo userInfo = bllWeixin.Get <UserInfo>(string.Format("UserId='{0}' and WebsiteOwner='{1}'", receiverUserId, websiteOwner));

            if (userInfo == null)
            {
                return(string.Format("用户 {0} 不存在", receiverUserId));
            }
            notificaiton.Number = userInfo.TotalScore.ToString();
            notificaiton.Amount = userInfo.TotalScore.ToString();
            notificaiton.Remark = "您可以点击下方菜单进入五步会,赚取更多积分!";
            return(bllWeixin.SendTemplateMessage(bllWeixin.GetAccessToken(), userInfo.WXOpenId, notificaiton));
        }
Пример #6
0
        public void ProcessRequest(HttpContext context)
        {
            string title  = context.Request["title"];
            string detail = context.Request["detail"];
            string time   = context.Request["time"];

            if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(detail))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "标题,内容不能为空";
                bllActivity.ContextResponse(context, resp);
                return;
            }
            string receiverOpenid = context.Request["receiveropenid"];

            if (string.IsNullOrWhiteSpace(receiverOpenid))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "接收者OpenId不能为空";
                bllActivity.ContextResponse(context, resp);
                return;
            }
            string url     = context.Request.Form["toUrl"];
            string haveUrl = context.Request["haveUrl"];

            if (string.IsNullOrWhiteSpace(time))
            {
                time = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            }

            string accessToken = bllWeixin.GetAccessToken();

            JToken sendData = JToken.Parse("{}");

            sendData["touser"] = receiverOpenid;
            string activityId = string.Empty;

            if (!string.IsNullOrWhiteSpace(url))
            {
                sendData["url"] = url;
            }
            else if (haveUrl == "1")
            {
                activityId      = bllActivity.GetGUID(TransacType.ActivityAdd);
                sendData["url"] = "http://guoye.gotocloud8.net/customize/guoye/#/tongzhi/" + activityId;
                //SendData["url"] = "http://guoyetest.comeoncloud.net/customize/guoye/#/tongzhi/" + ActivityID;
            }

            sendData["K1"] = "标题:" + title;
            sendData["K2"] = detail;
            sendData["K3"] = time;
            sendData["K4"] = "";
            resp.errmsg    = bllWeixin.SendTemplateMessage(accessToken, keyValueId, sendData);
            if (!string.IsNullOrWhiteSpace(resp.errmsg))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                bllActivity.ContextResponse(context, resp);
                return;
            }

            if (string.IsNullOrWhiteSpace(url) && haveUrl == "1")
            {
                JuActivityInfo activity = new JuActivityInfo();
                activity.JuActivityID        = Convert.ToInt32(activityId);
                activity.ActivityName        = title;
                activity.ActivityDescription = detail;
                activity.ArticleType         = CommonPlatform.Helper.EnumStringHelper.ToString(ContentType.Notice);
                activity.CategoryId          = categoryId;
                activity.K8           = time;
                activity.K12          = context.Request["url"];
                activity.K13          = context.Request["haveUrl"];
                activity.WebsiteOwner = bllWeixin.WebsiteOwner;
                if (context.Session[SessionKey.UserID] == null)
                {
                    activity.UserID = activity.WebsiteOwner;
                }
                else
                {
                    activity.UserID = context.Session[SessionKey.UserID].ToString();
                }
                if (bllActivity.Add(activity))
                {
                    resp.isSuccess = true;
                }
                else
                {
                    resp.errmsg  = "发送成功,但记录失败";
                    resp.errcode = (int)APIErrCode.OperateFail;
                }
            }
            else
            {
                resp.isSuccess = true;
            }
            bllActivity.ContextResponse(context, resp);
        }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            string id = context.Request["id"];

            if (string.IsNullOrWhiteSpace(id))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "消息模板编号不能为空";
                bllWeixin.ContextResponse(context, resp);
                return;
            }

            string openId = context.Request["openid"];
            string userId = context.Request["userid"];

            if (string.IsNullOrWhiteSpace(openId) && string.IsNullOrWhiteSpace(userId))
            {
                BLLJIMP.Model.UserInfo toUser = bllWeixin.GetCurrentUserInfo();
                if (toUser != null && !string.IsNullOrWhiteSpace(toUser.WXOpenId))
                {
                    openId = toUser.WXOpenId;
                }
            }
            else if (string.IsNullOrWhiteSpace(openId) && !string.IsNullOrWhiteSpace(userId))
            {
                BLLJIMP.Model.UserInfo toUser = bllWeixin.GetByKey <BLLJIMP.Model.UserInfo>("UserID", userId);
                if (toUser != null && !string.IsNullOrWhiteSpace(toUser.WXOpenId))
                {
                    openId = toUser.WXOpenId;
                }
            }

            if (string.IsNullOrWhiteSpace(openId))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "接收者openId不能为空";
                bllWeixin.ContextResponse(context, resp);
                return;
            }
            string k1       = context.Request["k1"];
            string k2       = context.Request["k2"];
            string k3       = context.Request["k3"];
            string k4       = context.Request["k4"];
            string k5       = context.Request["k5"];
            string k6       = context.Request["k6"];
            string k7       = context.Request["k7"];
            string k8       = context.Request["k8"];
            string k9       = context.Request["k9"];
            string k10      = context.Request["k10"];
            JToken sendData = JToken.Parse("{}");

            sendData["touser"] = openId;

            if (!string.IsNullOrWhiteSpace(k1))
            {
                sendData["K1"] = k1;
            }
            if (!string.IsNullOrWhiteSpace(k2))
            {
                sendData["K2"] = k2;
            }
            if (!string.IsNullOrWhiteSpace(k3))
            {
                sendData["K3"] = k3;
            }
            if (!string.IsNullOrWhiteSpace(k4))
            {
                sendData["K4"] = k4;
            }
            if (!string.IsNullOrWhiteSpace(k5))
            {
                sendData["K5"] = k5;
            }
            if (!string.IsNullOrWhiteSpace(k6))
            {
                sendData["K6"] = k6;
            }
            if (!string.IsNullOrWhiteSpace(k7))
            {
                sendData["K7"] = k7;
            }
            if (!string.IsNullOrWhiteSpace(k8))
            {
                sendData["K8"] = k8;
            }
            if (!string.IsNullOrWhiteSpace(k9))
            {
                sendData["K9"] = k9;
            }
            if (!string.IsNullOrWhiteSpace(k10))
            {
                sendData["K10"] = k10;
            }

            string url = context.Request.Form["toUrl"];

            if (!string.IsNullOrWhiteSpace(url))
            {
                sendData["url"] = url;
            }

            string accessToken = bllWeixin.GetAccessToken();

            resp.errmsg = bllWeixin.SendTemplateMessage(accessToken, id, sendData);
            if (!string.IsNullOrWhiteSpace(resp.errmsg))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                bllWeixin.ContextResponse(context, resp);
                return;
            }
            resp.isSuccess = true;
            bllWeixin.ContextResponse(context, resp);
        }
Пример #8
0
        public void ProcessRequest(HttpContext context)
        {
            string accessToken = bllWeixin.GetAccessToken();
            //dealid   要约id
            //buyerid  买方id
            //buyername 买方名字
            //sellerid    卖方id
            //sellername 卖方名字
            //receiveropenid  微信接收方openid
            //receiverphone   微信接收方手机
            //identity  0是买方,1是卖方
            //title 标题
            //detail 要约详情
            //time  发布时间,精确到分钟
            string title  = context.Request["title"];
            string detail = context.Request["detail"];

            if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(detail))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "标题,内容不能为空";
                bllActivity.ContextResponse(context, resp);
                return;
            }
            string receiverOpenid = context.Request["receiveropenid"];

            if (string.IsNullOrWhiteSpace(receiverOpenid))
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = "接收者OpenId不能为空";
                bllActivity.ContextResponse(context, resp);
                return;
            }

            JuActivityInfo activity = new JuActivityInfo();

            activity.JuActivityID        = Convert.ToInt32(bllActivity.GetGUID(TransacType.ActivityAdd));
            activity.ActivityName        = title;
            activity.ActivityDescription = detail;
            activity.ArticleType         = CommonPlatform.Helper.EnumStringHelper.ToString(ContentType.YaoYue);
            activity.K1 = context.Request["buyerid"];
            activity.K2 = context.Request["buyername"];
            activity.K3 = context.Request["sellerid"];
            activity.K4 = context.Request["sellername"];
            activity.K5 = context.Request["receiveropenid"];
            activity.K6 = context.Request["receiverphone"];
            activity.K7 = context.Request["dealid"];
            activity.K8 = context.Request["time"];

            if (string.IsNullOrWhiteSpace(activity.K8))
            {
                activity.K8 = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            }

            activity.K9           = context.Request["identity"];
            activity.CreateDate   = DateTime.Now;
            activity.WebsiteOwner = bllWeixin.WebsiteOwner;
            if (context.Session[SessionKey.UserID] == null)
            {
                activity.UserID = activity.WebsiteOwner;
            }
            else
            {
                activity.UserID = context.Session[SessionKey.UserID].ToString();
            }
            if (activity.K9 == "1")
            {
                activity.CategoryId = categoryId1;
            }
            else
            {
                activity.CategoryId = categoryId0;
            }

            if (bllActivity.Add(activity))
            {
                JToken sendData = JToken.Parse("{}");
                sendData["touser"] = activity.K5;
                sendData["url"]    = "http://guoye.gotocloud8.net/customize/guoye/#/yaoyue/" + activity.JuActivityID;
                //SendData["url"] = "http://guoyetest.comeoncloud.net/customize/guoye/#/yaoyue/" + activity.JuActivityID;
                sendData["K1"] = "要约编号:" + activity.K7;
                string sender = "国烨网\n";
                if (activity.K9 == "1")
                {
                    sender += "买家:" + activity.K2;
                }
                else
                {
                    sender += "卖家:" + activity.K4;
                }
                sendData["K2"] = sender;
                sendData["K3"] = activity.K8;
                sendData["K4"] = "标题:" + activity.ActivityName + "\n要约内容:" + activity.ActivityDescription;
                resp.errmsg    = bllWeixin.SendTemplateMessage(accessToken, keyValueId, sendData);
                resp.isSuccess = true;
            }
            else
            {
                resp.errmsg = "提交失败";
            }
            bllWeixin.ContextResponse(context, resp);
        }