分享一个某公司的短信接口

                                                                                                                                                                                                          

如果朋友需要的话可以找我要DLL

 

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;



/// <summary>
/// SmS :  的摘要说明
/// 作者:  苏飞
/// 地点:  
/// 时间:  2009年9月15日
/// </summary>
public class SmS
{
    
/// <summary>
    
/// 短信接口
    
/// </summary>
    public SmS() { }
    
/// <summary>
    
/// -----------------------------即时发送--------------------------------------
    
/// 
    
///  这里是软件序列号    手机号       短信内容     优先级
    
///  int result=SendSMS(textBox1.Text,textBox6.Text,textBox5.Text,textBox16.Text);
    
///  if(result==1)
    
///      MessageBox.Show("发送成功" );
    
///  else if(result==101)
    
///      MessageBox.Show("网络故障" );
    
///  else if(result==102)
    
///      MessageBox.Show("其它故障" );
    
///  else if(result==0)
    
///      MessageBox.Show("失败" );
    
///  else if(result==100)
    
///      MessageBox.Show("序列号码为空或无效" );
    
///  else if(result==107)
    
///      MessageBox.Show("手机号码为空或者超过1000个" );
    
///  else if(result==108)
    
///      MessageBox.Show("手机号码分割符号不正确" );
    
///  else if(result==109)
    
///      MessageBox.Show("部分手机号码不正确,已删除,其余手机号码被发送" );
    
///  else if(result==110)
    
///      MessageBox.Show("短信内容为空或超长(70个汉字)" );
    
///  else if(result==201)
    
///      MessageBox.Show("计费失败,请充值" );
    
///  else if(result==-1)
    
///      MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="sn">这里是软件序列号</param>
    
/// <param name="mn">手机号  多个手机号用逗号分隔</param>
    
/// <param name="ct"> 短信内容 </param>
    
/// <param name="priority">优先级</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "SendSMS")]
    
private static extern int SendSMS(string sn, string mn, string ct, string priority);

    
/// <summary>
    
/// --------------------------------即时发送(扩展)---------------------------------
    
/// 
    
///    即时发送(扩展)   这里是软件序列号  手机号       短信内容      附加号        优先级
    
///    int result=SendSMSEx(textBox1.Text,textBox6.Text,textBox5.Text,textBox8.Text,textBox16.Text);
    
///    if(result==1)
    
///        MessageBox.Show("发送成功" );
    
///    else if(result==101)
    
///        MessageBox.Show("网络故障" );
    
///    else if(result==102)
    
///        MessageBox.Show("其它故障" );
    
///    else if(result==0)
    
///        MessageBox.Show("失败" );
    
///    else if(result==100)
    
///        MessageBox.Show("序列号码为空或无效" );
    
///    else if(result==107)
    
///        MessageBox.Show("手机号码为空或者超过1000个" );
    
///    else if(result==108)
    
///        MessageBox.Show("手机号码分割符号不正确" );
    
///    else if(result==109)
    
///        MessageBox.Show("部分手机号码不正确,已删除,其余手机号码发送成功" );
    
///    else if(result==110)
    
///        MessageBox.Show("短信内容为空或超长(70个汉字)" );
    
///    else if(result==111)
    
///        MessageBox.Show("附加号码过长(8位)" );
    
///    else if(result==201)
    
///        MessageBox.Show("计费失败,请充值" );
    
///    else if(result==-1)
    
///        MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="sn">这里是软件序列号</param>
    
/// <param name="mn">手机号  多个手机号用逗号分隔</param>
    
/// <param name="mn">手机号 </param>
    
/// <param name="ct">短信内容</param>
    
/// <param name="addi">附加号</param>
    
/// <param name="priority">优先级</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "SendSMSEx")]
    
private static extern int SendSMSEx(string sn, string mn, string ct, string addi, string priority);

    
/// <summary>
    
/// -----------------------------------定时发送------------------------------------------
    
/// 
    
///  //定时发送        这里是软件序列号      手机号      短信内容      发送时间     优先级
    
///  int result=SendScheSMS(textBox1.Text,textBox6.Text,textBox5.Text,textBox7.Text,textBox16.Text);
    
///  if(result==1)
    
///      MessageBox.Show("发送成功");
    
///  else if(result==101)
    
///      MessageBox.Show("网络故障" );
    
///  else if(result==102)
    
///      MessageBox.Show("其它故障" );
    
///  else if(result==0)
    
///      MessageBox.Show("失败" );
    
///  else if(result==100)
    
///      MessageBox.Show("序列号码为空或无效" );
    
///  else if(result==107)
    
///      MessageBox.Show("手机号码为空或者超过1000个" );
    
///  else if(result==108)
    
///      MessageBox.Show("手机号码分割符号不正确" );
    
///  else if(result==109)
    
///      MessageBox.Show("部分手机号码不正确,已删除,其余手机号码发送成功" );
    
///  else if(result==110)
    
///      MessageBox.Show("短信内容为空或超长(70个汉字)" );
    
///  else if(result==112)
    
///      MessageBox.Show("定时时间为空或格式不正确" );
    
///  else if(result==201)
    
///      MessageBox.Show("计费失败,请充值" );
    
///  else if(result==-1)
    
///      MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="sn">这里是软件序列号</param>
    
/// <param name="mn">手机号  多个手机号用逗号分隔</param>
    
/// <param name="mn">手机号 </param>
    
/// <param name="ct">短信内容</param>
    
/// <param name="ti">发送时间 格式:(yyyymmddhhnnss)20050415173000</param>
    
/// <param name="priority">优先级</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "SendScheSMS")]
    
private static extern int SendScheSMS(string sn, string mn, string ct, string ti, string priority);

    
/// <summary>
    
///---------------------------------定时发送(扩展)----------------------------------------
    
/// <example >
    
///  //定时发送(扩展)      这里是软件序列号      手机号      短信内容      发送时间        附加号   优先级
    
///  int result=SendScheSMSEx(textBox1.Text,textBox6.Text,textBox5.Text,textBox7.Text,textBox8.Text,textBox16.Text);
    
///  if(result==1)
    
///      MessageBox.Show("发送成功");
    
///  else if(result==101)
    
///      MessageBox.Show("网络故障" );
    
///  else if(result==102)
    
///      MessageBox.Show("其它故障" );
    
///  else if(result==0)
    
///      MessageBox.Show("失败" );
    
///  else if(result==100)
    
///      MessageBox.Show("序列号码为空或无效" );
    
///  else if(result==107)
    
///      MessageBox.Show("手机号码为空或者超过1000个" );
    
///  else if(result==108)
    
///      MessageBox.Show("手机号码分割符号不正确" );
    
///  else if(result==109)
    
///      MessageBox.Show("部分手机号码不正确,已删除,其余手机号码发送成功" );
    
///  else if(result==110)
    
///      MessageBox.Show("短信内容为空或超长(70个汉字)" );
    
///  else if(result==111)
    
///      MessageBox.Show("附加号码过长(8位)" );
    
///  else if(result==112)
    
///      MessageBox.Show("定时时间为空或格式不正确" );
    
///  else if(result==201)
    
///      MessageBox.Show("计费失败" );
    
///  else if(result==-1)
    
///      MessageBox.Show("未知故障" );
    
/// </example>        
    
/// </summary>
    
/// <param name="sn">这里是软件序列号</param>
    
/// <param name="mn">手机号  多个手机号用逗号分隔</param>
    
/// <param name="mn">手机号  </param>
    
/// <param name="ct">短信内容</param>
    
/// <param name="ti">发送时间</param>
    
/// <param name="addi">附加号</param>
    
/// <param name="priority">优先级</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "SendScheSMSEx")]
    
private static extern int SendScheSMSEx(string sn, string mn, string ct, string ti, string addi, string priority);

    
/// <summary>
    
/// ------------------------------------接收短信---------------------------------------
    
/// 
    
///   deleSQF mySmsContent = new deleSQF(getSMSContent);
    
///   //接收短信                序列号       函数指针
    
///   int result = 2;
    
///   while(result == 2)  //当result = 2 时,说明还有下一批短信等待接收,这时需重新再调用一次ReceiveSMS方法
    
///   {
    
///       result    =ReceiveSMS(textBox1.Text,mySmsContent);
    
///       if(result==1)
    
///           MessageBox.Show("接收短信成功");
    
///       else if(result==101)
    
///           MessageBox.Show("网络故障" );
    
///       else if(result==102)
    
///           MessageBox.Show("其它故障" );
    
///       else if(result==105)
    
///           MessageBox.Show("参数指针为空" );
    
///       else if(result==0)
    
///           MessageBox.Show("失败" );
    
///       else if(result==-1)
    
///           MessageBox.Show("未知故障" );
    
///   }
    
/// </summary>
    
/// <param name="sn"> 序列号</param>
    
/// <param name="mySmsContent">函数指针</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "ReceiveSMS")]
    
private static extern int ReceiveSMS(string sn, deleSQF mySmsContent);

    
/// <summary>
    
///------------------------------------接收短信(扩展)---------------------------------------
    
/// 
    
////    deleSQF mySmsContent = new deleSQF(getSMSContent);
    
////         //接收短信(扩展)             序列号     函数指针
    
////         int result= 2;            
    
////         while(result == 2) //当result = 2 时,说明还有下一批短信等待接收,这时需重新再调用一次ReceiveSMSEx方法
    
////         {      
    
////             result = ReceiveSMSEx(textBox1.Text,mySmsContent);
    
////             if(result==1)
    
////                 MessageBox.Show("接收短信成功");
    
////             else if(result==101)
    
////                 MessageBox.Show("网络故障" );
    
////             else if(result==102)
    
////                 MessageBox.Show("其它故障" );
    
////             else if(result==105)
    
////                 MessageBox.Show("参数指针为空" );
    
////             else if(result==0)
    
////                 MessageBox.Show("失败" );
    
////             else if(result==-1)
    
////                 MessageBox.Show("未知故障" );
    
////         }
    
/// </summary>
    
/// <param name="sn">序列号</param>
    
/// <param name="mySmsContent">函数指针</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "ReceiveSMSEx")]  // 接收短信
    private static extern int ReceiveSMSEx(string sn, deleSQF mySmsContent);


    [DllImport(
"EUCPComm.dll", EntryPoint = "ReceiveStatusReport")]  // 接收短信报告
    private static extern int ReceiveStatusReport(string sn, delegSMSReport mySmsReport);

    [DllImport(
"EUCPComm.dll", EntryPoint = "ReceiveStatusReportEx")]  // 接收短信报告(带批量ID)
    private static extern int ReceiveStatusReportEx(string sn, delegSMSReportEx mySmsReportEx);


    
/// <summary>
    
///  -------------------------------------注册----------------------------------------------- 
    
/// 
    
///          //注册               序列号        密码 
    
///         int result=Register(textBox1.Text,textBox2.Text,"1","1","1","1","1","1","1","1");
    
///         if(result==1)
    
///             MessageBox.Show("注册成功" );
    
///         else if(result==101)
    
///             MessageBox.Show("网络故障" );
    
///         else if(result==102)
    
///             MessageBox.Show("其它故障" );
    
///         else if(result==0)
    
///             MessageBox.Show("失败" );
    
///         else if(result==100)
    
///             MessageBox.Show("序列号码为空或无效" );
    
///         else if(result==103)
    
///             MessageBox.Show("注册企业基本信息失败,当软件注册号码注册成功,但整体还是失败,要重新注册" );
    
///         else if(result==104)
    
///             MessageBox.Show("注册信息填写不完整" );
    
///         else if(result==114)
    
///             MessageBox.Show("得到标识错误" );
    
///         else if(result==-1)
    
///             MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="sn">序列号</param>
    
/// <param name="pwd">密码</param>
    
/// <param name="EntName">用户名名</param>
    
/// <param name="LinkMan">联系人</param>
    
/// <param name="Phone">电话</param>
    
/// <param name="Mobile">手机号</param>
    
/// <param name="Email">Email</param>
    
/// <param name="Fax"></param>
    
/// <param name="sAddress">地址</param>
    
/// <param name="Postcode"></param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "Register")]
    
private static extern int Register(string sn, string pwd, string EntName, string LinkMan, string Phone, string Mobile, string Email, string Fax, string sAddress, string Postcode);

    
/// <summary>
    
/// -----------------------------------------余额----------------------------------------------------- 
    
/// 
    
///      System.Text.StringBuilder balance = new System.Text.StringBuilder(10);
    
///        //得到余额            注册号         余额
    
///        int result=GetBalance(textBox1.Text, balance);
    
///        string mybalance = balance.ToString(0,balance.Length-2);
    
///        if(result==1)
    
///            MessageBox.Show(balance + "元");
    
///        else if(result==101)
    
///            MessageBox.Show("网络故障" );
    
///        else if(result==102)
    
///            MessageBox.Show("其它故障" );
    
///        else if(result==100)
    
///            MessageBox.Show("序列号码为空或无效" );
    
///        else if(result==105)
    
///            MessageBox.Show("参数balance指针为空" );
    
///        else if(result==0)
    
///            MessageBox.Show("失败" );
    
///        else if(result==-1)
    
///            MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="m">注册号 </param>
    
/// <param name="balance"> 余额</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "GetBalance", CallingConvention = CallingConvention.Winapi)]
    
private static extern int GetBalance(string m, System.Text.StringBuilder balance);

