不了解思路,在百度上一整天也没有一些有效的解决方法。以前没有接触过,不知道群发的思路是什么,看过一些别人的资料但我感觉有点深奥,头痛啊,因此恳请各位前辈前来帮助,问题一解决小弟马上散分,来者就有份吖!
思路,代码都行,欢迎前辈们指导!
有短信接口了?
如何调用的话应该有很详细的使用说明了吧
我以前做过的项目是用时代互联的短信接口,把开发接口包下下来,里面有很详细的使用说明。
你这里的群发是组群发吗? 我的思路是这样的:你可以先选一个组,然后在选择组里的成员(即手机号),再在文本框中输入短信的内容,点击发送就可以了啊。 其实短信发送不是真正的直接发到移动的网关的 ,中间需要一个就像你所说的猫,或者MAS(短信通道)。在短信平台中发短信就是将数据放到数据库中就好了。
1.将需要群发的内容录入数据库
2.设置表的一个字段,比如 send ,默认为0
3.select top 1 from table where send=0 order by id desc 访问一条未发送的记录
4.发送成功后,设置已发送的这条记录send为1
public partial class FormMain : CommonLib.FormBase
{
private SmsBase sms;
public FormMain()
{
InitializeComponent();
}
private void FormMain_Load(object sender, EventArgs e)
{
this.mobilePhones = new string[1]; //手机号码数组(目前只能装一个元素)
mobilePhones[0] = string.Empty;
tmr.Interval = Int32.Parse(FileConfig.GetConfigValue("TimerInterval")) * 1000;
int smsVersion = Int32.Parse(FileConfig.GetConfigValue("SmsVersion"));
switch (smsVersion)
{
case 1:
sms = new SmsV1();
break;
case 2:
sms = new SmsV2();
break;
default:
Common.MsgStop2(string.Format("未定义的短信接口版本[{0}]。", smsVersion));
sms = new SmsBase();
break;
}
}
private void ShowInfo(string info)
{
if (edInfo.Lines.Length > 2000)
edInfo.Text = string.Empty;
if (info != "")
edInfo.AppendText(DateTime.Now.ToString() + " " + info + "\r\n");
else
edInfo.AppendText("\r\n");
}
private void tmr_Tick(object sender, EventArgs e)
{
tmr.Enabled = false;
if (CheckSmsService())
{
if (Int32.Parse(FileConfig.GetConfigValue("SmsVersion")) == 2)// add by tansy 2010 7 29
{
RecSmsMessage();
SmsOperation();
SendSmsMessage();
}
if (Int32.Parse(FileConfig.GetConfigValue("SmsVersion")) == 1)
{
SendSmsMessage();
}
if (Int32.Parse(FileConfig.GetConfigValue("SmsVersion")) == 0)
{
return;
}
}
tmr.Enabled = true;
}
//检查短信接口工作是否正常
private bool CheckSmsService()
{
ShowInfo("检测短信接口......");
if(sms.CheckInterface())
{
ShowInfo("短信接口工作正常");
return true;
}
else
{
ShowInfo(sms.ErrInfo);
Common.WriteLog(sms.ErrInfo);
return false;
}
}
//发送短信
DataTable table = null;
int recID; //待发信息表记录ID
string[] mobilePhones; //手机号码数组(目前只能装一个元素)
string smsMessage; //待发的短信内容
private void SendSmsMessage()
{
//检索待发短信(发送失败次数超过3次的短信,将不再发送)
ShowInfo("检索待发短信......");
string commandText = @"SELECT * FROM SmsMessage WHERE SendTime IS NULL AND RetryTimes <= 3 and SendMessage <> ''"; //and SendMessage='"+string.Empty+"' ";
if (CommonDB.OpenSql(commandText, ref table) != MyConst.RET_OK)
{
ShowInfo("检索待发短信失败:" + CommonDB.ErrorInfo);
Common.WriteLog("检索待发短信失败:" + CommonDB.ErrorInfo);
return;
}
if (table.Rows.Count < 1)
{
ShowInfo("没有需要发送的短信");
return;
}
//循环发送待发短信
string msgInfo;
foreach (DataRow row in table.Rows)
{
recID = row.Field<int>("RecID");
this.mobilePhones[0] = row.Field<string>("MobilePhone").Trim();
this.smsMessage = row.Field<string>("SendMessage").Trim();
msgInfo = string.Format(@"[手机号] {0} [待发短信] {1}......", this.mobilePhones[0], this.smsMessage.Substring(0, 20));
//手机号或待发短信有一个为空,则跳过该待发记录
if (this.mobilePhones[0] == string.Empty || this.smsMessage == string.Empty)
{
ShowInfo(msgInfo + "跳过");
this.MarkOK();
continue;
}
//正式发送短信
if(sms.Send(this.mobilePhones, this.smsMessage))
{
ShowInfo(msgInfo + "成功");
this.MarkOK();
}
else
{
ShowInfo(msgInfo + "失败");
Common.WriteLog(sms.ErrInfo);
this.MarkFail();
}
}
}