generated from root/miduo_server
爱玩登录
parent
f827a3d5f8
commit
ce94292672
|
@ -32,13 +32,15 @@ public class GetUserController extends HttpServlet {
|
|||
//初始化所有需要的验证方式
|
||||
serviceMap.put("MHT", new LdVerifyService("MHT"));
|
||||
serviceMap.put("XP", new XPVerifyService("XP"));
|
||||
serviceMap.put("CH",new CaohuaVerifyService("CH"));//草花
|
||||
//草花
|
||||
serviceMap.put("CH",new CaohuaVerifyService("CH"));
|
||||
serviceMap.put("QUICK", new QuickVerifyService("QUICK"));
|
||||
serviceMap.put("YX", new YxylVerifyService("YX"));
|
||||
serviceMap.put("DY", new V3367VerifyService("DY"));
|
||||
serviceMap.put("QUICK2", new QuickVerifyService2("QUICK2"));
|
||||
serviceMap.put("YOUGU", new YouGuVerifyService("YG"));
|
||||
serviceMap.put("DUOYOU", new DuoYouVerifyService("DUOYOU"));
|
||||
serviceMap.put("AIWAN", new AiWanVerifyService("AIWAN"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +48,7 @@ public class GetUserController extends HttpServlet {
|
|||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
@ -70,6 +73,7 @@ public class GetUserController extends HttpServlet {
|
|||
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
DBObject res = new BasicDBObject();
|
||||
String openId = request.getParameter("openId");
|
||||
|
@ -108,15 +112,18 @@ public class GetUserController extends HttpServlet {
|
|||
returnErrorToFront(res,response,"token is empty");
|
||||
return;
|
||||
}
|
||||
String platform = request.getParameter("platform"); //平台类型
|
||||
//平台类型
|
||||
String platform = request.getParameter("platform");
|
||||
if (platform == null || platform.isEmpty()) {
|
||||
returnErrorToFront(res,response,"platform is empty");
|
||||
return;
|
||||
}
|
||||
String admin = request.getParameter("admin"); //平台类型
|
||||
|
||||
String gid = request.getParameter("gid"); //gid
|
||||
String pid = request.getParameter("pid"); //pid
|
||||
//平台类型
|
||||
String admin = request.getParameter("admin");
|
||||
//gid
|
||||
String gid = request.getParameter("gid");
|
||||
//pid
|
||||
String pid = request.getParameter("pid");
|
||||
String channel = request.getParameter("channel");
|
||||
String sub_channel = request.getParameter("sub_channel");
|
||||
/*if (StringUtils.checkIsEmpty(admin)) {
|
||||
|
@ -240,6 +247,7 @@ public class GetUserController extends HttpServlet {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(request, response);
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Deprecated
|
||||
public class GetUserHwController extends HttpServlet {
|
||||
private final static String _COLLECTION_NAME = "user_info";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GetUserHwController.class);
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
package com.ljsd.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ljsd.pojo.VerifyParams;
|
||||
import com.ljsd.util.AppConstans;
|
||||
import com.ljsd.util.HttpUtils;
|
||||
import com.ljsd.util.TimeUtil;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class AiWanVerifyService extends AbstractVerifyService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVerifyService.class);
|
||||
public static int isTestLan = 0;
|
||||
|
||||
public static final String app_key = "FKzLkGPIyMwYjXhRYfMWBsqikOfSPLkX";
|
||||
public static final String app_id = "lbqitk9b39vk9ee5";
|
||||
|
||||
public AiWanVerifyService(String sign) {
|
||||
super(sign);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
//test
|
||||
if (isTestLan == 1) {
|
||||
boolean result = loginVerfifyByTestLan(openId, token);
|
||||
if (!result) {
|
||||
response.sendError(400, "verify fail");
|
||||
LOGGER.error("test verify fail");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//正式 切不是pc
|
||||
else if (!"3".equals(platform)) {
|
||||
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();
|
||||
VerifyParams testParam = getTestParam(params, request, openId, token);
|
||||
result = verifyTest(testParam);
|
||||
}
|
||||
// //商务服
|
||||
// else if(sub_channel.equals("20201222")){
|
||||
// //result = loginVerfifyShangwu("MHT", openId, token, MHTSDKConstans.rhappIdshangwu);
|
||||
// }
|
||||
//正式服appId
|
||||
else {
|
||||
VerifyParams params = new VerifyParams();
|
||||
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 boolean verifyTest(VerifyParams params) {
|
||||
return doVerify(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyFormat(VerifyParams params) {
|
||||
return doVerify(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean doVerify(VerifyParams params) {
|
||||
LOGGER.info("AiWanVerifyService登录验证-->{}", params.getOpenId());
|
||||
String url = "https://apicn-sdk.jxywl.cn/user/auth";
|
||||
Map<String, String> parms = new HashMap<>();
|
||||
parms.put("app_id", app_id);
|
||||
parms.put("account", params.getOpenId());
|
||||
parms.put("token", params.getToken());
|
||||
parms.put("time", params.getTime());
|
||||
parms.put("sign", params.getParamSign());
|
||||
boolean result = false;
|
||||
try {
|
||||
String r = HttpUtils.doPost(url, parms);
|
||||
JSONObject jsonObject = JSON.parseObject(r);
|
||||
int errno = jsonObject.getIntValue("code");
|
||||
LOGGER.info("AiWanVerifyService请求结果:{}", r);
|
||||
if (errno == 200) {
|
||||
result = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.info("AiWanVerifyService验证失败,IOException");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VerifyParams getTestParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
|
||||
return getFormatParam(params, request, openId, token);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VerifyParams getFormatParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
|
||||
String time = String.valueOf(TimeUtil.nowInt());
|
||||
SortedMap<String, String> map = new TreeMap<>();
|
||||
map.put("app_id", app_id);
|
||||
map.put("account", openId);
|
||||
map.put("token", token);
|
||||
map.put("time", time);
|
||||
|
||||
params.setAppId(app_id);
|
||||
params.setOpenId(openId);
|
||||
params.setToken(token);
|
||||
params.setTime(time);
|
||||
params.setParamSign(getSign(map));
|
||||
return params;
|
||||
}
|
||||
|
||||
private static String getSign(Map<String, String> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
builder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
String substring = builder.substring(0, builder.length() - 1);
|
||||
LOGGER.info("AiWan参数拼装sign(未加密):" + substring + app_key);
|
||||
return DigestUtils.md5Hex(substring + app_key);
|
||||
}
|
||||
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// SortedMap<String, String> map = new TreeMap<>();
|
||||
// map.put("app_id", "ovdqy3we3nekjrz8");
|
||||
// map.put("account", "2020092315165768");
|
||||
// map.put("token", "NwVe8n4zMizM1Mzg3MzZfMTY");
|
||||
// map.put("time", "1600845363");
|
||||
// System.out.println("================================================");
|
||||
// System.out.println("自己计算的sign:" + getSign(map));
|
||||
// System.out.println("渠道提供的sign:" + "0aea0c2c60bb6988f83d8a8023906af5");
|
||||
// }
|
||||
}
|
|
@ -94,7 +94,15 @@ public class TimeUtil {
|
|||
* 获取当前时间,秒
|
||||
* @return
|
||||
*/
|
||||
public static long nowInt(){
|
||||
return System.currentTimeMillis()/1000;
|
||||
public static int nowInt(){
|
||||
return (int) System.currentTimeMillis()/1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间,秒
|
||||
* @return
|
||||
*/
|
||||
public static long nowLong(){
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue