Esempio n. 1
0
        public void Subscribe(WX_EventQueue info)
        {
            var app = appBLL.GetByPK(info.AppId);

            if (app != null)
            {
                CustomService customSvr = new CustomService(app.AppId, app.AppSecret);
                customSvr.SendText(info.OpenID, "欢迎您关注公众号");
                GetUserInfo(info.OpenID, app.AppId, app.AppSecret);
            }
        }
        /// <summary>
        /// 发送消息给用户
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ActionResult TaleToUser(WX_CustomMsg msg)
        {
            msg.MsgId      = Guid.NewGuid().ToString();
            msg.CreateTime = DateTime.Now;
            msg.MsgSource  = "客服";
            var Ap = new WX_AppManager().GetByPK(msg.AppId);

            //发送到微信
            CustomService customSvr = new CustomService(Ap.AppId, Ap.AppSecret);

            customSvr.SendText(msg.OpenID, msg.Content);
            bool IsTrue = new WX_CustomMsgManager().Add(msg);

            return(Json(IsTrue, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 订阅(关注)事件 如果用户还未关注公众号,则用户可以关注公众号,关注后微信会将带场景值关注事件推送给开发者
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageText>(requestMessage);

            responseMessage.Content = "欢迎您加入五福商城大家庭";

            //新关注用户的openId
            var openId       = requestMessage.FromUserName;
            var userInfo     = new UserOAuthService().UserInfo(openId);
            var parentOpenId = "";

            //如果是场景关注
            if (!string.IsNullOrEmpty(requestMessage.EventKey) && requestMessage.EventKey.StartsWith("qrscene_"))
            {
                parentOpenId = requestMessage.EventKey.Replace("qrscene_", "");//推荐人的openid
                if (openId != parentOpenId)
                {
                    //给推荐人发送推荐成功消息
                    string notifyMsg     = string.Format(@"用户【{0}】,通过您的二维码加入了商城,加入时间:{1}", userInfo.nickname, DateTime.Now.ToString());
                    var    customService = new CustomService();
                    customService.SendText(parentOpenId, notifyMsg);
                }
            }
            //将新关注的用户添加到数据库保存
            Task.Factory.StartNew(() =>
            {
                //用户信息保存到数据库
                var userGenerator = new UserGenerator();
                userGenerator.CreateUser(new Models.UserInfo
                {
                    OpenId       = openId,
                    UnionId      = userInfo.unionid,
                    NickName     = userInfo.nickname,
                    Province     = userInfo.province,
                    City         = userInfo.city,
                    County       = userInfo.country,
                    Gender       = userInfo.sex.ToString(),
                    Portrait     = userInfo.headimgurl,
                    ParentOpenId = parentOpenId
                });
            });
            return(responseMessage);
        }
Esempio n. 4
0
        public ActionResult TaleToUser(WX_CustomMsg msg)
        {
            SYS_User SYSUSER = Session["SYSUSER"] as SYS_User;

            msg.UserId     = SYSUSER.UserId;
            msg.MsgId      = Guid.NewGuid().ToString();
            msg.CreateTime = DateTime.Now;
            msg.MsgSource  = "客服";
            msg.AppId      = SYSUSER.AppId;

            //发送到微信
            CustomService customSvr = new CustomService(SYSUSER.AppId, SYSUSER.WX_App.AppSecret);

            customSvr.SendText(msg.OpenID, msg.Content);

            bool IsTrue = new WXDataBLL.WXCustom.WX_CustomMsgManager().Add(msg);

            return(Json(IsTrue, JsonRequestBehavior.AllowGet));
        }