Commit cc63386c by 唐功亮

【修改】 登录接口 增加手机号用户登录

parent 63b24814
package io.office.modules.manage.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.office.common.exception.RRException;
import io.office.common.utils.IPUtils;
import io.office.common.utils.R;
import io.office.modules.manage.dao.MemberDao;
import io.office.modules.manage.entity.MemberEntity;
import io.office.modules.manage.utils.DESUtils;
import io.office.modules.manage.utils.HttpUtlis;
import io.office.modules.manage.utils.MD5Util;
import io.office.modules.sys.service.SysUserTokenService;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;
......@@ -66,11 +73,35 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
Integer levels = null; //用户权限 空.代表普通用户 0.代表中心管理员,1.代表校验管理员 其他4位.代表分中心管理员
Integer isQY=2; //是否开通企业认证 1.开通 2.未开通
Integer isXT=2; //是否是业务大厅系统成员 1.是 2.否
Integer id=0; //用户ID
String search="ws2";// 用户来源 manager:业务大厅手机号用户 ws2:member表用户
String carno=null;// 条码卡号
String phone=null;//手机号码
//判断用户是否是手机号 是手机号调用 第三方接口登录 不是继续
if (matchPhoneNumber(userName)){
//TODO tgl 调用第三方登录接口
//用第三方登录接口
userType=1;
//对 用户名密码进行DES加密
String phoen_M = DESUtils.byteToHexString(DESUtils.DES_CBC_Encrypt(userName.getBytes(),DESUtils.Key.getBytes()));
String passwrod_M = DESUtils.byteToHexString(DESUtils.DES_CBC_Encrypt(passWord.getBytes(),DESUtils.Key.getBytes()));
String url="http://wsdt.gs1cn.org/anccoh/login?method=loginValidate&phone="+phoen_M+"&password="+passwrod_M;
String s = doGet(url);
if (s==null){
throw new RRException("服务器繁忙,登录失败");
}else {
JSONObject jsonObject = JSON.parseObject(s);
String status = jsonObject.getString("status");
if (!status.equals("1")){
throw new RRException("登录失败"+jsonObject.getString("msg"));
}else {
//登录成功
search="manager";
phone=userName;
//TODO tgl 需要中国编码官网提供 条码卡数据 来判断是否是系统用户
}
}
}else {
//查询Member表
MemberEntity memberEntity = memberDao.selectByName(userName);
......@@ -85,6 +116,7 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
userType=3;
}else {//条码卡用户
userType=2;
carno=userName;
}
//获取权限
levels=memberDao.selectCode_agen(userName);
......@@ -103,7 +135,7 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
if (user==null){
throw new RRException("用户不存在!");
}
String phone = user.getPhone();
phone = user.getPhone();
String password = user.getPass();
String passwordMD5 = MD5Util.md5Encrypt32Upper(passWord);
//判断密码是否正确
......@@ -112,10 +144,10 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
}
//TODO tgl 参数不正确添加登录日志 log_login
logLoginDao.insert(new LogLoginEntity(1,userName,"用户来源","条码卡号",phone,new Date(), IPUtils.getIpAddr(request),request.getRequestURL().toString()));
//添加登录日志 log_login
}
logLoginDao.insert(new LogLoginEntity(1,userName,search,carno,phone,new Date(), IPUtils.getIpAddr(request),request.getRequestURL().toString()));
JSONObject jsonObject = new JSONObject();
......@@ -142,4 +174,24 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
}
return Pattern.matches(regex, phoneNumber);
}
private static String doGet(String url) {
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url);
int code = 0;
try {
code = client.executeMethod(getMethod);
if (code == 200) {
String res = getMethod.getResponseBodyAsString();
return res;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
\ No newline at end of file
package io.office.modules.manage.utils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
public class DESUtils {
public static final String Key="loginkey";
public static byte[] DES_CBC_Encrypt(byte[] content, byte[] keyBytes){
try {
DESKeySpec keySpec=new DESKeySpec(keyBytes);
SecretKeyFactory keyFactory=SecretKeyFactory.getInstance("DES");
SecretKey key=keyFactory.generateSecret(keySpec);
Cipher cipher=Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(keySpec.getKey()));
byte[] result=cipher.doFinal(content);
return result;
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("exception:"+e.toString());
}
return null;
}
public static String byteToHexString(byte[] bytes) {
StringBuffer sb = new StringBuffer(bytes.length);
String sTemp;
for (int i = 0; i < bytes.length; i++) {
sTemp = Integer.toHexString(0xFF & bytes[i]);
if (sTemp.length() < 2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}
return sb.toString();
}
}
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