参考 :https://help.aliyun.com/document_detail/55284.html?spm=5176.doc55289.6.557.ufgnZi
技术支持:李柏静
我自己简单看了一下,感觉不是很懂,只会简单的配置这些。先把代码放在这里,周末抽时间具体学习一下。
下面是代码部分
package xc.fuping.utils;
import java.util.Timer;
import java.util.TimerTask;
import com.alibaba.fastjson.JSONObject;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import xc.common.model.FupingInfo;
import xc.common.model.FupingMsgRecord;
public class DayuSdk {
private static String url = "http://gw.api.taobao.com/router/rest";
// 从以下开始为阿里大于短信发送,
public static String alidayuKey = "alidayuKey";
public static String alidayusecret = "alidayusecret";
public static String alidayuSign = "通知";
public static TimerTask timerTask;
public static Timer timer;
public static void main(String[] args) throws ApiException {
sendTipsSMS("13333333333", "小米", "吃饭",1);
}
/**
*
* @Description 采用模板:${name}同志,你有以下工作${work}未完成。
* @author 随风丶小柏
* @date 2017年8月6日 上午9:57:48
* @param mobile
* @param name 用户姓名
* @param poor 平困户
* @param var 项目:无安全住房保障 ,五安全用电、无安全用电
* @param recordID 短信发送记录
* @return
*/
public static boolean sendTipsSMS(String mobile, String name,String work,int recordID) {
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
req.setExtend("123456");
req.setSmsType("normal");
req.setSmsFreeSignName(alidayuSign);
req.setSmsParamString("{\"name\":\"" + name + "\",\"work\":\""+work+"\"}");
req.setRecNum(mobile);
req.setSmsTemplateCode("SMS_80325029");
//FupingInfo info = FupingInfo.dao.findById(1);
//int count = info.getMsgRemain();
boolean ret = false;
try {
ret = !resendMessage(req,recordID);//发送成功
} catch (ApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
// 阿里大于短信发送结果,result为0即为成功
public static boolean checkSendIsSuccessful(String json,int recordID) {
JSONObject jsonObject = JSONObject.parseObject(json);
boolean successful = jsonObject.containsKey("error_response");
return successful;
}
/**
*
* @Description 发送信息接口方法。发送失败延迟5秒发送
* @author 随风丶小柏
* @date 2017年8月6日 上午9:55:59
* @param req
* @param recordID 短信记录ID
* @return
* @throws ApiException
*/
public static boolean resendMessage(final AlibabaAliqinFcSmsNumSendRequest req,final int recordID) throws ApiException {
final TaobaoClient client = new DefaultTaobaoClient(url, alidayuKey, alidayusecret);
AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
String body = rsp.getBody();
System.out.println(body);
boolean errcode = checkSendIsSuccessful(body,recordID);
return errcode;
}
}