generated from root/miduo_server
登录服重构
parent
637f805076
commit
2462b5a381
|
@ -1,9 +1,11 @@
|
||||||
package com.ljsd.controller;
|
package com.ljsd.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.ljsd.redis.RedisKey;
|
import com.ljsd.redis.RedisKey;
|
||||||
import com.ljsd.redis.RedisUtil;
|
import com.ljsd.service.LdVerifyService;
|
||||||
import com.ljsd.util.*;
|
import com.ljsd.service.VerifyService;
|
||||||
|
import com.ljsd.service.XPVerifyService;
|
||||||
|
import com.ljsd.util.BaseGlobal;
|
||||||
|
import com.ljsd.util.MD5Util;
|
||||||
import com.mongodb.BasicDBObject;
|
import com.mongodb.BasicDBObject;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -15,19 +17,24 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class GetUserController extends HttpServlet {
|
public class GetUserController extends HttpServlet {
|
||||||
private final static String _COLLECTION_NAME = "user_info";
|
private final static String _COLLECTION_NAME = "user_info";
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GetUserController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GetUserController.class);
|
||||||
public static int isTestLan=0;
|
|
||||||
|
|
||||||
public static void initLanState(){
|
private static Map<String, VerifyService> serviceMap = new HashMap<>();
|
||||||
Properties properties = BaseGlobal.getInstance().properties;
|
public static void initHandler(){
|
||||||
isTestLan = Integer.parseInt(properties.getProperty("isTestLan"));
|
//初始化所有需要的验证方式
|
||||||
|
serviceMap.put("MHT", new LdVerifyService("MHT"));
|
||||||
|
serviceMap.put("XP", new XPVerifyService("XP"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GetUserController() {
|
public GetUserController() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -104,6 +111,7 @@ public class GetUserController extends HttpServlet {
|
||||||
|
|
||||||
String gid = request.getParameter("gid"); //gid
|
String gid = request.getParameter("gid"); //gid
|
||||||
String pid = request.getParameter("pid"); //pid
|
String pid = request.getParameter("pid"); //pid
|
||||||
|
String channel = request.getParameter("channel");
|
||||||
|
|
||||||
/*if (StringUtils.checkIsEmpty(admin)) {
|
/*if (StringUtils.checkIsEmpty(admin)) {
|
||||||
response.sendError(400, "platform is empety");
|
response.sendError(400, "platform is empety");
|
||||||
|
@ -111,8 +119,10 @@ public class GetUserController extends HttpServlet {
|
||||||
}*/
|
}*/
|
||||||
LOGGER.info("the opendId = {},token={},platform={} admin=>{}",openId,token,platform,admin);
|
LOGGER.info("the opendId = {},token={},platform={} admin=>{}",openId,token,platform,admin);
|
||||||
try {
|
try {
|
||||||
boolean vertify = vertify(response, request, admin, platform, pid, openId, token);
|
//根据前端发过来的种类进行校验
|
||||||
if(!vertify){
|
boolean verify = serviceMap.get(channel).verify(response, request, admin, platform, pid, openId, token);
|
||||||
|
|
||||||
|
if(!verify){
|
||||||
returnErrorToFront(res,response,"校验失败,请重新登录");
|
returnErrorToFront(res,response,"校验失败,请重新登录");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -181,154 +191,41 @@ public class GetUserController extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean vertify(HttpServletResponse response,HttpServletRequest request,String admin,String platform,String pid,String openId,String token){
|
|
||||||
try {
|
|
||||||
Properties properties = BaseGlobal.getInstance().properties;
|
|
||||||
|
|
||||||
if(!KTSDKConstans.appsecret.equals(admin)) {
|
|
||||||
if (isTestLan == 1) { //test
|
|
||||||
boolean result = loginVerfifyByTestLan(openId, token);
|
|
||||||
if (!result) {
|
|
||||||
response.sendError(400, "verify fail");
|
|
||||||
LOGGER.error("test verify fail");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!"3".equals(platform)) {//正式 切不是pc
|
|
||||||
String sub_channel = request.getParameter("sub_channel");
|
|
||||||
boolean result = false;
|
|
||||||
if (sub_channel != null && !sub_channel.equals("")) {
|
|
||||||
if (sub_channel.equals("1000")) {
|
|
||||||
//测试服appId
|
|
||||||
result = loginVerfify("MHT", openId, token, MHTSDKConstans.rhappid);
|
|
||||||
} else if(sub_channel.equals("20201222")){
|
|
||||||
//商务服
|
|
||||||
result = loginVerfifyShangwu("MHT", openId, token, MHTSDKConstans.rhappIdshangwu);
|
|
||||||
} else {
|
|
||||||
//正式服appId
|
|
||||||
String appId_online = properties.getProperty("appId_online");
|
|
||||||
LOGGER.info("appId_online:{}",appId_online);
|
|
||||||
result = loginVerfify("MHT", openId, token, appId_online);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!result) {
|
|
||||||
response.sendError(400, "verify fail");
|
|
||||||
LOGGER.error("verify fail");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// else {
|
|
||||||
// boolean result = loginVerfifyByTestLan(openId, token);
|
|
||||||
// if (!result) {
|
|
||||||
// response.sendError(400, "verify fail");
|
|
||||||
// LOGGER.error("test verify fail");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
this.doGet(request, response);
|
this.doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static boolean loginVerfifyShangwu(String channelName,String openId,String token,String appId){
|
||||||
|
// try{
|
||||||
|
// String loginUrl = MHTSDKConstans.loginVerifyShangwu;
|
||||||
|
// Map<String, String> params = new HashMap<>();
|
||||||
|
//
|
||||||
|
// params.put("userToken", token);
|
||||||
|
// params.put("appId", appId);
|
||||||
|
// params.put("channelName", channelName);
|
||||||
|
// params.put("uid", openId);
|
||||||
|
//// loginUrl+"?"+"sid="+params.get("sid")+"&appid="+
|
||||||
|
// String loginResult = HttpUtils.doPost(loginUrl,params);
|
||||||
|
// if(loginResult == null || loginResult.isEmpty()){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// return parseLoginResult(loginResult);
|
||||||
|
// }catch(Exception e){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
public static boolean loginVerfify(String channelName,String openId,String token,String appId){
|
|
||||||
try{
|
|
||||||
Properties properties = BaseGlobal.getInstance().properties;
|
|
||||||
|
|
||||||
String login_url = properties.getProperty("login_url");
|
|
||||||
LOGGER.info("login_url={}",login_url);
|
|
||||||
String loginUrl = MHTSDKConstans.loginVerify;
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
|
|
||||||
params.put("sid", token);
|
|
||||||
params.put("appid", appId);
|
|
||||||
params.put("channellevel1", channelName);
|
|
||||||
String sign = getSign(getParamString(params), appId, MHTSDKConstans.secretKey);
|
|
||||||
params.put("sign", sign);
|
|
||||||
// loginUrl+"?"+"sid="+params.get("sid")+"&appid="+
|
|
||||||
String loginResult = HttpUtils.doPost(login_url,params);
|
|
||||||
LOGGER.info("loginResult=>{}",loginResult);
|
|
||||||
if(loginResult == null || loginResult.isEmpty()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parseLoginResult(loginResult);
|
|
||||||
}catch(Exception e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public static boolean loginVerfifyShangwu(String channelName,String openId,String token,String appId){
|
|
||||||
try{
|
|
||||||
String loginUrl = MHTSDKConstans.loginVerifyShangwu;
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
|
|
||||||
params.put("userToken", token);
|
|
||||||
params.put("appId", appId);
|
|
||||||
params.put("channelName", channelName);
|
|
||||||
params.put("uid", openId);
|
|
||||||
// loginUrl+"?"+"sid="+params.get("sid")+"&appid="+
|
|
||||||
String loginResult = HttpUtils.doPost(loginUrl,params);
|
|
||||||
if(loginResult == null || loginResult.isEmpty()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return parseLoginResult(loginResult);
|
|
||||||
}catch(Exception e){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean loginVerfifyByTestLan(String openId,String token) throws Exception {
|
|
||||||
String tokenInRedis = BaseGlobal.getInstance().redisApp.get(RedisKey.LOGIN_TOKEN, openId, String.class, -1);
|
|
||||||
LOGGER.info("loginVerfifyByTestLan tokenInRedis={} client=>{}",tokenInRedis, token);
|
|
||||||
return token.equals(tokenInRedis);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static boolean parseLoginResult(String orderResult){
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(orderResult);
|
|
||||||
int state = jsonObject.getIntValue("code");
|
|
||||||
if(state != 200){
|
|
||||||
String content = jsonObject.getString("message");
|
|
||||||
LOGGER.info("parseLoginResult content={}",content);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建签名
|
|
||||||
* sign=md5hex(paramString+md5hex(appid)+md5hex(secret))
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String getSign(String paramString,String appid,String secret){
|
|
||||||
|
|
||||||
return MD5Util.encrypByMd5(paramString + MD5Util.encrypByMd5(appid) + MD5Util.encrypByMd5(secret));
|
|
||||||
}
|
|
||||||
private static String getParamString(Map<String,String> param){
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
param.forEach((k,v)->{
|
|
||||||
if(builder.length()>0){
|
|
||||||
builder.append("&");
|
|
||||||
}
|
|
||||||
builder.append(k).append("=").append(v);
|
|
||||||
});
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// boolean mht = loginVerfify("MHT", "2318137", "be385683efe228aadac0c8b5822a6fba");
|
String paramSign = "d53b3e8ef74bf72d8aafce3a1c8671a0" ;
|
||||||
|
String secretKey = "";
|
||||||
|
String timeStamp = "0";
|
||||||
|
String openId = "1238";
|
||||||
|
String verifyStr = openId+"&"+timeStamp+"&"+secretKey;
|
||||||
|
String s = MD5Util.encrypByMd5(verifyStr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
package com.ljsd.controller;
|
package com.ljsd.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.ljsd.plat.MHTHyTestPlat;
|
import com.ljsd.plat.MHTHyTestPlat;
|
||||||
import com.ljsd.plat.PlatProcess;
|
import com.ljsd.plat.PlatProcess;
|
||||||
import com.ljsd.redis.RedisKey;
|
import com.ljsd.util.AppConstans;
|
||||||
import com.ljsd.util.BaseGlobal;
|
import com.ljsd.util.BaseGlobal;
|
||||||
import com.ljsd.util.HttpUtils;
|
|
||||||
import com.ljsd.util.KTSDKConstans;
|
|
||||||
import com.ljsd.util.MHTSDKConstans;
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -18,10 +12,9 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.util.Properties;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class GetUserHwController extends GetUserController {
|
public class GetUserHwController extends HttpServlet {
|
||||||
private final static String _COLLECTION_NAME = "user_info";
|
private final static String _COLLECTION_NAME = "user_info";
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GetUserHwController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GetUserHwController.class);
|
||||||
public static int isTestLan=0;
|
public static int isTestLan=0;
|
||||||
|
@ -40,12 +33,12 @@ public class GetUserHwController extends GetUserController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean vertify(HttpServletResponse response, HttpServletRequest request, String admin, String platform, String pid, String openId, String token) {
|
public boolean vertify(HttpServletResponse response, HttpServletRequest request, String admin, String platform, String pid, String openId, String token) {
|
||||||
try {
|
try {
|
||||||
if(!KTSDKConstans.appsecret.equals(admin)) {
|
if(!AppConstans.appsecret.equals(admin)) {
|
||||||
if (isTestLan == 1) { //test
|
if (isTestLan == 1) { //test
|
||||||
boolean result = loginVerfifyByTestLan(openId, token);
|
boolean result=true;
|
||||||
|
// t = loginVerfifyByTestLan(openId, token);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
response.sendError(400, "verify fail");
|
response.sendError(400, "verify fail");
|
||||||
LOGGER.error("test verify fail");
|
LOGGER.error("test verify fail");
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.ljsd.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/5/26
|
||||||
|
* @discribe 存一些需要用来验证的参数信息
|
||||||
|
*/
|
||||||
|
public class VerifyParams {
|
||||||
|
private String channel;
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
private String timeStamp;
|
||||||
|
|
||||||
|
private String paramSign;//参数中的sign
|
||||||
|
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
public String getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChannel(String channel) {
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecretKey() {
|
||||||
|
return secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecretKey(String secretKey) {
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeStamp() {
|
||||||
|
return timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamp(String timeStamp) {
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParamSign() {
|
||||||
|
return paramSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParamSign(String paramSign) {
|
||||||
|
this.paramSign = paramSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpenId() {
|
||||||
|
return openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenId(String openId) {
|
||||||
|
this.openId = openId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
package com.ljsd.service;
|
||||||
|
|
||||||
|
import com.ljsd.pojo.VerifyParams;
|
||||||
|
import com.ljsd.redis.RedisKey;
|
||||||
|
import com.ljsd.util.AppConstans;
|
||||||
|
import com.ljsd.util.BaseGlobal;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/5/26
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
public abstract class AbstractVerifyService implements VerifyService {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVerifyService.class);
|
||||||
|
protected Properties properties;
|
||||||
|
public static int isTestLan=0;
|
||||||
|
|
||||||
|
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
public AbstractVerifyService(String sign) {
|
||||||
|
this.sign = sign;
|
||||||
|
properties = BaseGlobal.getInstance().properties;
|
||||||
|
isTestLan = Integer.parseInt(properties.getProperty("isTestLan"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verify(HttpServletResponse response, HttpServletRequest request, String admin, String platform, String pid, String openId, String token){
|
||||||
|
|
||||||
|
try {
|
||||||
|
//如果是自己人不需要验证了
|
||||||
|
if(AppConstans.appsecret.equals(admin)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isTestLan == 1) { //test
|
||||||
|
boolean result = loginVerfifyByTestLan(openId, token);
|
||||||
|
if (!result) {
|
||||||
|
response.sendError(400, "verify fail");
|
||||||
|
LOGGER.error("test verify fail");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!"3".equals(platform) ) {//正式 切不是pc
|
||||||
|
String sub_channel = request.getParameter("sub_channel");
|
||||||
|
boolean result = false;
|
||||||
|
if (sub_channel != null && !sub_channel.equals("")) {
|
||||||
|
if (sub_channel.equals("1000")) {
|
||||||
|
//测试服构建参数
|
||||||
|
VerifyParams params = new VerifyParams();
|
||||||
|
params.setAppId(properties.getProperty("appId_test"));
|
||||||
|
params.setSecretKey(properties.getProperty("secretKey_test"));
|
||||||
|
VerifyParams testParam = getTestParam(params,request, openId, token);
|
||||||
|
result = verifyTest(testParam);
|
||||||
|
} else if(sub_channel.equals("20201222")){
|
||||||
|
//商务服
|
||||||
|
//result = loginVerfifyShangwu("MHT", openId, token, MHTSDKConstans.rhappIdshangwu);
|
||||||
|
} else {
|
||||||
|
//正式服appId
|
||||||
|
VerifyParams params = new VerifyParams();
|
||||||
|
params.setAppId(properties.getProperty("appId_online"));
|
||||||
|
params.setSecretKey(properties.getProperty("secretKey_online"));
|
||||||
|
VerifyParams formatParam = getFormatParam(params,request, openId, token);
|
||||||
|
result = verifyFormat(formatParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!result) {
|
||||||
|
response.sendError(400, "verify fail");
|
||||||
|
LOGGER.error("verify fail");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServiceSign(){
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean loginVerfifyByTestLan(String openId,String token) throws Exception {
|
||||||
|
String tokenInRedis = BaseGlobal.getInstance().redisApp.get(RedisKey.LOGIN_TOKEN, openId, String.class, -1);
|
||||||
|
LOGGER.info("loginVerfifyByTestLan tokenInRedis={} client=>{}",tokenInRedis, token);
|
||||||
|
return token.equals(tokenInRedis);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public abstract boolean verifyTest(VerifyParams params);
|
||||||
|
///,properties.getProperty("appId_test"),properties.getProperty("secretKey_test")
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean verifyFormat(VerifyParams params);
|
||||||
|
// (channel,openId,token,properties.getProperty("appId_online"),properties.getProperty("secretKey_online"));
|
||||||
|
|
||||||
|
abstract boolean doVerify(VerifyParams params);
|
||||||
|
|
||||||
|
|
||||||
|
protected abstract VerifyParams getTestParam(VerifyParams params,HttpServletRequest request,String openId,String token);
|
||||||
|
|
||||||
|
protected abstract VerifyParams getFormatParam(VerifyParams params,HttpServletRequest request,String openId,String token);
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.ljsd.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ljsd.pojo.VerifyParams;
|
||||||
|
import com.ljsd.util.HttpUtils;
|
||||||
|
import com.ljsd.util.MD5Util;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/5/26
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
public class LdVerifyService extends AbstractVerifyService{
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(LdVerifyService.class);
|
||||||
|
|
||||||
|
|
||||||
|
public LdVerifyService(String sign) {
|
||||||
|
super(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static String getParamString(Map<String,String> param){
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
param.forEach((k,v)->{
|
||||||
|
if(builder.length()>0){
|
||||||
|
builder.append("&");
|
||||||
|
}
|
||||||
|
builder.append(k).append("=").append(v);
|
||||||
|
});
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static boolean parseLoginResult(String orderResult){
|
||||||
|
try {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(orderResult);
|
||||||
|
int state = jsonObject.getIntValue("code");
|
||||||
|
if(state != 200){
|
||||||
|
String content = jsonObject.getString("message");
|
||||||
|
LOGGER.info("parseLoginResult content={}",content);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 构建签名
|
||||||
|
* sign=md5hex(paramString+md5hex(appid)+md5hex(secret))
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getSign(String paramString,String appid,String secret){
|
||||||
|
|
||||||
|
return MD5Util.encrypByMd5(paramString + MD5Util.encrypByMd5(appid) + MD5Util.encrypByMd5(secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
//String channel, String openId, String token ,String appId,String secretKey
|
||||||
|
boolean doVerify(VerifyParams verifyParams){
|
||||||
|
try{
|
||||||
|
String login_url = properties.getProperty("login_url");
|
||||||
|
|
||||||
|
LOGGER.info("login_url={}",login_url);
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
||||||
|
params.put("sid", verifyParams.getToken());
|
||||||
|
params.put("appid", verifyParams.getAppId());
|
||||||
|
params.put("channellevel1", verifyParams.getChannel());
|
||||||
|
String sign = getSign(getParamString(params), verifyParams.getAppId(), verifyParams.getSecretKey() );
|
||||||
|
params.put("sign", sign);
|
||||||
|
// loginUrl+"?"+"sid="+params.get("sid")+"&appid="+
|
||||||
|
String loginResult = HttpUtils.doPost(login_url,params);
|
||||||
|
LOGGER.info("loginResult=>{}",loginResult);
|
||||||
|
if(loginResult == null || loginResult.isEmpty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return parseLoginResult(loginResult);
|
||||||
|
}catch(Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verifyTest(VerifyParams params) {
|
||||||
|
|
||||||
|
return doVerify(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verifyFormat(VerifyParams params) {
|
||||||
|
|
||||||
|
return doVerify(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected VerifyParams getTestParam(VerifyParams params,HttpServletRequest request, String openId, String token) {
|
||||||
|
return getMHTParam(params,token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected VerifyParams getFormatParam(VerifyParams params,HttpServletRequest request, String openId, String token) {
|
||||||
|
return getMHTParam(params,token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VerifyParams getMHTParam(VerifyParams params,String token){
|
||||||
|
params.setChannel("MHT");
|
||||||
|
params.setToken(token);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.ljsd.service;
|
||||||
|
|
||||||
|
import com.ljsd.pojo.VerifyParams;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/5/26
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
public interface VerifyService {
|
||||||
|
|
||||||
|
boolean verify(HttpServletResponse response, HttpServletRequest request, String admin, String platform, String pid, String openId, String token);
|
||||||
|
|
||||||
|
String getServiceSign();
|
||||||
|
|
||||||
|
boolean verifyTest(VerifyParams params);
|
||||||
|
|
||||||
|
boolean verifyFormat(VerifyParams params);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.ljsd.service;
|
||||||
|
|
||||||
|
import com.ljsd.pojo.VerifyParams;
|
||||||
|
import com.ljsd.util.MD5Util;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/5/26
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
public class XPVerifyService extends AbstractVerifyService {
|
||||||
|
|
||||||
|
public XPVerifyService(String sign) {
|
||||||
|
super(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verifyTest(VerifyParams params) {
|
||||||
|
return doVerify(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verifyFormat(VerifyParams params) {
|
||||||
|
return doVerify(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean doVerify(VerifyParams params) {
|
||||||
|
|
||||||
|
String timeStamp = params.getTimeStamp();
|
||||||
|
|
||||||
|
long differenceTime = Math.abs(Long.parseLong(timeStamp)-System.currentTimeMillis()/1000);
|
||||||
|
if(differenceTime>5*60){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String paramSign = params.getParamSign();
|
||||||
|
String secretKey = params.getSecretKey();
|
||||||
|
String openId = params.getOpenId();
|
||||||
|
String verifyStr = openId+"&"+timeStamp+"&"+secretKey;
|
||||||
|
String s = MD5Util.encrypByMd5(verifyStr);
|
||||||
|
|
||||||
|
return s.equals(paramSign);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected VerifyParams getTestParam(VerifyParams params,HttpServletRequest request, String openId, String token) {
|
||||||
|
|
||||||
|
return getParam(params,request,openId,token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected VerifyParams getFormatParam(VerifyParams params,HttpServletRequest request, String openId, String token) {
|
||||||
|
return getParam(params,request,openId,token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VerifyParams getParam(VerifyParams params,HttpServletRequest request,String openId,String token){
|
||||||
|
String timeStamp = request.getParameter("timeStamp");
|
||||||
|
params.setTimeStamp(timeStamp);
|
||||||
|
params.setParamSign(token);
|
||||||
|
params.setOpenId(openId);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.ljsd.util;
|
||||||
|
|
||||||
|
public class AppConstans {
|
||||||
|
|
||||||
|
|
||||||
|
public static String appsecret = "d53b3e8ef74bf72d8aafce3a1c8671a0";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ public class BaseGlobal {
|
||||||
mongoDBPool = new MyMongoDBPool();
|
mongoDBPool = new MyMongoDBPool();
|
||||||
redisApp = new RedisApp();
|
redisApp = new RedisApp();
|
||||||
initHandler("com.ljsd.plat");
|
initHandler("com.ljsd.plat");
|
||||||
GetUserController.initLanState();
|
GetUserController.initHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package com.ljsd.util;
|
|
||||||
|
|
||||||
public class KTSDKConstans {
|
|
||||||
public static String appid = "129213";
|
|
||||||
public static String appkey = "c0fb59eb68559b6c9c1463e4d5d0c806";
|
|
||||||
public static String appsecret = "d53b3e8ef74bf72d8aafce3a1c8671a0";
|
|
||||||
|
|
||||||
public static String androidVerify = "http://sujie.passport.ktsdk.com/user/verifyAccount";
|
|
||||||
public static String iosVerify = "http://sujie.passport.ktsdk.com/userios/verifyAccount";
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue