public void sendCodeByEmail(String email, String account, String code) {
// 验证码生成
String vcode = "";
for (Integer i = 0; i < 4; i++) {
int in = (int) (Math.random() * 10);
if (in == 0) {
in = 1;
}
vcode = vcode + in;
}
Map map = new HashMap();
map.put("account", account);
map.put("vcode", vcode);
map.put("email", email);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
map.put("date", format.format(new Date()));
// 验证信息
CompanyValidate validate = new CompanyValidate();
validate.setTargetName(email);
validate.setVcode(vcode);
validate.setTargetType(TYPE_EMAIL);// 邮箱验证
// 保存验证信息
companyValidateDao.insertValidate(validate);
String key = "";
try {
key = MD5.encode(account + email + vcode);
map.put("key", key);
} catch (Exception e) {
return;
}
// 发送邮件
String sms_flag = (String) MemcachedUtils.getInstance().getClient()
.get("baseConfig.sms.flag");
if ("true".equals(sms_flag)) {
if (code.equals("0")) {
map.put("address", AddressTool.getAddress("www")+ "/doValidEmail.htm?key=" + key + "&account" + account+ "&vcode=" + vcode);
MailUtil.getInstance().sendMail("邮件密码找回", email,
"feiliao91-pwd-mail", map, 0);
} else if (code.equals("1")) {
map.put("address", AddressTool.getAddress("trade")
+ "/security/unValidEmail.htm?key=" + key + "&account="
+ account + "&vcode=" + vcode + "&email=" + email);
MailUtil.getInstance().sendMail("邮件解绑", email,
"feiliao91-email-mailUnbind", map, 0);
} else if (code.equals("2")) {
map.put("address", AddressTool.getAddress("trade")
+ "/security/doValidEmail.htm?key=" + key + "&account="
+ account + "&vcode=" + vcode + "&email=" + email);
MailUtil.getInstance().sendMail("邮件绑定", email,
"feiliao91-email-mailBind", map, 0);
}
} else {
// 本地打印信息
System.out.println(map);
}
}