    [DllImport(
"EUCPComm.dll", EntryPoint = "ChargeUp")]  // 存值
    private static extern int ChargeUp(string sn, string acco, string pass);

    [DllImport(
"EUCPComm.dll", EntryPoint = "GetPrice")]  // 价格
    private static extern int GetPrice(string m, System.Text.StringBuilder balance);

    [DllImport(
"EUCPComm.dll", EntryPoint = "RegistryTransfer")]  //申请转接
    private static extern int RegistryTransfer(string sn, string mn);

    [DllImport(
"EUCPComm.dll", EntryPoint = "CancelTransfer")]  // 注销转接
    private static extern int CancelTransfer(string sn);

    
/// <summary>
    
/// ----------------------------------注销序列号----------------------------------  
    
/// 
    
///         //注销序列号            注册号
    
///         int result=UnRegister(textBox1.Text);
    
///         if(result==1)
    
///             MessageBox.Show("注销成功");
    
///         else if(result==101)
    
///             MessageBox.Show("网络故障" );
    
///         else if(result==102)
    
///             MessageBox.Show("其它故障" );
    
///         else if(result==0)
    
///             MessageBox.Show("失败" );
    
///         else if(result==100)
    
///             MessageBox.Show("序列号码为空或无效" );
    
///         else if(result==-1)
    
///             MessageBox.Show("未知故障" );
    
/// </summary>
    
/// <param name="sn">注册号</param>
    
/// <returns>返回一个整型</returns>
    [DllImport("EUCPComm.dll", EntryPoint = "UnRegister")]  // 注销
    private static extern int UnRegister(string sn);

