工作需要,使用电信提供的webservice接口发送彩信,调了几天,终于可以把彩信发送出去了,代码如下:
package com.onewaveinc.message;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.util.ByteArrayDataSource;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.types.URI;
import com.onewaveinc.pnp.mms.ChargingInformation;
import com.onewaveinc.pnp.mms.DeliveryInformation;
import com.onewaveinc.pnp.mms.MessagePriority;
import com.onewaveinc.pnp.mms.SendMessageBindingStub;
import com.onewaveinc.pnp.mms.SendMessageServiceLocator;
import com.onewaveinc.pnp.mms.SimpleReference;
import com.onewaveinc.properties.PropertiesManage;
import com.onewaveinc.utils.MD5;
public class Message {
public static void main(String[] args) {
SendMessageServiceLocator loc = new SendMessageServiceLocator();
String url = PropertiesManage.getValue("url");
System.out.println("接口地址: " + url);
loc.setSendMessageEndpointAddress(url);
try {
SendMessageBindingStub binding = (SendMessageBindingStub) loc.getSendMessage();
binding.setTimeout(60000);
//添加头信息
String spId = PropertiesManage.getValue("message.header.spId");
String spPassword = PropertiesManage.getValue("message.header.spPassword");
SimpleDateFormat formatter = new SimpleDateFormat("MMddhhmmss");
String timeStamp = formatter.format(Calendar.getInstance().getTime());
//密码加密
spPassword = MD5.compile(spId + spPassword + timeStamp);
System.out.println("密码加密后:" + spPassword);
String productId = PropertiesManage.getValue("message.header.productId");
String SAN = PropertiesManage.getValue("message.header.SAN");
String transactionId = PropertiesManage.getValue("message.header.transactionId");
String transEnd = PropertiesManage.getValue("message.header.transEnd");
String linkId = PropertiesManage.getValue("message.header.linkId");
String OA = PropertiesManage.getValue("message.header.OA");
String FA = PropertiesManage.getValue("message.header.FA");
String multicastMessaging = PropertiesManage.getValue("message.header.multicastMessaging");
SOAPHeaderElement header = new SOAPHeaderElement("http://www.chinatelecom.com.cn/schema/ctcc/common/v2_1", "RequestSOAPHeader");
header.addChildElement("spId").addTextNode(spId);
header.addChildElement("spPassword").addTextNode(spPassword);
header.addChildElement("timeStamp").addTextNode(timeStamp);
header.addChildElement("productId").addTextNode(productId);
header.addChildElement("SAN").addTextNode(SAN);
header.addChildElement("transactionId").addTextNode(transactionId);
header.addChildElement("transEnd").addTextNode(transEnd);
header.addChildElement("linkId").addTextNode(linkId); // linkID
header.addChildElement("OA").addTextNode(OA);
header.addChildElement("FA").addTextNode(FA);
header.addChildElement("multicastMessaging").addTextNode(multicastMessaging);
binding.setHeader(header);
//短信接收者
URI[] uris = new URI[args.length];
for (int i = 0; i < args.length; i++) {
uris[i] = new URI(args[i]);
System.out.println("消息接收号码: " + args[i]);
}
//短信发送者
String sender = PropertiesManage.getValue("message.sender");
//短信主题
String sub = PropertiesManage.getValue("message.subject");
System.out.println("消息内容: " + sub);
//计费信息
ChargingInformation info = new ChargingInformation();
info.setDescription(PropertiesManage.getValue("charging.description"));
info.setAmount(new BigDecimal(Integer.valueOf(PropertiesManage.getValue("charging.amount"))));
info.setCode(PropertiesManage.getValue("charging.code"));
info.setCurrency(PropertiesManage.getValue("charging.currency"));
//状态报告接口
SimpleReference request = null;
if ("on".equals(PropertiesManage.getValue("reference.need"))) {
request = new SimpleReference();
request.setCorrelator(PropertiesManage.getValue("reference.correlator"));
request.setInterfaceName(PropertiesManage.getValue("reference.interfaceName"));
request.setEndpoint(new URI(PropertiesManage.getValue("reference.endpoint")));
}
//彩信内容
if ("on".equals(PropertiesManage.getValue("message.need"))) {
String fileName = PropertiesManage.getValue("message.content");
String[] fileNames = fileName.split(";");
for (String name : fileNames) {
System.out.println("彩信内容: " + name);
File file = new File(name);
DataHandler dh = new DataHandler(new FileDataSource(file));
AttachmentPart ap= new AttachmentPart(dh);
ap.setContentId(file.getName());
ap.setContentLocation(file.getName());
if (file.getName().indexOf("smil") > 0) {
ap.setContentType("application/smil");
} else if (file.getName().endsWith("txt")) {
ap.setContentType("text/plain;charset=utf-8");
} else if (file.getName().endsWith("amr")) {
ap.setContentType("audio/amr");
} else if (file.getName().endsWith("mp3")) {
ap.setContentType("audio/mpeg");
} else {
ap.setContentType(ap.getContentType());
}
binding.addAttachment(ap);
}
}
System.out.println("消息发送中...");
String value = binding.sendMessage(uris, sender, sub, MessagePriority.Default, info, request);
System.out.println("返回的彩信状态查询标识符为:" + value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
但是悲哀的发现这段代码运行起来可以发送图片和文字等信息并且能显示,但是音频文件如amr什么的却只能显示为附件不能直接播放,以为是contenttype的问题,所以添加了设置contenttype的代码ap.setContentType(...);但还是不能解决问题...
测试发现下发的彩信文件名称会少掉第一个字符和最后一个字符,导致amr文件成了am文件,以至于手机播放器不能识别,故将contentid前后各加一字符,问题解决,但至今未知原因
分享到:
相关推荐
中国电信综合业务接入网关(ISAG)开放接口协议01-总册
依据电信《中国电信综合业务接入网关_ISAG_开放接口协议》编写的彩信上行和下行模块。已经测试过,下行可以收到,上行能够解析并能够保存附件。
1、电信提供的isag 接口只有java 实例; 2、wsdl说明文件有问题,必须手工编辑; 3、文档和代码不对应; 4、该资源本人已经联调测试通过; 5、提供了wsdl 生成C#本地代码的批处理; 6、通过测短信发送demo;
中国电信ISAG接口开发文档(含接口WSDL)
依据电信《中国电信综合业务接入网关_ISAG_开放接口协议》编写的彩信上行和下行模块。已经测试过,下行可以收到,上行能够解析并能够保存附件。下行目前只支持gif和txt格式文件。
中国电信综合业务接入网关(ISAG)开放接口技术规范--MMS RC V1.1.0
中国电信综合业务管理平台ISMP接口规范,中国电信综合业务管理平台ISAG接口规范
因为短信也是ISAG的一个接入的一个基本功能,而且相对WAP PUSH和彩信接口比 较简单,接口与彩信和WAP PUSH相近,理解ISAG短信接入的接口协议也有利于了解整 个ISAG的接口协议。所以这里还是就ISAG接入短信业务进行...
ISAG 接口demoISAG 接口demoISAG 接口demoISAG 接口demo
中国电信sp接入ISAG平台彩信开发实例,减少sp开发过程时间。避免参数错误,而手机端接收有问题.本人一个礼拜时间花了很多心血搞定的东东,你懂的
电信 isag 接口文档 包含总册、短信、彩信 和 wap push部分
电信sp开发的包,相信有从事这方面工作的人都知道它
中国电信CDMA 移动业务网络全国业务接入网关(NSAG)设备 中国电信综合业务管理平台ISMP接口 中国电信综合业务接入网关(ISAG)开放接口--ECC -SMS -WAP Push -MMS -LCS
中国电信综合业务接入网关_ISAG_开放接口协议01-总册 RC V1.0.0.pdf 中国电信综合业务接入网关_ISAG_开放接口协议02-SMS RC V1.0.0.pdf 中国电信综合业务接入网关_ISAG_开放接口协议03-MMS RC V1.0.0.pdf ...
76个WSDL 标准报文格式样例 CPSP接口开发培训.ppt ISAG接入URL.txt SP测试FAQ帮助文档_0617.doc SP业务开发帮助(eclipse).CHM code 从ISAG接入sp首先看(必读)!!!.pdf
附录三: SendMessage彩信发送接口报文数据: 104 1.1请求(SP发起): 104 1.2 ISAG响应 106 二. 与ISMP接口实现 107 1.ISMP简介 107 1.1与ISMP相关的术语 107 2.业务流程 109 2.1点播业务流程 109 2.2包月业务流程 ...
电信综合网关协议,包含短信协议、彩信协议、WEBPUSh等等,并且包含示范代码,最优化您的开发,
ISAG短信MessageNotificationService接口实例,MessageNotificationService接口包括notifySmsReception和notifySmsDeliveryReceipt两个方法,在...开发时需要安装配置Tomcat + AXIS2 ,在工程中加入AXIS2的lib库。...
这份不是最新的,最新的看 http://download.csdn.net/source/2348590
isag开发需要用到的wsdl文件。可以方便与进行编写。