Пример #1
0
        //[Extension]
        public string SendVCode(byte[] param)
        {
            string result = string.Empty;

            try
            {
                if (param == null || param.Length < 1)
                {
                    return("参数有误");
                }

                string data = Common.AESHelper.AESDecryptString(param, SP.ep.AesKey);
                if (data.Length == 0)
                {
                    return("参数有误");
                }

                ReceiveMsgStruct msg = JsonConvertEx.JsonToObject <ReceiveMsgStruct>(data);

                ////if(Cache) 需要其他的判断

                if (msg.RequestTime + 30 * 10000000 < DateTime.Now.Ticks)
                {
                    return("请求已过期");
                }

                //获取全局唯一标识
                msg.UniqueID    = UniqueIDMaker.Make();
                msg.ReceiveTime = DateTime.Now.Ticks;

                bool RFlag = AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteSendQueue(msg));

                if (RFlag)
                {
                    result = "已接收";
                    AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogDB_SMSReceiveList(msg));
                }
                else
                {
                    result = "系统繁忙";
                    AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogFile("插入发送队列出现繁忙"));
                }
            }
            catch (Exception ex)
            {
                AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogFile("接受ws请求出现异常", ex));
            }

            return(result);
        }
Пример #2
0
        private List <SendMsgStruct> EmaySendAction(ReceiveMsgStruct[] array)
        {
            //if (array.Length>0 && array[0] == null)
            //{
            //    Debug.WriteLine("becalled");
            //    return new List<SendMsgStruct>();
            //}

            List <SendMsgStruct> ErrorResultList = new List <SendMsgStruct>();

            if (array != null && array.Length > 0)
            {
                List <ReceiveMsgStruct> copyList = new List <ReceiveMsgStruct>();

                Guid BatchID = UniqueIDMaker.Make();
                LastExecTime = DateTime.Now;

                SMSRequestBody body = new SMSRequestBody();

                foreach (ReceiveMsgStruct item in array)
                {
                    if (item.ReceiveTime + 30 * 10000000 < LastExecTime.Ticks)
                    {
                        //"请求已过期";
                        SendMsgStruct sendItem = new SendMsgStruct()
                        {
                            CSShortName = item.CSShortName,
                            UserName    = item.UserName,
                            HName       = SMSHandlerType.Emay.ToString(),
                            UniqueID    = item.UniqueID,
                            ReceiveTime = item.ReceiveTime,
                            TelNumber   = item.TelNumber,
                            Content     = item.Content,
                            BatchID     = BatchID,
                            SendTime    = LastExecTime.Ticks,
                            SendState   = (int)SendStateType.OutTime
                        };

                        AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogDB_SMSSendList(SendMsgStruct.Copy(sendItem)));
                    }
                    else
                    {
                        copyList.Add(item);
                        body.smses.Add(new SMSRequestEntity()
                        {
                            mobile      = item.TelNumber,
                            content     = item.Content,
                            customSmsId = ""
                        });
                    }
                }

                if (copyList.Count == 0)
                {
                    return(ErrorResultList);
                }

                //使用copyList来处理发送

                body.requestTime = DateTime.Now.Ticks;
                SMSResponseBody responseBody = EmaySender.Instance.BatchSend(body);

                //#region forTestCnki
                //SMSResponseBody responseBody = new SMSResponseBody();
                //responseBody.flag = false;
                //responseBody.resultCode = "forTestCnki";
                //#endregion

                //加入dblog
                foreach (ReceiveMsgStruct item in copyList)
                {
                    SendMsgStruct sendItem = new SendMsgStruct()
                    {
                        CSShortName = item.CSShortName,
                        UserName    = item.UserName,
                        HName       = SMSHandlerType.Emay.ToString(),
                        UniqueID    = item.UniqueID,
                        ReceiveTime = item.ReceiveTime,
                        TelNumber   = item.TelNumber,
                        Content     = item.Content,
                        BatchID     = BatchID,
                        SendTime    = body.requestTime
                    };
                    if (responseBody != null && responseBody.flag == true)
                    {
                        sendItem.SendState = (int)SendStateType.SendOK;
                    }
                    else
                    {
                        sendItem.SendState = (int)SendStateType.SendError;
                        sendItem.ErrorMsg  = (responseBody == null ? "SendException" : responseBody.resultCode);

                        ErrorResultList.Add(sendItem);
                    }

                    AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogDB_SMSSendList(SendMsgStruct.Copy(sendItem)));
                }
            }
            //防止引用结果被篡改
            List <SendMsgStruct> resultList = new List <SendMsgStruct>();

            foreach (SendMsgStruct item in ErrorResultList)
            {
                resultList.Add(SendMsgStruct.Copy(item));
            }

            return(ErrorResultList);
        }