first commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package org.jeecg;
|
||||
|
||||
import java.util.Properties;
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.*;
|
||||
|
||||
/**
|
||||
* 邮件发送示例
|
||||
*
|
||||
* @author jeecg
|
||||
*/
|
||||
public class MailSender {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 邮箱用户名和密码
|
||||
final String username = "jeewx@jeecg.org";
|
||||
final String password = "RwE9kDjaLTFh2A7h";
|
||||
|
||||
// 邮箱配置信息
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.host", "smtp.exmail.qq.com"); // 邮箱服务器地址
|
||||
props.put("mail.smtp.port", "465"); // 邮箱服务器端口号
|
||||
props.put("mail.smtp.auth", "true"); // 启用身份验证
|
||||
props.put("mail.smtp.ssl.enable", "true"); // 启用 SSL 加密
|
||||
|
||||
// 创建 Session 对象,用于与邮箱服务器进行通信
|
||||
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
// 创建邮件对象
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(username)); // 设置发件人邮箱地址
|
||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("418799587@qq.com")); // 设置收件人邮箱地址
|
||||
message.setSubject("设置邮件主题"); // 设置邮件主题
|
||||
message.setText("设置邮件内容"); // 设置邮件内容
|
||||
|
||||
// 发送邮件
|
||||
Transport.send(message);
|
||||
System.out.println("发送成功");
|
||||
|
||||
} catch (MessagingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.jeecg;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.jeecg.common.util.RestUtil;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
/**
|
||||
* @Description: TODO
|
||||
* @author: scott
|
||||
* @date: 2022年05月10日 14:02
|
||||
*/
|
||||
public class TestMain {
|
||||
public static void main(String[] args) {
|
||||
// 请求地址
|
||||
String url = "https://api3.boot.jeecg.com/sys/user/list";
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = getHeaders();
|
||||
// 请求方式是 GET 代表获取数据
|
||||
HttpMethod method = HttpMethod.GET;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
private static HttpHeaders getHeaders() {
|
||||
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String mediaType = MediaType.APPLICATION_JSON_VALUE;
|
||||
headers.setContentType(MediaType.parseMediaType(mediaType));
|
||||
headers.set("Accept", mediaType);
|
||||
headers.set("X-Access-Token", token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user