程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 短信貓相關問題,貓相關問題

短信貓相關問題,貓相關問題

編輯:C#入門知識

短信貓相關問題,貓相關問題


 【短信貓相關問題】

 

 

【getDeviceNameByRFID】的引用。注意

stringBuilder.Append(DbHelperSQL.getDeviceNameByRFID(dt.Rows[i]["RFID"].ToString())); //ToString()後面的()!!!

 

 

一系列配置

 

 

【短信貓SmsHelper】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace EquipMonitorConsole.DuanXinMao
{
    class SmsHelper
    {
        [STAThread]
        [DllImport("sms.dll", EntryPoint = "Sms_Connection")]
        public static extern uint Sms_Connection(string CopyRight, uint Com_Port, uint Com_BaudRate, out string Mobile_Type, out string CopyRightToCOM);//輸出變量out別動

        [DllImport("sms.dll", EntryPoint = "Sms_Disconnection")]
        public static extern uint Sms_Disconnection();

        [DllImport("sms.dll", EntryPoint = "Sms_Send")]
        public static extern uint Sms_Send(string Sms_TelNum, string Sms_Text);

        [DllImport("sms.dll", EntryPoint = "Sms_Receive")]
        public static extern uint Sms_Receive(string Sms_Type, out string Sms_Text);

        [DllImport("sms.dll", EntryPoint = "Sms_Delete")]
        public static extern uint Sms_Delete(string Sms_Index);

        [DllImport("sms.dll", EntryPoint = "Sms_AutoFlag")]
        public static extern uint Sms_AutoFlag();

        [DllImport("sms.dll", EntryPoint = "Sms_NewFlag")]
        public static extern uint Sms_NewFlag();


        public bool connectSmsAndSend(String tele_num, String content)
        {

            bool result = false;
            //1. 連接短信貓
            String TypeStr = "";
            String CopyRightToCOM = "";
            String CopyRightStr = "//上海迅賽信息技術有限公司,網址www.xunsai.com//";
            String com_port = "3";

            if (Sms_Connection(CopyRightStr, uint.Parse(com_port), 9600, out TypeStr, out CopyRightToCOM) == 1) ///5為串口號,0為紅外接口,1,2,3,...為串口
            {
                Console.WriteLine("連接成功!");
                Log.WriteLog(LogType.LogInfo, "連接成功!", true);
                if (Sms_Send(tele_num, content) == 1)
                {
                    Console.WriteLine("發送成功!");
                    Log.WriteLog(LogType.LogInfo, "發送成功!", true);
                    result = true;
                }
                else
                {
                    Console.WriteLine("發送失敗!");
                    Log.WriteLog(LogType.LogInfo, "發送失敗!", true);

                }
                Sms_Disconnection();


            }
            else
            {
                Console.WriteLine("連接失敗!");
                Log.WriteLog(LogType.LogInfo, "連接失敗!", true);
            }
            return result;
        }
    }
}

 

【短信貓DuanXinMao】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EquipMonitorConsole.DuanXinMao
{
    public class DuanXinMaotest
    {
        public static string EnableFlag;
        public static string Receivemobiles;
        public static bool hasSendOneSMS=false;
        string[] arrays = Receivemobiles.Split(';');
        public void DuanXinMaofun(String smsContent)   //public static void DuanXinMaofun()
        {
            SmsHelper smshelper = new SmsHelper();
            for (int i = 0; i < arrays.Length; i++)
            {
                if (arrays[i].Equals("15601596871"))
                {
                    if (!hasSendOneSMS)
                    {
                        smshelper.connectSmsAndSend(arrays[i], smsContent);
                        hasSendOneSMS = true;
                        Log.WriteLog(LogType.LogInfo, "已發送一條短信:收件人:"+arrays[i]+" 內容:"+smsContent, true);
                    }
                }
                else {
                    smshelper.connectSmsAndSend(arrays[i], smsContent);
                    Log.WriteLog(LogType.LogInfo, "已發送一條短信:收件人:" + arrays[i] + " 內容:" + smsContent, true);
                }

                
                
            }

        }
    }
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved