首页 > 编程 > Java > 正文

java 阿里大于短信发送功能代码

2019-11-08 01:50:28
字体:
来源:转载
供稿:网友

业务要求:公司购买阿里大于服务,需要使用阿里大于的接口服务,发送短信。

功能代码:

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);	}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表