?? mmssender.java~3~
字號:
/* * Created on Jan 21, 2005 * * @see CWapPostExample in the jWap library * @see Sender in the MmsLib library */import java.net.InetAddress;import javax.swing.*;/*import net.sourceforge.jwap.wsp.CWSPMethodManager;import net.sourceforge.jwap.wsp.CWSPSession;import net.sourceforge.jwap.wsp.IWSPUpperLayer;import com.tripod.cookiebreak.wsp.adapt.Content_Type;import com.tripod.cookiebreak.common.adapt.IOUtil;import com.tripod.cookiebreak.mms.MMSPDUDecodeHelper;import com.tripod.cookiebreak.mms.misc.DataString;import com.tripod.cookiebreak.mms.misc.MMSAddress;import com.tripod.cookiebreak.mms.misc.MMSBody;import com.tripod.cookiebreak.mms.misc.MMSPart;import com.tripod.cookiebreak.mms.mmspdu.m_send_req;*/public class MMSSender implements IWSPUpperLayer { protected InetAddress wapGateway; protected int wapGatewayPort; protected String postUri; protected byte[] pduToSend; protected String contentType; protected CWSPSession session; protected CWSPMethodManager m; /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_connect_cnf() */ public void s_connect_cnf() { try { System.out.println("connected: " + wapGateway); System.out.println("sending WSP POST data"); m = session.s_post(pduToSend, contentType, postUri); } catch (Exception e) { e.printStackTrace(); } } /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_suspend_ind(short) */ public void s_suspend_ind(short reason) { System.out.println("s_suspend_ind(short reason)"); } /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_resume_cnf() */ public void s_resume_cnf() { System.out.println("s_resume_cnf()"); } /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_disconnect_ind(short) */ public void s_disconnect_ind(short reason) { System.out.println("disconnected: " + wapGateway); } /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_disconnect_ind(java.net.InetAddress[]) */ public void s_disconnect_ind(InetAddress[] redirect) { System.out.println("s_disconnect_ind(InetAddress[] redirect)"); } /* * (non-Javadoc) * * @see net.sourceforge.jwap.wsp.IWSPUpperLayer#s_methodResult_ind(byte[], * java.lang.String, boolean) */ public void s_methodResult_ind(byte[] payload, String contentType, boolean moreData) { // response goes in here if (moreData) System.out.println("there's more data coming"); System.out.println("response content type: " + contentType); try { String filename = "tmp/" + contentType.replace('/', '_') + System.currentTimeMillis(); IOUtil.save(filename, payload); System.out.println("response saved as: " + filename); if (!moreData) { System.out.println("disconnecting from WAP gateway " + wapGateway); m.s_methodResult(null); session.s_disconnect(); if ("application/vnd.wap.mms-message".equalsIgnoreCase(contentType)) { System.out.println("starting to parse response"); MMSPDUDecodeHelper parser = new MMSPDUDecodeHelper(); parser.setPayload(payload); parser.parse(); } } } catch (Exception e) { e.printStackTrace(); } } /* * connects to the wap gateway and starts the WSP session */ private void init() { try { session = new CWSPSession(wapGateway, wapGatewayPort, this); System.out.println("connecting to WAP gateway " + wapGateway); session.s_connect(); } catch (Exception e) { e.printStackTrace(); } } public MMSSender(InetAddress wapGateway, int wapGatewayPort, String postUri, byte[] pduToSend) { this.pduToSend = pduToSend; this.postUri = postUri; this.wapGateway = wapGateway; this.wapGatewayPort = wapGatewayPort; this.contentType = "application/vnd.wap.mms-message"; init(); } public static void main(String[] args) throws Exception { /* * @see http://www.smart.com.ph/SMART/Products/Smart+Amazing+Phone/Users+Guide/SAP_UG_data.htm * or contact your provider for your own settings * prefer IP than named addresses * (ie use http://10.102.61.238:8002/ than http://smart.com.ph:8002/) * so that there would be no need for name resolution */ String wapIPAddress = "10.102.61.46"; String mmsc = "http://10.102.61.238:8002/"; // set up the pdu to send MMSBody body = new MMSBody(); Content_Type text = new Content_Type("text/plain"); // make sure this text file exists MMSPart part0 = new MMSPart(IOUtil.load("tmp/test.text"), text); body.addEntry(part0); m_send_req test = new m_send_req(); test.setFrom(new MMSAddress("+639211234567", MMSAddress.global_phone_number)); test.addTo(new MMSAddress("+639211234567", MMSAddress.global_phone_number)); test.setSubject(new DataString("i have sent my mms through my pc!")); Content_Type mms = new Content_Type( "application/vnd.wap.multipart.mixed"); test.setContent_Type(mms); test.setMessage_Body(body); MMSSender poster = new MMSSender(InetAddress.getByName(wapIPAddress), 9201, mmsc, test.getPDU()); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -