示例#1
0
        //推送给申请人
        public static void Push(string staffNumber, string companyId, byte status)
        {
            UserModels user1 = (from u in sdb.Users where u.StaffNumber == staffNumber && u.CompanyId == companyId select u).FirstOrDefault();

            if (user1 != null)
            {
                string info = null;
                if (status == 3)
                {
                    info = "你的申请审核通过!";
                }
                else if (status == 1)
                {
                    info = "你的申请处于在审核!";
                }
                else if (status == 5)
                {
                    info = "你的申请无效";
                }
                else
                {
                    info = "你的申请审核拒绝";
                }
                PushPayload payload = CompanyPushAPI.PushObject_auto_alias(user1.CompanyId, user1.UserName, "heh", info, "2");//选择一种方式
                try
                {
                    var result1 = client.SendPush(payload); //推送
                }
                catch (APIRequestException e)               //处理请求异常
                {
                    var message = "Error response from JPush server. Should review and fix it." + "HTTP Status:" + e.Status + "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode;
                }
                catch (APIConnectionException e)//处理连接异常
                {
                    var message = e.Message;
                }
            }
        }
示例#2
0
        //推送给自己
        public static void PushMe(string companyId, string userName, int status, string applyName)
        {
            PushPayload payload = new PushPayload();

            //对审批流状态进行判断,区分申请的审核类型
            if (status == 0)                                                                                               //进入审批流
            {
                payload = CompanyPushAPI.PushObject_auto_alias(companyId, userName, "heh", info + applyName + info1, "2"); //选择一种方式
            }
            else if (status == 3)                                                                                          //进入自动审核完成,提交就审核完成
            {
                payload = CompanyPushAPI.PushObject_auto_alias(companyId, userName, "heh", info + applyName + info2, "2"); //选择一种方式
            }
            else if (status == 6)                                                                                          //进入手动审核,需要自己审核完成
            {
                payload = CompanyPushAPI.PushObject_auto_alias(companyId, userName, "heh", info + applyName + info3, "2"); //选择一种方式
            }
            //else//进入没有对应的审批流模板,此申请无效
            //{
            //    payload = CompanyPushAPI.PushObject_auto_alias(user.UserName, "heh", "你的请假申请提交成功!此申请无效", "2");//选择一种方式
            //}
            // PushPayload
            try
            {
                var result1 = client.SendPush(payload); //推送
            }
            catch (APIRequestException e)               //处理请求异常
            {
                var message = "Error response from JPush server. Should review and fix it." + "HTTP Status:" + e.Status + "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode;
                //return Json(message, JsonRequestBehavior.AllowGet);
            }
            catch (APIConnectionException e)//处理连接异常
            {
                var message = e.Message;
                // return Json(e.Message, JsonRequestBehavior.AllowGet);
            }
        }
示例#3
0
        //推送到审核人
        public static void Audit(string temp, string companyId)
        {
            string[] auditors = temp.Split(',');
            string[] audit    = new string[auditors.Length];
            for (int i = 0; i < auditors.Length; i++)
            {
                string temp1 = auditors[i];
                audit[i] = temp1.Substring(0, 11);
            }
            PushPayload payload = CompanyPushAPI.PushObject_auto_alias(companyId, audit, "heh", "你需要审核的申请!", "2");//选择一种方式

            try
            {
                var result1 = client.SendPush(payload); //推送
            }
            catch (APIRequestException e)               //处理请求异常
            {
                var message = "Error response from JPush server. Should review and fix it." + "HTTP Status:" + e.Status + "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode;
            }
            catch (APIConnectionException e)//处理连接异常
            {
                var message = e.Message;
            }
        }
