예제 #1
0
        public static void SendSMS_SMPP(RabbitHelper rabbitHelper, SmsModel sms)
        {
            string ErrorMessage = String.Empty;
            int    ErrorCode    = SmppHelper.SendSMS(sms);

            if (ErrorCode == AppConst.SYS_ERR_OK)
            {
                sms.ERR_CODE       = ErrorCode;
                sms.RECEIVE_RESULT = ErrorMessage;
                rabbitHelper.PublishMessage(AppConfig.QUEUE_SUCCESS, JsonConvert.SerializeObject(sms));
            }
            else
            {
                sms.ERR_CODE       = ErrorCode;
                sms.RECEIVE_RESULT = ErrorMessage;
                rabbitHelper.PublishMessage(AppConfig.QUEUE_ERROR, JsonConvert.SerializeObject(sms));
            }
        }
예제 #2
0
        public static int SendSMS(SmsModel sms)
        {
            bool IsConnected = SmppHelper.smppClient.Connected;

            if (!IsConnected)
            {
                IList <SmppModel> listSMPP = new List <SmppModel>();

                if (!String.IsNullOrEmpty(sms.SMPP_IP_1))
                {
                    listSMPP.Add(new SmppModel()
                    {
                        HOST_NAME = sms.SMPP_IP_1,
                        PORT      = String.IsNullOrEmpty(sms.SMPP_PORT_1) ? 0 : Convert.ToInt32(sms.SMPP_PORT_1),
                        ADDR_TON  = Convert.ToByte("1"),
                        ADDR_NPI  = Convert.ToByte("1"),
                        SYSTEM_ID = sms.SMPP_USER,
                        PASSWORD  = sms.SMPP_PASS
                    });
                }

                if (!String.IsNullOrEmpty(sms.SMPP_IP_2))
                {
                    listSMPP.Add(new SmppModel()
                    {
                        HOST_NAME = sms.SMPP_IP_2,
                        PORT      = String.IsNullOrEmpty(sms.SMPP_PORT_2) ? 0 : Convert.ToInt32(sms.SMPP_PORT_2),
                        ADDR_TON  = Convert.ToByte("1"),
                        ADDR_NPI  = Convert.ToByte("1"),
                        SYSTEM_ID = sms.SMPP_USER,
                        PASSWORD  = sms.SMPP_PASS
                    });
                }

                IsConnected = SmppHelper.ConnectSMPP(listSMPP);
            }

            if (IsConnected && SmppHelper.smppClient.Connected)
            {
                IList <SubmitSmResp> response = SmppHelper.smppClient.Submit(
                    SMS.ForSubmit()
                    .From(sms.SENDER_NAME.Trim())
                    .To(sms.PHONE.Trim()).Coding(DataCodings.Default)
                    .Text(sms.SMS_CONTENT.Trim())
                    .DeliveryReceipt());

                if (response.All(x => x.Status == CommandStatus.ESME_ROK))
                {
                    logger.Info(AppConst.A("SendSMS_SMPP", sms.SENDER_NAME, sms.PHONE, sms.SMS_CONTENT, response[0].Status, response[0].MessageId, response[0].Request));
                    return(AppConst.SYS_ERR_OK);
                }
                else
                {
                    logger.Info(AppConst.A("SendSMS_SMPP", response[0].MessageId, response[0].Request));
                    return((int)response[0].Status);
                }
            }
            else
            {
                logger.Info(AppConst.A("SendSMS_SMPP", "Connect SMPP fail!", "Switch send SMS to API"));
                return(AppConst.SYS_ERR_EXCEPTION);
            }
        }