Ejemplo n.º 1
0
        /// <summary>
        /// Sends the SMS.
        /// </summary>
        /// <param name="sendTime">
        /// 簡訊預定發送時間
        ///     -立即發送:if sendTime = null
        ///     -預約發送:請傳入計時間,若小於系統接單將不予,若傳遞時間已逾現在之,將立即發送。
        /// </param>
        /// <returns></returns>
        public SEND_SMS_RESULT SendParamSMS(DateTime?sendTime, string subject, List <Every8d_MessageReceiver> messageReceivers)
        {
            EnsureSessionKey();

            string contentXML = string.Format("<REPS>{0}</REPS>", string.Join("", messageReceivers.Select(p => p.ToString())));

            // < REPS >
            //  < USER NAME = "TEST" MOBILE = "+886900000001" EMAIL = "" SENDTIME = "" >< ![CDATA[ok okjava hello <>@#$%^&*()]]></USER>
            //  < USER NAME = "Eric1" MOBILE = "+886900000002" EMAIL = "*****@*****.**" SENDTIME = "" >< ![CDATA[這是什麼的測試內容喔 <>@#$%^&*()]]></USER>
            // </ REPS >

            // "4.0,1,1.0,0,65408eb7-1df2-449c-9cb9-4a9162c70cda"
            string resultString = this.SMSService.sendParamSMS(
                this.sessionKey,
                subject ?? string.Empty,
                contentXML,
                sendTime.HasValue ? sendTime.Value.ToString(SendTimeFormat) : string.Empty);

            /*
             * 傳送成功 回傳字串內容格式為:CREDIT,SENDED,COST,UNSEND,BATCH_ID,各值中間以逗號分隔。
             * CREDIT:發送後剩餘點數。負值代表發送失敗,系統無法處理該命令
             * SENDED:發送通數。
             * COST:本次發送扣除點數
             * UNSEND:無額度時發送的通數,當該值大於0而剩餘點數等於0時表示有部份的簡訊因無額度而無法被發送。
             * BATCH_ID:批次識別代碼。為一唯一識別碼,可藉由本識別碼查詢發送狀態。格式範例:220478cc-8506-49b2-93b7-2505f651c12e
             */
            string[] tokens = resultString.Split(',');
            if (tokens.Length != 5)
            {
                throw new Exception(string.Format("解析錯誤 {0},contentXML = {1}", resultString, contentXML));
            }

            var result = new SEND_SMS_RESULT();

            result.CREDIT   = Convert.ToDouble(tokens[0]);
            result.SENDED   = Convert.ToInt32(tokens[1]);
            result.COST     = Convert.ToDouble(tokens[2]);
            result.UNSEND   = Convert.ToInt32(tokens[3]);
            result.BATCH_ID = tokens[4];

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends the SMS.
        /// </summary>
        /// <param name="subject">簡訊類別描述,發送紀錄查詢時參考用,可不填</param>
        /// <param name="content">簡訊發送 內容</param>
        /// <param name="mobile">格式為 : +886912345678,多筆接收人時,請以逗點隔開</param>
        /// <param name="sendTime">
        /// 簡訊預定發送時間
        ///     -立即發送:if sendTime = null
        ///     -預約發送:請傳入計時間,若小於系統接單將不予,若傳遞時間已逾現在之,將立即發送。
        /// </param>
        /// <returns></returns>
        private SEND_SMS_RESULT SendSMS(DateTime?sendTime, string subject, string content, params string[] mobiles)
        {
            EnsureSessionKey();

            // "4.0,1,1.0,0,65408eb7-1df2-449c-9cb9-4a9162c70cda"
            string resultString = this.SMSService.sendSMS(
                this.sessionKey,
                subject,
                content,
                string.Join(",", mobiles),
                sendTime.HasValue ? sendTime.Value.ToString(SMSClient.SendTimeFormat) : string.Empty);

            /*
             * 傳送成功 回傳字串內容格式為:CREDIT,SENDED,COST,UNSEND,BATCH_ID,各值中間以逗號分隔。
             * CREDIT:發送後剩餘點數。負值代表發送失敗,系統無法處理該命令
             * SENDED:發送通數。
             * COST:本次發送扣除點數
             * UNSEND:無額度時發送的通數,當該值大於0而剩餘點數等於0時表示有部份的簡訊因無額度而無法被發送。
             * BATCH_ID:批次識別代碼。為一唯一識別碼,可藉由本識別碼查詢發送狀態。格式範例:220478cc-8506-49b2-93b7-2505f651c12e
             */
            string[] tokens = resultString.Split(',');
            if (tokens.Length != 5)
            {
                throw new Exception(string.Format("解析錯誤 {0}", resultString));
            }

            var result = new SEND_SMS_RESULT();

            result.CREDIT   = Convert.ToDouble(tokens[0]);
            result.SENDED   = Convert.ToInt32(tokens[1]);
            result.COST     = Convert.ToDouble(tokens[2]);
            result.UNSEND   = Convert.ToInt32(tokens[3]);
            result.BATCH_ID = tokens[4];

            return(result);
        }