更新
This commit is contained in:
parent
b977324bb7
commit
63f5226c01
@ -15,14 +15,14 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "pages/index/nIndex",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
}, //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
||||
},
|
||||
//pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
|
||||
{
|
||||
"path": "pages/index/web",
|
||||
"style": {
|
||||
@ -36,7 +36,6 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "pages/Chat/chat",
|
||||
"style": {
|
||||
@ -63,8 +62,6 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"path": "pages/index/navigation",
|
||||
"style": {
|
||||
@ -87,7 +84,6 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"path": "pages/login/register",
|
||||
"style": {
|
||||
@ -182,24 +178,30 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "components/bt-cropper/index",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : ""
|
||||
"path": "components/bt-cropper/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/busNavigation/busNavigation",
|
||||
"path": "pages/busNavigation/busNavigation",
|
||||
"style": {
|
||||
"navigationBarTitleText": "公交导航",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/busNavigation/busNavigation",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : ""
|
||||
"path": "pages/busNavigation/busNavigation",
|
||||
"style": {
|
||||
"navigationBarTitleText": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/my/Contact",
|
||||
"style": {
|
||||
"navigationBarTitleText": "",
|
||||
"enablePullDownRefresh": true,
|
||||
"navigationBarTitleText": "Contact"
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -214,7 +216,8 @@
|
||||
"selectedColor": "#32714f",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#F8F8F8",
|
||||
"list": [{
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/index/nIndex",
|
||||
"iconPath": "/static/imgs/home.png",
|
||||
"selectedIconPath": "/static/imgs/homex.png",
|
||||
@ -225,7 +228,8 @@
|
||||
"iconPath": "/static/imgs/circle.png",
|
||||
"selectedIconPath": "/static/imgs/circlex.png",
|
||||
"text": "Chat"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/my/my",
|
||||
"iconPath": "/static/imgs/my.png",
|
||||
"selectedIconPath": "/static/imgs/myx.png",
|
||||
|
@ -1,14 +1,6 @@
|
||||
<template>
|
||||
<view class="contact-container">
|
||||
<u-card title="Contact Us" class="card">
|
||||
<view class="info">
|
||||
<u-icon name="map" size="28" color="#2E7D32"/>
|
||||
<text class="info-text">123 Main Street, New York, NY 10001</text>
|
||||
</view>
|
||||
<view class="info">
|
||||
<u-icon name="phone" size="28" color="#2E7D32"/>
|
||||
<text class="info-text">+1 (123) 456-7890</text>
|
||||
</view>
|
||||
<view class="info">
|
||||
<u-icon name="email" size="28" color="#2E7D32"/>
|
||||
<text class="info-text">contact@company.com</text>
|
||||
@ -33,6 +25,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import request from "@/utils/request";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -46,26 +40,26 @@ export default {
|
||||
{
|
||||
required: true,
|
||||
message: 'Please enter your name',
|
||||
trigger: ['blur', 'change']
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
email: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please enter your email address',
|
||||
trigger: ['blur', 'change']
|
||||
trigger: ['blur']
|
||||
},
|
||||
{
|
||||
pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
||||
message: 'Please enter a valid email address',
|
||||
trigger: ['blur', 'change']
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
message: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please enter your feedback',
|
||||
trigger: ['blur', 'change']
|
||||
trigger: ['blur']
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -75,6 +69,15 @@ export default {
|
||||
submitForm() {
|
||||
this.$refs.formRef.validate().then(res => {
|
||||
uni.showToast({title: 'Successfully', icon: 'success'});
|
||||
request({
|
||||
url: 'contact/sendEmail',
|
||||
method: 'post',
|
||||
data: {
|
||||
name: this.form.name,
|
||||
email: this.form.email,
|
||||
message: this.form.message
|
||||
}
|
||||
})
|
||||
this.form = {name: '', email: '', message: ''};
|
||||
}).catch(errors => {
|
||||
uni.$u.toast('Validation failed')
|
||||
|
@ -47,7 +47,7 @@
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version> <!-- 使用适当的版本 -->
|
||||
</dependency>
|
||||
<!-- 支付-->
|
||||
<!-- 支付-->
|
||||
<dependency>
|
||||
<groupId>com.stripe</groupId>
|
||||
<artifactId>stripe-java</artifactId>
|
||||
@ -65,17 +65,17 @@
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||
<!-- <artifactId>gson</artifactId>-->
|
||||
<!-- <version>2.10.1</version> <!– 确保使用最新版本 –>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||
<!-- <artifactId>gson</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||
<!-- <artifactId>gson</artifactId>-->
|
||||
<!-- <version>2.10.1</version> <!– 确保使用最新版本 –>-->
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||
<!-- <artifactId>gson</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- spring-boot-devtools -->
|
||||
<dependency>
|
||||
@ -98,7 +98,7 @@
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql驱动包 -->
|
||||
<!-- Mysql驱动包 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
@ -126,6 +126,13 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--邮箱-->
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@ -154,7 +161,7 @@
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<warName>${project.artifactId}</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.dc.app.controller;
|
||||
|
||||
import com.dc.app.domain.request.ContactRequest;
|
||||
import com.dc.common.core.domain.AjaxResult;
|
||||
import com.dc.common.utils.MailUtils;
|
||||
import com.dc.system.mapper.SysConfigMapper;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description: 联系我们
|
||||
* @Author: 86187
|
||||
* @Date: 2025/03/14 10:15
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/contact")
|
||||
public class ContactController {
|
||||
|
||||
@Resource
|
||||
SysConfigMapper sysConfigMapper;
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @param request 请求体
|
||||
* @return 返回参数
|
||||
*/
|
||||
@PostMapping("/sendEmail")
|
||||
public AjaxResult sendEmail(@RequestBody ContactRequest request) {
|
||||
String emailProtocol = sysConfigMapper.getcheckConfigKeyUnique("email_protocol");
|
||||
String emailSMTPHost = sysConfigMapper.getcheckConfigKeyUnique("email_SMTPHost");
|
||||
String emailPort = sysConfigMapper.getcheckConfigKeyUnique("email_port");
|
||||
String emailAccount = sysConfigMapper.getcheckConfigKeyUnique("email_account");
|
||||
String emailPassword = sysConfigMapper.getcheckConfigKeyUnique("email_password");
|
||||
String emailReceive = sysConfigMapper.getcheckConfigKeyUnique("email_receive");
|
||||
|
||||
Set<String> emails = new HashSet<>();
|
||||
emails.add(emailReceive);
|
||||
boolean flag = MailUtils.sendEmail(emails, request.getEmail(), request.getName(), request.getName() + ":" + request.getMessage(), emailProtocol, emailSMTPHost, emailPort, emailAccount, emailPassword);
|
||||
if (!flag) return AjaxResult.error("发送失败");
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.dc.app.domain.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 联系我们请求参数
|
||||
* @Author: 86187
|
||||
* @Date: 2025/03/14 10:47
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class ContactRequest {
|
||||
private String name;
|
||||
private String email;
|
||||
private String message;
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.dc.common.utils;
|
||||
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Description: 邮箱工具类
|
||||
* @Author: 86187
|
||||
* @Date: 2025/03/14 10:21
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class MailUtils {
|
||||
|
||||
|
||||
// 邮件协议
|
||||
private static final String emailProtocol = "smtp";
|
||||
// 发件人的SMTP服务器地址(企业邮箱)
|
||||
private static final String emailSMTPHost = "smtp.qq.com";
|
||||
// 端口
|
||||
private static final String emailPort = "465";
|
||||
// 发件人邮箱地址
|
||||
private static final String emailAccount = "3422692813@qq.com"; // 这个是企业邮箱
|
||||
// 发件人邮箱授权码
|
||||
private static final String emailPassword = "tbpxqvywlanfchhe";
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @param emails 收件人邮箱地址
|
||||
* @param title 标题
|
||||
* @param sendEmail 发件人
|
||||
* @param content 内容
|
||||
* @param emailProtocol 邮件协议
|
||||
* @param emailSMTPHost 发件人的SMTP服务器地址
|
||||
* @param emailPort 端口
|
||||
* @param emailAccount 发件人邮箱地址
|
||||
* @param emailPassword 发件人邮箱授权码
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean sendEmail(Set<String> emails, String title, String sendEmail, String content, String emailProtocol, String emailSMTPHost, String emailPort, String emailAccount, String emailPassword) {
|
||||
// 未传收件人邮箱地址则直接返回
|
||||
if (emails == null || emails.isEmpty()) return false;
|
||||
try {
|
||||
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
||||
Properties props = new Properties();
|
||||
props.setProperty("mail.transport.protocol", emailProtocol); // 使用的协议(JavaMail规范要求)
|
||||
props.setProperty("mail.smtp.host", emailSMTPHost); // 指定smtp服务器地址
|
||||
props.setProperty("mail.smtp.port", emailPort); // 指定smtp端口号
|
||||
// 使用smtp身份验证
|
||||
props.setProperty("mail.smtp.auth", "true"); // 需要请求认证
|
||||
props.put("mail.smtp.ssl.enable", "true"); // 开启SSL
|
||||
props.put("mail.smtp.ssl.protocols", "TLSv1.2"); // 指定SSL版本
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
// 由于Properties默认不限制请求时间,可能会导致线程阻塞,所以指定请求时长
|
||||
props.setProperty("mail.smtp.connectiontimeout", "10000");// 与邮件服务器建立连接的时间限制
|
||||
props.setProperty("mail.smtp.timeout", "10000");// 邮件smtp读取的时间限制
|
||||
props.setProperty("mail.smtp.writetimeout", "10000");// 邮件内容上传的时间限制
|
||||
// 2. 根据配置创建会话对象, 用于和邮件服务器交互
|
||||
Session session = Session.getDefaultInstance(props);
|
||||
session.setDebug(false); // 设置为debug模式, 可以查看详细的发送log
|
||||
// 3. 创建邮件
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
// 4. From: 发件人(昵称有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改昵称)
|
||||
message.setFrom(new InternetAddress(emailAccount, sendEmail, "UTF-8"));
|
||||
// 5. To: 收件人(可以增加多个收件人、抄送、密送)
|
||||
// MimeMessage.RecipientType.TO: 发送 MimeMessage.RecipientType.CC:抄送 MimeMessage.RecipientType.BCC:密送
|
||||
int size = emails.size();
|
||||
// 单个目标邮箱还是多个
|
||||
if (size == 1) {
|
||||
String email = emails.iterator().next();
|
||||
message.setRecipient(Message.RecipientType.TO, new InternetAddress(email, email, "UTF-8"));
|
||||
} else {
|
||||
InternetAddress[] addresses = new InternetAddress[emails.size()];
|
||||
int i = 0;
|
||||
for (String email : emails) {
|
||||
addresses[i++] = new InternetAddress(email, email, "UTF-8");
|
||||
}
|
||||
message.setRecipients(MimeMessage.RecipientType.TO, addresses);
|
||||
}
|
||||
// 6. Subject: 邮件主题(标题有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改标题)
|
||||
message.setSubject(title, "UTF-8");
|
||||
// 7. Content: 邮件正文(可以使用html标签)(内容有广告嫌疑,避免被邮件服务器误认为是滥发广告以至返回失败,请修改发送内容)
|
||||
message.setContent(content, "text/html;charset=UTF-8");
|
||||
// 8. 设置发件时间
|
||||
message.setSentDate(new Date());
|
||||
// 9. 保存设置
|
||||
message.saveChanges();
|
||||
// 10. 根据 Session 获取邮件传输对象
|
||||
Transport transport = session.getTransport();
|
||||
transport.connect(emailAccount, emailPassword);
|
||||
// 11. 发送邮件, 发到所有的收件地址, message.getAllRecipients()获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
// 12. 关闭传输连接
|
||||
transport.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("报错"+e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("18766413289@163.com");
|
||||
// System.out.println(MailUtils.sendEmail(set, "测试发送邮件的接口!",
|
||||
// "您好!这是我发送的一封测试发送接口的邮件,看完请删除记录。","stmp", "smtp.qq.com", "465", "18766413289@163.com", "tbpxqvywlanfchhe"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user