示例#4
0
        [ValidateInput(false)]// [ValidateAntiForgeryToken]
        public ActionResult Create(CompanyPush companypush, HttpPostedFileBase file)
        {
            var staff = (from s in db.Staffs
                         select new StaffModel
            {
                department = s.Department,
                text = s.StaffNumber + "-" + s.Name,
                value = s.StaffNumber
            }).ToList();

            var group = (from d in db.Departments
                         select new StaffModel {
                department = d.DepartmentId, name = d.Name
            }).ToList();
            var number = (from s in db.Staffs group s by s.Department into g select new { department = g.Key, number = g.Count() }).ToList();

            ViewBag.Receiver = staff;
            ViewBag.Group    = group;
            List <SelectListItem> strict = (from u in db.StaffParams//获取所有地区
                                            where u.StaffParamTypeId == 13
                                            select new { Strict = u.Value }).Distinct().ToList().Select(s => new SelectListItem
            {
                Text  = s.Strict,
                Value = s.Strict
            }).Distinct().ToList();
            List <SelectListItem> department = (from u in db.Departments//获取所有部门
                                                select new { Department = u.Name }).Distinct().ToList().Select(s => new SelectListItem
            {
                Text  = s.Department,
                Value = s.Department
            }).Distinct().ToList();

            ViewBag.strict     = strict;
            ViewBag.department = department;
            if (ModelState.IsValid)
            {
                string miniType   = file.ContentType;
                Stream fileStream = file.InputStream;
                string path       = AppDomain.CurrentDomain.BaseDirectory + "files\\push\\";
                string filename   = Path.GetFileName(file.FileName);
                file.SaveAs(Path.Combine(path, filename));
                CompanyPush p = new CompanyPush();
                p.Type         = Request["Type"];
                p.Tag          = Request["Tag"].TrimEnd(',');
                p.TagContent   = companypush.TagContent;
                p.TagTitle     = companypush.TagTitle;
                p.Target       = companypush.Target;
                p.PersonName   = this.Name;
                p.RecordPerson = this.UserName;
                p.RecordTime   = DateTime.Now;
                p.Url          = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/files/push/" + filename;

                string[]    selects = p.Tag.Split(',');
                PushPayload payload = new PushPayload();
                if (p.Target.Equals("所有用户"))
                {
                    payload = CompanyPushAPI.PushObject_all(this.CompanyId, p.TagContent);//选择一种方式
                }
                else if (p.Target.Equals("选择用户(只要符合其中一种条件的推送)"))
                {
                    payload = CompanyPushAPI.PushObject_tags(this.CompanyId, selects, p.TagContent);//选择一种方式
                }
                else if (p.Target.Equals("指定用户"))
                {
                    string[] person = new string[selects.Length];
                    for (int i = 0; i < selects.Length; i++)
                    {
                        string     temp = selects[i];
                        UserModels user = (from u in sdb.Users where u.CompanyId == this.CompanyId && u.StaffNumber == temp select u).FirstOrDefault();
                        if (user != null)
                        {
                            person[i] = user.UserName;
                        }
                    }
                    payload = CompanyPushAPI.PushObject_alias(person, p.TagContent);//选择一种方式
                }
                else
                {
                    payload = CompanyPushAPI.PushObject_tags_and(this.CompanyId, selects, p.TagContent);//选择一种方式
                }
                JPushClient client = new JPushClient(JPushApiExample.app_key, JPushApiExample.master_secret);

                try
                {
                    var result1 = client.SendPush(payload);//推送
                    //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法
                    //System.Threading.Thread.Sleep(10000);
                    /*如需查询上次推送结果执行下面的代码*/
                    // var apiResult = client.getReceivedApi(result.msg_id.ToString());
                    //var apiResultv3 = client.getReceivedApi_v3(result1.msg_id.ToString());
                    /*如需查询某个messageid的推送结果执行下面的代码*/
                    //   var queryResultWithV2 = client.getReceivedApi("1739302794");
                    // var querResultWithV3 = client.getReceivedApi_v3("1739302794");
                }
                catch (APIRequestException e)//处理请求异常
                {
                    if (e.ErrorCode.Equals(1011))
                    {
                        var message1 = "您发送的推送目标组合条件不成立";
                        return(Json(message1, JsonRequestBehavior.AllowGet));
                    }
                    var message = "Error response from JPush server. Should review and fix it." + "HTTP Status:" + e.Status + "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode;
                    return(Json(message, JsonRequestBehavior.AllowGet));
                }
                catch (APIConnectionException e)//处理连接异常
                {
                    var message = e.Message;
                    return(Json(e.Message, JsonRequestBehavior.AllowGet));
                }
                db.CompanyPushes.Add(p);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(companypush));
        }