公司业务某项目需要调中国移动云mas的发送短信:
1.首先登陆云MAS平台网址:云MAS业务平台_中国移动,
下载案例,从demo源码lib里把SDK的jar包拿出来.
2.项目引入SDK有两种方式:
1).安装到maven仓库,依赖引进
pom.xml文件引进依赖:
<dependency>
<groupId>com.masmgc</groupId>
<artifactId>masmgc-sdk-sms</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
解决依赖冲突:因为jar包中使用springframework等,
可以直接删除:
2).在项目中的resource下建立lib直接加进jar,
import com.mascloud.sdkclient.Client;
@PostMapping(value = "/sendMas")
public Integer sendMas(@RequestBody JSONObject code) {
String mobile = code.get("mobiles").toString();
String msg = code.get("content").toString();
Client client = Client.getInstance();
// 登录地址需另外提供
boolean isLoggedin = client.login(url, account, psd, name);
if (isLoggedin) {
System.out.println("发送短信登录成功");
} else {
System.out.println("发送短信登录失败");
}
// 普通短信
String[] codeArray = mobile.split(",");//获取用户手机号
int rt = client.sendDSMS(codeArray, msg, "123", 1, sign, null, true);
System.out.println("发送短信返回值:" + rt);
return rt;
}