    [DllImport(
"EUCPComm.dll", EntryPoint = "SetProxy")]  // 设置代理服务器 
    private static extern int SetProxy(string IP, string Port, string UserName, string PWD);

    [DllImport(
"EUCPComm.dll", EntryPoint = "RegistryPwdUpd")]  // 修改序列号密码
    private static extern int RegistryPwdUpd(string sn, string oldPWD, string newPWD);

    
//回调(接收短信)
    private static void getSMSContent(string mobile, string senderaddi, string recvaddi, string ct, string sd, ref int flag)
    {
        
string mob = mobile;
        
string content = ct;
        
int myflag = flag;
        JavascriptHelp.Alert(mob 
+ "----" + content);
    }


    
private delegate void deleSQF(string mobile, string senderaddi, string recvaddi, string ct, string sd, ref int flag);
    deleSQF mySmsContent 
= new deleSQF(getSMSContent);

    
//回调(接收状态报告)
    private static void getSMSReport(string mobile, string errorCode, string serviceCodeAdd, string reportType, ref int flag)
    {
        
string mob = mobile;
        
int myflag = flag;
    }
    
private delegate void delegSMSReport(string mobile, string errorCode, string serviceCodeAdd, string reportType, ref int flag);
    delegSMSReport mySmsReport 
= new delegSMSReport(getSMSReport);

    
//回调(接收状态报告)带批量ID
    private static void getSMSReportEx(ref long seq, string mobile, string errorCode, string serviceCodeAdd, string reportType, ref int flag)
    {
        
string mob = mobile;
        
int myflag = flag;
    }
    
private delegate void delegSMSReportEx(ref long seq, string mobile, string errorCode, string serviceCodeAdd, string reportType, ref int flag);
    delegSMSReportEx mySmsReportEx 
= new delegSMSReportEx(getSMSReportEx);



    
//-------------------------------------------------------------公共使用的方法-----------------------------------------------------------------------

    
/// <summary>
    
/// 注册     先注册再使用在发送短信之前先注册,即先调用这个方法
    
/// </summary>
    private static void Register()
    {
        
try
        {
            
//注册               序列号        密码 
            int result = Register("0SDK-EMY""848""1""1""1""1""1""1""1""1");
            
if (result == 1)
                JavascriptHelp.Alert(
"注册成功");
            
else if (result == 101)
                JavascriptHelp.Alert(
"网络故障");
            
else if (result == 102)
                JavascriptHelp.Alert(
"其它故障");
            
else if (result == 0)
                JavascriptHelp.Alert(
"失败");
            
else if (result == 100)
                JavascriptHelp.Alert(
"序列号码为空或无效");
            
else if (result == 103)
                JavascriptHelp.Alert(
"注册企业基本信息失败,当软件注册号码注册成功,但整体还是失败,要重新注册");
            
else if (result == 104)
                JavascriptHelp.Alert(
"注册信息填写不完整");
            
else if (result == 114)
                JavascriptHelp.Alert(
"得到标识错误");
            
else if (result == -1)
                JavascriptHelp.Alert(
"未知故障");
        }
        
catch (Exception ex)
        {
            JavascriptHelp.Alert(ex.Message.ToString().Trim());
        }
    }

    
/// <summary>
    
/// 发送信息
    
/// </summary>
    
/// <param name="Tell">手机号  多个手机号用逗号","分隔</param>
    
/// <param name="Context">短信内容</param>
    public static void SendSMS(string Tell, string Context)
    {
        
try
        {
            
//先注册一下
            Register();
            
//即时发送      这里是软件序列号    手机号       短信内容     优先级
            int result = SendSMS("fdfdf", Tell, Context, "5");
            
if (result == 1)
                JavascriptHelp.Alert(
"发送成功");
            
else if (result == 101)
                JavascriptHelp.Alert(
"网络故障");
            
else if (result == 102)
                JavascriptHelp.Alert(
"其它故障");
            
else if (result == 0)
                JavascriptHelp.Alert(
"失败");
            
else if (result == 100)
                JavascriptHelp.Alert(
"序列号码为空或无效");
            
else if (result == 107)
                JavascriptHelp.Alert(
"手机号码为空或者超过1000个");
            
else if (result == 108)
                JavascriptHelp.Alert(
"手机号码分割符号不正确");
            
else if (result == 109)
                JavascriptHelp.Alert(
"部分手机号码不正确,已删除,其余手机号码被发送");
            
else if (result == 110)
                JavascriptHelp.Alert(
"短信内容为空或超长(70个汉字)");
            
else if (result == 201)
                JavascriptHelp.Alert(
"计费失败,请充值");
            
else if (result == -1)
                JavascriptHelp.Alert(
"未知故障");

            
//发送后要注销一下
            UnRegister();
        }
        
catch (Exception ex)
        {
            JavascriptHelp.Alert(ex.Message.ToString().Trim());
        }
    }

    
/// <summary>
    
/// 注销
    
/// </summary>
    private static void UnRegister()
    {
        
try
        {
            
//注销序列号            注册号
            int result = UnRegister("0SDK-EMY-0130-JIWTR");
            
if (result == 1)
                JavascriptHelp.Alert(
"注销成功");
            
else if (result == 101)
                JavascriptHelp.Alert(
"网络故障");
            
else if (result == 102)
                JavascriptHelp.Alert(
"其它故障");
            
else if (result == 0)
                JavascriptHelp.Alert(
"失败");
            
else if (result == 100)
                JavascriptHelp.Alert(
"序列号码为空或无效");
            
else if (result == -1)
                JavascriptHelp.Alert(
"未知故障");
        }
        
catch (Exception ex)
        {
            JavascriptHelp.Alert(ex.Message.ToString().Trim());
        }
    }
}

 

转载于:https://www.cnblogs.com/sufei/archive/2009/11/07/1597861.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值