- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
请问有没有什么方法可以在 Java 中使用 MM7 协议(protocol)发送彩信?
如果有免费的 API 可以生成适当的 SOAP 消息,也请告诉我。我处于死胡同,我真的需要一种方法来做到这一点。也欢迎您提出明智的建议。
提前致谢。
最佳答案
MMS Soap 应如下所示:3GPP MM7 SOAP Spesicifation .
这是我的做法:
您将需要 activation.jar、saaj-api.jar、activation.jar 和 saaj-impl.jar(以及任何其他相关的 jar 文件)。
这是您可以开始的方式。
package com.pixelandtag.mms.soap;
import java.io.IOException;
import java.net.URL;
import java.sql.Timestamp;
import javax.activation.DataHandler;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
public class MMSGen {
private static final String TxId = "";
private static final String MM7_VERSION = "";
private static final String VASPID = "";
private static final String VASID = "";
private static final String SHORTCODE = "";
private static final String SERVICE_CODE = "";
private static final String LINKED_ID = "";
private static final String MMSCMPMMS0000 = "";
private static final String EARLIEST_DELIVERY_TIME = "2006-11-09T13:01:04+03:00";
private static final String EXPIRY_DATE = "2007-11-10T13:01:04+03:00";
private static final String DELIVERY_REPORT = "false";
private static final String READ_REPLY = "false";
private static final String SUBJECT = "";
private static final String DISTRIBUTION_INDICATION = "false";
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
try {
//SOAP Message created
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
//Now accessing the elements of the soap message
SOAPPart soapPart = message.getSOAPPart();
//Get the envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
//You can now use the getHeader and getBody methods
//of envelope to retrieve its empty SOAPHeader and SOAPBody objects.
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
//Other ways of getting the body and header
//header = message.getSOAPHeader();
//body = message.getSOAPBody();
//Deleting a node.
//header.detachNode();
SOAPFactory soapFactory = SOAPFactory.newInstance();
//================CONSTRUCTING HEADER
Name headerName = soapFactory.createName("TransactionID",
"mm7", "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2");
SOAPHeaderElement headerElement = header.addHeaderElement(headerName);
headerElement.setTextContent("TID."+TxId);
headerElement.setMustUnderstand(true);
//===============HEADER DONE======================
//===============CONSTRUCTING BODY==============
Name bodyName = soapFactory.createName("SubmitReq");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name attributeName = envelope.createName("xmlsn");//change name to proper to xmls, though it does not print out
bodyElement.addAttribute(attributeName, "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2");
bodyName = soapFactory.createName("MM7Version");
SOAPElement MM7Version = bodyElement.addChildElement(bodyName);
MM7Version.setTextContent(MM7_VERSION);
bodyName = soapFactory.createName("SenderIdentification");
SOAPElement SenderIdentification = bodyElement.addChildElement(bodyName);
bodyName = soapFactory.createName("SenderAddress");
SOAPElement senderAddress = SenderIdentification.addChildElement(bodyName);
bodyName = soapFactory.createName("ShortCode");
SOAPElement shortCode = senderAddress.addChildElement(bodyName);
shortCode.setTextContent(SHORTCODE);
bodyName = soapFactory.createName("Recipients");
SOAPElement recipients = bodyElement.addChildElement(bodyName);
bodyName = soapFactory.createName("To");
SOAPElement to = recipients.addChildElement(bodyName);
bodyName = soapFactory.createName("Number");
SOAPElement number = to.addChildElement(bodyName);
number.setTextContent(MMSCMPMMS0000);
bodyName = soapFactory.createName("VASPID");
SOAPElement vaspID = SenderIdentification.addChildElement(bodyName);
vaspID.setTextContent(VASPID);
bodyName = soapFactory.createName("VASID");
SOAPElement vasID = SenderIdentification.addChildElement(bodyName);
vasID.setTextContent(VASID);
bodyName = soapFactory.createName("ServiceCode");
SOAPElement serviceCode = bodyElement.addChildElement(bodyName);
serviceCode.setTextContent(SERVICE_CODE);
bodyName = soapFactory.createName("LinkedID");
SOAPElement linkedID = bodyElement.addChildElement(bodyName);
linkedID.setTextContent(LINKED_ID);
bodyName = soapFactory.createName("MessageClass");
SOAPElement messageClass = bodyElement.addChildElement(bodyName);
messageClass.setTextContent(MessageClass.Personal.toString());
bodyName = soapFactory.createName("EarliestDeliveryTime");
SOAPElement earliestDeliveryTime = bodyElement.addChildElement(bodyName);
earliestDeliveryTime.setTextContent(EARLIEST_DELIVERY_TIME);
bodyName = soapFactory.createName("ExpiryDate");
SOAPElement expiryDate = bodyElement.addChildElement(bodyName);
expiryDate.setTextContent(EXPIRY_DATE);
bodyName = soapFactory.createName("DeliveryReport");
SOAPElement deliveryReport = bodyElement.addChildElement(bodyName);
deliveryReport.setTextContent(DELIVERY_REPORT);
bodyName = soapFactory.createName("ReadReply");
SOAPElement readReply = bodyElement.addChildElement(bodyName);
readReply.setTextContent(READ_REPLY);
bodyName = soapFactory.createName("Priority");
SOAPElement priority = bodyElement.addChildElement(bodyName);
priority.setTextContent(Priority.Normal.toString());
bodyName = soapFactory.createName("Subject");
SOAPElement subject = bodyElement.addChildElement(bodyName);
subject.setTextContent(SUBJECT);
bodyName = soapFactory.createName("ChargedParty");
SOAPElement chargedParty = bodyElement.addChildElement(bodyName);
chargedParty.setTextContent(ChargedParty.Recipient.toString());
bodyName = soapFactory.createName("DistributionIndicator");
SOAPElement distributionIndicator = bodyElement.addChildElement(bodyName);
distributionIndicator.setTextContent(DISTRIBUTION_INDICATION);
bodyName = soapFactory.createName("Content");
SOAPElement content = bodyElement.addChildElement(bodyName);
attributeName = envelope.createName("href");//change name to proper to xmls, though it does not print out
SOAPElement attr = content.addAttribute(attributeName, "cid:A0");
attributeName = envelope.createName("allowAdaptations");//change name to proper to xmls, though it does not print out
attr = content.addAttribute(attributeName, "false");
//=====================BODY DONE================
//=================create attachment===========
// AttachmentPart attachment = message.createAttachmentPart();
//Simple attach
/* String stringContent = "Update address for Sunny Skies " +
"Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439";
attachment.setContent(stringContent, "application/smil");
attachment.setContentId("update_address");
message.addAttachmentPart(attachment); */
URL url = new URL("http://www.petermak.nl/webalbum_peter_mak_aannemersbedrijf011002.jpg");
DataHandler dataHandler = new DataHandler(url);
AttachmentPart attachment1 =
message.createAttachmentPart(dataHandler);
// attachment.setContent(stringContent, "application/smil");
attachment1.setContentId("attached_image");
message.addAttachmentPart(attachment1);
URL url2 = new URL("file:///C:\\Users\\Timo\\Desktop\\MMS Pis\\pic_test.jpg");
dataHandler = new DataHandler(url2);
AttachmentPart attachment2 = message.createAttachmentPart(
dataHandler);
attachment2.setContentId("attached_image2");
message.addAttachmentPart(attachment2);
java.net.URL endpoint = new URL("http://theendpoint.");
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection =
soapConnectionFactory.createConnection();
SOAPMessage response = connection.call(message, endpoint);
System.out.println("\nRESPONSE:\n");
response.writeTo(System.out);
System.out.println();
connection.close();
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
关于java - 如何使用 Java 使用 MM7 发送彩信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880735/
我正在尝试使用这两种格式解析日期 2014-12-03T10:05:59.5646+08:00: yyyy-MM-dd'T'HH:mm:ss yyyy-MM-dd'T'HH:mm:ssXXX 当我使用
Paypal 返回以下格式的时间戳: yyyy-MM-ddTHH:mm:ssZ 我不知道该怎么办... 如何在 php 中使用本地时区将其转换为 yyyy-MM-dd HH:mm:ss? 我很想pre
我正在使用 Excel 2010 或 Excel 2007 导入包含日期/时间信息的 CSV 文件。我的 CSV 文件中的时间戳具有以下格式:yyyy-mm-dd hh:mm:ss。 (例如:2015
这个问题已经有答案了: Separate Date and Time objects (2 个回答) 已关闭 4 年前。 如何从 SimpleDateFormat("MM/dd/yyyy kk:mm"
这个问题已经有答案了: Java string to date conversion (17 个回答) 已关闭 6 年前。 我需要将日期字符串转换为另一种特定格式。 例如:我有一个日期,可以是 YYY
我想将字符串:24/11/2016 04:30 pm 转换为日期时间值:11/24/2016 04:30 pm。 我的代码为: DateTime date = DateTime.ParseExact(
我想使用 linux 将像“26/11/05 06:00:01,057000000”这样的纪元转换为 yyyy-mm-ddThh:mm:ss? 我曾尝试使用以下脚本但没有成功: echo 26/11/
这个问题在这里已经有了答案: mysql YYYY-MM-DDThh:mm:ss (1 个回答) 关闭 6 年前。 我想上传包含 yyyy-mm-ddThh:mm:ss.sssZ 数据的 csv 文
我在“dd-MM-yyyy HH:mm”中有一个字符串,需要将其转换为格式为日期的对象“yyyy-MM-dd HH:mm”。 下面是我用来转换的代码 oldScheduledDate = "16-05
我有一个数据框(df),它有一个日期列(列名:sale_date),它以以下格式存储数据 dd/mm/yy hh:mm:ss 我正在尝试将其转换为 yyyy-mm-dd hh:mm:ss。尝试了以下但
我的数据库中有日期时间列(格式为 YYYY-mm-dd hh:mm:ss)。 我需要将其转换为 dd-mm-YYYY hh:mm:ss 格式。 我该怎么办?帮助我。 最佳答案 不确定如何在 javas
想知道它们是否代表不同的格式或本质上相同(只是新与旧的演示文稿)。 最佳答案 基于DateTimeFormatter : Offset X and x: This formats the offset
如标题所示,我有一个问题。我需要将 LocalDataTime yyyy-MM-ssThh-mm-ss 解析为 LocalDataTime yyyy-MM-ss hh-mm-ss 但是当我这样做时 S
我想用 mySQL 将我的数据从“yyyy-mm-ddThh-mm-ss.sssZ”转换为“yyyy-mm-dd hh-mm-ss”。 我尝试使用 convert_tz: mysql> SELECT
这个问题在这里已经有了答案: LOAD DATA INFILE easily convert YYYYMMDD to YYYY-MM-DD? (1 个回答) 关闭 6 年前。 我正在尝试将 CSV
我需要更改 string 的日期格式。原始字符串的格式如下: var timeStamp = '2014/07/30 - 14:15:36' 这是我想要实现的日期格式: var timeStampAr
我正在尝试将 yyyy-MM-dd'T'HH:mm:ss.SSSz 格式的日期格式化为 yyyy-mm-dd HH:mm:ss,这应该很容易,但我无法获得它可以工作。 需要解析的日期格式为:2012-
我正在尝试通过传递时间戳作为命令行参数来使用 Synapse 管道运行 Spark 作业。在与 Spark 作业相关的代码运行之前,synapse 正在将字符串命令行参数值从 ISO 格式 2019-
我试过下面的代码: String created_Date = "25-Nov-15 14:23:34"; SimpleDateFormat sdf = new SimpleDateFormat("d
我创建了一个函数,它以与原始格式不同的格式返回日期。基本上,我正在使用此 Select MonthSub('2014-04-10',2)# 语句进行测试,它应该返回2014-02,而不是 2014-0
我是一名优秀的程序员,十分优秀!