Commit f9b84fc5 authored by m1991's avatar m1991

sms工具类变动

parent b9749a7d
...@@ -140,6 +140,12 @@ ...@@ -140,6 +140,12 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>4.6.7</version> <version>4.6.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<!-- MAVEN构建 --> <!-- MAVEN构建 -->
......
package cn.wisenergy.common.utils;
import java.util.zip.CRC32;
/**
*
* @author eaves.zhu
*/
public class DeviceIdUtil {
/**
* @author eaves.zhu
* @param deviceId
* @return int
* CRC32
*/
public static long getCRC32(String deviceId){
CRC32 crc32 = new CRC32();
crc32.update(deviceId.getBytes());
long tmp = crc32.getValue();
return tmp;
}
}
\ No newline at end of file
package cn.wisenergy.common.utils;
import org.apache.log4j.Logger;
/**
*
* @author zen.wang zenyes@gmail.com
*/
public class ShareCodeUtil {
/** 自定义进制(0,1没有加入,容易与o,l混淆) */
private static final char[] r=new char[]{'F', 'L', 'G', 'W', '5', 'X', 'C', '3', '9', 'Z', 'M', '6', '7', 'Y', 'R', 'T', '2', 'H', 'S', '8', 'D', 'V', 'E', 'J', '4', 'K', 'Q', 'P', 'U', 'A', 'N', 'B'};
/** 进制长度 */
private static final int binLen=r.length;
private static Logger logger = Logger.getLogger(ShareCodeUtil.class);
private static final long startNumber = 100048576L;
// private static final long startNumber = 0L;
/**
*
* @param id ID
* @return 随机码
*/
public static String idToCode(long id,long costomStartNumber) {
if(costomStartNumber<0){
costomStartNumber = startNumber;
}
id += costomStartNumber;
char[] buf=new char[32];
int charPos=32;
while((id / binLen) > 0) {
int ind=(int)(id % binLen);
// System.out.println(num + "-->" + ind);
buf[--charPos]=r[ind];
id /= binLen;
}
buf[--charPos]=r[(int)(id % binLen)];
// System.out.println(num + "-->" + num % binLen);
String str=new String(buf, charPos, (32 - charPos));
return str.toUpperCase();
}
public static String idToCode(long idL){
return idToCode(idL,-1L);
}
public static String idToCode(String id){
long idL = Long.parseLong(id);
return idToCode(idL,-1L);
}
public static String idToCode(String id,long costomStartNumber){
long idL = Long.parseLong(id);
return idToCode(idL,costomStartNumber);
}
public static long codeToId(String code) {
code = code.toUpperCase();
char chs[]=code.toCharArray();
long res=0L;
for(int i=0; i < chs.length; i++) {
int ind=0;
for(int j=0; j < binLen; j++) {
if(chs[i] == r[j]) {
ind=j;
break;
}
}
if(i > 0) {
res=res * binLen + ind;
} else {
res=ind;
}
// logger.debug(ind + "-->" + res);
}
res -= startNumber;
return res;
}
}
\ No newline at end of file
package cn.wisenergy.web.sms; package cn.wisenergy.common.utils;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.web.config.SmsConfig; import cn.wisenergy.web.config.SmsConfig;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonRequest;
......
...@@ -158,6 +158,16 @@ ...@@ -158,6 +158,16 @@
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.3.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:2.3.0" level="project" />
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" /> <orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.6.7" level="project" /> <orderEntry type="library" name="Maven: cn.hutool:hutool-all:4.6.7" level="project" />
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-core:4.5.18" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.jacoco:org.jacoco.agent:runtime:0.8.6" level="project" />
<orderEntry type="library" name="Maven: org.ini4j:ini4j:0.5.4" level="project" />
<orderEntry type="library" name="Maven: io.opentracing:opentracing-api:0.33.0" level="project" />
<orderEntry type="library" name="Maven: io.opentracing:opentracing-util:0.33.0" level="project" />
<orderEntry type="library" name="Maven: io.opentracing:opentracing-noop:0.33.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: commons-pool:commons-pool:1.6" level="project" /> <orderEntry type="library" name="Maven: commons-pool:commons-pool:1.6" level="project" />
......
...@@ -9,4 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -9,4 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface RecommendUserMapper extends BaseMapper<RecommendUser> { public interface RecommendUserMapper extends BaseMapper<RecommendUser> {
RecommendUser getByUserId(String userId); RecommendUser getByUserId(String userId);
Integer zcByUserId(String userId);
} }
...@@ -53,7 +53,7 @@ public interface UsersMapper extends BaseMapper<User> { ...@@ -53,7 +53,7 @@ public interface UsersMapper extends BaseMapper<User> {
* @param userId 用户id * @param userId 用户id
* @return 用户信息 * @return 用户信息
*/ */
User getByUserId(@Param("userId") String userId); Integer getByUserId(@Param("userId") String userId);
/** /**
* 获取用户信息 * 获取用户信息
...@@ -76,6 +76,17 @@ public interface UsersMapper extends BaseMapper<User> { ...@@ -76,6 +76,17 @@ public interface UsersMapper extends BaseMapper<User> {
public List<User> getUsersListByMap(Map<String,Object> param); public List<User> getUsersListByMap(Map<String,Object> param);
//根据手机号查询用户Integer //根据手机号查询用户Integer
Integer queryUsersByPhone(@Param("beInvitedCode")String userId); Integer queryUsersByPhone(@Param("userId")String userId);
/**
* 用户注册
* @param userId
* @param inviteCode
* @param beInvitedCode
* @param userLevel
*/
Integer save(@Param("userId")String userId, @Param("inviteCode") String inviteCode, @Param("beInvitedCode") String beInvitedCode, @Param("userLevel") Integer userLevel);
Integer insertbyint(@Param("userId")String userId, @Param("beInvitedCode") String beInvitedCode);
Integer edit1(@Param("userId")String userId);
Integer getuserIdById(@Param("userId")String userId);
} }
...@@ -71,5 +71,15 @@ ...@@ -71,5 +71,15 @@
user_id=#{userId} user_id=#{userId}
</where> </where>
</select> </select>
<!--根据用户邀请码更新直推表-->
<select id="zcByUserId" >
select
id
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -145,9 +145,12 @@ ...@@ -145,9 +145,12 @@
</where> </where>
</select> </select>
<!--用户添加--> <!--用户注册-->
<insert id="save"> <insert id="save">
insert into user(user_id,password) value (#{userId},#{password}) insert into user(user_id,invite_code,be_invited_code,user_level) value (#{userId},#{inviteCode},#{beInvitedCode},#{userLevel})
</insert>
<insert id="insertbyint">
insert into user(user_id,be_invited_code) value (#{userId},#{beInvitedCode})
</insert> </insert>
<select id="queryUsersByPhone" resultType="java.lang.Integer"> <select id="queryUsersByPhone" resultType="java.lang.Integer">
...@@ -159,6 +162,27 @@ ...@@ -159,6 +162,27 @@
user_id=#{userId} user_id=#{userId}
</where> </where>
</select> </select>
<select id="getuserIdById" resultType="cn.wisenergy.model.app.User">
select
id
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
<update id="edit1" parameterType="cn.wisenergy.model.app.User">
UPDATE
<include refid="table"/>
<set>
<if test="userLevel != null">user_level =#{userLevel},</if>
<if test="inviteCode != null">invite_code =#{inviteCode},</if>
update_time =now()
</set>
<where>
user_id = #{userId}
</where>
</update>
<!--分页查询所有用户信息 --> <!--分页查询所有用户信息 -->
<select id="getUsersListByMap" resultType="cn.wisenergy.model.app.User" parameterType="java.util.Map"> <select id="getUsersListByMap" resultType="cn.wisenergy.model.app.User" parameterType="java.util.Map">
......
...@@ -44,7 +44,7 @@ public class Page<T> implements Serializable { ...@@ -44,7 +44,7 @@ public class Page<T> implements Serializable {
this.list = list; this.list = list;
} }
public Page(int pageNo, int pageSize, Integer total) { public Page(int pageNo, int pageSize,Integer total) {
pageNo = (pageNo==0 )? DEFAULT_PAGE_NO : pageNo; pageNo = (pageNo==0 )? DEFAULT_PAGE_NO : pageNo;
pageSize = (pageSize==0 )?DEFAULT_PAGE_SIZE : pageSize; pageSize = (pageSize==0 )?DEFAULT_PAGE_SIZE : pageSize;
this.beginPos=(pageNo-1)*pageSize; this.beginPos=(pageNo-1)*pageSize;
......
package cn.wisenergy.model.app; package cn.wisenergy.model.app;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.math.BigDecimal;
/*** /**
* 短信记录 * 短信记录
*/ * Created by m1991 on 2021/2/28 22:56
public class SmsLog implements Serializable { */
public class SmsLog {
// //
private Long id; private Long id;
//短信类型(0:注册、登录验证码,1:修改密码,2:订单状态通知信息) //短信类型(0:注册、登录验证码,1:修改密码,2:订单状态通知信息)
...@@ -30,70 +30,91 @@ public class SmsLog implements Serializable { ...@@ -30,70 +30,91 @@ public class SmsLog implements Serializable {
//是否删除(0:否,1:是) //是否删除(0:否,1:是)
private Integer isDelete; private Integer isDelete;
//get set 方法 //get set 方法
public void setId (Long id){ public Long getId() {
this.id=id; return id;
} }
public Long getId(){
return this.id; public void setId(Long id) {
this.id = id;
} }
public void setCodeType (Integer codeType){
this.codeType=codeType; public Integer getCodeType() {
return codeType;
} }
public Integer getCodeType(){
return this.codeType; public void setCodeType(Integer codeType) {
this.codeType = codeType;
} }
public void setPhone (String phone){
this.phone=phone; public String getPhone() {
return phone;
} }
public String getPhone(){
return this.phone; public void setPhone(String phone) {
this.phone = phone;
} }
public void setMessage (String message){
this.message=message; public String getMessage() {
return message;
} }
public String getMessage(){
return this.message; public void setMessage(String message) {
this.message = message;
} }
public void setFailInfo (String failInfo){
this.failInfo=failInfo; public String getFailInfo() {
return failInfo;
} }
public String getFailInfo(){
return this.failInfo; public void setFailInfo(String failInfo) {
this.failInfo = failInfo;
} }
public void setStatus (Integer status){
this.status=status; public Integer getStatus() {
return status;
} }
public Integer getStatus(){
return this.status; public void setStatus(Integer status) {
this.status = status;
} }
public void setCreatedUserId (Long createdUserId){
this.createdUserId=createdUserId; public Long getCreatedUserId() {
return createdUserId;
} }
public Long getCreatedUserId(){
return this.createdUserId; public void setCreatedUserId(Long createdUserId) {
this.createdUserId = createdUserId;
} }
public void setUpdatedUserId (Long updatedUserId){
this.updatedUserId=updatedUserId; public Long getUpdatedUserId() {
return updatedUserId;
} }
public Long getUpdatedUserId(){
return this.updatedUserId; public void setUpdatedUserId(Long updatedUserId) {
this.updatedUserId = updatedUserId;
} }
public void setCreatdTime (Date creatdTime){
this.creatdTime=creatdTime; public Date getCreatdTime() {
return creatdTime;
} }
public Date getCreatdTime(){
return this.creatdTime; public void setCreatdTime(Date creatdTime) {
this.creatdTime = creatdTime;
} }
public void setUpdatedTime (Date updatedTime){
this.updatedTime=updatedTime; public Date getUpdatedTime() {
return updatedTime;
} }
public Date getUpdatedTime(){
return this.updatedTime; public void setUpdatedTime(Date updatedTime) {
this.updatedTime = updatedTime;
} }
public void setIsDelete (Integer isDelete){
this.isDelete=isDelete; public Integer getIsDelete() {
return isDelete;
} }
public Integer getIsDelete(){
return this.isDelete; public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
} }
} }
...@@ -105,4 +105,99 @@ public class User extends Model<User> implements Serializable{ ...@@ -105,4 +105,99 @@ public class User extends Model<User> implements Serializable{
@ApiModelProperty(name = "updateTime", value = "修改时间") @ApiModelProperty(name = "updateTime", value = "修改时间")
private Date updateTime; private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
public BigDecimal getCrossBorderLine() {
return crossBorderLine;
}
public void setCrossBorderLine(BigDecimal crossBorderLine) {
this.crossBorderLine = crossBorderLine;
}
public String getIdCardNumber() {
return idCardNumber;
}
public void setIdCardNumber(String idCardNumber) {
this.idCardNumber = idCardNumber;
}
public String getFansNickname() {
return fansNickname;
}
public void setFansNickname(String fansNickname) {
this.fansNickname = fansNickname;
}
public String getFansId() {
return fansId;
}
public void setFansId(String fansId) {
this.fansId = fansId;
}
public String getInviteCode() {
return inviteCode;
}
public void setInviteCode(String inviteCode) {
this.inviteCode = inviteCode;
}
public String getBeInvitedCode() {
return beInvitedCode;
}
public void setBeInvitedCode(String beInvitedCode) {
this.beInvitedCode = beInvitedCode;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
} }
...@@ -72,28 +72,6 @@ ...@@ -72,28 +72,6 @@
<artifactId>itext-asian</artifactId> <artifactId>itext-asian</artifactId>
<version>5.2.0</version> <version>5.2.0</version>
</dependency> </dependency>
<!--有赞SDK-->
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-core</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-gen</artifactId>
<version>1.0.7.78771202102051104-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-api</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-common</artifactId>
<version>1.0.7-RELEASE</version>
</dependency>
</dependencies> </dependencies>
<!-- MAVEN构建 --> <!-- MAVEN构建 -->
......
...@@ -3,8 +3,6 @@ package cn.wisenergy.service.app; ...@@ -3,8 +3,6 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.User; import cn.wisenergy.model.app.User;
import java.util.List;
/** /**
* @ Description: 用户接口 * @ Description: 用户接口
* @ Author : 86187 * @ Author : 86187
...@@ -19,16 +17,27 @@ public interface UserService { ...@@ -19,16 +17,27 @@ public interface UserService {
* @param userId 用户id * @param userId 用户id
* @return 用户信息 * @return 用户信息
*/ */
R<User> getById(String userId); R<Integer> getById(String userId);
/** /**
* 获取用户信息 * 获取用户信息
* @param userId 用户id * @param userId 用户id
* @return 用户信息 * @return 用户信息
*/ */
User getByUserId(String userId); Integer getByUserId(String userId);
//根据手机号查询用户 //根据手机号查询用户
public User queryUsersByPhone(String id); public User queryUsersByPhone(String id);
//根据OpenId查询用户
public User queryUsersByOpenId(String openId);
/**
*用户注册
*/
Integer userByZx(String userId, String beInvitedCode);
// Integer selectbyint(String userId,String beInvitedCode);
//
// Integer getuserIdById(String userId);
} }
package cn.wisenergy.service.app.impl; package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.common.utils.ShareCodeUtil;
import cn.wisenergy.mapper.UsersMapper; import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.User; import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.UserService; import cn.wisenergy.service.app.UserService;
...@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.xml.transform.Result;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -28,13 +31,13 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -28,13 +31,13 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
private UsersMapper usersMapper; private UsersMapper usersMapper;
@Override @Override
public R<User> getById(String userId) { public R<Integer> getById(String userId) {
return R.ok(usersMapper.getByUserId(userId)); return R.ok(usersMapper.getByUserId(userId));
} }
@Override @Override
public User getByUserId(String userId) { public Integer getByUserId(String userId) {
return usersMapper.getByUserId(userId); return usersMapper.getByUserId(userId);
} }
...@@ -51,4 +54,38 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -51,4 +54,38 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
return null; return null;
} }
@Override
public User queryUsersByOpenId(String id) {
return null;
}
@Override
public Integer userByZx(String userId, String beInvitedCode) {
/**
* 判断用户等级是否为空,空的话填写0
*/
if(null==beInvitedCode || ""==beInvitedCode){
beInvitedCode= String.valueOf(1);
}
// 插入用户手机号与推荐人邀请码
usersMapper.insertbyint(userId,beInvitedCode);
//根据插入的用户手机号,查询用户唯一ID
Integer yqm=usersMapper.getByUserId(userId);
//用户唯一ID调用生成6位邀请码
String inviteCode= ShareCodeUtil.idToCode(yqm);
//根据用户手机号,更新用户信息
User user = new User();
user.setInviteCode(inviteCode);
user.setUserLevel(0);
usersMapper.updateById(user);
//插入直推用户表
//插入用户团队表
//根据邀请码查询推荐人的普通用户字段+1
//根据邀请码递归所有团队成员普通用户+1
}
} }
package cn.wisenergy.web.sms; package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.RedisUtils; import cn.wisenergy.common.utils.RedisUtils;
import cn.wisenergy.common.utils.StringUtil; import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.web.sms.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -17,6 +21,17 @@ public class SmsController { ...@@ -17,6 +21,17 @@ public class SmsController {
@Autowired @Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
/**
*
* @param phone
* @param codeType 0注册/登录验证 1修改密码 2订单通知信息
* @return
* @throws Exception
*/
@ApiOperation(value = "发送验证码", notes = "发送验证码", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "phone", value = "用户手机号", required = true, dataType = "String"),
@ApiImplicitParam(name = "codeType", value = "验证码", dataType = "Integer")})
@RequestMapping("/verifyCode") @RequestMapping("/verifyCode")
public Result verifyCode(String phone,Integer codeType) throws Exception { public Result verifyCode(String phone,Integer codeType) throws Exception {
//判断phone和codeType是否符合输入类型 //判断phone和codeType是否符合输入类型
...@@ -28,15 +43,15 @@ public class SmsController { ...@@ -28,15 +43,15 @@ public class SmsController {
} }
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,phone,codeType+""); String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,phone,codeType+"");
//判断是否超过60S //判断是否超过60S
String oldCode=redisUtils.getValue(key); String Codekey=redisUtils.getValue(key);
if(!StringUtils.isBlank(oldCode)){ if(!StringUtils.isBlank(Codekey)){
throw new BaseException(ResultEnum.CODESEND_ERROR); throw new BaseException(ResultEnum.CODESEND_ERROR);
} }
//生成随机数 //生成随机数
String code= MathUtils.random(); String code= MathUtils.random();
//保存至Redis //保存至Redis
redisUtils.set(key,code,Constants.Duration.MINUTE_INT); redisUtils.set(Codekey,code,Constants.Duration.MINUTE_INT);
boolean flag=smsUtils.sendMessage(phone,Constants.Sms.TemplateCode.LOGIN_OR_REGISTER,code); boolean flag=smsUtils.sendMessage(phone,Constants.Sms.TemplateCode.LOGIN_DL_REGISTER,code);
return flag? ResultUtils.returnSuccess():ResultUtils.returnFail(); return flag? ResultUtils.returnSuccess():ResultUtils.returnFail();
} }
} }
\ No newline at end of file
package cn.wisenergy.web.sms; package cn.wisenergy.web.admin.controller.app;
//import cn.est.config.UserConfig;
//import cn.est.constants.ResultEnum; import cn.wisenergy.common.utils.SmsUtils;
//import cn.est.dto.Result; import cn.wisenergy.web.sms.Result;
//import cn.est.po.Brand; import cn.wisenergy.web.sms.ResultUtils;
//import cn.est.service.BrandService; import cn.wisenergy.web.sms.ShareCodeUtil;
//import cn.est.utils.ResultUtils; import io.swagger.annotations.Api;
//import cn.est.utils.SmsUtils; import io.swagger.annotations.ApiOperation;
//import cn.est.utils.StringUtil; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller @Api(tags = "短信服务测试,邀请码测试")
@RestController
@RequestMapping("/ZX")
@Slf4j
public class TestController { public class TestController {
// @Autowired // @Autowired
...@@ -25,6 +28,7 @@ public class TestController { ...@@ -25,6 +28,7 @@ public class TestController {
// @Autowired // @Autowired
// private UserConfig useronfig; // private UserConfig useronfig;
@ApiOperation(value = "测试Hello Wolrd", notes = "测试", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/index") @RequestMapping("/index")
@ResponseBody @ResponseBody
public String index() { public String index() {
...@@ -49,17 +53,17 @@ public class TestController { ...@@ -49,17 +53,17 @@ public class TestController {
public static void main(String [] args){ public static void main(String [] args){
String b = ShareCodeUtil.idToCode(123456); String b = ShareCodeUtil.idToCode(1);
String a= ShareCodeUtil.idToCode(0,0+1); String a= ShareCodeUtil.idToCode(19919990669,0+1);
System.out.println(b); System.out.println(b);
} }
@ApiOperation(value = "测试短信服务,发送手机号", notes = "测试短信服务,发送手机号", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/testSms") @RequestMapping("/testSms")
@ResponseBody @ResponseBody
public Result testException()throws Exception{ public Result testException()throws Exception{
// System.out.println(useronfig.getUserName()+"---"+useronfig.getSex()); // System.out.println(useronfig.getUserName()+"---"+useronfig.getSex());
return smsUtils.sendMessage("18518666833","SMS_212170059","2111")?ResultUtils.returnSuccess():ResultUtils.returnFail(); return smsUtils.sendMessage("19919990669","SMS_212170059","2111")? ResultUtils.returnSuccess():ResultUtils.returnFail();
} }
} }
...@@ -79,49 +79,4 @@ public class UserController extends BaseController { ...@@ -79,49 +79,4 @@ public class UserController extends BaseController {
return R.ok(token); return R.ok(token);
} }
// /**
// * 手机号登录
// * @param userId
// * @param sms
// * @return
// * @throws Exception
// */
// @ApiOperation(value = "获取用户手机号登录接口", notes = "获取用户手机号登录接口", httpMethod = "POST")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String"),
// @ApiImplicitParam(name = "sms", value = "短信验证码", required = true, dataType = "String")})
// @RequestMapping("/login/sms")
// public Result loginBySms(String userId, String sms)throws Exception{
// User users=null;
// String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
// String redisCode=redisUtils.getValue(key);
// if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
// throw new BaseException(ResultEnum.FAIL_VERIFY);
// }
// redisUtils.delete(key);
// //根据手机号判断用户是否存在
// //不存在则保存用户信息
// users=userService.queryUsersByPhone(userId);
// if(null==users){
// users=new User();
//// users.setAccount(phone);
//// users.setUserName(phone);
//// userService.qdtxAddUsers(users);
// }
// String token=createToken(users);
// if(!StringUtil.isBlank(token)){
// return ResultUtils.returnDataSuccess(StringUtil.createSimpleMap("token",token));
// }
// return ResultUtils.returnFail();
// }
//
// public String createToken(User users)throws Exception{
// String token=StringUtil.createToken();
// //保存token
// String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
// UsersDto usersDto=new UsersDto();
// BeanUtils.copyProperties(users,usersDto);
// redisUtils.set(tokenKey, JSONObject.toJSONString(usersDto),Constants.Duration.HALF_HOUR_INT);
// return token;
// }
} }
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.web.sms.*;
import cn.wisenergy.common.utils.RedisUtils;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.model.app.User;
import cn.wisenergy.model.app.UsersDto;
import cn.wisenergy.service.app.UserService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
* Created by m1991 on 2021/3/2 13:35
*/
@Api(tags = "登录/注册")
@Slf4j
@RequestMapping("/api/user/login/sms")
@RestController
public class loginController {
@Autowired
private RedisUtils redisUtils;
@Autowired
private UserService usersService;
@Autowired
private Result result;
/**
* 手机登录接口
* @param userId
* @param sms
* @return
* @throws Exception
*/
@ApiOperation(value = "登录", notes = "登录", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "sms", value = "验证码", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping("/login/sms")
public Result loginBySms(String userId,String sms)throws Exception{
User users=null;
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
throw new BaseException(ResultEnum.FAIL_VERIFY);
}
redisUtils.delete(key);
//根据手机号判断用户是否存在
//不存在则保存用户信息--修改为提示用户注册
users=usersService.queryUsersByPhone(userId);
if(null==users){
throw new BaseException(ResultEnum.FAIL_ACCOUNT_NOT_EXIST);
// users=new User();
// users.setUserId(userId);
// usersService.qdtxAddUsers(users);;
}
String token=createToken(users);
if(!StringUtil.isBlank(token)){
return ResultUtils.returnDataSuccess(StringUtil.createSimpleMap("token",token));
}
return ResultUtils.returnFail();
}
public String createToken(User users)throws Exception{
String token=StringUtil.createToken();
//保存token
String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
UsersDto usersDto=new UsersDto();
BeanUtils.copyProperties(users,usersDto);
redisUtils.set(tokenKey, JSONObject.toJSONString(usersDto),Constants.Duration.HALF_HOUR_INT);
return token;
}
@ApiOperation(value = "获取用户登录token信息", notes = "获取用户登录token信息", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/info")
public Result info(HttpServletRequest request)throws Exception{
String token=request.getHeader("token");
String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
String userDtoJson=redisUtils.getValue(tokenKey);
if(StringUtil.isBlank(userDtoJson)){
throw new BaseException(ResultEnum.FILE_NOT_LOGIN);
}
UsersDto usersDto=JSONObject.parseObject(userDtoJson,UsersDto.class);
usersDto.setPassword(null);
return ResultUtils.returnDataSuccess(userDtoJson);
}
//用户注册
@ApiOperation(value = "用户注册", notes = "用户注册", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String"),
@ApiImplicitParam(name = "beInvitedCode", value = "推荐人邀请码", dataType = "String"),
@ApiImplicitParam(name = "sms", value = "验证码", dataType = "String")
})
@RequestMapping("/register")
public Result register(@RequestParam String userId, @RequestParam String beInvitedCode, String sms)throws Exception {
User users=null;
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
throw new BaseException(ResultEnum.FAIL_VERIFY);
}
redisUtils.delete(key);
//判断phone是否符合输入类型
if(!userId.matches(Constants.RegConstant.PHONE_REGSTR)){
throw new BaseException(ResultEnum.PHONE_ERROR);
}
usersService.userByZx(userId,beInvitedCode);
return ResultUtils.returnFail("注册成功!","0");
}
}
...@@ -63,13 +63,15 @@ public class ShiroConfig { ...@@ -63,13 +63,15 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon"); filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
filterChainDefinitionMap.put("/swagger-resources/**", "anon"); filterChainDefinitionMap.put("/swagger-resources/**", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon"); filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/api/sms/verifyCode", "anon");
filterChainDefinitionMap.put("/api/sms/**", "anon");
filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址 filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址
filterChainDefinitionMap.put("/webSocket/**", "anon");//socket filterChainDefinitionMap.put("/webSocket/**", "anon");//socket
filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口 filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口
filterChainDefinitionMap.put("/**", "oauth2"); // 其他路径均需要身份认证,一般位于最下面,优先级最低 filterChainDefinitionMap.put("/**", "oauth2"); // 其他路径均需要身份认证,一般位于最下面,优先级最低
// 设置拦截器 // 设置拦截器
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean; return shiroFilterFactoryBean;
} }
......
...@@ -48,14 +48,28 @@ public class Constants { ...@@ -48,14 +48,28 @@ public class Constants {
//正则的一些常量 //正则的一些常量
public static class RegConstant{ public static class RegConstant{
//手机号正则 //手机号正则
public static String PHONE_REGSTR = "^[1][0-9]{10}$"; public static String PHONE_REGSTR = "^1[0-9]{10}$";
//密码正则 //密码正则
public static String PASSWORD_REGSTR = "^([A-Z]|[a-z]|[0-9]|[_]){6,10}$"; public static String PASSWORD_REGSTR = "^([A-Z]|[a-z]|[0-9]|[_]){6,10}$";
} }
//SMS相关常量 //SMS相关常量
public static class Sms{ public static class Sms{
public static class TemplateCode{ public static class TemplateCode{
public static String LOGIN_OR_REGISTER="SMS_197895260"; //对存入redis的tokn用户进行标注
public static String LOGIN_BZ_REGISTER="xts";
//身份验证验证码
public static String LOGIN_SF_REGISTER="SMS_212170059";
//登录确认验证码
public static String LOGIN_DL_REGISTER="SMS_212170058";
//登录异常验证码
public static String LOGIN_DLYC_REGISTER="SMS_212170057";
//用户注册验证码
public static String LOGIN_ZC_REGISTER="SMS_212170056";
//修改密码验证码
public static String LOGIN_XGMM_REGISTER= "SMS_212170055";
// 信息变更验证码
public static String LOGIN_XXBG_REGISTER= "SMS_212170054";
} }
public static class CodeType{ public static class CodeType{
......
...@@ -16,7 +16,7 @@ public enum ResultEnum { ...@@ -16,7 +16,7 @@ public enum ResultEnum {
FAIL_LOGIN("1002", "登录失败"), FAIL_LOGIN("1002", "登录失败"),
FAIL_VERIFY("1003", "验证码错误"), FAIL_VERIFY("1003", "验证码错误"),
FAIL_ACCOUNT_EXIST("1004", "账号已存在"), FAIL_ACCOUNT_EXIST("1004", "账号已存在"),
FAIL_ACCOUNT_NOT_EXIST("1005", "账号不存在"), FAIL_ACCOUNT_NOT_EXIST("1005", "账号不存在,请注册!"),
FAIL_TIMESTAMP_NOT_NULL("1006", "时间戳不能为空"), FAIL_TIMESTAMP_NOT_NULL("1006", "时间戳不能为空"),
FAIL_VISIT_SOURCE_NOT_NULL("1007", "访问来源不能为空"), FAIL_VISIT_SOURCE_NOT_NULL("1007", "访问来源不能为空"),
PHONE_ERROR("1008","手机号码格式不正确"), PHONE_ERROR("1008","手机号码格式不正确"),
......
...@@ -67,9 +67,9 @@ public class ValidateParamInterceptor extends HandlerInterceptorAdapter { ...@@ -67,9 +67,9 @@ public class ValidateParamInterceptor extends HandlerInterceptorAdapter {
// 阿里支付 // 阿里支付
map.put("/api/pay/alipay", Arrays.asList("orderNo", "amount")); map.put("/api/pay/alipay", Arrays.asList("orderNo", "amount"));
// 验证码登录、注册接口 // 验证码登录、注册接口
map.put("/api/sms/login/sms", Arrays.asList("phone", "sms")); map.put("/api/sms/login/sms", Arrays.asList("userId", "sms"));
// 发送验证码接口 // 发送验证码接口
map.put("/api/sms/verifyCode", Arrays.asList("phone", "codeType")); map.put("/api/sms/verifyCode", Arrays.asList("userId", "codeType"));
return map; return map;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment