Exemplo n.º 1
0
        //推送消息的封装方法
        public string SendNotificationByUserId(string receivedUserIds, string titleString, string contentString, string senderUserId, string senderUserName, string businessTableName, string businessKeyName, string businessKeyValue, Eva.Library.Data.AccessDataTrans.IAccessDataTrans iAccessDataTrans)
        {
            sara.dd.ldsw.idal.Itbl_app_pushnotification       idal = new sara.dd.ldsw.dal.tbl_app_pushnotification();
            Eva.Library.Data.AccessDataTrans.IAccessDataTrans t;
            if (iAccessDataTrans == null)
            {
                t = commonclass.commonclass.CreateIAccessDataTrans();
            }
            else
            {
                t = iAccessDataTrans;
            }
            string sendIds = "";

            try
            {
                if (iAccessDataTrans == null)
                {
                    t.getTrans().begin();
                }
                string[] receivedUserIdArray = receivedUserIds.Split(',');
                for (int i = 0; i < receivedUserIdArray.Length; i++)
                {
                    sara.dd.ldsw.model.tbl_app_pushnotification p = new model.tbl_app_pushnotification();
                    p.sys_creatdate     = System.DateTime.Now;
                    p.sys_creatuserid   = senderUserId;
                    p.sys_creatusername = senderUserName;

                    p.sys_lasteditdate     = System.DateTime.Now;
                    p.sys_lastedituserid   = senderUserId;
                    p.sys_lasteditusername = senderUserName;

                    p.sys_deldate = DateTime.Parse("1900-01-01");
                    p.sys_delflag = "0";

                    p.f_content  = contentString;
                    p.f_title    = titleString;
                    p.f_status   = "未发送";
                    p.f_statusid = "0";

                    p.f_send_datetime         = System.DateTime.Now;
                    p.f_send_userid           = senderUserId;
                    p.f_send_username         = senderUserName;
                    p.f_businesstablename     = businessTableName;
                    p.f_businesstablekeyname  = businessKeyName;
                    p.f_businesstablekeyvalue = businessKeyValue;
                    p.f_recive_userid         = receivedUserIdArray[i];

                    string  sql = " select u_name,f_value8,f_value6 from t_user where u_id = '" + p.f_recive_userid + "'";
                    DataSet ds  = t.Query(sql);

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        p.f_recive_username     = ds.Tables[0].Rows[0]["u_name"].ToString();
                        p.f_recive_deviceid     = ds.Tables[0].Rows[0]["f_value8"].ToString();
                        p.f_recive_devicetype   = ds.Tables[0].Rows[0]["f_value6"].ToString();
                        p.f_recive_devicetypeid = ds.Tables[0].Rows[0]["f_value6"].ToString();
                    }

                    sendIds += idal.Add(p, t) + "^";
                }



                string sqlString = "";

                sqlString += " select sys_id,";
                sqlString += " (select count(*)+" + sendIds.Split('^').Length.ToString() + " from tbl_app_pushnotification where f_recive_userid = a.f_recive_userid and f_statusid in ('1')) as f_badge,";
                sqlString += " f_title,";
                sqlString += " f_content,";
                sqlString += " f_recive_devicetype,";
                sqlString += " f_recive_deviceid,";
                sqlString += " f_recive_userid,";
                //sqlString += " f_recive_certificate,";
                sqlString += " f_businesstablename,";
                sqlString += " f_businesstablekeyname,";
                sqlString += " f_businesstablekeyvalue";
                sqlString += " from tbl_app_pushnotification a where a.f_statusid = '0'";
                sqlString += " and sys_id in ('" + sendIds.Replace("^", "','") + "')";

                DataTable dt = t.Query(sqlString).Tables[0];


                string successId = "";
                string result    = "";
                foreach (DataRow dr in dt.Rows)
                {
                    PushNotificationClass thread = new PushNotificationClass(Server.MapPath("~"));
                    switch (dr["f_recive_devicetype"].ToString())
                    {
                    case "ios":
                        thread.typeString = "ios";

                        thread.iosBadgeString     = dr["f_badge"].ToString();
                        thread.iosDeviceIDString  = dr["f_recive_deviceid"].ToString();
                        thread.iosParameterString = dr["f_businesstablename"].ToString() + "^" + dr["f_businesstablekeyname"].ToString() + "^" + dr["f_businesstablekeyvalue"].ToString();
                        thread.iosTitleString     = dr["f_title"].ToString();

                        break;

                    case "android":
                        thread.typeString     = "android";
                        thread.androidUserids = dr["f_recive_deviceid"].ToString();
                        thread.androidMessage = dr["f_title"].ToString();

                        break;
                    }

                    Thread thread_temp = new Thread(new ThreadStart(thread.PushForThread));
                    thread_temp.Start();
                    if (result == "")
                    {
                        successId += dr["sys_id"].ToString() + "^";
                    }
                }


                sqlString = "update tbl_app_pushnotification set f_statusid = '1',f_status = '已发送' where sys_id in ('" + successId.TrimEnd('^').Replace("^", "','") + "')";
                t.ExecuteSql(sqlString);

                if (iAccessDataTrans == null)
                {
                    t.getTrans().commit();
                }
            }
            catch (Exception ex)
            {
                if (iAccessDataTrans == null)
                {
                    t.getTrans().rollback();
                }
                throw ex;
            }



            return("");
        }
