如何在 C# 中使用 usb 调制解调器发送群发短信

How to send bulk sms using usb modem in C#

我已经成功编码为一次向一个手机号码发送短信,但我想批量发送。

我正在使用文本框输入号码我想在文本框中输入几个数字并发送到该文本框中的所有号码。

表单代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using GsmComm.PduConverter;
using GsmComm.PduConverter.SmartMessaging;
using GsmComm.GsmCommunication;
using GsmComm.Interfaces;
using GsmComm.Server;
using System.Globalization;
using System.Text.RegularExpressions;
using MySql.Data.MySqlClient;

namespace yahapalana_DB
{
    public partial class sms : Form
    {
        public sms()
        {
            InitializeComponent();
        }

        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");
        }

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

                string[] slist = text.Split(':');
                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(textmsg.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");
            }  
        }

        private void button2_Click(object sender, EventArgs e)
        {

            add_number au = new add_number();
            au.ShowDialog();
        }
    }
}

嗯,您正在从文本框中拆分字符串,但您从未使用过它。我已经通过 foreach 扩展了您的 for,并将 mobno.Text 替换为数字项目中的项目。

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

            string[] slist = text.Split(':');

            foreach (string mobno in slist) {
                SmsSubmitPdu pdu;
                byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
                pdu = new SmsSubmitPdu(textmsg.Text,mobno,dcs);
                int times = 1;

                comm.SendMessage(pdu);
            }

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