移动企信通 SMEIDLL.dll 调用问题求助
在c#中使用smeidll.dll,corp_IFInitInte易做图ce成功,但corp_Login_R返回失败
各位大侠有碰到过的请指点一二。 --------------------编程问答-------------------- 帐号和密码不正确吧 --------------------编程问答-------------------- 给你看看我的代码,不过我用的是cmpp2,我想方法都差不多,希望对你有所帮助
====================================================================
public class clsSMEI
{
#region "华为API声明"
[DllImport("SMEIDll.dll")]
protected static extern bool CMPP2_IFInitInte易做图ce(int dwCodeProtocol, //和短讯中心连接的协议类型,1-内部协议(保留)
// 2-网关协议(保留)
// 5-CMPP协议(中国移动的互联互通协议)
// 6-SMGP协议(固网网关协议)
int dwDriverProtocol, //和短讯中心连接的网络协议,1-TCP/IP协议
// 2-COM协议(保留)
// 3-X25协议(保留)
string pDriverParam //网络协议参数。字符串,参数之间以空格隔开
//例如:TCP/IP协议的参数为“IP地址 端口号 超时时间”
// 129.9.123.8 5016 5000
);
[DllImport("SMEIDll.dll")]
protected static extern bool CMPP2_IFExitInte易做图ce();
[DllImport("SMEIDll.dll")]
protected static extern bool CMPP2_Login_R(string SystemID, //在短讯中心注册的接口名,最大长度只支持6个字符
string Password, //接口密码,最大长度支持16个字符
byte byIFver
);
[DllImport("SMEIDll.dll")]
protected extern static bool CMPP2_Logout();
[DllImport("SMEIDll.dll", EntryPoint = "CMPP2_SubmitSM",
SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
protected static extern int CMPP2_SubmitSM(byte byMsgID,
byte byPKTotal,
byte byPKNumber,
byte SRR,
byte byMsgLevel,
string serviceSubType,
byte byFeeUserType,
string sFeeAddr,
byte PID,
byte UDHI,
byte DCS,
string sSPID,
string sFeeType,
string sFeeCode,
string schedule,
string Expire,
string orgAddr,
byte byUserNum,
string sDestAddrs,
uint UDLen,
string UserData,
ref int FCS);
[DllImport("SMEIDLL.dll", CharSet=CharSet.Ansi)]
protected static extern int CMPP2_GetDeliverSM(
out ulong sm_ID, //返回:短讯ID
[MarshalAs(UnmanagedType.LPStr)] StringBuilder DestAddr, //返回:目标地址
[MarshalAs(UnmanagedType.LPStr)]StringBuilder ServiceID, //service_id 业务类型
[MarshalAs(UnmanagedType.U1)] out byte PID, //返回:协议类型
[MarshalAs(UnmanagedType.U1)] out byte UDHI,
[MarshalAs(UnmanagedType.U1)] out byte DCS, //返回:编码方案
[MarshalAs(UnmanagedType.LPStr)] StringBuilder OrgAddr, //返回:源地址
[MarshalAs(UnmanagedType.U1)] out byte StatusReport, //是否为状态报告
out ulong UDLen,
[MarshalAs(UnmanagedType.LPStr)] StringBuilder UserData
);
[DllImport("SMEIDLL.dll", CharSet=CharSet.Ansi)]
protected static extern int HasDeliverMessage(long dwTimeOut);
#endregion
public const string ConstLineNo = "********"; //专线接入号
public const string ConstSystemID = "*****"; //登陆用户帐号
public const string ConstSystemPassword = "******"; //登陆用户密码
public const string ConstDriverParam = "221.130.33.92 7890 5000"; //服务器参数
/// <summary>
/// 专线初始化,并登陆到网关
/// </summary>
/// <returns></returns>
public static bool Init()
{
if(CMPP2_IFInitInte易做图ce(5,1,ConstDriverParam))
{
return CMPP2_Login_R(ConstSystemID,ConstSystemPassword,32);
}
return false;
}
/// <summary>
/// 退出网关登陆,并退出专线初始化
/// </summary>
/// <returns></returns>
public static bool Exit()
{
if(CMPP2_Logout())
return CMPP2_IFExitInte易做图ce();
return false;
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="strDSimNumber">发送方号码</param>
/// <param name="strContent">发送消息</param>
/// <returns>成功返回0,失败返回非0</returns>
public static int SendSMS(string strDSimNumber,string strContent)
{
int intRet;
byte byMsgID = 0; //MAX_MSG_ID,CMPP的字段,消息ID
byte byPKTotal = 1; //相同Msg_id的消息总条数,从开始
byte byPKNumber = 1; //相同Msg_id的消息序号,从开始
byte SRR = 1; //是否需要状态报告
byte byMsgLevel = 0; //信息级别
string serviceSubType = "";//业务子类型,联通("LT"),移动("") 移动现在改成"MBJ0010501"了
byte byFeeUserType = 2; //计费用户类型字段,:对目的终端MSISDN计费;:对源终端MSISDN计费;:对SP计费;3:表示本字段无效
string sFeeAddr = ""; //MAX_ADDR_LEN,被计费用户地址
byte PID = 0; //协议类型
byte UDHI = 0; //1表示UD为一个结构,表示缺省
byte DCS = 15; //数据编码方案
string sSPID = ""; //MAX_SPID_LEN,信息内容来源
string sFeeType = "01"; //MAX_FEE_TYPE_LEN,资费类别
string sFeeCode = "00"; //MAX_FEE_CODE_LEN,资费代码
string schedule = ""; //超时时间char[MAX_TIMESTAMP_LEN]
string Expire = ""; //定时char[MAX_TIMESTAMP_LEN]
string orgAddr = ConstLineNo; //源地址char[MAX_ADDR_LEN],此处即为专线接入号
byte byUserNum = 1; //接收消息的用户数
int FCS=0;
uint uLen=(uint)System.Text.Encoding.Default.GetBytes(strContent).Length;
intRet= CMPP2_SubmitSM( byMsgID,
byPKTotal,
byPKNumber,
SRR,
byMsgLevel,
serviceSubType,
byFeeUserType,
sFeeAddr,
PID,
UDHI,
DCS,
sSPID,
sFeeType,
sFeeCode,
schedule,
Expire,
orgAddr,
byUserNum,
strDSimNumber,
uLen,
strContent,
ref FCS);
return intRet;
}
/// <summary>
/// 获取上行信息
/// </summary>
/// <param name="strSSimNumber">发送方号码</param>
/// <param name="strDSimNumber">接收方号码</param>
/// <param name="strUserData">发送的消息</param>
/// <param name="strDoneTime">上行时间</param>
/// <returns>成功返回0,失败返回非0</returns>
public static int GetDeliverSMS(out string strSSimNumber,out string strDSimNumber,out string strUserData,out string strDoneTime,out byte StatusReport)
{
ulong SM_ID;
ulong UDLen;
byte UDHI,PID,DCS;
StringBuilder DestAddr = new StringBuilder(256);
StringBuilder OrgAddr = new StringBuilder(256);
StringBuilder UserData = new StringBuilder(256);
StringBuilder strServiceID= new StringBuilder(256);
strUserData=string.Empty;
strDoneTime=string.Empty;
strSSimNumber=string.Empty;
strDSimNumber=string.Empty;
int intRet = CMPP2_GetDeliverSM(out SM_ID,DestAddr,strServiceID,out PID,out UDHI,out DCS,OrgAddr,out StatusReport,out UDLen,UserData);
if(intRet==0)
{
strUserData = UserData.ToString();
strDoneTime = DateTime.Now.ToString();
strSSimNumber=OrgAddr.ToString();
strDSimNumber=DestAddr.ToString();
}
return intRet;
}
} --------------------编程问答-------------------- 移动企信通这个东东不太好用! --------------------编程问答-------------------- CMPP2_GetDeliverSM 竟然返回11
附录表里没有这个代码!
也没收到短信。郁闷了 --------------------编程问答-------------------- --------------------编程问答-------------------- 你把smeidll.dll这个动态库的C++的函数,以及你在C#中对应的定义贴出来,
看看是否函数定义出了问题。。。
补充:.NET技术 , C#