联通SGIP协议C#源代码

完整版...

 

 

 

SGIP_C#源代码  

 

 

注:

      1、下载后请把sgip.gif的后缀名改为RAR***(作废)

      2、数据库设计请在我的blog里面找《联通短信网关(SGIP 1.2) 数据库设计脚本

      2、 原版的代码请到dzend.com里去下载,这里的代码有修改!!

 

config.xml  配置文件!

-------------------------

<?xml version="1.0" encoding="utf-8" ?>
<config>
  <config1>
    <ip></ip>
    <port>1433</port>
  </config1>
  <config2>
    <ip>192.168.13.20</ip>
    <port>1433</port>
    <sid>xsb</sid>
    <user>sa</user>
    <pass>screen</pass>
  </config2>
  <config3>
    <ip>127.0.0.1</ip>
    <port>8801</port>
    <user>test</user>
    <pass>test</pass>
    <spcode>3028071970</spcode>
    <areacode>0280</areacode>
  </config3>
  <config4>
    <ip>127.0.0.1</ip>
    <port>8802</port>
    <user>test</user>
    <pass>test</pass>
  </config4>
  <config5>
    <xlspath>D:/upLoad_xls/</xlspath>
    <noSearchNoBackInfo>true</noSearchNoBackInfo>
    <sheetname>sms</sheetname>
    <RestartTimerSpan>1000</RestartTimerSpan>
    <SmsFlagSolution>2</SmsFlagSolution>   
    <WindowServerReSpan>10000</WindowServerReSpan>
  </config5>
</config>

 

测试代码  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
    {
        /// <summary>
        /// 数据库的IP地址
        /// </summary>
        public static string DB_IP = "";
        /// <summary>
        /// 数据的端口
        /// </summary>
        public static int DB_PORT = 1433;
        /// <summary>
        /// 数据库名称
        /// </summary>
        public static string DB_NAME = "";
        /// <summary>
        /// 数据库的登录名
        /// </summary>
        public static string DB_USERNAME = "";
        /// <summary>
        /// 数据库的密码
        /// </summary>
        public static string DB_PASSWORD = "";
        /// <summary>
        /// 短信中心的短信网关地址
        /// </summary>
        public static string SMG_IP = "";
        /// <summary>
        /// 短信中心短信网关的端口
        /// </summary>
        public static int SMG_PORT = 8802;
        /// <summary>
        /// 短信中心短信网关的登录用户
        /// </summary>
        public static string SMG_USER = "";
        /// <summary>
        /// 短信中心短信网关的登录密码
        /// </summary>
        public static string SMG_PASS = "";
        /// <summary>
        /// 企业代码
        /// </summary>
        public static string SMG_SPCODE = "";
        /// <summary>
        /// 区号
        /// </summary>
        public static string SMG_AREACODE = "";
        /// <summary>
        /// SP端监听地址
        /// </summary>
        public static string SP_IP = "";
        /// <summary>
        /// SP端监听端口
        /// </summary>
        public static int SP_PORT = 8801;
        /// <summary>
        /// SP端登录用户
        /// </summary>
        public static string SP_USER = "";
        /// <summary>
        /// SP端登录密码
        /// </summary>
        public static string SP_PASS = "";
        /// <summary>
        /// 短信查询方案Excel存放的根目录
        /// </summary>
        private string XlsPath = "";
        /// <summary>
        /// 短信查询方案时,无信息是否反馈信息提示
        /// </summary>
        private string noSearchNoBackInfo = "true";
        /// <summary>
        /// 短信查询方案Excel模板工作簿名
        /// </summary>
        private string sheetname = "";
        /// <summary>
        /// 网络异常时服务重启时间间隔, -1表示不重启
        /// </summary>
        private int RestartTimerSpan = -1;

        /// <summary>
        /// 短信发送标记更新方案,-1表示发送前就更新
        /// </summary>
        private int SmsFlagSolution = -1;
        private Logic m_Logic;
        private DBClass m_DB;
        public mainForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 重载系统关闭窗口事件
        /// </summary>
        /// <param name="m"></param>
        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 初始化
        /// <summary>
        /// 初始化
        /// </summary>
        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 = "";
            }
        }

        #region ' 短信查询服务 '
        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
    }
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值