4常用的消息体说明
应用程序使用smgpapi.dll,通常用到的消息体和其中的参数值如下:
1. SMGPSendSingle_T:
typedef struct tagSMGPSendSingle
{
BYTE nNeedReport; /* 是否要求返回状态报告(0=不要求,1=要求) */
BYTE nMsgLevel; /* 信息级别(0-9,0=最低优先级) */
char sServiceID[SmgpServiceIdLen_M + 1];/* 业务类型*/
BYTE nMsgFormat;    /* 短消息格式*/
char sFeeType[SmgpFeeTypeLen_M + 1];    /* 资费类别*/
char sFeeCode[SmgpFeeCodeLen_M + 1];    /* 资费代码*/
char sFixedFee[SmgpFeeCodeLen_M + 1]; /* 包月费/封顶费 */
char sValidTime[SmgpValidTimeLen_M + 1]; /* 存活有效期*/
char sAtTime[SmgpValidTimeLen_M + 1]; /* 定时发送时间*/
char sSrcTermID[SmgpTermIDLen_M + 1]; /* 短消息发送用户号码*/
char sChargeTermID[SmgpTermIDLen_M + 1];/* 计费号码*/
    char sDestTermID[SmgpTermIDLen_M + 1];/* 短消息接收号码*/
    BYTE nMsgLen;  /* 短消息长度*/
    char sMsgContent[SmgpMsgContentLen_M +1];/* 短消息内容, nMsgLen=0时表示存放短消息的文件名*/
    char sMsgID[SmgpMsgIdLen_M + 1]; /* 返回的短消息标识*/
    DWORD nErrorCode; /* 错误代码*/
BYTE bMsgType; /* 短消息类型 */
}SMGPSendSingle_T;
输出参数:
sMsgID    为返回响应的短消息标识
nErrorCode 为返回响应的错误码,其中0为正确响应,非零为错误码
输入参数:
nNeedReport 为是否返回状态报告 0不要求,1=要求
nMsgLevel   为信息级别(0-9),其中0为最低优先级
sServiceID  为业务类型
nMsgFormat  为短消息格式0为ASCII编码方式,8为UCS2编码方式,15不编码
sFeeType    为资费类别00免费,01按条收费,02包月
sFeeCode    为资费代码(以分为单位)
sFixedFee   为包月费/封顶费(以分为单位)
sValidTime  为存活有效期,NULL为短消息中心的缺省有效期
sAtTime     为定时发送时间,NULL为及时发送
sSrcTermID  为发送用户号码
sChargeTermID 为计费号码
sDestTermID   为目的用户号码
nMsgLen   为短消息长度
sMsgContent   为短消息内容, nMsgLen=0时表示存放短消息的文件名(文件名为文本文件,以.TXT为后缀)
2. SMGPSendBatch_T:
typedef struct tagSMGPSendBatch
{
BYTE nNeedReport; /* 是否要求返回状态报告(0=不要求,1=要求) */
BYTE nMsgLevel; /* 信息级别(0-9,0=最低优先级) */
char sServiceID[SmgpServiceIdLen_M + 1]; /* 业务类型*/
BYTE nMsgFormat; /* 短消息格式*/
char sFeeType[SmgpFeeTypeLen_M + 1]; /* 资费类别*/
char sFeeCode[SmgpFeeCodeLen_M + 1]; /* 资费代码*/
char sFixedFee[SmgpFeeCodeLen_M + 1]; /* 包月费/封顶费 */
char sValidTime[SmgpValidTimeLen_M + 1]; /* 存活有效期*/
char sAtTime[SmgpValidTimeLen_M + 1]; /* 定时发送时间*/
char sSrcTermID[SmgpTermIDLen_M + 1]; /* 短消息发送用户号码*/
char sChargeTermID[SmgpTermIDLen_M + 1];/* 计费号码*/
    char sDestTermIDFile[101]; /* 短消息接收号码*/
    BYTE nMsgLen; /* 短消息长度*/
    char sMsgContent[SmgpMsgContentLen_M +1];/* 短消息内容,nMsgLen=0时表示存放短消息的文件名*/
    char sMsgIDFile[101]; /* 保存所有短消息的返回MsgID和ErrorCode的文件名*/
    BYTE bMsgType; /* 短消息子类型*/
}SMGPSendBatch_T;
基本同SMGPSendSingle_T,其中sDestTermIDFile为存放目的用户的文件名(文件名为文本文件,以.TXT为后缀),每个用户之间以逗号,或空格,或分号格开,最多发送100个用户。
群发不等待响应,收到的响应放在sMsgIDFile表示的文件
3. SendBatchResp_T:
    typedef struct tagSendBatchResp
{
DWORD nErrorCode;
BYTE sMsgID[SmgpMsgIdLen_M + 1];
char sPhoneNo[SmgpTermIDLen_M + 1];
char RecvTime[30];
}SendBatchResp_T;
输出:
sMsgID    为返回响应的短消息标识
nErrorCode 为返回响应的错误码,其中0为正确响应,非零为错误码
sPhoneNo   为目的用户号码
RecvTime   为接收响应的时间4. IsReport_T:
typedef struct tagIsReport
{
char sSrcTermID[SmgpTermIDLen_M + 1];/*原用户地址*/
char sDestTermID[SmgpTermIDLen_M +1];/*目的用户地址*/
char RecvTime[30]; /*接收时间*/
char sReportContent[150]; /*状态报告内容*/
}IsReport_T;
输出:
sSrcTermID  为原用户号码
sDestTermID 为目的用户号码
RecvTime    为接收响应的时间
    SReportContent 为接收的状态报告内容5. SMGPActiveTest_T:
