Ejemplo n.º 1
0
  public HashMap<String, String> rcheck(String msgid) throws IOException {
    if (this.userid == null || this.password == null) {
      System.out.println("setuser required");
      return null;
    }

    HashMap<String, String> map = new HashMap<String, String>();

    map.put("VERSION", VERSION_STR);
    map.put("COMMAND", "CHECK-RESULT");
    if (this.crypt.equals("MD5")) map.put("CRYPT-METHOD", "MD5");
    map.put("AUTH-ID", this.userid);
    map.put("AUTH-PASS", this.password);
    map.put("LANGUAGE", "JAVA");
    map.put("MESSAGE-ID", msgid);

    CSCP cscp = new CSCP();
    cscp.addparam(CSCPPARAM.ID_MESSAGE, TBSP.build(map));
    cscp.build();
    String packet = cscp.getPacketString();
    fos.write(packet.getBytes(), 0, packet.getBytes().length);
    fos.flush();

    CSCP cscp2 = new CSCP();
    cscp2.read(bis);
    CSCPPARAM ack = cscp2.getparam(CSCPPARAM.ID_MESSAGE);
    return TBSP.parse(ack.getBody());
  }
Ejemplo n.º 2
0
  /** send all of messages */
  public void send() throws IOException {
    if (this.userid == null || this.password == null) {
      System.out.println("setuser required");
      return;
    }

    for (int i = 0; i < pduList.size(); i++) {
      byte[] packet = assembleFields(pduList.get(i));
      fos.write(packet, 0, packet.length);
      fos.flush();

      CSCP cscp = new CSCP();
      cscp.read(bis);
      CSCPPARAM ack = cscp.getparam(CSCPPARAM.ID_MESSAGE);
      if (ack == null) {
        System.out.println("no ack returned");
        break;
      }
      String tbspstr = ack.getBody();

      HashMap<String, String> map = TBSP.parse(tbspstr);

      result.add(map);
    }
  }
Ejemplo n.º 3
0
  private byte[] encodeGroupCancel(String groupId) throws IOException {
    HashMap<String, String> map = new HashMap<String, String>();

    map.put("VERSION", VERSION_STR);
    map.put("MODULE-VERSION", MODULE_VERSION);
    map.put("COMMAND", "GROUP-CANCEL");
    if (this.app_version != null) map.put("APP-VERSION", this.app_version);
    if (groupId != null) map.put("GROUP-ID", groupId);
    if (this.crypt.equals("MD5")) map.put("CRYPT-METHOD", "MD5");
    if (this.userid != null) map.put("AUTH-ID", this.userid);
    if (this.password != null) map.put("AUTH-PASS", this.password);
    map.put("LANGUAGE", "JAVA");

    CSCP cscp = new CSCP();
    cscp.addparam(CSCPPARAM.ID_MESSAGE, TBSP.build(map));
    return cscp.build();
  }
Ejemplo n.º 4
0
  public HashMap<String, String> cancelGroup(String groupId) throws IOException {
    if (this.userid == null || this.password == null) {
      System.out.println("setuser required");
      return null;
    }

    byte[] packet = encodeGroupCancel(groupId);
    fos.write(packet, 0, packet.length);
    fos.flush();

    CSCP cscp = new CSCP();
    cscp.read(bis);
    CSCPPARAM ack = cscp.getparam(CSCPPARAM.ID_MESSAGE);
    if (ack == null) {
      System.out.println("no ack returned");
      return null;
    }
    String tbspstr = ack.getBody();
    return TBSP.parse(tbspstr);
  }
Ejemplo n.º 5
0
  private byte[] assembleFields(SmsMessagePdu pdu) throws IOException {
    HashMap<String, String> map = new HashMap<String, String>();

    map.put("VERSION", VERSION_STR);
    map.put("COMMAND", "SEND");
    if (pdu.type != null) map.put("TYPE", pdu.type);
    if (pdu.messageId != null) map.put("MESSAGE-ID", pdu.messageId);
    if (pdu.groupId != null) map.put("GROUP-ID", pdu.groupId);
    if (pdu.destinationAddress != null) map.put("CALLED-NUMBER", pdu.destinationAddress);
    if (pdu.scAddress != null) map.put("CALLING-NUMBER", pdu.scAddress);
    if (pdu.subject != null) map.put("SUBJECT", pdu.subject);
    if (pdu.text != null) map.put("MESSAGE", pdu.text);
    if (pdu.refName != null) map.put("CALLED-NAME", pdu.refName);
    if (pdu.reservDate != null) map.put("RESERVE-DATE", pdu.reservDate);
    if (this.crypt.equals("MD5")) map.put("CRYPT-METHOD", "MD5");
    if (this.userid != null) map.put("AUTH-ID", this.userid);
    if (this.password != null) map.put("AUTH-PASS", this.password);
    map.put("LANGUAGE", "JAVA");
    if (this._charset != null) map.put("CHARSET", this._charset);
    if (this.app_version != null) map.put("APP-VERSION", this.app_version);

    CSCP cscp = new CSCP();
    if (pdu.imageFile != null) {
      File file = new File(pdu.imageFile);
      String filename = file.getName();
      map.put("ATTACHMENT", filename);
      FileInputStream reader = new FileInputStream(file);
      byte[] bytearray = new byte[3 + filename.length() + (int) file.length()];
      System.arraycopy(String.format("%3d", filename.length()).getBytes(), 0, bytearray, 0, 3);
      System.arraycopy(filename.getBytes(), 0, bytearray, 3, filename.length());
      reader.read(bytearray, 3 + filename.length(), (int) file.length());
      cscp.addparam(CSCPPARAM.ID_ATTACHMENT, bytearray);
    }
    cscp.addparam(CSCPPARAM.ID_MESSAGE, TBSP.build(map));
    return cscp.build();
  }