예제 #1
0
        /// <summary>
        /// 获取个人小程序码图片
        /// </summary>
        /// <param name="path">小程序码跳转的路径</param>
        /// <param name="session">用户session</param>
        /// <returns></returns>
        public string GetUserQRCode(string path, string session)
        {
            HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,参数path:" + path + "------session:" + session);
            string imgPath = "";
            //判断数据库中是否有值
            SB_UserEL userEL = GetUserELBySession(session);

            //如果QRCode有值,则返回数据库中QRCode的值
            if (!string.IsNullOrEmpty(userEL.QRCode) && userEL.QRCode != "")
            {
                //获取图片名称
                string qrCodeImageName = userEL.QRCode;
                //获取图片路径
                string qrCodeImagePath = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_User"];
                imgPath = qrCodeImagePath + qrCodeImageName;
            }
            //数据库中QRCode没有数据,则需要获取小程序码图片保存图片,并把图片名称保存到数据库中
            else
            {
                //获取token
                WX_TokenBLL tokenBLL = new WX_TokenBLL();
                string      token    = tokenBLL.GetToken();
                //获取小程序码接口
                string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token;
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("path", path);
                JavaScriptSerializer js = new JavaScriptSerializer();
                js.MaxJsonLength = int.MaxValue;
                string json = js.Serialize(dic);
                HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,获取小程序码的json:" + json);
                HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,url:" + url + "-----Path:" + path);
                //post返回的小程序码流
                Stream QRCodeStream = WeChatAppDecrypt.Post(url, json);
                //将图片流转换成图片
                Bitmap tp = new Bitmap(QRCodeStream);
                string QRCodeSave_User = System.Configuration.ConfigurationManager.AppSettings["QRCodeSave_User"];
                string image_userName  = Guid.NewGuid().ToString();
                string qrCodeImageName = image_userName + ".jpg";
                HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,保存小程序图片路径名称:" + QRCodeSave_User + qrCodeImageName);
                tp.Save(QRCodeSave_User + qrCodeImageName);
                //把小程序码图片名称保存到数据库中
                userEL.QRCode = qrCodeImageName;
                int  ra;
                long returnValue = userEL.ExecNonQuery(27, out ra);
                HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,保存小程序图片名称结果:" + ra);
                if (ra > 0)
                {
                    string QRCodeGet_User = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_User"];
                    imgPath = QRCodeGet_User + qrCodeImageName;
                }
                else
                {
                    imgPath = "error";
                }
            }
            HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,返回的结果:" + imgPath);
            return(imgPath);
        }
