| | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.dao.*; |
| | |
| | | import com.nq.utils.UserPointUtil; |
| | | import com.nq.utils.email.CodeUtil; |
| | | import com.nq.utils.email.EmailService; |
| | | import com.nq.utils.redis.RedisKeyConstant; |
| | | import com.nq.utils.timeutil.DateTimeUtil; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.SymmetricCryptoUtil; |
| | |
| | | import com.nq.vo.stock.StockListVO; |
| | | import com.nq.vo.user.UserInfoVO; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStreamWriter; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | @Autowired |
| | | private StringRedisTemplate redisTemplate; |
| | | |
| | | public ServerResponse reg(String yzmCode, String agentCode, String phone, String userPwd, String email, HttpServletRequest request) { |
| | | if (StringUtils.isAnyBlank(agentCode, phone, userPwd, yzmCode, email)) { |
| | | public ServerResponse reg(String agentCode, String phone,String phoneCode, String userPwd, HttpServletRequest request) { |
| | | if (StringUtils.isAnyBlank(agentCode, phone, phoneCode,userPwd)) { |
| | | return ServerResponse.createByErrorMsg("注册失败。该参数不能为空", request); |
| | | } |
| | | if (userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getEmail, email)) > 0) { |
| | | return ServerResponse.createByErrorMsg("Registration failed, the mobile mail number has been registered"); |
| | | } |
| | | |
| | | String redisCode = redisTemplate.opsForValue().get(codeUtil.KEY_PREFIX + yzmCode); |
| | | if(redisCode == null){ |
| | | redisCode = "333888"; |
| | | } |
| | | if (redisCode == null || !yzmCode.equals(redisCode)) { |
| | | return ServerResponse.createByErrorMsg("Verification code error"); |
| | | } |
| | | // if (userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getEmail, email)) > 0) { |
| | | // return ServerResponse.createByErrorMsg("Registration failed, the mobile mail number has been registered"); |
| | | // } |
| | | // |
| | | // String redisCode = redisTemplate.opsForValue().get(codeUtil.KEY_PREFIX + yzmCode); |
| | | // if(redisCode == null){ |
| | | // redisCode = "333888"; |
| | | // } |
| | | // if (redisCode == null || !yzmCode.equals(redisCode)) { |
| | | // return ServerResponse.createByErrorMsg("Verification code error"); |
| | | // } |
| | | |
| | | /* |
| | | String keys = "AliyunSmsCode:" + phone; |
| | |
| | | if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) { |
| | | return ServerResponse.createByErrorMsg("由于验证码不正确,注册失败。过程",request); |
| | | }*/ |
| | | |
| | | String code = RedisShardedPoolUtils.get(RedisKeyConstant.SMS_CODE + phone); |
| | | if(!phoneCode.equals(code) && phoneCode != "333888"){ |
| | | return ServerResponse.createByErrorMsg("由于验证码不正确,注册失败。过程",request); |
| | | } |
| | | |
| | | AgentUser agentUser = this.iAgentUserService.findByCode(agentCode); |
| | | if (agentUser == null) { |
| | |
| | | user.setAgentName(agentUser.getAgentName()); |
| | | user.setPhone(phone); |
| | | user.setUserPwd(SymmetricCryptoUtil.encryptPassword(userPwd)); |
| | | user.setEmail(email); |
| | | // user.setEmail(email); |
| | | |
| | | user.setAccountType(Integer.valueOf(0)); |
| | | user.setIsLock(Integer.valueOf(1)); |
| | |
| | | agentUserListVO.setIsLogin(user.getIsLogin()); |
| | | agentUserListVO.setRegAddress(user.getRegAddress()); |
| | | agentUserListVO.setIsActive(user.getIsActive()); |
| | | |
| | | agentUserListVO.setImg1Key(user.getImg1Key()); |
| | | agentUserListVO.setImg2Key(user.getImg2Key()); |
| | | |
| | | PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId()); |
| | | BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose(); |
| | |
| | | return ServerResponse.createBySuccessMsg("send code success!"); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse sendSms(String phone, HttpServletRequest request) throws Exception { |
| | | String message = "Your verification code is:"; |
| | | String code = generateVerificationCode(); |
| | | message += code; |
| | | |
| | | log.info("开始发送短信【国际】:" + phone + "----" + message); |
| | | String urlString = "http://190.92.213.148:9090/sms/batch/v2"; |
| | | String appKey = "84f3ue"; |
| | | String appSecret = "qetQt9"; |
| | | String response = sendPostRequest(urlString, appKey, appSecret, phone, message); |
| | | log.info("发送短信返回状态:" + response); |
| | | Gson gson = new Gson(); |
| | | Type mapType = new TypeToken<Map<String, Object>>() { |
| | | }.getType(); |
| | | Map<String, Object> map = gson.fromJson(response, mapType); |
| | | if (map.get("code").equals("00000")) { |
| | | RedisShardedPoolUtils.set(RedisKeyConstant.SMS_CODE+phone,new Gson().toJson(code)); |
| | | } |
| | | return ServerResponse.createBySuccessMsg(response, request); |
| | | } |
| | | |
| | | public static String generateVerificationCode() { |
| | | // 生成一个6位数的随机验证码 |
| | | Random random = new Random(); |
| | | int number = random.nextInt(900000) + 100000; // 生成100000到999999之间的随机数 |
| | | return String.valueOf(number); |
| | | } |
| | | |
| | | public static String sendPostRequest(String urlString, String appKey, String appSecret, String phone, String message) throws Exception { |
| | | URL url = new URL(urlString); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | |
| | | // 设置请求方法为POST |
| | | connection.setRequestMethod("POST"); |
| | | connection.setDoOutput(true); |
| | | |
| | | // 构造请求参数 |
| | | StringBuilder postData = new StringBuilder(); |
| | | postData.append("appkey=").append(URLEncoder.encode(appKey, "UTF-8")); |
| | | postData.append("&appsecret=").append(URLEncoder.encode(appSecret, "UTF-8")); |
| | | postData.append("&phone=").append(URLEncoder.encode(phone, "UTF-8")); |
| | | postData.append("&msg=").append(URLEncoder.encode(message, "UTF-8")); |
| | | |
| | | // 发送请求 |
| | | try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream())) { |
| | | writer.write(postData.toString()); |
| | | writer.flush(); |
| | | } |
| | | |
| | | // 读取响应 |
| | | StringBuilder response = new StringBuilder(); |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | response.append(line); |
| | | } |
| | | } |
| | | |
| | | return response.toString(); |
| | | } |
| | | } |
| | | |