| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aliyuncs.CommonResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Strings; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.utils.aliyun.ALiYunSmSUtil; |
| | | import com.doumee.dao.business.SmsrecordMapper; |
| | | import com.doumee.dao.business.model.Smsrecord; |
| | | import com.doumee.service.business.SmsrecordService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 短信验证码Service实现 |
| | |
| | | return smsrecordMapper.selectCount(wrapper); |
| | | } |
| | | |
| | | |
| | | /****************************************移动端接口开始********************************************************************/ |
| | | |
| | | |
| | | /** |
| | | * 发送短信 目前只有短信验证码 |
| | | * @param memberId |
| | | * @param phone |
| | | */ |
| | | @Override |
| | | public void sendSms(Integer memberId,String phone){ |
| | | smsrecordMapper.update(null, |
| | | new UpdateWrapper<Smsrecord>() |
| | | .set("STATUS",2) |
| | | .eq("PHONE",phone) |
| | | .eq("STATUS",0) |
| | | ); |
| | | String digits = Strings.randomNumeric(4); |
| | | //发送验证码 |
| | | Map<String,Object> map = new HashMap<String,Object>(); |
| | | map.put("code",digits); |
| | | CommonResponse response = ALiYunSmSUtil.sendMessage(phone,map); |
| | | if(response.getHttpResponse().isSuccess()){ |
| | | JSONObject data = JSONObject.parseObject(response.getData()); |
| | | String returnCode = data.getString("Code"); |
| | | if(!returnCode.equals("OK")){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"短信发送失败:" + data.getString("Message")); |
| | | } |
| | | } |
| | | //存储短信验证码 |
| | | Smsrecord smsrecord = new Smsrecord(); |
| | | smsrecord.setCreateTime(new Date()); |
| | | smsrecord.setMemberId(memberId); |
| | | smsrecord.setPhone(phone); |
| | | smsrecord.setContent("验证码短信"); |
| | | smsrecord.setType(Constants.ZERO); |
| | | smsrecord.setValidDate(DateUtil.afterMinutesDate(3)); |
| | | smsrecord.setCode(digits); |
| | | smsrecord.setStatus(Constants.ZERO); |
| | | smsrecord.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(smsrecord); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证码验证 |
| | | * @param memberId |
| | | * @param phone |
| | | * @param code |
| | | */ |
| | | @Override |
| | | public void verifyCode(Integer memberId,String phone,String code){ |
| | | Smsrecord smsrecord = smsrecordMapper.selectOne(new QueryWrapper<Smsrecord>() |
| | | .eq("MEMBER_ID",memberId) |
| | | .eq("PHONE",phone) |
| | | .eq("CODE",code) |
| | | .eq("TYPE",Constants.ZERO) |
| | | .eq("STATUS",Constants.ZERO) |
| | | .last(" limit 1 ") |
| | | ); |
| | | if(Objects.isNull(smsrecord)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"验证码输入错误或已过期!"); |
| | | } |
| | | if(smsrecord.getValidDate().getTime()<System.currentTimeMillis()){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"验证码已过期请重新获取!"); |
| | | } |
| | | smsrecord.setStatus(Constants.ONE); |
| | | smsrecord.setUpdateTime(new Date()); |
| | | smsrecordMapper.updateById(smsrecord); |
| | | } |
| | | |
| | | |
| | | |
| | | } |