예제 #2
0
        /// <summary>
        /// 发送微信服务通知
        /// </summary>
        /// <param name="userOpenID">发送目的用户的openid</param>
        /// <param name="formID">提交表单的formid</param>
        /// <param name="hongBaoValueDecimal">红包值</param>
        public void SendServNotice(string userOpenID, string formID, decimal hongBaoValueDecimal, string companyID)
        {
            //通过公司id获取公司名称
            string companyName = "公司";

            if (!string.IsNullOrEmpty(companyID))
            {
                CompanysEL companyEL = new CompanysEL();
                companyEL.ID = long.Parse(companyID);
                DataTable dt_company = companyEL.ExecDT(2);
                if (dt_company != null && dt_company.Rows.Count > 0)
                {
                    companyName = dt_company.Rows[0]["CompanyName"].ToString();
                }
            }

            SortedDictionary <string, object> m_values = new SortedDictionary <string, object>();

            m_values.Add("touser", userOpenID);                                         //接收者(用户)的 openid
            m_values.Add("template_id", "2bqqDRenEIyb5D0V8ngm7BYn0tukqGdOFEYx5m2-z28"); //所需下发的模板消息的id(小程序后台配置)
            m_values.Add("page", "pages/mycard/mycard");                                //点击模板卡片后的跳转页面
            m_values.Add("form_id", formID);                                            //表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id

            SortedDictionary <string, object> m_values_data       = new SortedDictionary <string, object>();
            SortedDictionary <string, object> m_values_data_Item1 = new SortedDictionary <string, object>();

            m_values_data_Item1.Add("value", "迎春纳福 喜送红包");//
            // m_values_data_Item1.Add("color", "#173177");//
            m_values_data.Add("keyword1", m_values_data_Item1);

            SortedDictionary <string, object> m_values_data_Item2 = new SortedDictionary <string, object>();

            m_values_data_Item2.Add("value", hongBaoValueDecimal + "元现金红包");//
            m_values_data_Item2.Add("color", "#F70909");
            m_values_data.Add("keyword2", m_values_data_Item2);

            SortedDictionary <string, object> m_values_data_Item3 = new SortedDictionary <string, object>();

            m_values_data_Item3.Add("value", "您已经成功领取" + companyName + "送出的" + hongBaoValueDecimal + "元新春红包。\n点击进入小程序,免费开启自己企业的新春红包,为好友送祝福吧!");//
            //m_values_data_Item3.Add("color", "#F70909");
            m_values_data.Add("keyword3", m_values_data_Item3);

            m_values.Add("data", m_values_data);//模板内容

            JavaScriptSerializer js = new JavaScriptSerializer();

            js.MaxJsonLength = int.MaxValue;

            string json = js.Serialize(m_values);

            BLL.Common.Logger.Error("发模板消息提交的json数据:" + json);


            //string xml = ToXml(m_values);//获取xml文件
            //BLL.Common.Logger.Error("发模板消息提交的xml数据:" + xml);

            try
            {
                //获取access_token
                WX_TokenBLL tokenBLL     = new WX_TokenBLL();
                string      access_token = tokenBLL.GetToken();
                //发送模板消息 接口地址
                string url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + access_token;
                //post提交
                //string result = apiPost(xml, url);
                string result = Post(url, json);
                BLL.Common.Logger.Error("发模板消息结果:" + result);
                //xml转换成字典
                //SortedDictionary<string, object> resultDictionary = FromXml(result);
                //BLL.Common.Logger.Error("errmsg数据:" + resultDictionary["errmsg"].ToString());
                //if (resultDictionary["errmsg"].ToString() == "ok")
                //{
                //    BLL.Common.Logger.Error("发送模板成功!");
                //}
                Dictionary <string, object> result_Dic = new Dictionary <string, object>();
                result_Dic = js.Deserialize <Dictionary <string, object> >(result);
                if (result_Dic.Keys.Contains("errcode"))
                {
                    if (result_Dic["errcode"].ToString() == "0")
                    {
                        BLL.Common.Logger.Error("发送模板成功!");
                    }
                }
            }
            catch (Exception exp)
            {
                BLL.Common.Logger.Error("发送模板错误:" + exp.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// 获取用户综合信息
        /// </summary>
        /// <param name="session">本人session</param>
        /// <param name="sessionFriend">需要获取信息的用户session</param>
        /// <returns></returns>
        public string GetUserInfoBySessionAndSessionFriend(string session, string sessionFriend)
        {
            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取用户信息方法获取到参数session:" + session + "-----sessionFriend:" + sessionFriend);
            JavaScriptSerializer        js  = new JavaScriptSerializer();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            //通过sessionFriend获取用户
            SB_UserEL userel = new SB_UserEL();

            userel.Session_True = sessionFriend;
            userel.ExecuteEL(41);

            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取用户信息结果(大于0说明成功):" + userel.ID);
            if (userel.ID > 0)
            {
                dic.Add("UserName", userel.UserName);
                dic.Add("UserTel", userel.UserTel);
                dic.Add("Duty", userel.Duty);
                dic.Add("UserEmail", userel.UserEmail);
                dic.Add("Detail", userel.Detail);
                dic.Add("ImgUrl", userel.ImgUrl);
                dic.Add("Session", userel.Session_True);
                #region  人气值
                //组合人气值,人气值=好友查看的次数(好友第一次查看有效,一次以上的不记录)+所有群组群友人数和
                int popularityInt = 0; //人气值
                                       //用户查看人气值
                PopularityBLL popularityBLL = new PopularityBLL();
                //通过Session换取UserID
                UserBLL userBLL       = new UserBLL();
                long    userID        = userBLL.GetUserIDBySession(session);
                long    userID_Friend = userBLL.GetUserIDBySession(sessionFriend);
                HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend方法获取到的用户ID  userID:" + userID + "---userID_Friend:" + userID_Friend);
                int friendLookInt = popularityBLL.GetPopularityNumber(userID);
                HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend方法用户查看人气值为:" + friendLookInt);
                popularityInt += friendLookInt;
                //群组群友人数和
                GroupBLL groupBLL    = new GroupBLL();
                int      groupNumber = groupBLL.GetGroupPopularityNumber(userID);
                HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend方法群组人气值为:" + groupNumber);
                popularityInt += groupNumber;
                dic.Add("Popularity", popularityInt);//人气
                #endregion
                string companyName = "";
                //通过公司ID查询公司名称
                CompanysEL compEL = new CompanysEL();
                compEL.ID = userel.CompanyID;
                compEL.ExecuteEL(2);
                HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取公司信息结果(公司名称为):" + compEL.CompanyName);
                if (!string.IsNullOrEmpty(compEL.CompanyName))
                {
                    companyName = compEL.CompanyName;
                }
                dic.Add("CompanyName", companyName);
                dic.Add("CompanyIcon", compEL.CompanyIcon);
                dic.Add("CompanyID", compEL.ID);
                ///公司简介
                string companyIntroduceStr = compEL.Introduce;
                string introduceStr        = companyIntroduceStr.Length < 50 ? companyIntroduceStr : companyIntroduceStr.Substring(0, 50).ToString() + "...";
                dic.Add("CompanyIntroduce", introduceStr);
                //查看是否有查看sessionFriend用户的记录,有就不用管,没有的话就在SB_Popularity添加一个记录
                bool isLook = popularityBLL.IsLooked(userID, userID_Friend);
                HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend方法,此用户是否被查看过:" + isLook);
                if (!isLook) //如果没有记录就添加一个
                {
                    long insertPopularity = popularityBLL.InsertPopularity(userID, userID_Friend);
                    HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend人气值增加结果:" + insertPopularity);
                }
            }
            //获取公司关键字
            CompanysBLL companyBLL = new CompanysBLL();
            string      tags       = companyBLL.GetCompanyTag_String(userel.CompanyID.ToString());
            dic.Add("Tags", tags);
            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取公司关键字:" + tags);
            //获取点赞个数
            ThumbsBLL thumbsBLL = new ThumbsBLL();
            string    thumbs    = thumbsBLL.GetThumbs(sessionFriend);
            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取点赞个数:" + thumbs);
            dic.Add("Thumb", thumbs.ToString());//点赞个数
            //这里要注意,第一个参数是好友的sesison,第二个参数是自己的session
            string isHadThumb = thumbsBLL.IsHadThumb(sessionFriend, session);
            dic.Add("IsHadThumb", isHadThumb);//是否被点赞
            //获取保存数
            FriendsBLL friendsBLL = new FriendsBLL();
            int        saves      = friendsBLL.GetSaveNumber(sessionFriend);
            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend获取保存个数:" + saves);
            dic.Add("Save", saves.ToString());//保存个数

            //如果session==sessionFriend,说明是自己看自己
            if (session == sessionFriend)
            {
                dic.Add("Who", "0");
            }
            else
            {
                //查看sessionFriend是否是session的好友
                bool isFriend = friendsBLL.IsFriend(session, sessionFriend);
                if (isFriend)
                {
                    //说明是好友
                    dic.Add("Who", "1");
                }
                else
                {
                    //说明不是好友
                    dic.Add("Who", "2");
                }
            }
            //小程序的token
            WX_TokenBLL tokenBLL = new WX_TokenBLL();
            string      token    = tokenBLL.GetToken();
            dic.Add("Token", token);

            string strJson = js.Serialize(dic);
            HF.Cloud.BLL.Common.Logger.Error("GetUserInfoBySessionAndSessionFriend返回的数据为:" + strJson);
            return(strJson);
        }
예제 #4
0
        /// <summary>
        /// 获取群组小程序码图片路径
        /// </summary>
        /// <param name="path">小程序码跳转路径</param>
        /// <param name="groupID">群组ID</param>
        /// <returns></returns>
        public string GetQRCode_Group(string path, string groupID)
        {
            HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,获取的参数path:" + path + "------groupID:" + groupID);
            string imgPath = "";
            //判断数据库中是否有值
            GroupEL groupEL = new GroupEL();

            groupEL.ID = long.Parse(groupID);
            DataTable dt = groupEL.ExecDT(3);

            HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,查找群组记录:" + dt.Rows.Count);
            if (dt != null && dt.Rows.Count > 0)
            {
                //如果数据库中"QRCode"有值,则从数据库中取值
                if (!string.IsNullOrEmpty(dt.Rows[0]["QRCode"].ToString()) && dt.Rows[0]["QRCode"].ToString() != "")
                {
                    //获取图片名称
                    string qrCodeImageName = dt.Rows[0]["QRCode"].ToString();
                    //获取图片路径
                    string qrCodeImagePath = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"];
                    imgPath = qrCodeImagePath + qrCodeImageName;
                }
                //如果没有值则请求小程序服务器获取小程序码图片,并把图片名称保存到数据库中
                else
                {
                    //获取token
                    WX_TokenBLL tokenBLL = new WX_TokenBLL();
                    string      token    = tokenBLL.GetToken();
                    //获取小程序码接口
                    string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token;
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("path", path);
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    js.MaxJsonLength = int.MaxValue;
                    string json = js.Serialize(dic);
                    HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,url:" + url + "-----Path:" + path);
                    //post返回的小程序码流
                    Stream QRCodeStream = WeChatAppDecrypt.Post(url, json);
                    //将图片流转换成图片
                    Bitmap tp = new Bitmap(QRCodeStream);
                    string QRCodeSave_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeSave_Group"];
                    string image_userName   = Guid.NewGuid().ToString();
                    string qrCodeImageName  = image_userName + ".jpg";
                    tp.Save(QRCodeSave_Group + qrCodeImageName);
                    //把小程序码图片名称保存到数据库中
                    groupEL.QRCode = qrCodeImageName;
                    int  ra;
                    long returnValue = groupEL.ExecNonQuery(21, out ra);
                    HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,保存小程序图片名称结果:" + ra);
                    if (ra > 0)
                    {
                        string QRCodeGet_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"];
                        imgPath = QRCodeGet_Group + qrCodeImageName;
                    }
                    else
                    {
                        imgPath = "error";
                    }
                }
            }
            else
            {
                imgPath = "error";
            }
            HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,小程序码图片路径:" + imgPath);
            return(imgPath);
        }