How to send mm7 from soap clientin php? | Search |
NowSMS Support Forums ⬆ MMS & SMS Technical Discussions (unsupported) ⬆ Archive through July 24, 2007 ⬆ |
◄ ► |
Author | Message | |||
Gezerler New member Username: Gezerpunta Post Number: 2 Registered: 03-2007 |
Hi Can anybody send examples for php? Infact I must translate java code but my php info is not enough sı java code public class SendMessage { private static MimeBodyPart createPart(File f) throws Exception { MimeBodyPart mimefile = new MimeBodyPart(); DataSource ds = new FileDataSource(f); DataHandler dh = new DataHandler(ds); mimefile = new javax.mail.internet.MimeBodyPart(); mimefile.setDataHandler(dh); mimefile.setFileName(f.getName()); String cid = mimefile.getContentID(); if (cid == null) { cid = mimefile.getFileName(); mimefile.setHeader(Constants.HEADER_CONTENT_ID, '<' + cid + '>'); } System.out.println(mimefile.toString()); return mimefile; } public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("Usage: java " + SendMessage.class.getName() + " SOAP-router-URL envelope-file content-dir"); return; } // get the envelope to send FileReader fr = new FileReader(args[1]); DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); Document doc = xdb.parse(new InputSource(fr)); if (doc == null) { throw new SOAPException(Constants.FAULT_CODE_CLIENT, "parsing error"); } Envelope msgEnv = Envelope.unmarshall(doc.getDocumentElement()); // send the message Message msg = new Message(); MimeMultipart mimemulti = new javax.mail.internet.MimeMultipart("related"); File dir = new File(args[2]); if (!dir.exists() || !dir.isDirectory()) { System.err.println("Invalid content-dir"); return; } File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { mimemulti.addBodyPart(createPart(files[i])); } // add the part to the multi part as context MimeBodyPart mf = new MimeBodyPart(); mf.setContent(mimemulti); // mf.writeTo(new FileOutputStream("SendMessage.java")); msg.addBodyPart(mf); msg.send(new URL(args[0]), "urn:mm7SubmitReq", msgEnv); // receive whatever from the transport and dump it to the screen System.out.println("RESPONSE:"); System.out.println("--------"); // msg SOAPTransport st = msg.getSOAPTransport(); BufferedReader br = st.receive(); String line; while ((line = br.readLine()) != null) { System.out.println(line); } } |