Exemplo n.º 1
0
        /// <summary>
        /// 处理取消关注事件
        /// </summary>
        /// <param name="xmlModel"></param>
        /// <returns></returns>
        public string UnSubscribeHandle(ref Dictionary <string, string> xmlModel)
        {
            string result        = "";
            string wxappusername = xmlModel["ToUserName"];   //事件发给哪个公众号ID,这里用于验证是否本公众号的消息,防止虚构数据
            string wxopenid      = xmlModel["FromUserName"]; //事件是哪个粉丝发起的(粉丝的openid)
            string strCreateTime = xmlModel["CreateTime"];

            if (string.IsNullOrEmpty(strCreateTime))
            {
                //无消息创建时间,无法排重,放弃处理
                return("");
            }
            double wxcreatetime;

            if (!double.TryParse(strCreateTime, out wxcreatetime))
            {
                //无法将createtime转换成功,无法排重,放弃处理
                return("");
            }

            DALWXMessageHandleBasic mydal = new DALWXMessageHandleBasic();

            #region 事件消息排重
            //事件消息排重
            bool success = true;
            success = mydal.EventMsgPreventDuplicates(wxopenid, wxcreatetime);
            if (!success)
            {
                //事件消息排重失败,放弃处理
                return("");
            }
            #endregion

            #region 换取并判断是否存在wxappid

            string wxappid = WXApiInfo.wxappid;
            #endregion

            //WXUser bllWXUser = new WXUser();
            //bllWXUser.UnSubscribe(wxopenid, wxappid);
            //处理取消关注的方法
            string          errmsg = "";
            BLLWXFansManage mybll  = new BLLWXFansManage();
            mybll.SubscribeLog(wxopenid, 0, ref errmsg);//关注日志
            success = mybll.UnSubscribe(wxopenid, ref errmsg);


            return(result);
        }