示例#1
0
        /// <summary>
        /// 短信发送
        /// </summary>
        /// <param name="TelList"></param>
        /// <param name="strMsg"></param>
        /// <param name="errMsg"></param>
        /// <param name="smsIDGroup"></param>
        /// <returns></returns>
        public static long SendSms(ArrayList TelList, string strMsg, out string errMsg, out SmsIDGroup[] smsIDGroup)
        {
            MobsetApi mobsetMms    = new MobsetApi();
            long      lCorpID      = CorpID;
            string    strLoginName = UserName;
            string    strPasswd    = UserPassword;
            string    strTimeStamp = DateTime.Now.ToString("MMddHHmmss");
            string    strInput     = lCorpID + strPasswd + strTimeStamp;
            string    strMd5       = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strInput, "MD5");

            String strAddNum = "001"; //扩展码
            String tTimer    = "";    // = "2005-05-05 12:00:00"; //定时时间,yyyy-MM-dd HH:mm:ss
            long   lLongSms  = 1;     //使用长短信方式发送
                                      //SmsIDGroup[] smsIDGroup = new SmsIDGroup[2];
            long ret = 0;

            errMsg = "";
            List <SmsIDGroup> lsig   = new List <SmsIDGroup>();
            ArrayList         tltemp = new ArrayList();

            for (int i = 0; i < TelList.Count; i++)
            {
                tltemp.Add(TelList[i]);
                if (((i + 1) >= 40 && (i + 1) % 40 == 0) || (i == TelList.Count - 1))
                {
                    //发送
                    MobileListGroup[] strMobiles2 = new MobileListGroup[tltemp.Count];  //目标号码
                    for (int j = 0; j < tltemp.Count; j++)
                    {
                        strMobiles2[j]        = new MobileListGroup();
                        strMobiles2[j].Mobile = tltemp[j].ToString();
                    }
                    try
                    {
                        SmsIDGroup[] smsidgroup2;
                        ret = mobsetMms.Sms_Send(lCorpID, strLoginName, strMd5, strTimeStamp, strAddNum, tTimer, lLongSms, strMobiles2, strMsg, out errMsg, out smsidgroup2);
                        if (ret < 0)
                        {
                            break;
                        }
                        foreach (SmsIDGroup sig in smsidgroup2)
                        {
                            lsig.Add(sig);
                        }
                    }
                    catch (Exception ex) { throw ex; }
                    tltemp = new ArrayList();
                }
            }
            smsIDGroup = new SmsIDGroup[lsig.Count];
            for (int i = 0; i < lsig.Count; i++)
            {
                smsIDGroup[i] = lsig[i];
            }
            return(ret);
        }
示例#2
0
        private void SendImpl(long[] to, string body, params object[] arguments)
        {
            try
            {
                if (to == null || to.Length == 0)
                {
                    throw new ArgumentNullException("to");
                }

                if (string.IsNullOrEmpty(body))
                {
                    throw new ArgumentNullException("body");
                }

                string       errMsg;
                SmsIDGroup[] smsIDGroup;

                string strMsg;
                if (arguments != null && arguments.Length > 0)
                {
                    strMsg = string.Format(body, arguments);
                }
                else
                {
                    strMsg = body;
                }

                int index = 0;
                while (index < to.Length)
                {
                    int    count        = Math.Min(to.Length - index, SendMax);
                    string strTimeStamp = DateTime.Now.ToString("MMddHHmmss");
                    string strInput     = string.Concat(AppId, Token, strTimeStamp);
                    string strMd5       = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strInput, "MD5");

                    MobileListGroup[] strMobiles = new MobileListGroup[count];
                    for (int i = index; i < (index + count); ++i)
                    {
                        strMobiles[i - index] = new MobileListGroup()
                        {
                            Mobile = to[i].ToString()
                        }
                    }
                    ;

                    long ret = mobsetMms.Sms_Send(int.Parse(AppId), Account, strMd5, strTimeStamp, AddNum, string.Empty, LongSms, strMobiles, strMsg, out errMsg, out smsIDGroup);
                    if (ret > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("Total:").Append(to.Length).Append(' ').Append("Succuss:").Append(ret).AppendLine();
                        foreach (SmsIDGroup item in smsIDGroup)
                        {
                            sb.Append(item.Mobile).Append(':').Append(item.SmsID).Append(',');
                        }
                        WriteLog(string.Concat("SendSMS", Environment.NewLine, sb.ToString()));
                    }
                    else
                    {
                        throw new Exception(errMsg);
                    }
                    index += count;
                }
            }
            catch (Exception ex)
            {
                WriteLog(string.Concat("SendSMS", Environment.NewLine, ex.ToString()));
            }
        }