hugeng 5 years ago
parent
commit
2c5e4196b4

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 4 - 2
src/main/java/com/yc/education/controller/admin/UserController.java

@@ -2,6 +2,7 @@ package com.yc.education.controller.admin;
 
 
 import com.yc.education.model.User;
 import com.yc.education.model.User;
 import com.yc.education.service.UserService;
 import com.yc.education.service.UserService;
+import com.yc.education.util.HttpSender;
 import com.yc.education.util.MailUtils;
 import com.yc.education.util.MailUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
@@ -23,11 +24,12 @@ public class UserController {
 
 
     @RequestMapping(value = "submit_form.html",method = RequestMethod.POST)
     @RequestMapping(value = "submit_form.html",method = RequestMethod.POST)
     @ResponseBody
     @ResponseBody
-    public String submitForm(User user)  throws MessagingException {
+    public String submitForm(User user)  throws Exception {
         userService.save(user);
         userService.save(user);
         String str = "<h5>姓名: "+user.getName()+"</h5><h5>Email: "+user.getEmail()
         String str = "<h5>姓名: "+user.getName()+"</h5><h5>Email: "+user.getEmail()
                 +"</h5><h5>联系方式: "+user.getPhone()+"</h5><h5>需求类别: "+user.getItems()+"</h5><h5>项目信息:</h5>&nbsp;&nbsp;&nbsp;&nbsp;"+user.getDetails();
                 +"</h5><h5>联系方式: "+user.getPhone()+"</h5><h5>需求类别: "+user.getItems()+"</h5><h5>项目信息:</h5>&nbsp;&nbsp;&nbsp;&nbsp;"+user.getDetails();
-        MailUtils.sendMail("1985833793@qq.com",str);//接收者及文本详情
+        HttpSender.sendMail("项目合作",str,"andy@jzdsh.com");//接收者及文本详情
+        System.err.println("这儿执行了没 ");
         return "ok";
         return "ok";
     }
     }
 }
 }

+ 139 - 47
src/main/java/com/yc/education/util/HttpSender.java

@@ -1,60 +1,34 @@
 package com.yc.education.util;
 package com.yc.education.util;
 
 
-
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.Random;
-
-import javax.servlet.http.HttpSession;
-
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 
 