typedef struct tagSMGPActiveTest
{
DWORD nErrorCode;
}SMGPActiveTest_T;
输出:
    nErrorCode为返回响应的错误码,其中0为正确响应,非零为错误码6. SMGPDeliverReq_T:
typedef struct tagSMGPDeliver
{
WORD nTimeout;
SMGPDeliverResp_T tSMGPDeliverResp;
}SMGPDeliverReq_T;
输入:
    nTimeout 为响应的超时时间
输出:
tSMGPDeliverResp Deliver消息内容
/*收到的Delivery消息,给用户的响应*/
typedef struct tagSMGPDeliverResp
{
BYTE sMsgID[SmgpMsgIdLen_M + 1];
BYTE nMsgFormat;
char sSrcTermID[SmgpTermIDLen_M + 1];
BYTE nIsReport;
BYTE nMsgLen;
char sMsgContent[SmgpMsgContentLen_M + 1];
char sDestTermID[SmgpTermIDLen_M + 1];
char sRecvTime[SmgpRecvTimeLen_M + 1]; /* 定时发送时间*/
}SMGPDeliverResp_T;
参数:
sMsgID:    为短消息标识
   nMsgFormat  为消息格式
    sSrcTermID  原用户地址
    nIsReport   是否为状态报告 0不是,1是
    nMsgLen     消息内容长度
    sMsgContent 消息内容
    sDestTermID 目的用户号码
    sRecvTime 接收时间

