Пример #1
0
        // 发送一条消息。可以大于 70 字,分为多条发送
        public static int SendMessage(string strTel,
                                      string strMessage,
                                      string strLibraryCode,
                                      out string strError)
        {
            if (string.IsNullOrEmpty(strTel) == true ||
                string.IsNullOrEmpty(strMessage) == true)
            {
                strError = "strMessage 和 strTel 参数不能为空";
                return(-1);
            }

            ConfigParam param = null;

            try
            {
                param = ConfigParam.LoadConfig(strLibraryCode);
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return(-1);
            }


            if (strMessage.Length <= param.nMaxChars)
            {
                return(SendOneMessage(
                           param,
                           strTel,
                           strMessage,
                           strLibraryCode,
                           out strError));
            }

            int nCount = 0;

            for (; ;)
            {
                int nLength = strMessage.Length;
                if (nLength > param.nMaxChars)
                {
                    nLength = param.nMaxChars;
                }
                string strPart = strMessage.Substring(0, nLength);
                int    nRet    = SendOneMessage(
                    param,
                    strTel,
                    strPart,
                    strLibraryCode,
                    out strError);
                if (nRet <= 0)
                {
                    return(nRet);
                }
                nCount += nRet;

                if (strMessage.Length <= nLength)
                {
                    break;
                }
                strMessage = strMessage.Substring(nLength);
            }

            return(nCount);
        }