消息未使用jsmpp提交给手机

时间:2012-10-01 09:40:16

标签: jsmpp

我正在尝试使用以下代码向手机发送消息:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsmsoutgoing;

import java.io.IOException;
import java.util.Date;
import org.jsmpp.InvalidResponseException;
import org.jsmpp.PDUException;
import org.jsmpp.bean.Alphabet;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.ESMClass;
import org.jsmpp.bean.GeneralDataCoding;
import org.jsmpp.bean.MessageClass;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.RegisteredDelivery;
import org.jsmpp.bean.ReplaceIfPresentFlag;
import org.jsmpp.bean.SMSCDeliveryReceipt;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.examples.MessageReceiverListenerImpl;
import org.jsmpp.extra.NegativeResponseException;
import org.jsmpp.extra.ResponseTimeoutException;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.SMPPSession;
import org.jsmpp.util.AbsoluteTimeFormatter;
import org.jsmpp.util.MessageId;
import org.jsmpp.util.TimeFormatter;

public class Jsmsoutgoing {

    /**
     * @param args the command line arguments
     */
    private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();
    public static void main(String[] args) {
        // TODO code application logic here


         SMPPSession session = new SMPPSession();
         session.setMessageReceiverListener(new MessageReceiverListenerImpl());
         String host = "X";
             int port = y;
             String userName = "user";
             String password = "pass";
             String TON = "0";
             String NPI = "1";
             String systemType = "generic";
        try {
            session.connectAndBind(
                         host,
                         port, 
                         BindType.BIND_TRX, 
                         userName, 
                         password, 
                         systemType, 
                         TypeOfNumber.INTERNATIONAL, 
                         NumberingPlanIndicator.ISDN,
                         null);
            System.out.println("Session Connected");

        } catch (IOException e) {
            System.out.println("Failed connect and bind to host");
            e.printStackTrace();
        }

        try {

            String messageId = session.submitShortMessage(
                    "CMT", 
                    TypeOfNumber.INTERNATIONAL, 
                    NumberingPlanIndicator.UNKNOWN, 
                    "SENDERNUMBER", 
                    TypeOfNumber.INTERNATIONAL, 
                    NumberingPlanIndicator.UNKNOWN, 
                    "RECEIVERNUMBER", 
                    new ESMClass(), 
                    (byte)0, 
                    (byte)1,  
                    null, 
                    null, 
                    new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE),
                    (byte)0,
                    new GeneralDataCoding(false, true, MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT), 
                    (byte)0,
                    "Test from TEST".getBytes()
                    );
            System.out.println("Message submitted, message_id is " + messageId);
            //System.out.println("Message submitted, message_id is " + messageId);
            Thread.sleep(2000);
        } 
        catch(PDUException e)
        {
            System.out.println("PDU Exeption");
            e.printStackTrace();
        }    
        catch (ResponseTimeoutException e) {
            // Response timeout
            System.out.println("Response timeout");
            e.printStackTrace();
        } catch (InvalidResponseException e) {
            // Invalid response
            System.out.println("Receive invalid respose");
            e.printStackTrace();
        } catch (NegativeResponseException e) {
            // Receiving negative response (non-zero command_status)
            System.out.println("Receive negative response");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IO error occur");
            e.printStackTrace();
        }
        catch (InterruptedException e) {
            System.out.println("Thread interrupted");
            e.printStackTrace();
        }

        session.unbindAndClose();
    }


}

任何人,任何想法?

由于

0 个答案:

没有答案