解决方案 »

  1.   

    5消息结构和错误码定义
    /*API中的错误码*/
    #define Code_Error_Offset_M 0
    #define Code_No_Err_M 0 + Code_Error_Offset_M
    #define Decode_No_Err_M 0 + Code_Error_Offset_M
    #define Code_In_Para_Null_M 1 + Code_Error_Offset_M
    #define Recv_Msg_TimeOut_M 2 + Code_Error_Offset_M
    #define Invalid_Msg_Len_M 4 + Code_Error_Offset_M
    #define Invalid_Fee_Code_M 5 + Code_Error_Offset_M
    #define Msg_Len_Too_Long_M 6 + Code_Error_Offset_M
    #define Invalid_ServiceID_M 7 + Code_Error_Offset_M
    #define Send_Too_Fast_M 8 + Code_Error_Offset_M
    #define Invalid_ICP_M 10 + Code_Error_Offset_M
    #define Invalid_MsgFormat_M 11 + Code_Error_Offset_M
    #define Invalid_Fee_Type_M 12 + Code_Error_Offset_M
    #define Invalid_ValidTime_M 13 + Code_Error_Offset_M
    #define Invalid_AtTime_M 14 + Code_Error_Offset_M
    #define Invalid_chargeTermId_M 15 + Code_Error_Offset_M
    #define Invalid_DestTermId_M 16 + Code_Error_Offset_M
    #define Cannot_Open_DestTermIdFile_M 17 + Code_Error_Offset_M
    #define Cannot_Open_MsgFile_M 18 + Code_Error_Offset_M
    #define Invalid_MsgContent_M 19 + Code_Error_Offset_M
    #define Failure_Connect_M 20 + Code_Error_Offset_M
    #define Failure_Login_M 21 + Code_Error_Offset_M
    #define Failure_Recv_M 22 + Code_Error_Offset_M
    #define OverFlow_SendQueue_M 23 + Code_Error_Offset_M
    #define OverTake_System_M 24 + Code_Error_Offset_M
    #define Invalid_Connect_M 25 + Code_Error_Offset_M /*连接已经建立*/
    #define System_Error_M 99 + Code_Error_Offset_M<2>常量定义
    #define SmgpIcpShareKeyLen_M 50
    #define SmgpClientIDLen_M 8
    #define SmgpAuthCodeLen_M 16
    #define SmgpServiceIdLen_M 10
    #define SmgpFeeTypeLen_M 2
    #define SmgpFeeCodeLen_M 6
    #define SmgpFixedFeeLen_M 6
    #define SmgpValidTimeLen_M 17
    #define SmgpRecvTimeLen_M 14
    #define SmgpMsgIdLen_M 10
    #define SmgpTermIDLen_M 21
    #define SmgpDestTermIDCount_M 10
    #define SmgpMsgContentLen_M 252<3>消息结构
    typedef struct tagSMGPSendSingle
    {
    BYTE nNeedReport; /* 是否要求返回状态报告(0=不要求,1=要求) */
    BYTE nMsgLevel; /* 信息级别(0-9,0=最低优先级) */
    char sServiceID[SmgpServiceIdLen_M + 1]; /* 业务类型*/
    BYTE nMsgFormat; /* 短消息格式*/
    char sFeeType[SmgpFeeTypeLen_M + 1]; /* 资费类别*/
    char sFeeCode[SmgpFeeCodeLen_M + 1]; /* 资费代码*/
    char sFixedFee[SmgpFeeCodeLen_M + 1]; /* 包月费/封顶费 */
    char sValidTime[SmgpValidTimeLen_M + 1];/* 存活有效期*/
    char sAtTime[SmgpValidTimeLen_M + 1]; /* 定时发送时间*/
    char sSrcTermID[SmgpTermIDLen_M + 1]; /* 短消息发送用户号码*/
    char sChargeTermID[SmgpTermIDLen_M + 1];/* 计费号码*/
        char sDestTermID[SmgpTermIDLen_M + 1];/* 短消息接收号码*/
        BYTE nMsgLen; /* 短消息长度*/
        char sMsgContent[SmgpMsgContentLen_M +1];/* 短消息内容,nMsgLen=0时表示存放短消息的文件名*/
        char sMsgID[SmgpMsgIdLen_M + 1]; /* 返回的短消息标识*/
        DWORD nErrorCode; /* 错误代码*/
    BYTE bMsgType; /* 短消息类型 */
    }SMGPSendSingle_T;typedef struct tagSMGPSendBatch
    {
    BYTE nNeedReport; /* 是否要求返回状态报告(0=不要求,1=要求) */
    BYTE nMsgLevel; /* 信息级别(0-9,0=最低优先级) */
    char sServiceID[SmgpServiceIdLen_M + 1]; /* 业务类型*/
    BYTE nMsgFormat;     /* 短消息格式*/
    char sFeeType[SmgpFeeTypeLen_M + 1]; /* 资费类别*/
    char sFeeCode[SmgpFeeCodeLen_M + 1]; /* 资费代码*/
    char sFixedFee[SmgpFeeCodeLen_M + 1]; /* 包月费/封顶费 */
    char sValidTime[SmgpValidTimeLen_M + 1];/* 存活有效期*/
    char sAtTime[SmgpValidTimeLen_M + 1]; /* 定时发送时间*/
    char sSrcTermID[SmgpTermIDLen_M + 1]; /* 短消息发送用户号码*/
    char sChargeTermID[SmgpTermIDLen_M + 1];/* 计费号码*/
        char sDestTermIDFile[101]; /* 短消息接收号码*/
        BYTE nMsgLen;    /* 短消息长度*/
        char sMsgContent[SmgpMsgContentLen_M +1];/* 短消息内容,nMsgLen=0时表示存放短消息的文件名*/
        char sMsgIDFile[101];/* 保存所有短消息的返回MsgID和ErrorCode的文件名*/
        BYTE bMsgType;/* 短消息子类型*/
    }SMGPSendBatch_T;typedef struct tagSendBatchResp
    {
    DWORD nErrorCode;
    BYTE sMsgID[SmgpMsgIdLen_M + 1];
    char sPhoneNo[SmgpTermIDLen_M + 1];
    char RecvTime[30];
    }SendBatchResp_T;typedef struct tagIsReport
    {
    char sSrcTermID[SmgpTermIDLen_M + 1];/*原用户地址*/
    char sDestTermID[SmgpTermIDLen_M +1];/*目的用户地址*/
    char RecvTime[30]; /*接收时间*/
    char sReportContent[150]; /*状态报告内容*/
    }IsReport_T;typedef struct tagSMGPActiveTest
    {
    DWORD nErrorCode;
    }SMGPActiveTest_T;/*收到的Delivery消息,给用户的响应*/
    typedef struct tagSMGPDeliverResp
    {
    BYTE sMsgID[SmgpMsgIdLen_M + 1];
    BYTE nMsgFormat;
    char sSrcTermID[SmgpTermIDLen_M + 1];
    BYTE nIsReport;
    BYTE nMsgLen;
    char sMsgContent[SmgpMsgContentLen_M + 1];
    char sDestTermID[SmgpTermIDLen_M + 1];
    char sRecvTime[SmgpRecvTimeLen_M + 1]; /* 定时发送时间*/
    }SMGPDeliverResp_T;typedef struct tagSMGPDeliver
    {
    WORD nTimeout;
    SMGPDeliverResp_T tSMGPDeliverResp;
    }SMGPDeliverReq_T;
    6 配置文件说明
    在配置文件中(../config/smgpc.ini)
    AutoLogon 1为自动登录,0为手动登录
    CPId 表示自动登录的CP接入号码(AutoLogon=1时起作用)
    CPShareKey  表示自动登录的CP接入号密码(AutoLogon=1时起作用)
    ServerIP 表示y要接入的网关IP
    SubmitRekey 表示CP与网关断开连接后,自动连接的次数
    RequestTimeout 表示接收消息的超时时间
      

  2.   

    利用属性把API全部改写成C#的再调用呀,我们当初用华为的短信网关也是这样呀
      

  3.   

    http://www.codeproject.com/csharp/win32.asp
    这是大部分WIN API在C#中的调用方法,你可以对照这些,写出你的API函数调用方法和参数类型的声明,肯定可以的!
      

  4.   

    建议不要用中兴的api,还是参考SMGP1.3自己写一个把,比用API快
      

  5.   

    参考http://www.codeproject.com/csharp/win32.asp
      

  6.   

    看了一下InitSMGPAPI函数,好像要把连接字符串放到INI文件里。而且API提供很详细了,估计不用你手动使用Socket连接服务器了。在C#里使用“特性”调用非托管的DLL,好像是[ImportDll()]
    然后使用C#语法重写DLL里的函数,注意要加一个程序在外部的指示字,具体是什么忘了,去查语法参考吧。注意写的时候注意参数类型的大小要匹配。