| | |
| | | package com.java110.web.smo.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.cache.CommonCache; |
| | | import com.java110.common.constant.ServiceConstant; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.ValidateCodeFactory; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * 登录信息实现类 |
| | | * Created by wuxw on 2019/3/20. |
| | |
| | | public class LoginServiceSMOImpl extends BaseComponentSMO implements ILoginServiceSMO { |
| | | private final static Logger logger = LoggerFactory.getLogger(LoginServiceSMOImpl.class); |
| | | |
| | | |
| | | private static char[] chs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); |
| | | private static final int NUMBER_OF_CHS = 4; |
| | | private static final int IMG_WIDTH = 65; |
| | | private static final int IMG_HEIGHT = 25; |
| | | private static Random r = new Random(); |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | |
| | | } |
| | | |
| | | loginInfo.put("passwd", AuthenticationFactory.passwdMd5(loginInfo.getString("passwd"))); |
| | | responseEntity = this.callCenterService(restTemplate,pd,loginInfo.toJSONString(),ServiceConstant.SERVICE_API_URL+"/api/user.service.login",HttpMethod.POST); |
| | | responseEntity = this.callCenterService(restTemplate,pd,loginInfo.toJSONString(), "http://api.java110.com:8008/api/user.service.login",HttpMethod.POST); |
| | | if(responseEntity.getStatusCode() == HttpStatus.OK){ |
| | | pd.setToken(JSONObject.parseObject(responseEntity.getBody()).getString("token")); |
| | | } |
| | |
| | | verifyCodeImage = new ResponseEntity<>(ValidateCodeFactory.outputImage(200, 80, verifyCode), HttpStatus.OK); |
| | | |
| | | //将验证码存入Redis中 |
| | | CommonCache.setValue(pd.getSessionId()+"_validateCode",verifyCode,CommonCache.defaultExpireTime); |
| | | CommonCache.setValue(pd.getSessionId()+"_validateCode",verifyCode.toLowerCase(),CommonCache.defaultExpireTime); |
| | | |
| | | }catch (Exception e){ |
| | | logger.error("生成验证码失败,",e); |
| | |
| | | |
| | | String code = CommonCache.getValue(pd.getSessionId()+"_validateCode"); |
| | | |
| | | if(JSONObject.parseObject(pd.getReqData()).getString("validateCode").equals(code)){ |
| | | if(JSONObject.parseObject(pd.getReqData()).getString("validateCode").toLowerCase().equals(code)){ |
| | | verifyResult = new ResponseEntity<>("成功", HttpStatus.OK); |
| | | }else{ |
| | | pd.setToken(""); |
| | | verifyResult = new ResponseEntity<>("验证码错误", HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | |