generated from root/miduo_server
草花登录SDK
parent
30201a5b71
commit
5627738980
|
@ -1,6 +1,7 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.service.CaohuaVerifyService;
|
||||
import com.ljsd.service.LdVerifyService;
|
||||
import com.ljsd.service.VerifyService;
|
||||
import com.ljsd.service.XPVerifyService;
|
||||
|
@ -15,8 +16,7 @@ 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.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -31,6 +31,7 @@ public class GetUserController extends HttpServlet {
|
|||
//初始化所有需要的验证方式
|
||||
serviceMap.put("MHT", new LdVerifyService("MHT"));
|
||||
serviceMap.put("XP", new XPVerifyService("XP"));
|
||||
serviceMap.put("CH",new CaohuaVerifyService("CH"));//草花
|
||||
|
||||
}
|
||||
|
||||
|
@ -194,6 +195,7 @@ public class GetUserController extends HttpServlet {
|
|||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(request, response);
|
||||
|
||||
}
|
||||
|
||||
// public static boolean loginVerfifyShangwu(String channelName,String openId,String token,String appId){
|
||||
|
|
|
@ -20,6 +20,12 @@ public class VerifyParams {
|
|||
|
||||
private String openId;
|
||||
|
||||
private String extraData;
|
||||
|
||||
private String platformAppid;
|
||||
|
||||
private String platformId;
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
@ -75,4 +81,28 @@ public class VerifyParams {
|
|||
public void setOpenId(String openId) {
|
||||
this.openId = openId;
|
||||
}
|
||||
|
||||
public String getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
public void setExtraData(String extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
public String getPlatformAppid() {
|
||||
return platformAppid;
|
||||
}
|
||||
|
||||
public void setPlatformAppid(String platformAppid) {
|
||||
this.platformAppid = platformAppid;
|
||||
}
|
||||
|
||||
public String getPlatformId() {
|
||||
return platformId;
|
||||
}
|
||||
|
||||
public void setPlatformId(String platformId) {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ public abstract class AbstractVerifyService implements VerifyService {
|
|||
protected Properties properties;
|
||||
public static int isTestLan=0;
|
||||
|
||||
//草花参数
|
||||
public static String caohua_login_url;
|
||||
public static String caohua_app_id;
|
||||
public static String caohua_secret_key;
|
||||
|
||||
|
||||
private String sign;
|
||||
|
||||
|
@ -30,6 +35,9 @@ public abstract class AbstractVerifyService implements VerifyService {
|
|||
this.sign = sign;
|
||||
properties = BaseGlobal.getInstance().properties;
|
||||
isTestLan = Integer.parseInt(properties.getProperty("isTestLan"));
|
||||
caohua_login_url = properties.getProperty("caohua_login_url");
|
||||
caohua_app_id = properties.getProperty("caohua_app_id");
|
||||
caohua_secret_key = properties.getProperty("caohua_secret_key");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
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 javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author xuexinpeng
|
||||
* @date 2021/6/7
|
||||
* @discribe 草花登录验证
|
||||
*/
|
||||
public class CaohuaVerifyService extends AbstractVerifyService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CaohuaVerifyService.class);
|
||||
|
||||
|
||||
public CaohuaVerifyService(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(app_id=265&ext_data={}&platform_appid=0&platform_id=5186318E52F5ED4801ABE1D13D509443DE)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String getSign(String app_id,String ext_data, String platform_appid, String platform_id,String appkey) {
|
||||
return MD5Util.encrypByMd5("app_id="+app_id+"&ext_data="+ext_data+"&platform_appid="+platform_appid+"&platform_id="+platform_id+appkey);
|
||||
}
|
||||
|
||||
//String channel, String openId, String token ,String appId,String secretKey
|
||||
boolean doVerify(VerifyParams verifyParams) {
|
||||
try {
|
||||
//String login_url ="https://data-msdk.caohua.com/login/verifyAccount";
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("app_id",verifyParams.getAppId());
|
||||
params.put("platform_id",verifyParams.getPlatformId());
|
||||
params.put("platform_appid",verifyParams.getPlatformAppid());
|
||||
params.put("ext_data",verifyParams.getExtraData());
|
||||
String sign = getSign(verifyParams.getAppId(),verifyParams.getExtraData(),verifyParams.getPlatformAppid(),verifyParams.getPlatformId(),verifyParams.getSecretKey());
|
||||
params.put("sign",sign);
|
||||
LOGGER.info("loginParam : "+params.toString());
|
||||
String loginResult = HttpUtils.doPost(caohua_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) {
|
||||
String platformId = request.getParameter("pid");
|
||||
String platformAppid = request.getParameter("platform_appid");
|
||||
String ext_data = request.getParameter("ext_data");
|
||||
String sign = request.getParameter("sign");
|
||||
//params.setAppId("1135");
|
||||
params.setAppId(caohua_app_id);
|
||||
params.setPlatformId(platformId);
|
||||
params.setPlatformAppid(platformAppid);
|
||||
params.setExtraData(ext_data);
|
||||
//params.setSecretKey("2d74a35892ca1f4f8070bd6afe796cd9");
|
||||
params.setSecretKey(caohua_secret_key);
|
||||
params.setParamSign(sign);
|
||||
return params;
|
||||
}
|
||||
|
||||
private VerifyParams getMHTParam(VerifyParams params, String token) {
|
||||
params.setChannel("MHT");
|
||||
params.setToken(token);
|
||||
return params;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// //String paramSign = "d53b3e8ef74bf72d8aafce3a1c8671a0" ;
|
||||
// //String secretKey = "";
|
||||
// //String timeStamp = "0";
|
||||
// //String openId = "1238";
|
||||
// //String verifyStr = openId+"&"+timeStamp+"&"+secretKey;
|
||||
// String verifyStr = "app_id=265&ext_data={}&platform_appid=0&platform_id=5186318E52F5ED4801ABE1D13D509443DE";
|
||||
// //String s //= MD5Util.encrypByMd5(verifyStr);// 111ceafc44a97b3fa877012abb43f689
|
||||
// String s =getSign("265","{}","0","51","86318E52F5ED4801ABE1D13D509443DE");
|
||||
// System.err.println(s.equals("111ceafc44a97b3fa877012abb43f689"));
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -27,4 +27,12 @@ redis_maxWaitMillis = 20
|
|||
redis_maxIdle = 5
|
||||
redis_testOnBorrow = false
|
||||
|
||||
isTestLan = 1
|
||||
isTestLan = 0
|
||||
|
||||
#草花SDK
|
||||
caohua_login_url = https://data-msdk.caohua.com/login/verifyAccount
|
||||
caohua_app_id = 1135
|
||||
caohua_secret_key = 2d74a35892ca1f4f8070bd6afe796cd9
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue