我想发送批量短信 [英] I want send bulk sms

查看:104
本文介绍了我想发送批量短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用USB调制解调器发送批量短信。我喜欢将数字加载到文本框然后发送到所有数字。我编码一次发送单个短信。主要是发送批量短信。

我需要删除空格并分别选择数字并发送相同的短信给所有这些。



这是我写的发送单个短信的代码mobno,msg是文本框:

I want to send bulk sms using usb modem.I like to load numbers to textbox and and then send to all numbers.I coded to send single sms at a time.Main thing is to send bulk sms.
I need to remove white spaces and select numbers separately and send send same sms to all of them.

This is the code I wrote to send single sms mobno,msg are text boxes:

private void button1_Click(object sender, EventArgs e)
{
    try {

        SmsSubmitPdu pdu;
        byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
        pdu = new SmsSubmitPdu(msg.Text, mobno.Text, dcs);
        int times = 1;
        for (int i = 0; i < times; i++)
        {
            comm.SendMessage(pdu);
        }

        MessageBox.Show("Message sent sucessfully");
    } catch (Exception ex) {
        MessageBox.Show("Modem not avaliable");
    }


}



这是我的调制解调器加载概念:




here is my modem loading concept:

      private GsmCommMain comm;
     private delegate void SetTextCallback(string text);
     private SmsServer smsServer;

     TextBox txtmsg = new TextBox();
     TextBox txtno = new TextBox();


     private void button3_Click(object sender, EventArgs e)
     {
         if (comboBox1.Text == "")
         {
             MessageBox.Show("Invalied Port Name");
             return;
         }
         comm = new GsmCommMain(comboBox1.Text, 9600, 150);
         Cursor.Current = Cursors.Default;
         bool retry;
         do
         {
             retry = false;
             try
             {
                 Cursor.Current = Cursors.WaitCursor;
                 comm.Open();
                 Cursor.Current = Cursors.Default;
                 MessageBox.Show("Connect Successfully");
             }
             catch (Exception)
             {
                 Cursor.Current = Cursors.Default;
                 if (MessageBox.Show(this, "Modem not available", "Check", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry) retry = true;
                 { return; }
             }
         } while (retry);
     }

     private void sms_Load(object sender, EventArgs e)
     {
         comboBox1.Items.Add("Com1");
         comboBox1.Items.Add("Com2");
         comboBox1.Items.Add("Com3");
         comboBox1.Items.Add("Com4");
         comboBox2.Items.Add("Com1");
         comboBox2.Items.Add("Com2");
         comboBox2.Items.Add("Com3");
         comboBox2.Items.Add("Com4");

}

推荐答案

为什么使用调制解调器?如果您尝试以便宜的价格执行短信,请搜索电子邮件发送至文本 - Google搜索 [ ^ ]。基本上向包含< phonenumber> @< emailgateway>组成的SMS网关发送电子邮件。每个主要的细胞提供者都有其中之一。主要的缺点是无法收到回复。



或者如果你正在按照你的建议为公司做好工作,那么他们应该能够这个项目的资金很少。 Twilio - 用于文本消息传递的API,VoIP& amp;云中的语音 [ ^ ]提供了令人惊叹的.NET API,用于发送和接收SMS消息以及多媒体消息。



我不适用于Twilio,但是我将他的短信服务用于我运行的网站,这对于个人项目而言非常惊人且便宜。



Hogan
Why are you using a modem? If you're trying to perform SMS on the cheap, search email to text - Google Search[^]. Basically send an email to a SMS gateway that consists of <phonenumber>@<emailgateway>. Each major cell provider has one of these. The major drawback is not being able to receive replies.

Or if you're preforming the work for a company like you suggest, then they should be able to put a little money towards the project. Companies like Twilio - APIs for Text Messaging, VoIP & Voice in the Cloud[^] provide amazing .NET APIs for sending and receiving SMS messages along with multi-media messages.

I don't work for Twilio, but I use their SMS service for a website I run and it is amazing and cheap enough for a personal project.

Hogan


试试这个。



mono.Text应该包含所有具有空格分隔的数字。





Try this.

mono.Text should contains all numbers with whitespace separation.


private void button1_Click(object sender, EventArgs e)
{
    try {
          foreach(string varMobNo in mono.Text.split(' '))
           {
 
            SmsSubmitPdu pdu;
            byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
            pdu = new SmsSubmitPdu(msg.Text, varMobNo , dcs);
            int times = 1;
            for (int i = 0; i < times; i++)
            {
              comm.SendMessage(pdu);
            }
            }
        MessageBox.Show("Message sent sucessfully");
    } catch (Exception ex) {
        MessageBox.Show("Modem not avaliable");
    }
 

}


文本框是如何组织的?

它是多行的,数字是分开的,或是用分号分隔,还是什么?



tharukanc 22分钟前

每行一个号码




然后它们已经分开:多行TextBox有一个Lines属性,它返回每个单独的行作为数组中的单个字符串:

"How is the textbox organised?
Is it multiline and the numbers each on separate lines, or is are they separated by semicolons, or what?"

tharukanc 22 mins ago
"for each line one number"


Then they are already separated: a multiline TextBox has a Lines property which returns each separate line as a single string within an array:
string[] numbers = myTextBox.Lines;



您可以使用简单的 foreach 循环来处理每个循环,并为每个循环删除空间是微不足道的:


You can use a simple foreach loop to process each of them, and removing spaces for each is trivial:

foreach (string line in numbers)
   {
   string number = line.Replace(" ", "");
   ... send SMS to number using your working code.
   }


这篇关于我想发送批量短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