【转+修改】容联云通讯api调用短信发送调用
转自 https://my.oschina.net/u/1995134/blog/814540
需要荣联云通讯 的 相对应SDKjar包。
CCP_REST_SMS_SDK_JAVA_v2.6.3r.jar
调用测试在main方法里:
public static void main(String[] args){
ResponseObj obj = FhPhoneMassageSender.testSender("176****5720","呵呵"); -- 手机号码及内容
System.out.println(obj.getResultMsg());
}
上代码:
import java.util.HashMap;
import java.util.Set; import com.cloopen.rest.sdk.CCPRestSmsSDK;public class FhPhoneMassageSender {
private static String sms_ytx_url="appsms.cloopen.com";
private static String sms_ytx_port="8883";
private static String sms_ytx_sid="*****************ff2dea1de4a6f";
private static String sms_ytx_token="fa9b5d*************2457508977";
private static String sms_ytx_appid="aaf98f89544cd9d9015475b429082343";
private static String sms_ytx_valid_min="5";
private static String sms_ytx_tempid="8****40";
/**
* <p class="detail">
* 功能:容联云通讯-发送短信
* </p>
* @author liuwh
* @date 2016-1-22
* @param tel 手机号码,多个用,分隔
* @param verifyCode 验证码
* @return
*/
public static ResponseObj sendRegCodeByYTX(String tel, String verifyCode,String verifyName){ ResponseObj obj = new ResponseObj(true, "操作成功");
HashMap<String, Object> result = null;
//初始化SDK
CCPRestSmsSDK restAPI = new CCPRestSmsSDK(); restAPI.init(Global.getConfig("sms_ytx_url"), Global.getConfig("sms_ytx_port")); restAPI.setAccount(Global.getConfig("sms_ytx_sid"), Global.getConfig("sms_ytx_token"));//账号、密码 restAPI.setAppId(Global.getConfig("sms_ytx_appid"));//应用ID String smsValidMin=Global.getConfig("sms_ytx_valid_min"); //验证码过期时间
if(StringUtils.isEmpty(smsValidMin)){
smsValidMin="5";
}
result = restAPI.sendTemplateSMS(tel, Global.getConfig("sms_ytx_tempid"),new String[]{verifyName,verifyCode, smsValidMin}); System.out.println("SDKTestGetSubAccounts result=" + result);
if("000000".equals(result.get("statusCode"))){
//正常返回输出data包体信息(map)
HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
Set<String> keySet = data.keySet();
for(String key:keySet){
Object object = data.get(key);
System.out.println(key +" = "+object);
}
}else{
//异常返回输出错误码和错误信息
System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
obj.setSuccessful(false);
obj.setResultMsg(String.valueOf(result.get("statusMsg")));
}
return obj;
} /**
* <p class="detail">
* 功能:容联云通讯-发送催款信息
* </p>
* @author liuwh
* @date 2016-1-22
* @param tel 手机号码,多个用,分隔
* @param verifyName 参数值(多个替换坑)
* @return
*/
public static ResponseObj sendPressMoneyByYTX(String tel,String... verifyName){ ResponseObj obj = new ResponseObj(true, "操作成功");
HashMap<String, Object> result = null;
//初始化SDK
CCPRestSmsSDK restAPI = new CCPRestSmsSDK(); restAPI.init(sms_ytx_url, sms_ytx_port); restAPI.setAccount(Global.getConfig("sms_ytx_sid"), Global.getConfig("sms_ytx_token"));//账号、密码 restAPI.setAppId(Global.getConfig("sms_ytx_appid"));//应用ID result = restAPI.sendTemplateSMS(tel, Global.getConfig("sms_ytx_press_tempid"), verifyName); if("000000".equals(result.get("statusCode"))){
//正常返回输出data包体信息(map)
HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
Set<String> keySet = data.keySet();
for(String key:keySet){
Object object = data.get(key);
System.out.println(key +" = "+object);
}
}else{
//异常返回输出错误码和错误信息
System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
obj.setSuccessful(false);
obj.setResultMsg(String.valueOf(result.get("statusMsg")));
}
return obj;
}
public static ResponseObj testSender(String tel,String... verifyName){
ResponseObj obj = new ResponseObj(true, "操作成功");
HashMap<String, Object> result = null;
//初始化SDK
CCPRestSmsSDK restAPI = new CCPRestSmsSDK(); restAPI.init(sms_ytx_url,sms_ytx_port); restAPI.setAccount(sms_ytx_sid, sms_ytx_token);//账号、密码 restAPI.setAppId(sms_ytx_appid);//应用ID result = restAPI.sendTemplateSMS(tel, sms_ytx_tempid, verifyName); if("000000".equals(result.get("statusCode"))){
//正常返回输出data包体信息(map)
HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
Set<String> keySet = data.keySet();
for(String key:keySet){
Object object = data.get(key);
System.out.println(key +" = "+object);
}
}else{
//异常返回输出错误码和错误信息
System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
obj.setSuccessful(false);
obj.setResultMsg(String.valueOf(result.get("statusMsg")));
}
return obj;
}
public static void main(String[] args){
ResponseObj obj = FhPhoneMassageSender.testSender("176****5720","呵呵");
System.out.println(obj.getResultMsg());
}
}
Global 是用来获取配置文件内容的。实际开发中可以像测试代码中那样把api需要的配置信息直接写在静态变量中。
ResponseObj 是自己封装的返回数据的类型:
package com.thinkgem.jeesite.common.utils; /**
* Created by antis on 2017/6/27.
*/
public class ResponseObj {
/**
* 总记录数
*/
private int total;
/**
* 当前记录集合
*/
private Object data;
/**
* 是否成功
*/
private boolean successful;
/**
* 结果消息
*/
private String resultMsg;
/**
* 错误类型
*/
private String type;
/**
* 添加数据
* @param data
* @return
*/
public static ResponseObj successResult(Object data) {
return new ResponseObj(1,data,true, "", "");
}
/**
* 添加数据
* @param data
* @return
*/
public static ResponseObj successResult(Object data,int total) {
return new ResponseObj(total,data,true, "", "");
}
/**
* 返回失败信息
* @param exMessage
* @return
*/
public static ResponseObj failedResult(String exMessage) {
return new ResponseObj(0, "", false,exMessage, "error");
}
/**
* 返回失败信息和类型
* @param exMessage
* @param type
* @return
*/
public static ResponseObj failedResult(String exMessage, String type) {
return new ResponseObj(0, "",false, exMessage, type);
}
/**
* 构造函数,类型为error
*
*/
public ResponseObj() {
type = "error";
}
public ResponseObj(boolean successful,String resultMsg){
this.successful = successful;
this.resultMsg = resultMsg;
}
public ResponseObj(int total, Object data, boolean successful,String resultMsg, String type) {
this.total = total;
this.data = data;
this.successful = successful;
this.resultMsg = resultMsg;
this.type = type;
}
/**
* @return the 总记录数
*/
public int getTotal() {
return total;
}
/**
* @param total 总记录数 the total to set
*/
public void setTotal(int total) {
this.total = total;
}
/**
* @return the 是否成功
*/
public boolean isSuccessful() {
return successful;
} /**
* @param successful 是否成功
* the successful to set
*/
public void setSuccessful(boolean successful) {
this.successful = successful;
} /**
* @return the data
*/
public Object getData() {
return data;
}
/**
* @param data the data to set
*/
public void setData(Object data) {
this.data = data;
}
/**
* @return the 结果消息
*/
public String getResultMsg() {
return resultMsg;
} /**
* @param resultMsg 结果消息
* the resultMsg to set
*/
public void setResultMsg(String resultMsg) {
this.resultMsg = resultMsg;
} /**
* @return the 错误类型
*/
public String getType() {
return type;
} /**
* @param type 错误类型
* the type to set
*/
public void setType(String type) {
this.type = type;
}
}
解释一下api需要的各个参数
private static String sms_ytx_url="appsms.cloopen.com"; --容联的appsms的url是固定不变的
private static String sms_ytx_port="8883"; --端口号,应该也是不变的
private static String sms_ytx_sid="*****************ff2dea1de4a6f"; --容联主账户的ACCOUNT SID
private static String sms_ytx_token="fa9b5d*************2457508977"; --容联主账户的AUTH TOKEN
private static String sms_ytx_appid="aaf98f89544cd9d9015475b429082343"; --正在开发的应用的 APP ID
private static String sms_ytx_valid_min="5"; --验证码有效时间 可以自己设置,分钟为单位
private static String sms_ytx_tempid="8****40"; --短信模板ID


