业务要求:公司购买阿里大于服务,需要使用阿里大于的接口服务,发送短信。
功能代码:
package com.wlsq.kso.util;import com.taobao.api.DefaultTaobaoClient;import com.taobao.api.TaobaoClient;import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;public class ALiMsg { // 阿里大于key secret static String appkey = "************"; static String secret = "************"; static String url = "http://gw.api.taobao.com/router/rest"; public static boolean sendSmsCode(String telephone, Integer phonecode) { try { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.setSmsType("normal"); req.setSmsFreeSignName("未来社区"); req.setSmsParamString("{/"name/":/"" +phonecode+ "/"}"); req.setRecNum(telephone); req.setSmsTemplateCode("*****"); AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req); } catch (Exception e) { return false; } return true; } public static void main(String[] args) { int a = (int) (Math.random() * (9999 - 1000 + 1)) + 1000;// 产生1000-9999的随机数 boolean target = sendSmsCode("13265740591", a); System.out.PRintln("短信发送状态:"+target); }}
新闻热点
疑难解答