一.登录官网,下载http接入文档(随着官网不断更新,可参考官网的文档)
官网地址为:云mas业务平台
进入云MAS管理平台,找到 管理-接口管理 的列表页。
(必读:本文对接方式是 java引用jar包,进行sdk协议对接,后台java代码是引用jar包,调用短信服务的http接口,所以你创建的短信接口协议必须是SDK2.0,这样后台才能接口调用成功。)
进入这个短信接口的详情页,查看一下配置项。
二.代码示范(亲测成功,先附上成功图片)
成功示范图
添加依赖jar包
Java+Demo对接中国移动 云MAS短信发送-Jar,点击0积分获取!!!
创建 MmsSend.java
package demo;
import com.umpay.masmgc.sdk.mms.compat.core.message.ap.ApMmsSubmitReq;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.bsi.api.client.Client;
import com.bsi.api.client.MmsClient;
import com.bsi.api.pojo.MM7;
import com.bsi.api.pojo.MM7Frame;
import com.cmcc.mm7.vasp.message.MM7DeliveryReportReq;
public class MmsSend {
// 1 组装无模板彩信
private MM7 createMM7_1( ) throws Exception {
String subject = "";// 主题
String signa = "sss"; // 签名
String[] mobiles = new String[]{ "***" };
MM7 mm7 = Client.getInstance( ).createMM7( subject, mobiles, signa );
List frames = new ArrayList( );
MM7Frame frame1 = mm7.addFrame( 15 );// 添加一帧
frame1.addImage( createByteByFileName( "./data/zq/1.jpg" ) );// byte[]类型参数
frame1.addText( createByteByFileName( "./data/zq/a.txt" ) );
frames.add( frame1 );// 添加到List
MM7Frame frame2 = mm7.addFrame( 15 );
frame2.addImage( createByteByFileName( "./data/zq/2.jpg" ) );
frame2.addText( createByteByFileName( "./data/zq/b.txt" ) );
frames.add( frame2 );
MM7Frame frame3 = mm7.addFrame( 15 );
frame3.addImage( createByteByFileName( "./data/zq/3.jpg" ) );
frame3.addText( createByteByFileName( "./data/zq/c.txt" ) );
frames.add( frame3 );
//
// MM7Frame frame4 = mm7.addFrame( 15 );
// frame4.addText( createByteByFileName( "./data/temp/4.txt" ) );
// frames.add( frame4 );
//
// MM7Frame frame5 = mm7.addFrame( 15 );
// frame5.addText( createByteByFileName( "./data/temp/5.txt" ) );
// frames.add( frame5 );
//
// MM7Frame frame6 = mm7.addFrame( 15 );
// frame6.addImage( createByteByFileName( "./data/temp/1490952420.jpg" ) );
// frames.add( frame6 );
//
// MM7Frame frame7 = mm7.addFrame( 15 );
// frame7.addAudio( createByteByFileName( "./data/temp/FFX61N8X.mid" ) );
// frames.add( frame7 );
//
// MM7Frame frame8 = mm7.addFrame( 15 );
// frame8.addImage( createByteByFileName( "./data/temp/riben_175.jpg" ) );
// frame8.addText( createByteByFileName( "./data/temp/riben_175.txt" ) );
// frames.add( frame8 );
return mm7;
}
// 2组装无模板定时彩信
private MM7 createMM7_2( ) throws Exception {
String subject = "test_subject";// 主题
String signa = "Vj7nlgsne"; // 签名
String[] mobiles = new String[]{ "15718861521","15718861521" };
SimpleDateFormat timer1 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
Date timer = timer1.parse( "2016-10-26 18:40:00" );
MM7 mm7 = Client.getInstance( ).createMM7( subject, mobiles, signa, timer );
List frames = new ArrayList( );
MM7Frame frame1 = mm7.addFrame( 15 );// 添加一帧
frame1.addText( createByteByFileName( "./data/temp/1.txt" ) );// byte[]类型参数
frames.add( frame1 );// 添加到List
MM7Frame frame2 = mm7.addFrame( 15 );
frame2.addText( createByteByFileName( "./data/temp/2.txt" ) );
frames.add( frame2 );
MM7Frame frame3 = mm7.addFrame( 15 );
frame3.addText( createByteByFileName( "./data/temp/3.txt" ) );
frames.add( frame3 );
MM7Frame frame4 = mm7.addFrame( 15 );
frame4.addText( createByteByFileName( "./data/temp/4.txt" ) );
frames.add( frame4 );
MM7Frame frame5 = mm7.addFrame( 15 );
frame5.addText( createByteByFileName( "./data/temp/5.txt" ) );
frames.add( frame5 );
MM7Frame frame6 = mm7.addFrame( 15 );
frame6.addText( createByteByFileName( "./data/temp/6.txt" ) );
frames.add( frame6 );
MM7Frame frame7 = mm7.addFrame( 15 );
frame7.addAudio( createByteByFileName( "./data/temp/FFX61N8X.mid" ) );
frames.add( frame7 );
MM7Frame frame8 = mm7.addFrame( 15 );
frame8.addImage( createByteByFileName( "./data/temp/riben_175.jpg" ) );
frame8.addText( createByteByFileName( "./data/temp/riben_175.txt" ) );
frames.add( frame8 );
return mm7;
}
private MM7 createMM7_3( ) throws Exception {
String subject = "test_subject";
String signa = "Vj7nlgsne";
String[] mobiles = new String[]{ "15718861521" };
String tempId = "bac6c06e42f34b70a8483b04591cfcc6";
MM7 mm7 = Client.getInstance( ).createMM7( subject, mobiles, signa, tempId );
return mm7;
}
private MM7 createMM7_4( ) throws Exception {
String subject = "test_subject";
String signa = "Vj7nlgsne";
String[] mobiles = new String[]{ "15718861521" };
String tempId = "bac6c06e42f34b70a8483b04591cfcc6";
SimpleDateFormat timer1 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
Date timer = timer1.parse( "2016-10-26 18:40:00" );
MM7 mm7 = Client.getInstance( ).createMM7( subject, mobiles, signa, timer, tempId );
return mm7;
}
public static void main( String[] args ) {
MmsSend mmsSend = new MmsSend( );
Client client = Client.getInstance( );
boolean success = client.login("http://112.******:***", "sss","sss", "ssss");
if( !success ) {
return;
}
ApMmsSubmitReq req_1 = null;
// ApMmsSubmitReq req_2 = null;
// ApMmsSubmitReq req_3 = null;
// ApMmsSubmitReq req_4 = null;
try {
req_1 = MmsClient.getInstance( ).MM72ApMmsSubmitReq( mmsSend.createMM7_1( ) );
// req_2 = MmsClient.getInstance( ).MM72ApMmsSubmitReq( mmsSend.createMM7_2( ) );
// req_3 = MmsClient.getInstance( ).MM72ApMmsSubmitReq( mmsSend.createMM7_3( ) );
// req_4 = MmsClient.getInstance( ).MM72ApMmsSubmitReq( mmsSend.createMM7_4( ) );
Map result_1 = client.sendMms( req_1 );
// Map result_2 = client.sendMms( req_2 );
// Map result_3 = client.sendMms( req_3 );
// Map result_4 = client.sendMms( req_4 );
System.out.println( result_1 );
// System.out.println( result_2 );
// System.out.println( result_3 );
// System.out.println( result_4 );
while( true ) {
// List< SubmitReportModel > StatusReportlist = client.getSubmitReport();
List StatusReportlist = client.getReport( );
if( StatusReportlist.size( ) > 0 ) {
for( int i = 0; i < StatusReportlist.size( ); i++ ) {
System.out.println( "-----------------------------------------"+StatusReportlist.get( i ).getMMStatus( ) );
}
}
try {
Thread.sleep( 1000 );
} catch( InterruptedException e ) {
}
}
} catch( Exception e ) {
System.out.println( e );
}
}
private byte[] createByteByFileName( String path ) {
byte[] b = null;
try {
b = Files.readAllBytes( Paths.get( path ) );
} catch( IOException e ) {
System.out.println( "文件路劲错误或者找不到该多媒体内容 {}" + e );
}
return b;
}
}
创建 Sdk2SmsSend.java (测试类)
package demo;
import java.util.List;
import com.mascloud.model.MoModel;
import com.mascloud.model.StatusReportModel;
import com.mascloud.sdkclient.Client;
import com.mascloud.util.JsonUtil;
public class Sdk2SmsSend {
public static void main( String[] args ) {
Client client = Client.getInstance( );
// 登录地址需另外提供
boolean isLoggedin = client.login( "http://112.35.4.197:15000", "zh****", "S********", "**********有限公司" );
if( isLoggedin ) {
System.out.println( "Login successed" );
} else {
System.out.println( "Login failed" );
return;
}
// 普通短信
int rt = client.sendDSMS( new String[]{ "188******96" }, "短信内容", "123", 1, "h**********fE", null, true );
System.out.println( rt );
// 模板短信
int rtm = client.sendTSMS( new String[]{ "188******96" }, "模板ID", new String[]{ "参数一", "参数二" }, "123", 0, "hWYR8VBfE", null );
System.out.println( rtm );
// 获取状态报告——开始
List statusReportlist = client.getReport( );
System.out.println( "getReport : " + JsonUtil.toJsonString( statusReportlist ) );
// 获取状态报告——结束
// 获取上行短信——开始
List deliverList = client.getMO( );
System.out.println( "getMO : " + JsonUtil.toJsonString( deliverList ) );
// 获取上行短信——结束
}
}
修改你自己对应的:账号、密码、短信签名编码
账号 对应 userAccount
密码 对应 password
企业名称 对应 ecname
接口URL 对应 url
----------------------------------------------------------------------
解释:
Http协议的Url参考:
1.http下login方法调用的接口:http://112.35.4.197:15000
2.http下sendMsg方法调用接口:http://112.35.1.155:1992/sms/norsubmit
Https协议的Url参考:
二平台
https 普通短信 https://112.35.10.201:28888/sms/submit
https 模板短信 https://112.35.10.201:28888/sms/tmpsubmit
五平台
https 普通短信 https://112.35.10.201:58888/sms/submit
https 模板短信 https://112.35.10.201:58888/sms/tmpsubmit
三.完整Demo
链接还未审核通过,稍后更新,点击0积分获取!!!