Exemplo n.º 2
0
        public string SendNotification(string sendIds, string clientInf)
        {
            Dictionary <string, string> resultDic = new Dictionary <string, string>();

            resultDic["result"]  = "";
            resultDic["message"] = "";
            _iAccessData         = commonclass.commonclass.CreateIAccessData();
            try
            {
                resultDic["result"]  = "true";
                resultDic["message"] = "";

                //接入消息发送代码。。。。。。

                string sqlString = "";

                sqlString += " select sys_id,";
                sqlString += " (select count(*)+" + sendIds.Split('^').Length.ToString() + " from tbl_app_pushnotification where f_recive_userid = a.f_recive_userid and f_statusid in ('1')) as f_badge,";
                sqlString += " f_title,";
                sqlString += " f_content,";
                sqlString += " f_recive_devicetype,";
                sqlString += " f_recive_deviceid,";
                sqlString += " f_recive_userid,";
                //sqlString += " f_recive_certificate,";
                sqlString += " f_businesstablename,";
                sqlString += " f_businesstablekeyname,";
                sqlString += " f_businesstablekeyvalue";
                sqlString += " from tbl_app_pushnotification a where a.f_statusid = '0'";
                sqlString += " and sys_id in ('" + sendIds.Replace("^", "','") + "')";

                DataTable             dt = _iAccessData.Query(sqlString).Tables[0];
                PushNotificationClass pc = new PushNotificationClass(Server.MapPath("~"));

                string successId = "";
                string result    = "";
                foreach (DataRow dr in dt.Rows)
                {
                    switch (dr["f_recive_devicetype"].ToString())
                    {
                    case "ios":
                        result = pc.PushMessageIos(dr["f_recive_deviceid"].ToString(),
                                                   dr["f_title"].ToString(),
                                                   dr["f_businesstablename"].ToString() + "^" + dr["f_businesstablekeyname"].ToString() + "^" + dr["f_businesstablekeyvalue"].ToString() + "^" + dr["sys_id"].ToString(),
                                                   dr["f_badge"].ToString());
                        break;

                    case "android":
                        result = pc.PushMessageAndroid(dr["f_recive_deviceid"].ToString(), dr["f_title"].ToString());
                        break;
                    }
                    if (result == "")
                    {
                        successId += dr["sys_id"].ToString() + "^";
                    }
                }


                sqlString = "update tbl_app_pushnotification set f_statusid = '1',f_status = '已发送' where sys_id in ('" + successId.TrimEnd('^').Replace("^", "','") + "')";
                _iAccessData.ExecuteSql(sqlString);

                NewLog("消息发送成功:" + sendIds, "sql_select", clientInf);
            }
            catch (Exception ex)
            {
                resultDic["result"]  = "false";
                resultDic["message"] = Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace);

                NewLog("消息发送失败:" + sendIds + ",异常信息:" + Eva.Library.Format.FormatTextTool.ErrorMessageFormat(ex.Message + ex.StackTrace), "sql_select", clientInf);
            }
            return(Eva.Library.Format.FormatEntityTool.FormatDicToJson(resultDic));
        }