package com.fh.service.SMS; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; 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; public class Alidayu { public static void main(String[] args) { try { Alidayu.sendSMS("13463267918","注册验证","SMS_22610058","1111"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } public static long sendSMS(String Mobile,String freeSignName,String smsTemplateCode,String vercode) throws MalformedURLException, UnsupportedEncodingException { Map<String, Object> map = getContextProperty(); //官网的URL String url=(String) map.get("url"); //成为开发者,创建应用后系统自动生成 String appkey=(String) map.get("appkey"); String secret=(String) map.get("secret"); //短信模板的内容 String json="{"code":""+vercode+"","product":""}"; // String json="{"code":""+vercode+"","product":""+(String) map.get("company")+""}"; TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.setExtend("123456"); req.setSmsType("normal"); req.setSmsFreeSignName(freeSignName); req.setSmsParamString(json); req.setRecNum(Mobile); req.setSmsTemplateCode(smsTemplateCode); AlibabaAliqinFcSmsNumSendResponse rsp; try { rsp = client.execute(req); System.out.println(rsp.getBody()); return 1; } catch (ApiException e) { e.printStackTrace(); } return 0; } public static Map<String, Object> getContextProperty() { Map<String, Object> ctxPropertiesMap = new HashMap<String, Object>(); Properties prop = new Properties(); try { InputStream in = Alidayu.class.getClassLoader().getResourceAsStream("alidayu.properties"); prop.load(new InputStreamReader(in, "UTF-8")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Iterator<String> it = prop.stringPropertyNames().iterator(); while(it.hasNext()){ String key = it.next(); String value = prop.getProperty(key); System.out.println(key+":"+value); ctxPropertiesMap.put(key, value); } return ctxPropertiesMap; } }
alidayu.properties
#官网的URL
url=https://eco.taobao.com/router/rest
#TOP分配给应用的AppKey
appkey=23492181
secret=f5ad7249451dfa2525f2df85763a7a35
#公司名称
#company=【资格宝】
#company=北京三义资格教育科技有限公司