前言 需要引入sdk包
  http://aliyundm.oss-cn-hangzhou.aliyuncs.com/example/aliyun-java-sdk-smsV1.zip 代码
  两种发送方式:getAcsResponse和doAction接口,这里演示简单的getAcsResponse。
  /**
  *
  * @param toPhone 要发送的手机号码
  * @param code 验证码
  * @return
  */
  public String getAcsResponse(String toPhone, String code) {
  SingleSendSmsResponse httpResponse = new SingleSendSmsResponse();
  String result = "";
  try {
  IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKey, accessSecret);
  DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Sms","sms.aliyuncs.com");
  IAcsClient client = new DefaultAcsClient(profile);
  SingleSendSmsRequest request = new SingleSendSmsRequest();
  request.setSignName(sign);// 控制台创建的签名名称
  request.setTemplateCode(templateCode);// 控制台创建的模板CODE
  JSONObject jsonCode = new JSONObject();
  jsonCode.accumulate("code", code);
  request.setParamString(jsonCode.toString());
  request.setRecNum(toPhone);
  request.setAcceptFormat(FormatType.JSON); // 格式为json
  httpResponse = client.getAcsResponse(request);
  logger.info("send msgcode response: {} ", httpResponse.toString());
  result = ConstUtils.ERROR_0;
  } catch (ClientException e) {
  e.printStackTrace();// //InvalidSignName.Malformed : The specified// sign name is wrongly formed.
  logger.error("send msgcode error :{}", e.getMessage());
  result = e.getErrCode();
  }
  return result;
  }