generated from root/miduo_server
开天登录
parent
4ea409d93b
commit
97d367942d
|
@ -149,8 +149,8 @@ public class GetUserController extends HttpServlet {
|
|||
verify = true;
|
||||
}
|
||||
} else {
|
||||
// 内网或者 游心,不需要验证
|
||||
if (AppConstans.appsecret.equals(admin) || "YX_YSL".equals(channel)) {
|
||||
// 内网或者 游心 开天,不需要验证
|
||||
if (AppConstans.appsecret.equals(admin) || "YX_YSL".equals(channel) || "KT".equals(channel)) {
|
||||
verify = true;
|
||||
} else {
|
||||
verify = serviceMap.get(channel).verify(response, request, admin, platform, pid, openId, token);
|
||||
|
@ -243,36 +243,4 @@ public class GetUserController extends HttpServlet {
|
|||
|
||||
}
|
||||
|
||||
// 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 void main(String[] args) {
|
||||
String paramSign = "d53b3e8ef74bf72d8aafce3a1c8671a0" ;
|
||||
String secretKey = "";
|
||||
String timeStamp = "0";
|
||||
String openId = "1238";
|
||||
String verifyStr = openId+"&"+timeStamp+"&"+secretKey;
|
||||
String s = MD5Util.encrypByMd5(verifyStr);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ljsd.util.HttpUtils;
|
||||
import com.ljsd.util.MD5Util;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
public class KTGetUserOpenIdController extends HttpServlet {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KTGetUserOpenIdController.class);
|
||||
|
||||
public static String login_url = "https://api.kt007.com/api/v1/verify/user";
|
||||
public static String appkey = "vNCn3fkgZHt6wxGYl9IQUJo0R4LKPjW2";
|
||||
|
||||
public KTGetUserOpenIdController() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
DBObject res = new BasicDBObject();
|
||||
String token = request.getParameter("access_token");
|
||||
if (token == null || token.isEmpty()) {
|
||||
returnErrorToFront(res, response, "token is empty");
|
||||
return;
|
||||
}
|
||||
String gid = request.getParameter("gid"); //gid
|
||||
String pid = request.getParameter("pid"); //pid
|
||||
String tm = request.getParameter("tm"); //tm
|
||||
String sign = request.getParameter("sign"); //sign
|
||||
LOGGER.info("the token = {},gid={},pid={} tm=>{} sign=>{}", token, gid, pid, tm, sign);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
SortedMap<String, String> params = new TreeMap<>();
|
||||
params.put("gid", gid);
|
||||
params.put("pid", pid);
|
||||
params.put("tm", tm);
|
||||
params.put("access_token", token);
|
||||
StringBuilder sbKey = new StringBuilder();
|
||||
Set<Map.Entry<String, String>> entries = params.entrySet();
|
||||
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> next = iterator.next();
|
||||
String key = next.getKey();
|
||||
String value = next.getValue();
|
||||
if (value == null || "".equals(value)) {
|
||||
continue;
|
||||
}
|
||||
if ("sign".equals(key) || "sign_type".equals(key)) {
|
||||
continue;
|
||||
}
|
||||
sbKey.append(key).append("=").append(value).append("&");
|
||||
}
|
||||
sbKey.append(appkey);
|
||||
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
||||
params.put("sign", mySign);
|
||||
String loginResult = HttpUtils.doPost(login_url,params);
|
||||
LOGGER.info("KTGetUserOpenIdController 加密前={} 加密后={} 请求结果={}", sbKey.toString(), mySign, loginResult);
|
||||
JSONObject jsonObject = JSONObject.parseObject(loginResult);
|
||||
int state = jsonObject.getIntValue("code");
|
||||
if (state == 200) {
|
||||
JSONObject data = (JSONObject) jsonObject.get("data");
|
||||
String openid = data.getString("openid");
|
||||
int is_certify = data.getIntValue("is_certify");
|
||||
int age = data.getIntValue("age");
|
||||
res.put("openid", openid);
|
||||
res.put("is_certify", is_certify);
|
||||
res.put("age", age);
|
||||
} else {
|
||||
returnErrorToFront(res, response, "SDK 返回错误");
|
||||
return;
|
||||
}
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(res);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void returnErrorToFront(DBObject res, HttpServletResponse response, String errorReason) throws IOException {
|
||||
res.put("errorCode", -1);
|
||||
res.put("reason", errorReason);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(res);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(request, response);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -174,6 +174,17 @@
|
|||
</servlet-mapping>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>getKTGameUserInfo</servlet-name>
|
||||
<servlet-class>com.ljsd.controller.KTGetUserOpenIdController</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>getKTGameUserInfo</servlet-name>
|
||||
<url-pattern>/getKTGameUserInfo</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<listener>
|
||||
<listener-class>com.ljsd.listener.WebContextListener</listener-class>
|
||||
</listener>
|
||||
|
|
Loading…
Reference in New Issue