近日我使用亚信的cmpp3.0 api接入网关发送短信,碰到几个问题:发送单条短信时CMPPSendSingle函数(即发送函数)返回的值是0(表示发送成功),但对方没有收到我的短信。并且返回的短信标识是一串汉字。小弟百思不得其解。 
    还请各位大侠指点一二,小弟感激涕零。 
    也可合作,报酬另议。 

解决方案 »

  1.   

    亚信的cmpp3.0 api?
    没用过
      

  2.   

    /*  --------------------------------------------------------------------------
        Name:       TestAPI.cpp
        Title:      Test CMPP API of ISMG for CMPP 1.1
        Package:    ISMG for CMPP 1.1    Written:    2001/01/01  Jeffrey Du <[email protected]> Asiainfo
        Revised:        Synopsis:   Test CMPP 1.1 API.
     -----------------------------------------------------------------------------*/#include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <string.h>#include "CMPPAPI.hpp"#define SEND_MODE_SINGLE 0
    #define SEND_MODE_BATCH 1
    void Usage(char *sProgram);typedef struct//发送参数
    {
    int  nNeedReply;
    int  nMsgLevel;
    char  sServiceID[10+1];
    int nMsgFormat;
    char sFeeType[2+1];
    char sFeeCode[6+1];
    char sValidTime[17+1];
    char sAtTime[17+1];
    char sSrcTermID[21+1];
    //char sDestTermID[21+1];
    char  sDestTermID[32 + 1];
    char sDestTermIDFile[100];
    char sMsgFile[100];
    char sMsgIDFile[100];
    char  cFeeTermType;
    char  cDestTermType;
    char  sLinkId[20 + 1];
    } SMArgument;
    int ReadArgumentFile(char *sFile, SMArgument *pSMArgument, int nOutput);//读取参数
    int main(int argc, char ** argv)
    {
    int sendFlag;
    char sMsgIDFile[100];
    int n, nErrorCode;
    SendBatchResp theSendBatchResp; int nSendMode = SEND_MODE_SINGLE, nOutput = 1;
    char sArgFile[100] = "e:\\cmppc.ini";
    SMArgument theSMArgument;
    char sMsgID[21+1];

    FILE *pFile;
    int nMsgLen;
    char sMsgContent[10240];
    char sFeeTerminalID[32 + 1] = "";
    int nFeeUserType = 0;
    char *sDestTermIDs = NULL;
    char *sContent = NULL;
    theSMArgument.cFeeTermType = 0;
    theSMArgument.cDestTermType = 0;
    char tempLinkId[21] = "12345678900987654321";
    memset( theSMArgument.sLinkId,0,21);
    memcpy(theSMArgument.sLinkId,tempLinkId,21); // get argument
    for(n=1; n<argc; ++n)
    {
    if(strcmp(argv[n], "-a") == 0)
    {
    if(InitCMPPAPI() != 0)
    {
    printf("Fail to call InitCMPPAPI!\n");
    exit(1);
    }
    if(CMMPActiveTest(&nErrorCode) == 0)
    {
    printf("CMMPActiveTest ok!\n");
    }
    else
    {
    printf("CMMPActiveTest fail, err=%d!\n", nErrorCode);
    exit(1);
    }
    exit(0);
    }
    else if(strcmp(argv[n], "-g") == 0)
    {
    n++;
    strcpy(sMsgIDFile, argv[n]); if(InitCMPPAPI() != 0)
    {
    printf("Fail to call InitCMPPAPI!\n");
    exit(1);
    } for(n=0; n<1000; ++n)
    {
    if(GetSendBatchResp(sMsgIDFile, n, &theSendBatchResp) != 0)
    {
    break;
    }
    printf("msgid=%s, error=%d, destno=%s!\n", 
    theSendBatchResp.sMsgID, theSendBatchResp.nErrorCode,
    theSendBatchResp.sPhoneNo);
    }
    exit(0);
    }
    else
    {
    Usage(argv[0]);
    exit(1);
    }
    }
    ///测试发送 for(n=1; n<argc; ++n)
    {
    if(strcmp(argv[n], "-B") == 0)
    {
    nSendMode = SEND_MODE_BATCH;
    }
    else if(strcmp(argv[n], "-S") == 0)
    {
    nSendMode = SEND_MODE_SINGLE;
    }
    else if(strcmp(argv[n], "-n") == 0)
    {
    nOutput = 0;
    }
    else if(strcmp(argv[n], "-a") == 0)
    {
    n++;
    strcpy(sArgFile, argv[n]);
    }
    else if(strcmp(argv[n], "-u") == 0)
    {
    n++;
    nFeeUserType = atoi(argv[n]);
    }
    else if(strcmp(argv[n], "-f") == 0)
    {
    n++;
    strcpy(sFeeTerminalID, argv[n]);
    }
    else if(strcmp(argv[n], "-d") == 0)
    {
    n++;
    sDestTermIDs = argv[n];
    }else if(strcmp(argv[n], "-T") == 0)
    {
      n++;
      theSMArgument.cFeeTermType = 1;
    }else if(strcmp(argv[n], "-t") == 0)
    {
      n++;
      theSMArgument.cDestTermType = 1;
    }
    else if(strcmp(argv[n], "-m") == 0)
    {
    n++;
    sContent = argv[n];
    }
    else
    {
    if(nOutput == 1)
    {
    Usage(argv[0]);
    }
    exit(1);
    }
    }

    if(nSendMode == SEND_MODE_SINGLE)
    {
    // get message from file
    struct stat sbuf; if(stat("e:\\msg.txt", &sbuf) != 0 )
    {
    nMsgLen = -1;
    }
    else
    {
    nMsgLen = sbuf.st_size;
    } if(nMsgLen <= 0)
    {
    if(nOutput == 1)
    {
    printf("Fail to read message file %s!\n", theSMArgument.sMsgFile);
    }
    exit(1);
    }
    pFile = fopen("e:\\msg.txt", "rb");
    fread(sMsgContent, nMsgLen, 1, pFile);
    fclose(pFile); // remove unseen character at the end of the sMsgContent, no binary format
    if(theSMArgument.nMsgFormat != 4 && theSMArgument.nMsgFormat != 8)
    {
    sMsgContent[nMsgLen] = 0;
    for(n=nMsgLen-1; n>0; --n)
    {
    if((unsigned char)sMsgContent[n] <= '\r')
    {
    sMsgContent[n] = 0;
    }
    else
    {
    break;
    }
    }
    nMsgLen = strlen(sMsgContent);
    } if(nOutput == 1)
    {
    printf("msg_len=%d!\n", nMsgLen);
    }
            sendFlag=CMPPSendSingle(1, 1,
    "xxxx", 15,
    "01","10",
    "","",
    "xxxx", "13920313081",//13920313081
    nMsgLen, sMsgContent,
    sMsgID, &nErrorCode,
    (char)"1","", 0, 0,
    theSMArgument.cFeeTermType,theSMArgument.cDestTermType,theSMArgument.sLinkId);
    ///参数及其值依次为:
        ///nNeedReply:1(是否要求返回状态确认报告)
    ///nMsgLevel:1(信息级别)
    ///sServiceID:xxxx(业务类型)--业务代码
    ///nMsgFormat:15(信息格式GB汉字)
    ///sFeeType:01(资费类别)
    ///sFeeCode:ALL(资费代码)
    ///sValidTime:""(存活有效期)
    ///sAtTime:""(定时发送时间)
    ///sSrcTermID:"xxxx"(源终端MSISDN号码)--服务代码
    ///sDestTermID:"13920313081"(接收业务的MSISDN号码)
    ///nMsgLen:略(消息长度)
    ///sMsgContent:略(消息内容)
    ///sMsgID:乱码(保存返回的短信标识)
    ///nErrorCode:略(错误代码)
    ///cFeeUserType:"2"(计费用户类型字段)
    ///sFeeTerminalId:""(被计费用户的号码)
    ///cTpPid:0(GSM协议类型)
    ///cTpUdhi:0(GSM协议类型)
    ///cFeeTermType:0(被计费用户的号码类型)
    ///cDestTermType:0(接收短信的用户的号码类型)
    ///sLinkId: 0x0013fd73 "12345678900987654321" (点播业务使用的LinkID,非点播类业务的MT流程不使用该字段)

    if( sendFlag!= 0)
    {
    if(nOutput == 1)
    {
    printf("Fail to call CMPPSendSingle, error=%d!\n", nErrorCode);
    }
    exit(1);
    }
    // write msgid and error code to file
    else
    {
    pFile =  fopen(theSMArgument.sMsgIDFile, "w");
    if(pFile != NULL)
    {
    fprintf(pFile, "%s\t%d\n", sMsgID, nErrorCode);
    fclose(pFile);
    }
    else
    {
    if(nOutput == 1)
    {
    printf("Fail to open file %s!\n", theSMArgument.sMsgIDFile);
    }
    }
    }
    }

    exit(0);
    return(0);
    /// Usage(argv[0]);
    exit(1);
    return(0);
    }void Usage(char *sProgram)
    {
    printf("Usage: %s [-a][-g msgid]\n", sProgram);
    printf("       -a: active test(call CMMPActiveTest)\n");
    printf("       -g: get msgid_file(call GetSendBatchResp)\n");
    printf("e.g.:  %s -a            # active test\n", sProgram);
    printf("e.g.:  %s -g msgid.txt  # printout message id file\n", sProgram);
    }
      

  3.   

    我直接在亚信的开发包的TestAPI中改的,由于是给别的公司做的。
    有些东西不宜直接透露,这些地方一律用“xxxx”替代,请大家原谅