【转+修改】容联云通讯api调用短信发送调用的更多相关文章
- python-在python3中使用容联云通讯发送短信验证码
容联云通讯是第三方平台,能够提供短信验证码和语音通信等功能,这里只测试使用短信验证码的功能,因此只需完成注册登录(无需实名认证等)即可使用其短信验证码免费测试服务,不过免费测试服务只能给控制台中指定的 ...
- 容联云通讯_提供网络通话、视频通话、视频会议、云呼叫中心、IM等融合通讯能力开放平台。
容联云通讯_提供网络通话.视频通话.视频会议.云呼叫中心.IM等融合通讯能力开放平台. undefined
- Luffy之注册认证(容联云通讯短信验证)
用户的注册认证 前端显示注册页面并调整首页头部和登陆页面的注册按钮的链接. 注册页面Register,主要是通过登录页面进行改成而成. 先构造前端页面 <template> <div ...
- mevan引入容联云通讯jar
首先从官网下载jar 然后拷贝到lib目录下 最后在pom.xml中这样写 <dependency> <groupId>cn.com</groupId> <a ...
- .Net语言 APP开发平台——Smobiler学习日志:如何调用API进行短信发送
最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 一.目标样式 我们要实现上图中的效果,需要如下的操作: 二.发送短信代码 VB: Pr ...
- Java版阿里云通信短信发送API接口实例(新)
阿里云通信(原名阿里大于)的短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力,支持快速发送短信验证码.短信通知等. 完美支撑双11期间2亿用户,发送6亿短信 ...
- asp.net mvc短信接口调用——阿里大于API开发心得
互联网上有许多公司提供短信接口服务,诸如网易云信.阿里大于等等.我在自己项目里需要使用到短信服务起到通知作用,实际开发周期三天,完成配置.开发和使用,总的说,阿里大于提供的接口易于开发,非常的方便,短 ...
- 阿里云短信服务调用例子-Python
阿里云短信服务调用例子 阿里云官方文档https://helpcdn.aliyun.com/document_detail/101893.html 首先需要安装阿里云PythonSDK(下面是pyth ...
- 短信接口调用以及ajax发送短信接口实现以及前端样式
我们短信api用的是云信使平台提供的非免费短信服务:官网提供的demo有两种,分别是function加其调用.class文件加其调用. 在这里我们用class文件加调用: 首先,ThinkPHP里面自 ...
随机推荐
- sql递归显示层级数据
;) as varchar(max)) as ssort from Category where ID = '123' union all select t.*, ) as varchar(max)) ...
- C#中的分部类和分部方法:partial
这篇文章主要介绍了C#中的分部类和分部方法,讲解了类的拆分和方法的定义的拆分,需要的朋友可以参考下可以将类或结构.接口或方法的定义拆分到两个或多个源文件中.每个源文件包含类型或方法定义的一部分,编译应 ...
- 几个常用的内存、CPU飙高 分析工具
Process Hacker.Windbg.vs2017 调试托管内存.Microsoft.Samples.Debugging.ants memory profiler.ants performanc ...
- ASP.NET之HTML
1.什么是html 用来描述网页的2.开发工具我们肯定是用vs啦3.img src 图片地址 <img src="img/aa.bmp" />; 4.超链接a标签 hr ...
- Java开发学习--Java 中基本类型和包装类之间的转换
Java 中基本类型和包装类之间的转换 基本类型和包装类之间经常需要互相转换,以 Integer 为例(其他几个包装类的操作雷同哦): 在 JDK1.5 引入自动装箱和拆箱的机制后,包装类和基本类型之 ...
- Spark内部结构详解
参考: https://github.com/JerryLead/SparkInternals/blob/master/markdown/english/5-Architecture.md?winzo ...
- [LeetCode]Delete and Earn题解(动态规划)
Delete and Earn Given an array nums of integers, you can perform operations on the array. In each op ...
- ES6学习笔记(四)-数值扩展
PS: 前段时间转入有道云笔记,体验非常友好,所以笔记一般记录于云笔记中,每隔一段时间,会整理一下, 发在博客上与大家一起分享,交流和学习. 以下:
- sql:MySql create FUNCTION,VIEW,PROCEDURE
use geovindu; #函数 DELIMITER $$ drop function if exists f_GetDepartmentName $$ CREATE function f_GetD ...
- 利用PHP QR Code生成二维码(带logo)
转自:http://www.cnblogs.com/txw1958/p/phpqrcode.html HP QR Code是一个PHP二维码生成类库,利用它可以轻松生成二维码,官网提供了下载和多个演示 ...