-public class HttpSender{
-	//用来产生随机验证码的
-	private static Random rand = new Random();
-	
-	private static String[] str = {"0","1","2","3","4","5","6","7","8","9"};
-	
-	
-
-	public static void main(String[] args) {
-
-		
-    	//存放产生的随机数
-    	String sms="";
-    	//生成六位数的随机数
-    	StringBuffer buf = new StringBuffer();
-		for(int i=0;i<6;i++){
-			buf.append(str[rand.nextInt(10)]);
-		}
-		sms= buf.toString();
-		System.out.println( buf.toString());
-		
-		//session.setAttribute("sms", buf.toString());
-		
-		String url = "http://www.uoleem.com.cn/api/";// 应用地址
-		String username = "xxltl";// 账号
-		String pwd = "xxltl63811727";// 密码
-		String mobile = "13772164740";// 手机号码,多个号码使用","分割
-		String content = "【香榭丽涂料】校验码:"+sms+",您正在注册香榭丽会员,请尽快操作!";// 短信内容
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.Date;
+import java.util.Properties;
 
 
-		try {
-			String returnString = HttpSender.batchSend(url, username, pwd, mobile, content);
-			System.out.println(returnString);
-			// TODO 处理返回值,参见HTTP协议文档
-		} catch (Exception e) {
-			// TODO 处理异常
-			e.printStackTrace();
-		}
-	}	
+public class HttpSender{
 	
 	
+	/**
+	 * uoleem短信服务  
+	 * @param url
+	 * @param username
+	 * @param pwd
+	 * @param mobile
+	 * @param content
+	 * @return
+	 * @throws Exception
+	 */
 	public static String batchSend(String url, String username, String pwd, String mobile, String content) throws Exception {
 	public static String batchSend(String url, String username, String pwd, String mobile, String content) throws Exception {
 		HttpClient client = new HttpClient();
 		HttpClient client = new HttpClient();
 		GetMethod method = new GetMethod();
 		GetMethod method = new GetMethod();
@@ -83,6 +57,124 @@ public class HttpSender{
 		} finally {
 		} finally {
 			method.releaseConnection();
 			method.releaseConnection();
 		}
 		}
+	}
+
+	//产品名称:云通信短信API产品,开发者无需替换
+	static final String product = "Dysmsapi";
+	//产品域名,开发者无需替换
+	static final String domain = "dysmsapi.aliyuncs.com";
+
+	// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
+	static final String accessKeyId = "nI7j7sUzmnm3HIGn";
+	static final String accessKeySecret = "1ATZnBIGvT6iWN6IIqryAvnUhE23LP";
+
+
+	/*//发送短信方法
+	public static boolean sendSms(String signname, String templatecode, String phone, String paramstring) throws ClientException {
+		//可自助调整超时时间
+		System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
+		System.setProperty("sun.net.client.defaultReadTimeout", "10000");
+
+		//初始化acsClient,暂不支持region化
+		IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
+		DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
+		IAcsClient acsClient = new DefaultAcsClient(profile);
+
+		//组装请求对象-具体描述见控制台-文档部分内容
+		SendSmsRequest request = new SendSmsRequest();
+		//必填:待发送手机号
+		request.setPhoneNumbers(phone);
+		//必填:短信签名-可在短信控制台中找到
+		request.setSignName(signname);
+		//必填:短信模板-可在短信控制台中找到
+		request.setTemplateCode(templatecode);
+		//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
+		request.setTemplateParam(paramstring);
+
+		//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
+		//request.setSmsUpExtendCode("90997");
+
+		//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
+		request.setOutId("yourOutId");
+
+		//hint 此处可能会抛出异常,注意catch
+		SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
+
+		if("OK".equals(sendSmsResponse.getCode())){
+			return true;
+		}else{
+			return false;
+		}
+	}
+*/
 
 
+	/**
+	 * 邮件发送帮助方法 
+	 * @param mailTitle
+	 * @param mailContent
+	 * @param re
+	 * @throws Exception
+	 */
+	public static void sendMail(String mailTitle,String mailContent,String re) throws Exception {  
+		Properties props = new Properties(); //可以加载一个配置文件  
+		// 使用smtp:简单邮件传输协议  
+		props.put("mail.smtp.host", "smtp.mxhichina.com");//存储发送邮件服务器的信息  
+		props.put("mail.smtp.auth", "true");//同时通过验证  
+		
+		Session session = Session.getInstance(props);//根据属性新建一个邮件会话  
+		//session.setDebug(true); //有他会打印一些调试信息。  
+		
+		MimeMessage message = new MimeMessage(session);//由邮件会话新建一个消息对象  
+		message.setFrom(new InternetAddress("kefu@jzdsh.com"));//设置发件人的地址  
+		message.setRecipient(Message.RecipientType.TO, new InternetAddress(re));//设置收件人,并设置其接收类型为TO  
+		message.setSubject(mailTitle);//设置标题  
+		//设置信件内容  
+		//message.setText(mailContent); //发送 纯文本 邮件 todo  
+		message.setContent(mailContent, "text/html;charset=utf-8"); //发送HTML邮件,内容样式比较丰富  
+		message.setSentDate(new Date());//设置发信时间  
+		message.saveChanges();//存储邮件信息  
+		
+		//发送邮件  
+		//Transport transport = session.getTransport("smtp");  
+		Transport transport = session.getTransport("smtp");  
+		transport.connect("kefu@jzdsh.com", "62340162Jzdsh"); //发件人邮箱和密码
+		transport.sendMessage(message, message.getAllRecipients());//发送邮件,其中第二个参数是所有已设好的收件人地址  
+		transport.close();  
+	}  
+
+	/**
+	 * 邮件发送帮助方法2  
+	 * @param mailTitle
+	 * @param mailContent
+	 * @param re
+	 * @throws Exception
+	 */
+	public static void sendorMail(String username,String password,String mailTitle,String mailContent,String re) throws Exception {  
+		Properties props = new Properties(); //可以加载一个配置文件  
+		// 使用smtp:简单邮件传输协议  
+		props.put("mail.smtp.host", "smtp.mxhichina.com");//存储发送邮件服务器的信息  
+		props.put("mail.smtp.auth", "true");//同时通过验证  
+		
+		Session session = Session.getInstance(props);//根据属性新建一个邮件会话  
+		//session.setDebug(true); //有他会打印一些调试信息。  
+		
+		MimeMessage message = new MimeMessage(session);//由邮件会话新建一个消息对象  
+		message.setFrom(new InternetAddress(username));//设置发件人的地址  
+		message.setRecipient(Message.RecipientType.TO, new InternetAddress(re));//设置收件人,并设置其接收类型为TO  
+		message.setSubject(mailTitle);//设置标题  
+		//设置信件内容  
+		//message.setText(mailContent); //发送 纯文本 邮件 todo  
+		message.setContent(mailContent, "text/html;charset=utf-8"); //发送HTML邮件,内容样式比较丰富  
+		message.setSentDate(new Date());//设置发信时间  
+		message.saveChanges();//存储邮件信息  
+		
+		//发送邮件  
+		//Transport transport = session.getTransport("smtp");  
+		Transport transport = session.getTransport("smtp");  
+		transport.connect(username, password); //发件人邮箱和密码
+		transport.sendMessage(message, message.getAllRecipients());//发送邮件,其中第二个参数是所有已设好的收件人地址  
+		transport.close();
+		System.err.println("这儿执行了没啊 ");
 	}
 	}
+	
 }
 }

