C#檢測有線電話來電號碼實現來電彈屏的實現方法

來源:互聯網
上載者:User

標籤:option   連接埠號碼   .net   client   component   []   eve   ast   行業   

在我們的程式開發中,有些行業用到有線電話的來電彈屏,而C#作為微軟的一個重要開發工具,應用廣泛,本代碼實現了C#調用DLL實現來電彈屏(以中盛有線電話來電顯示盒為例,該盒子穩定可靠,編程簡單)。

 

using ServiceDesk;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net;using System.Net.Sockets;using System.Runtime.InteropServices;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WinF{    public partial class Form1 : Form    {
      //最關鍵的是下面4行調用DLL的聲明 [DllImport("ZSCIDUDP.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZSCIDInit")] public static extern int ZSCIDInit(string AUDPS_IP, int AUDPS_Port, bool AIsSendState); [DllImport("ZSCIDUDP.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZSCIDFree")] public static extern void ZSCIDFree(int ARef); public int laidianCount { get; set; } public int FRef { get; set; } public void zsinit() { FRef = ZSCIDInit("127.0.0.1", 9013, false);//第一個參數是來電後要發到UDP監聽的IP,第二個參數是UDP監聽的連接埠號碼 } public void zsfree() { if (FRef > 0) { ZSCIDFree(FRef); FRef = 0; } } public Form1() { InitializeComponent(); UdpLisenter(); //這裡實現UDP監聽 } private void Form1_Load(object sender, EventArgs e) { zsinit(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { free(); } private void btn_init_Click(object sender, EventArgs e) { init(); } private void btn_free_Click(object sender, EventArgs e) { free(); } void init() { try { zsinit(); btn_free.Enabled = true; btn_init.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "ZSCIDInit異常"); } finally { txt_FRef.AppendText("初始化【FRef=" + FRef + "】" + Environment.NewLine); } } void free() { try { txt_FRef.AppendText("釋放前【FRef=" + FRef + "】" + Environment.NewLine); zsfree(); btn_free.Enabled = false; btn_init.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ZSCIDFree異常"); } finally { txt_FRef.AppendText("釋放後【FRef=" + FRef + "】" + Environment.NewLine); } } void StateHandler(string data) { txt_state.AppendText(data.ToString() + Environment.NewLine); } private void UdpLisenter() { Task.Factory.StartNew(() => { int updPort = 9013; UdpClient listener = new UdpClient(updPort); listener.DontFragment = true; listener.EnableBroadcast = true; IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Loopback, updPort); while (true) { try { byte[] bytes = listener.Receive(ref RemoteIpEndPoint); string data = System.Text.Encoding.Default.GetString(bytes); string PhoneNumber = getnum(data); writelog(PhoneNumber); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness); } string getnum(string data) { string PhoneNumber = ""; if (!string.IsNullOrWhiteSpace(data)) { string[] strs = data.Split(new string[] { "\r\n" }, StringSplitOptions.None); foreach (string k in strs) { string[] tttmp = k.Split(‘=‘); if (tttmp.Length > 1 && tttmp[0] == "NUM") PhoneNumber = tttmp[1]; } } return PhoneNumber; } void writelog(string number) { if (!string.IsNullOrWhiteSpace(number)) { txt_udprecieve.AppendText("[" + laidianCount++ + "]: " + number + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine); LaidianWriter wer = new LaidianWriter(); wer.Push(number); } } } }

 

C#檢測有線電話來電號碼實現來電彈屏的實現方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.