java腾讯云短信验证码发送

	
		com.github.qcloudsms
		qcloudsms
		1.0.5
	

	
		com.alibaba
		fastjson
		1.2.15
	
	
	
		com.aliyun
		aliyun-java-sdk-core
		4.0.6
	
	
		com.aliyun
		aliyun-java-sdk-dysmsapi
		1.1.0
	
/*

*腾讯短信验证码发送*/

  public Map sends(String mobile)throws Exception{

Map map =new HashMap();

int i =1;

// 短信应用SDK AppID 1400开头

      int appid =your appid;

      // 短信应用SDK AppKey

      String appkey =yourappkey;

// 需要发送短信的手机号码

        String[] phoneNumbers = { mobile }; //可填多个手机号

String randomCode = getRandomCode();

try {

SmsSingleSender ssender =new SmsSingleSender(appid, appkey);

SmsSingleSenderResult result = ssender.send(0,"86", phoneNumbers[0], randomCode+"为您的登录验证码,请于5分钟内填写。如非本人操作,请忽略本短信。","","");

i = result.result;

map.put("result",i);

map.put("randomCode",randomCode);

}catch (HTTPException e) {// HTTP响应码错误

          e.printStackTrace();

}catch (JSONException e) {// json解析错误

          e.printStackTrace();

}catch (IOException e) {// 网络IO错误

          e.printStackTrace();

}catch (org.json.JSONException e) {

e.printStackTrace();

}catch (com.github.qcloudsms.httpclient.HTTPException e) {

e.printStackTrace();

}

return map;

}

/**

    * 随机生成6位验证码

    * @return

    */

  private String getRandomCode(){

Random random =new Random();

StringBuffer result=new StringBuffer();

for (int i=0;i<6;i++){

result.append(random.nextInt(10));

}

return result.toString();

}

你可能感兴趣的:(java)