+ 5 - 4
src/main/java/com/yc/education/util/MailUtils.java

@@ -15,13 +15,14 @@ public class MailUtils {
 
 
         Properties props = new Properties();
         Properties props = new Properties();
         props.setProperty("mail.transport.protocol", "SMTP");
         props.setProperty("mail.transport.protocol", "SMTP");
-        props.setProperty("mail.host", "smtp.qq.com");
+        props.setProperty("mail.host", "smtp.jzdsh.com");
         props.setProperty("mail.smtp.auth", "true");// 指定验证为true
         props.setProperty("mail.smtp.auth", "true");// 指定验证为true
 
 
         // 创建验证器
         // 创建验证器
         Authenticator auth = new Authenticator() {
         Authenticator auth = new Authenticator() {
             public PasswordAuthentication getPasswordAuthentication() {
             public PasswordAuthentication getPasswordAuthentication() {
-                return new PasswordAuthentication("1985833793", "kmomyuwzmeeacbac");
+                System.err.println("这儿进来了.");
+                return new PasswordAuthentication("kefu", "nI7j7sUzmnm3HIGn");
             }
             }
         };
         };
 
 
@@ -30,11 +31,11 @@ public class MailUtils {
         // 2.创建一个Message,它相当于是邮件内容
         // 2.创建一个Message,它相当于是邮件内容
         Message message = new MimeMessage(session);
         Message message = new MimeMessage(session);
 
 
-        message.setFrom(new InternetAddress("1985833793@qq.com")); // 设置发送者
+        message.setFrom(new InternetAddress("kefu@jzdsh.com")); // 设置发送者
 
 
         message.setRecipient(RecipientType.TO, new InternetAddress(email)); // 设置发送方式与接收者
         message.setRecipient(RecipientType.TO, new InternetAddress(email)); // 设置发送方式与接收者
 
 
-        message.setSubject("客户");
+        message.setSubject("客户邮件");
 
 
         message.setText("这是一封客户需求请求邮件!");
         message.setText("这是一封客户需求请求邮件!");
 
 

+ 5 - 2
src/main/webapp/WEB-INF/jsp/user/index.jsp

@@ -19,11 +19,13 @@
     <link rel="stylesheet" href="${pageContext.request.contextPath}/user/css/swiper.3.1.7.min.css">
     <link rel="stylesheet" href="${pageContext.request.contextPath}/user/css/swiper.3.1.7.min.css">
     <link rel="stylesheet" href="${pageContext.request.contextPath}/user/css/plug-in.min.css">
     <link rel="stylesheet" href="${pageContext.request.contextPath}/user/css/plug-in.min.css">
     <link rel="shortcut icon" href="" />
     <link rel="shortcut icon" href="" />
-    <script type="text/javascript" src="${pageContext.request.contextPath}/static/admin/js/layer.js"></script>
+    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
     <script src="${pageContext.request.contextPath}/user/js/modernizr-2.6.2-respond-1.1.0.min.js"></script>
     <script src="${pageContext.request.contextPath}/user/js/modernizr-2.6.2-respond-1.1.0.min.js"></script>
 </head>
 </head>
 <body>
 <body>
+<%--
 <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
 <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
+--%>
 
 
 <div id="loading"><div id="loading-icon"><img src="${pageContext.request.contextPath}/user/images/loading.jpg" alt=""></div></div>
 <div id="loading"><div id="loading-icon"><img src="${pageContext.request.contextPath}/user/images/loading.jpg" alt=""></div></div>
 
 
@@ -740,7 +742,8 @@
             dataType : 'text',
             dataType : 'text',
             success : function(data){
             success : function(data){
                 if(data=='ok'){
                 if(data=='ok'){
-                    layer.msg('发送成功!',{icon:6,time:1000});
+                    alert('发送成功!');
+                   /* layer.msg('发送成功!',{icon:6,time:1000});*/
                 }
                 }
             },
             },
             error : function () {
             error : function () {