联通SGIP协议C#源代码
完整版...

SGIP_C#源代码
注:
1、下载后请把sgip.gif的后缀名改为RAR***(作废)
2、数据库设计请在我的blog里面找《联通短信网关(SGIP 1.2) 数据库设计脚本 》
2、 原版的代码请到dzend.com里去下载,这里的代码有修改!!
config.xml 配置文件!
-------------------------
测试代码 Form1.cs
--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeywaySoft.Public.SGIP;
using System.Diagnostics;
using System.Xml;
using System.IO;
using KeywaySoft.Public.SGIP.DataBase;
using System.Threading;
namespace 中国联通
{
public partial class mainForm : Form
{
///
/// 数据库的IP地址
///
public static string DB_IP = "";
///
/// 数据的端口
///
public static int DB_PORT = 1433;
///
/// 数据库名称
///
public static string DB_NAME = "";
///
/// 数据库的登录名
///
public static string DB_USERNAME = "";
///
/// 数据库的密码
///
public static string DB_PASSWORD = "";
///
/// 短信中心的短信网关地址
///
public static string SMG_IP = "";
///
/// 短信中心短信网关的端口
///
public static int SMG_PORT = 8802;
///
/// 短信中心短信网关的登录用户
///
public static string SMG_USER = "";
///
/// 短信中心短信网关的登录密码
///
public static string SMG_PASS = "";
///
/// 企业代码
///
public static string SMG_SPCODE = "";
///
/// 区号
///
public static string SMG_AREACODE = "";
///
/// SP端监听地址
///
public static string SP_IP = "";
///
/// SP端监听端口
///
public static int SP_PORT = 8801;
///
/// SP端登录用户
///
public static string SP_USER = "";
///
/// SP端登录密码
///
public static string SP_PASS = "";
///
/// 短信查询方案Excel存放的根目录
///
private string XlsPath = "";
///
/// 短信查询方案时,无信息是否反馈信息提示
///
private string noSearchNoBackInfo = "true";
///
/// 短信查询方案Excel模板工作簿名
///
private string sheetname = "";
///
/// 网络异常时服务重启时间间隔, -1表示不重启
///
private int RestartTimerSpan = -1;
///
/// 短信发送标记更新方案,-1表示发送前就更新
///
private int SmsFlagSolution = -1;
private Logic m_Logic;
private DBClass m_DB;
public mainForm()
{
InitializeComponent();
}
///
/// 重载系统关闭窗口事件
///
///
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
{
// Hide();
return;
}
base.WndProc(ref m);
}
private void button5_Click(object sender, EventArgs e)
{
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private void button1_Click(object sender, EventArgs e)
{
Initialization();
StartLogic();
}
private void StartLogic()
{
m_Logic = new Logic();
m_Logic.DB_IP = DB_IP;
m_Logic.DB_PORT = DB_PORT;
m_Logic.DB_NAME = DB_NAME;
m_Logic.DB_USERNAME = DB_USERNAME;
m_Logic.DB_PASSWORD = DB_PASSWORD;
m_Logic.SMG_IP = SMG_IP;
m_Logic.SMG_PORT = SMG_PORT;
m_Logic.SMG_USER = SMG_USER;
m_Logic.SMG_PASS = SMG_PASS;
m_Logic.SMG_SPCODE = SMG_SPCODE;
m_Logic.SMG_AREACODE = SMG_AREACODE;
m_Logic.SP_IP = SP_IP;
m_Logic.SP_PORT = SP_PORT;
m_Logic.SP_USER = SP_USER;
m_Logic.SP_PASS = SP_PASS;
m_Logic.SmsFlagSolution = SmsFlagSolution;
m_Logic.AddTextEvent += AddTextEvent;
m_Logic.SmsResearchEvent += new KeywaySoft.Public.SGIP.Base.SmsResearchDelegate(m_Logic_SmsResearchEvent);
m_Logic.StartEvent += StartEvent;
m_Logic.StopEvent += StopEvent;
m_Logic.Initialization();
m_Logic.Start();
}
private void button2_Click(object sender, EventArgs e)
{
m_Logic.Stop();
}
private void StartEvent()
{
SetButtonEnabled(button2, true);
SetButtonEnabled(button1, false);
}
private void StopEvent()
{
if (RestartTimerSpan > -1)
{
Thread.Sleep(RestartTimerSpan);
StartLogic();
}
else
{
SetButtonEnabled(button1, true);
SetButtonEnabled(button2, false);
}
}
private delegate void SetButtonEnabledDelegate(Button bt, bool b);
private void SetButtonEnabled(Button bt, bool b)
{
if (InvokeRequired)
{
Invoke(new SetButtonEnabledDelegate(SetButtonEnabled), new object[] { bt, b });
}
else
{
bt.Enabled = b;
}
}
private void AddTextEvent(string cont)
{
if (InvokeRequired)
{
Invoke(new KeywaySoft.Public.SGIP.Base.AddTextDelegate(AddTextEvent), cont);
}
else
{
if (this.listBox1.Items.Count > 200)
this.listBox1.Items.Clear();
listBox1.Items.Add(cont);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}
}
private void mainForm_Load(object sender, EventArgs e)
{
label1.BackColor = Color.Transparent;
label2.BackColor = Color.Transparent;
label3.BackColor = Color.Transparent;
label4.BackColor = Color.Transparent;
}
private void button3_Click(object sender, EventArgs e)
{
SetConfigForm frm = new SetConfigForm();
frm.ShowDialog();
}
#region 初始化
///
/// 初始化
///
public void Initialization()
{
XmlDocument xml = new XmlDocument();
xml.Load(Application.StartupPath + "/config.xml");
StringReader read = new StringReader(xml.SelectSingleNode("config").OuterXml);
DataSet ds = new DataSet();
ds.ReadXml(read);
DB_IP = ds.Tables[1].Rows[0]["ip"].ToString();
try
{
DB_PORT = int.Parse(ds.Tables[1].Rows[0]["port"].ToString());
}
catch
{
DB_PORT = 1433;
}
DB_NAME = ds.Tables[1].Rows[0]["sid"].ToString();
DB_USERNAME = ds.Tables[1].Rows[0]["user"].ToString();
DB_PASSWORD = ds.Tables[1].Rows[0]["pass"].ToString();
SMG_IP = ds.Tables[2].Rows[0]["ip"].ToString();
try
{
SMG_PORT = int.Parse(ds.Tables[2].Rows[0]["port"].ToString());
}
catch
{
SMG_PORT = 8801;
}
SMG_USER = ds.Tables[2].Rows[0]["user"].ToString();
SMG_PASS = ds.Tables[2].Rows[0]["pass"].ToString();
SMG_SPCODE = ds.Tables[2].Rows[0]["spcode"].ToString();
SMG_AREACODE = ds.Tables[2].Rows[0]["areacode"].ToString();
SP_IP = ds.Tables[3].Rows[0]["ip"].ToString();
try
{
SP_PORT = int.Parse(ds.Tables[3].Rows[0]["port"].ToString());
}
catch
{
SP_PORT = 8801;
}
SP_USER = ds.Tables[3].Rows[0]["user"].ToString();
SP_PASS = ds.Tables[3].Rows[0]["pass"].ToString();
XlsPath = ds.Tables[4].Rows[0]["xlspath"].ToString();
noSearchNoBackInfo = ds.Tables[4].Rows[0]["noSearchNoBackInfo"].ToString();
sheetname = ds.Tables[4].Rows[0]["sheetname"].ToString();
RestartTimerSpan = Convert.ToInt32(ds.Tables[4].Rows[0]["RestartTimerSpan"].ToString());
SmsFlagSolution = Convert.ToInt32(ds.Tables[4].Rows[0]["SmsFlagSolution"].ToString());
}
#endregion
private void timer1_Tick(object sender, EventArgs e)
{
label3.Text = Logic.SendMTCount.ToString();
label4.Text = Logic.RecvMOCount.ToString();
}
private void button6_Click(object sender, EventArgs e)
{
m_DB = new DBClass(DB_IP, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
if (m_DB.CheckSQLConnect())
{
string sql = string.Format("exec sp_SendSMS_Simple {0},'{1}'", this.tbPhone.Text.Trim(), this.tbMSG.Text.Trim());
m_DB.ExeSQL(sql);
this.tbMSG.Text = "";
this.tbPhone.Text = "";
}
}
private void button5_Click_1(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
private void button7_Click(object sender, EventArgs e)
{
m_DB = new DBClass(DB_IP, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
if (m_DB.CheckSQLConnect())
{
string sql = string.Format("exec sp_SendSMS_Simple {0},'{1}'", this.tbPhone.Text.Trim(), this.tbMSG.Text.Trim());
m_DB.ExeSQL(sql);
this.tbMSG.Text = "";
this.tbPhone.Text = "";
}
}
private void m_Logic_SmsResearchEvent(string number, string cont)
{
if (m_DB == null)
m_DB = new DBClass(DB_IP, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
if (m_DB.CheckSQLConnect())
{
// 手机号 查询内容 xls根目录
try
{
string sql = string.Format(" SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON SET ANSI_WARNINGS ON exec sp_sms_Research '{0}','{1}','{2}', '{3}', '{4}'", number, cont, XlsPath, noSearchNoBackInfo, sheetname);
m_DB.ExeSQL(sql);
}
catch(Exception ex)
{
AddTextEvent(ex.Message);
}
}
}
#endregion
}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
