全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4132
推到 Plurk!
推到 Facebook!

用pc發送MMS至手機

尚未結案
AndyC
一般會員


發表:11
回覆:9
積分:4
註冊:2004-07-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-29 17:46:51 IP:140.125.xxx.xxx 未訂閱
使用該處的Now SMS/MMS Gateway (NowSMS) http://www.nowsms.com/index.htm
package mmssender;    import java.io.*;
import java.util.*;
import java.net.*;
import com.nokia.mms.*;    class OriginatingApp
{
  public OriginatingApp() {
    MMMessage mm = new MMMessage();
    SetMessage(mm); //設定空簡元件
    AddContents(mm); //增加簡訊內容        MMEncoder encoder = new MMEncoder(); //對mms做編碼
    encoder.setMessage(mm);        try {
      encoder.encodeMessage(); //編碼設計好的簡訊
      byte[] out = encoder.getMessage(); //置入陣列
      createMmsFile(out, "abc.mms"); //建立mms簡訊的檔案
      System.out.println("abc.mms has finsh");          MMSender sender = new MMSender();
      //sender.setMMSCURL("http://localhost:1099"); //設定發送伺服器位址
      sender.setMMSCURL("http://140.125.32.24");
      //sender.setMMSCURL("http://210.71.14.139/mars.tw=666666");
      //sender.addHeader("X-NOKIA-MMSC-Charging", "100");          MMResponse mmResponse = sender.send(out); //傳送簡訊
      System.out.println("Message sent to "   sender.getMMSCURL());
      System.out.println("Response code: "   mmResponse.getResponseCode()   " "  
                         mmResponse.getResponseMessage());
      //若Response傳輸成功回傳200代碼確認          Enumeration keys = mmResponse.getHeadersList();
      while (keys.hasMoreElements()) { //儲存回傳標頭
        String key = (String) keys.nextElement();
        String value = (String) mmResponse.getHeaderValue(key);
        System.out.println(key   ": "   value);
      }
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }      private void SetMessage(MMMessage mm) { //設定header 參數
    mm.setVersion(IMMConstants.MMS_VERSION_10);
    mm.setMessageType(IMMConstants.MESSAGE_TYPE_M_SEND_REQ);
    mm.setTransactionId("0000000066"); //設定MMS封包序號
    mm.setDate(new Date(System.currentTimeMillis()));
    //mm.setFrom(" 358990000066/TYPE=PLMN");//前者為發送者 ADDRESS ;  358990000066指那  >>改ipv4傳送
    mm.setFrom("140.125.32.24/TYPE=IPv4");
    mm.addToAddress("7210/TYPE=PLMN");
    //mm.addToAddress(" 886937781095/TYPE=PLMN"); // >>改實際手機
    /*mm.addToAddress("123.124.125.125/TYPE=IPv4");
     mm.addToAddress("1234:5678:90AB:CDEF:FEDC:BA09:8765:4321/TYPE=IPv6");
                 mm.addToAddress("john.doe@nokia.com");*/
    mm.setDeliveryReport(true); //報告傳送情形
    mm.setReadReply(false); // 是否要收從接收者傳來的read report
    mm.setSenderVisibility(IMMConstants.SENDER_VISIBILITY_SHOW); //設定傳送方位址或號碼 是否顯示
    mm.setSubject("Someone has intruded into your house!!!"); //簡訊主旨
    mm.setMessageClass(IMMConstants.MESSAGE_CLASS_PERSONAL); //必加;設定簡訊屬性為個人
    mm.setPriority(IMMConstants.PRIORITY_LOW); //必加;設定重要性為低
    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_MIXED);
    //In case of multipart related message and a smil presentation available
    //mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_RELATED);
    //mm.setMultipartRelatedType(IMMConstants.CT_APPLICATION_SMIL);
    //mm.setPresentationId(""); // where  is the id of the content containing the SMIL presentation
  }      private void AddContents(MMMessage mm) {
    /*Path where contents are stored*/
    String path = "c:/"; //設定儲存簡訊內容的路徑        // Adds text content
    MMContent part1 = new MMContent();
    byte[] buf1 = readFile(path   "sample_text.txt");
    part1.setContent(buf1, 0, buf1.length); //設定內容來源、起始位元、長度
    part1.setContentId("<0>"); //簡訊id
    part1.setType(IMMConstants.CT_TEXT_PLAIN);
    mm.addContent(part1);        // Adds image content
    MMContent part2 = new MMContent();
    byte[] buf2 = readFile(path   "sample_image.gif");
    part2.setContent(buf2, 0, buf2.length);
    part1.setContentId("<1>");
    part2.setType(IMMConstants.CT_IMAGE_JPEG);
    mm.addContent(part2);
  }      private byte[] readFile(String filename) {
    int fileSize = 0;
    RandomAccessFile fileH = null;        // Opens the file for reading.
    try {
      fileH = new RandomAccessFile(filename, "r");
      fileSize = (int) fileH.length();
    }
    catch (IOException ioErr) {
      System.err.println("Cannot find "   filename);
      System.err.println(ioErr);
      System.exit(200);
    }        // allocates the buffer large enough to hold entire file
    byte[] buf = new byte[fileSize]; //分配足夠緩衝空間給檔案        // reads all bytes of file
    int i = 0;
    try {
      while (true) {
        try {
          buf[i  ] = fileH.readByte();
        }
        catch (EOFException e) {
          break;
        }
      }
    }
    catch (IOException ioErr) {
      System.out.println("ERROR in reading of file"   filename);
    }        return buf;
  }      private String getPath() { //取得檔案路徑
    URL url = getClass().getResource(getClass().getName()   ".class");
    String classPath = url.getHost()   url.getFile(); //取得主機名稱跟檔名
    int pos = classPath.lastIndexOf("/"); //取得"/"為第幾個字元
    return classPath.substring(0, pos   1); //取得從0~第pos個的字串為路徑,並回傳
  }      public void createMmsFile(byte[] output, String filename) { //建立mms檔案
    try {
      String path = getPath();
      File f = new File(path   filename);
      FileOutputStream out = new FileOutputStream(f);
      out.write(output);
      out.close();
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
}    //MMSC的目錄位置
//Main method//sender.setMMSCURL("http://mms.now.co.uk/peppenwu=peppenwu");
 
執行結果:
引言:null abc.mms has finsh Message sent to http://140.125.32.24 Response code: 200 OK CONTENT-TYPE: application/vnd.wap.mms-message CONTENT-LENGTH: 18 CONNECTION: close
發送結果 手機沒反應 是否在設定 Now SMS/MMS Gateway (NowSMS) 上有問題 ? 改成以7210模擬器 接收 也是沒有收到 mms訊息 是哪裡出了問題 ???? Now SMS/MMS Gateway (NowSMS) 設定如下 其餘依原安裝好的原值不動
AndyC
一般會員


發表:11
回覆:9
積分:4
註冊:2004-07-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-09 21:57:30 IP:140.125.xxx.xxx 未訂閱
現以電腦上接(傳輸線)手機來發送   先前程式執行並無建製MMS檔出來 修正
  private String getPath() { //取得檔案路徑
/*    URL url = getClass().getResource(getClass().getName() ".class");
    System.out.println(getClass().getName());
    System.out.println(url);
    String classPath = url.getHost()   url.getFile(); //取得主機名稱跟檔名
    int pos = classPath.lastIndexOf("/"); //取得"/"為第幾個字元
    return classPath.substring(0, pos   1); //取得從0~第pos個的字串為路徑,並回傳*/
    return "G:\\subject\\MMSsender\\classes\\mmssender\\";
  }
則可以建製 mms檔 ,但仍法發送mms訊息,若是透過 nowsms 上的 web page 發送 ,可以發送且確認可以收到訊息 請教現在是何處尚有地方修正或欠缺,以致無法發送mms訊息 ??
package mmssender;    import java.io.*;
import java.util.*;
import java.net.*;
import com.nokia.mms.*;    class OriginatingApp
{
  public OriginatingApp() {
    MMMessage mm = new MMMessage();
    SetMessage(mm); //設定空簡元件
    AddContents(mm); //增加簡訊內容        MMEncoder encoder = new MMEncoder(); //對mms做編碼
    encoder.setMessage(mm);        try {
      encoder.encodeMessage(); //編碼設計好的簡訊
      byte[] out = encoder.getMessage(); //置入陣列
      createMmsFile(out, "abcd.mms"); //建立mms簡訊的檔案
      System.out.println("abcd.mms has finsh");          MMSender sender = new MMSender();
      sender.setMMSCURL("http://140.125.32.24:8800");
      sender.addHeader("X-NOKIA-MMSC-Charging", "100");          MMResponse mmResponse = sender.send(out); //傳送簡訊
      System.out.println("Message sent to "   sender.getMMSCURL());
      System.out.println("Response code: "   mmResponse.getResponseCode()   " "  
                         mmResponse.getResponseMessage());
      //若Response傳輸成功回傳200代碼確認          Enumeration keys = mmResponse.getHeadersList();
      while (keys.hasMoreElements()) { //儲存回傳標頭
        String key = (String) keys.nextElement();
        String value = (String) mmResponse.getHeaderValue(key);
        System.out.println(key   ": "   value);
      }
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }      private void SetMessage(MMMessage mm) { //設定header 參數
    mm.setVersion(IMMConstants.MMS_VERSION_10);
    mm.setMessageType(IMMConstants.MESSAGE_TYPE_M_SEND_REQ);
    mm.setTransactionId("0000000066"); //設定MMS封包序號
    mm.setDate(new Date(System.currentTimeMillis()));
    mm.setFrom(" 886953258816/TYPE=PLMN");
    mm.addToAddress(" 886911699521/TYPE=PLMN");   //   小黃
     mm.addToAddress("1234:5678:90AB:CDEF:FEDC:BA09:8765:4321/TYPE=IPv6");
     mm.addToAddress("john.doe@nokia.com");*/
    mm.setDeliveryReport(true); //報告傳送情形
    mm.setReadReply(false); // 是否要收從接收者傳來的read report
    mm.setSenderVisibility(IMMConstants.SENDER_VISIBILITY_SHOW); //設定傳送方位址或號碼 是否顯示
    mm.setSubject("Someone has intruded into your house!!!"); //簡訊主旨
    mm.setMessageClass(IMMConstants.MESSAGE_CLASS_PERSONAL); //必加;設定簡訊屬性為個人
    mm.setPriority(IMMConstants.PRIORITY_HIGH); //必加;設定重要性為低
    mm.setContentType(IMMConstants.CT_APPLICATION_MULTIPART_MIXED);
  }      private void AddContents(MMMessage mm) {
    /*Path where contents are stored*/
    String path = "c:/"; //設定儲存簡訊內容的路徑        // Adds text content
    MMContent part1 = new MMContent();
    byte[] buf1 = readFile(path   "sample_text2.txt");
    part1.setContent(buf1, 0, buf1.length); //設定內容來源、起始位元、長度
    part1.setContentId("<0>"); //簡訊id
    part1.setType(IMMConstants.CT_TEXT_PLAIN);
    mm.addContent(part1);        // Adds image content
    /*MMContent part2 = new MMContent();
    byte[] buf2 = readFile(path   "sample_image.gif");
    part2.setContent(buf2, 0, buf2.length);
    part1.setContentId("<1>");
    part2.setType(IMMConstants.CT_IMAGE_JPEG);
    mm.addContent(part2);*/
  }      private byte[] readFile(String filename) {
    int fileSize = 0;
    RandomAccessFile fileH = null;        // Opens the file for reading.
    try {
      fileH = new RandomAccessFile(filename, "r");
      fileSize = (int) fileH.length();
    }
    catch (IOException ioErr) {
      System.err.println("Cannot find "   filename);
      System.err.println(ioErr);
      System.exit(200);
    }        // allocates the buffer large enough to hold entire file
    byte[] buf = new byte[fileSize]; //分配足夠緩衝空間給檔案        // reads all bytes of file
    int i = 0;
    try {
      while (true) {
        try {
          buf[i  ] = fileH.readByte();
        }
        catch (EOFException e) {
          break;
        }
      }
    }
    catch (IOException ioErr) {
      System.out.println("ERROR in reading of file"   filename);
    }        return buf;
  }      private String getPath() { //取得檔案路徑
/*    URL url = getClass().getResource(getClass().getName() ".class");
    System.out.println(getClass().getName());
    System.out.println(url);
    String classPath = url.getHost()   url.getFile(); //取得主機名稱跟檔名
    int pos = classPath.lastIndexOf("/"); //取得"/"為第幾個字元
    return classPath.substring(0, pos   1); //取得從0~第pos個的字串為路徑,並回傳*/
    return "G:\\subject\\MMSsender\\classes\\mmssender\\";
  }      public void createMmsFile(byte[] output, String filename) { //建立mms檔案
    try {
      String path = getPath();
      File f = new File(path   filename);
      System.out.println(path   filename);
      FileOutputStream out = new FileOutputStream(f);
      System.out.println("created !!!!!!");
      out.write(output);
      out.close();        }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
}
程式執行結果為
引言: G:\subject\MMSsender\classes\mmssender\abcd.mms created !!!!!! abcd.mms has finsh Message sent to http://140.125.32.24:8800 Response code: 200 OK CONTENT-TYPE: text/html
其中比之前的結果少二行 response 的內容
AndyC
一般會員


發表:11
回覆:9
積分:4
註冊:2004-07-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-09 21:58:30 IP:140.125.xxx.xxx 未訂閱
以下是NOWSMS 設定的頁面 enable server 後可以發送訊息的web page
系統時間:2024-04-26 8:11:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!