如何在 C# 中使用 USB 调制解调器发送批量短信
本文关键字:调制解调器 USB | 更新日期: 2023-09-27 18:30:26
我已经成功编码为一次向一个手机号码发送短信,但我想批量发送。
我正在使用文本框来输入数字,我想在文本框中输入几个数字并发送到该文本框中的所有数字。
这是表单代码:
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并替换了mobno。数字项中的项旁边的文本。
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");
}
}