示例#1
0
        /// <summary>
        /// 封装报文
        /// </summary>
        /// <param name="sendType"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static string getContentString(int sendType, MWMessage message, int authenticationMode)
        {
            if (sendType == 1)
            {
                return(getSingleContentString(message, authenticationMode));
            }
            else if (sendType == 2)
            {
                return(getBatchContentString(message, authenticationMode));
            }
            else if (sendType == 3)
            {
                return(getMultiMtContentString(message, authenticationMode));
            }
            else if (sendType == 4)
            {
                return(getMoContentString(message, authenticationMode));
            }
            else if (sendType == 5)
            {
                return(getRptContentString(message, authenticationMode));
            }
            else if (sendType == 6)
            {
                return(getBalanceContentString(message, authenticationMode));
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// 获取相同内群发封装UrlContent数据
        /// userid=kuke33&pwd=26dad7f364507df18f3841cc9c4ff94d&mobile=13800138000,13000130000,18000180000&content=%b2%e2%ca%d4%b6%cc%d0%c5&timestamp=0803192020&exno=0006&custid=b3d0a2783d31b21b8573&exdata=exdata000002
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static string getSingleContentString(MWMessage message, int authenticationMode)
        {
            string contents = null;

            if (authenticationMode == 0)
            {
                contents = string.Format(TMP_SEND_CONTENT_URLENCODE_NORMAL,
                                         message.UserId,
                                         message.Pwd,
                                         message.Mobile,
                                         HttpUtility.UrlEncode(message.Content, Encoding.GetEncoding("GBK")),
                                         message.TimeStamp,
                                         (string.IsNullOrEmpty(message.SvrType) ? string.Empty : message.SvrType),
                                         (string.IsNullOrEmpty(message.ExNo) ? string.Empty : message.ExNo),
                                         (string.IsNullOrEmpty(message.CustId) ? string.Empty : message.CustId),
                                         (string.IsNullOrEmpty(message.ExData) ? string.Empty : message.ExData));
            }
            else
            {
                contents = string.Format(TMP_SEND_CONTENT_URLENCODE_APIKEY,
                                         message.ApiKey,
                                         message.Mobile,
                                         HttpUtility.UrlEncode(message.Content, Encoding.GetEncoding("GBK")),
                                         message.TimeStamp,
                                         (string.IsNullOrEmpty(message.SvrType) ? string.Empty : message.SvrType),
                                         (string.IsNullOrEmpty(message.ExNo) ? string.Empty : message.ExNo),
                                         (string.IsNullOrEmpty(message.CustId) ? string.Empty : message.CustId),
                                         (string.IsNullOrEmpty(message.ExData) ? string.Empty : message.ExData));
            }

            return(contents);
        }
 /// <summary>
 /// 统一提交
 /// </summary>
 /// <param name="message">请求对象</param>
 /// <param name="sendType">请求类型,1:单发,2:相同内容群发,3:不同类型群发,4:获取上行,5:获取状态报告,6:获取账号余额</param>
 /// <returns></returns>
 private string submit(MWMessage message, int sendtype)
 {
     try
     {
         ISMS sms = null;
         if (messageType == 0)
         {
             sms = new UrlEncdoeSend();
         }
         else if (messageType == 1)
         {
             sms = new JsonSend();
         }
         else if (messageType == 2)
         {
             //sms = new XMLSend();
         }
         account.Ip            = "114.67.62.211";
         account.Port          = 7901;
         account.MasterIPState = 0;
         String ipport = getIpPortByAccount(account);
         if (string.IsNullOrEmpty(ipport))
         {
             return("没有可用的IP端口");
         }
         return(sms.execute(message, sendtype, ipport, authenticationMode, this.isKeepAlive));
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
        public void MWSendMsg(string phone, string code)
        {
            MWMessage msg = initMessage();

            msg.Mobile  = phone;
            msg.Content = string.Format(content_VerificationCode, code);
            msg.ExNo    = "";
            msg.CustId  = "";
            msg.ExData  = "";
            msg.SvrType = "";
            //提交
            string str = submit(msg, 1);
        }
        /// <summary>
        /// 初始发送对象
        /// </summary>
        /// <returns></returns>
        private MWMessage initMessage()
        {
            string    imeStamp = DateTime.Now.ToString("MMddHHmmss");
            string    password = encode(myaccount, "fG06bB", imeStamp);
            MWMessage msg      = new MWMessage()
            {
                UserId    = myaccount,
                TimeStamp = imeStamp,
                Pwd       = password,
                ApiKey    = ""
            };

            return(msg);
        }
示例#6
0
        /// <summary>
        /// 提交请求
        /// </summary>
        /// <param name="message">请求报文</param>
        /// <param name="sendType">请求类型,1:单发,2:相同内容群发,3:不同类型群发,4:获取上行,5:获取状态报告,6:获取账号余额</param>
        /// <param name="IpAndPort">IP/PORT,格式:ip:port,例如:122.11.1.88:8888</param>
        /// <param name="authenticationMode">鉴权方式,0:账号+密码,1:APIKEY</param>
        /// <param name="bKeepAlive">是否长连接,TRUE:长连接,FALSE:短连接</param>
        /// <returns></returns>
        public string execute(MWMessage message, int sendType, string IpAndPort, int authenticationMode, bool bKeepAlive)
        {
            string url            = getUrl(sendType, IpAndPort);
            string requestContent = JsonMessageTemplate.getContentString(sendType, message, authenticationMode);

            try
            {
                return(httpPost(requestContent, url, bKeepAlive));
            }
            catch (Exception ex)
            {
                //log.ErrorFormat("发送发生异常,IP={0},error={1}", IpAndPort, ex.Message);
                //Account.getInstance().setState(IpAndPort, false);
                return(ex.Message);
            }
        }
示例#7
0
        private static string getBalanceContentString(MWMessage message, int authenticationMode)
        {
            string contents = null;

            if (authenticationMode == 0)
            {
                contents = string.Format(TMP_BALANCE_URLENCODE_NORMAL,
                                         message.UserId,
                                         message.Pwd,
                                         message.TimeStamp);
            }
            else
            {
                contents = string.Format(TMP_BALANCE_URLENCODE_APIKEY,
                                         message.ApiKey,
                                         message.TimeStamp);
            }

            return(contents);
        }
示例#8
0
        private static string getMultiMtContentString(MWMessage message, int authenticationMode)
        {
            string contents = null;

            if (authenticationMode == 0)
            {
                contents = string.Format(TMP_MULT_CONTENT_URLENCODE_NORMAL,
                                         message.UserId,
                                         message.Pwd,
                                         message.TimeStamp,
                                         message.Multimt);
            }
            else
            {
                contents = string.Format(TMP_MULT_CONTENT_URLENCODE_APIKEY,
                                         message.ApiKey,
                                         message.TimeStamp,
                                         message.Multimt);
            }

            return(contents);
        }
        private static string getRptContentString(MWMessage message, int authenticationMode)
        {
            string contents = null;

            if (authenticationMode == 0)
            {
                contents = string.Format(TMP_RPT_JSON_NORMAL,
                                         message.UserId,
                                         message.Pwd,
                                         message.TimeStamp,
                                         message.RetSize);
            }
            else
            {
                contents = string.Format(TMP_RPT_JSON_APIKEY,
                                         message.ApiKey,
                                         message.TimeStamp,
                                         message.RetSize);
            }
            //两端加中括号
            contents = "{" + contents + "}";
            return(contents);
        }
示例#10
0
 /// <summary>
 /// 获取相同内群发封装UrlContent数据
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 private static string getBatchContentString(MWMessage message, int authenticationMode)
 {
     return(getSingleContentString(message, authenticationMode));
 }