|
|
@@ -3,11 +3,15 @@ package com.ydtech.modules.admin.controller;
|
|
|
import cn.dev33.satoken.session.SaSession;
|
|
|
import cn.dev33.satoken.session.TokenSign;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.google.code.kaptcha.Producer;
|
|
|
+import com.ydtech.components.aliyun.SMSVerificationCode;
|
|
|
+import com.ydtech.components.aliyun.SendSmsComponents;
|
|
|
+import com.ydtech.components.aliyun.SendSmsEnum;
|
|
|
import com.ydtech.config.MasterPasswordConfig;
|
|
|
import com.ydtech.constants.SysConstants;
|
|
|
import com.ydtech.constants.sys.SysPasswordEnum;
|
|
|
@@ -33,6 +37,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -424,6 +429,59 @@ public class SysLoginController {
|
|
|
return HttpResult.ok("登录成功", token);
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 短信发送
|
|
|
+// */
|
|
|
+// @GetMapping("/sendMsg")
|
|
|
+// public HttpResult sendMsg(@RequestParam String phone, @RequestParam String type, HttpServletRequest request) {
|
|
|
+// if (StringUtils.isEmpty(phone)) {
|
|
|
+// return HttpResult.error("手机号不能为空");
|
|
|
+// }
|
|
|
+//// if ("0".equals(type)) { // 0 登录 1 注册
|
|
|
+//// SysUser sysUser = sysUserService.findByPhone(phone);
|
|
|
+//// if (sysUser == null) {
|
|
|
+//// return HttpResult.error("手机号不存在!");
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//
|
|
|
+// Random rand = new Random();
|
|
|
+// // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
|
|
|
+// int randNumber = rand.nextInt(9999 - 1000 + 1) + 1000;
|
|
|
+// // 保存验证码到redis
|
|
|
+// redisTemplate.opsForValue().set(PHONE_VERIFICATION_CODE_KEY + phone, String.valueOf(randNumber), PHONE_VERIFICATION_CODE_KEY_TIME
|
|
|
+// , TimeUnit.MINUTES);
|
|
|
+//
|
|
|
+// String result = null;
|
|
|
+// String url = "http://v.juhe.cn/sms/send";//请求接口地址
|
|
|
+// Map params = new HashMap();//请求参数
|
|
|
+// params.put("mobile", phone);//接收短信的手机号码
|
|
|
+// params.put("tpl_id", "71853");//短信模板ID,请参考个人中心短信模板设置
|
|
|
+// String textVal = "#code#=" + randNumber;
|
|
|
+// params.put("tpl_value", textVal);//变量名和变量值对。如果你的变量名或者变量值中带有#&=中的任意一个特殊符号,请先分别进行urlencode编码后再传递,<a href="http://www.juhe.cn/news/index/id/50"
|
|
|
+// // target="_blank">详细说明></a>
|
|
|
+// params.put("key", "fbe7b165e9e13e52f3b1f2654eab9c0e");//应用APPKEY(应用详细页查询)
|
|
|
+// params.put("dtype", "json");//返回数据的格式,xml或json,默认json
|
|
|
+//
|
|
|
+// try {
|
|
|
+// result = net(url, params, "GET");
|
|
|
+// JSONObject object = JSONObject.parseObject(result);
|
|
|
+// if (object.getInteger("error_code") == 0) {
|
|
|
+//// System.out.println(object.get("result"));
|
|
|
+// return HttpResult.ok("发送成功");
|
|
|
+// } else {
|
|
|
+// System.out.println(object.get("error_code") + ":" + object.get("reason"));
|
|
|
+// return HttpResult.error("发送失败," + object.get("error_code") + ":" + object.get("reason"));
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// return HttpResult.ok("发送失败");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SendSmsComponents sendSms;
|
|
|
+
|
|
|
/**
|
|
|
* 短信发送
|
|
|
*/
|
|
|
@@ -443,30 +501,15 @@ public class SysLoginController {
|
|
|
// randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
|
|
|
int randNumber = rand.nextInt(9999 - 1000 + 1) + 1000;
|
|
|
// 保存验证码到redis
|
|
|
- redisTemplate.opsForValue().set(PHONE_VERIFICATION_CODE_KEY + phone, String.valueOf(randNumber), PHONE_VERIFICATION_CODE_KEY_TIME
|
|
|
- , TimeUnit.MINUTES);
|
|
|
-
|
|
|
- String result = null;
|
|
|
- String url = "http://v.juhe.cn/sms/send";//请求接口地址
|
|
|
- Map params = new HashMap();//请求参数
|
|
|
- params.put("mobile", phone);//接收短信的手机号码
|
|
|
- params.put("tpl_id", "71853");//短信模板ID,请参考个人中心短信模板设置
|
|
|
- String textVal = "#code#=" + randNumber;
|
|
|
- params.put("tpl_value", textVal);//变量名和变量值对。如果你的变量名或者变量值中带有#&=中的任意一个特殊符号,请先分别进行urlencode编码后再传递,<a href="http://www.juhe.cn/news/index/id/50"
|
|
|
- // target="_blank">详细说明></a>
|
|
|
- params.put("key", "fbe7b165e9e13e52f3b1f2654eab9c0e");//应用APPKEY(应用详细页查询)
|
|
|
- params.put("dtype", "json");//返回数据的格式,xml或json,默认json
|
|
|
+ redisTemplate.opsForValue()
|
|
|
+ .set(PHONE_VERIFICATION_CODE_KEY + phone, String.valueOf(randNumber), PHONE_VERIFICATION_CODE_KEY_TIME
|
|
|
+ , TimeUnit.MINUTES);
|
|
|
|
|
|
try {
|
|
|
- result = net(url, params, "GET");
|
|
|
- JSONObject object = JSONObject.parseObject(result);
|
|
|
- if (object.getInteger("error_code") == 0) {
|
|
|
-// System.out.println(object.get("result"));
|
|
|
- return HttpResult.ok("发送成功");
|
|
|
- } else {
|
|
|
- System.out.println(object.get("error_code") + ":" + object.get("reason"));
|
|
|
- return HttpResult.error("发送失败," + object.get("error_code") + ":" + object.get("reason"));
|
|
|
- }
|
|
|
+ SMSVerificationCode smsVerificationCode = new SMSVerificationCode(String.valueOf(randNumber));
|
|
|
+ String jsonString = JSON.toJSONString(smsVerificationCode);
|
|
|
+ sendSms.sendSms(phone, SendSmsEnum.SMS_220650023, jsonString);
|
|
|
+ return HttpResult.ok("发送成功");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|