generated from root/miduo_server
增加开箱子支付服代码
parent
47f702f044
commit
62f99f5ba3
|
|
@ -0,0 +1,9 @@
|
|||
*.iml
|
||||
.idea
|
||||
.gradle
|
||||
build
|
||||
out
|
||||
classes
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Manifest-Version: 1.0
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
group 'delivery'
|
||||
version ''
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'war'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile("javax.servlet:servlet-api:2.5")
|
||||
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.6.3'
|
||||
compile("ch.qos.logback:logback-core:1.1.11")
|
||||
compile("ch.qos.logback:logback-classic:1.1.11")
|
||||
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
|
||||
compile group: 'jstl', name: 'jstl', version: '1.2'
|
||||
compile group: 'taglibs', name: 'standard', version: '1.1.2'
|
||||
compile group: 'io.netty', name: 'netty-all', version: '4.0.21.Final'
|
||||
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.5.0'
|
||||
compile group: 'commons-lang', name: 'commons-lang', version: '2.5'
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,6 @@
|
|||
#Tue Nov 17 14:03:48 CST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
rootProject.name = 'delivery'
|
||||
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.ljsd.pojo.Operation;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className GameTitleController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description
|
||||
* @date 2022-02-22 10:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class GameTitleController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GameTitleController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String accountid = parameterMap.get("userId");
|
||||
String roleId = parameterMap.get("roleId");
|
||||
String roleName = parameterMap.get("roleName");
|
||||
String gameId = parameterMap.get("gameId");
|
||||
String serviceId = parameterMap.get("serviceId");
|
||||
//时间戳,毫秒,禁言时时间戳表示禁言截止日期,1表示永久禁言
|
||||
String opStatus = parameterMap.get("opStatus");
|
||||
String shutupTime = parameterMap.get("shutupTime");
|
||||
String chatContents = parameterMap.get("chatContents");
|
||||
String random = parameterMap.get("random");
|
||||
String sign = parameterMap.get("sign");
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info = accountid + roleId + HttpUtil.getEncode(roleName) +gameId + serviceId + opStatus + shutupTime + HttpUtil.getEncode(chatContents) + random + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
break;
|
||||
}
|
||||
LOGGER.info("GameTitleController==>info={},bt_md5Sign={},sig" + "={} sin derify fail !!!",info,sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Operation operation = new Operation(Integer.parseInt(roleId),Integer.parseInt(opStatus),Long.parseLong(shutupTime));
|
||||
String id = UUID.randomUUID().toString();
|
||||
BaseGlobal.redisApp.hset( serviceId + ":" + RedisKey.BT_GAME_OPERATION_KEY,"",id,operation,-1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
LOGGER.info("GameTitleController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.*;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.timer.ServerManager;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @ClassName: KSGetRoleListController
|
||||
* @Package com.ljsd.controller
|
||||
* @Description: ${快手获取角色列表}
|
||||
* @Author: zw
|
||||
* @date: 2020/6/18 10:27
|
||||
*/
|
||||
public class KSGetRoleListController extends HttpServlet {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KSGetRoleListController.class);
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
String data = req.getQueryString();
|
||||
LOGGER.info("reqData:--- " + data);
|
||||
PrintWriter out = resp.getWriter();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
String sign = req.getHeader("sign");
|
||||
if (sign == null) {
|
||||
// 签名错误
|
||||
jsonObject.addProperty("result", KSConstant.SIGN_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
String gameId = req.getParameter("game_id");
|
||||
String ts = req.getParameter("ts");
|
||||
long timeStamp = Long.parseLong(ts);
|
||||
long nowTime = System.currentTimeMillis();
|
||||
if (Math.abs(timeStamp - nowTime) > KSConstant.FIVE_MIN) {
|
||||
LOGGER.info("ksGetRoleList===>timeStamp:{},nowTime:{} " ,timeStamp,nowTime);
|
||||
jsonObject.addProperty("result", KSConstant.OTHER_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String resultSign = MyMD5Util.getSignature(data, KSConstant.APP_SECRET);
|
||||
if (!resultSign.equalsIgnoreCase(sign)) {
|
||||
LOGGER.error("签名错误---- sdkSign ={},-----resultSign={} ", sign, resultSign);
|
||||
//签名错误
|
||||
jsonObject.addProperty("result", KSConstant.SIGN_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
KSRoleListInfo infos = new KSRoleListInfo();
|
||||
infos.result = KSConstant.SUCCESS;
|
||||
infos.msg = "";
|
||||
infos.servers = createMyServerList(gameId);
|
||||
Gson gson = new Gson();
|
||||
out.print(gson.toJson(infos));
|
||||
out.flush();
|
||||
LOGGER.info("角色列表: " + gson.toJson(infos));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务器角色列表
|
||||
*
|
||||
* @param openId
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static List<KSServerInfo> createMyServerList(String openId) throws Exception {
|
||||
List<DBObject> servers = ServerManager.servers;
|
||||
Map<String, UserServerInfo> userServerInfoMap = BaseGlobal.redisApp.hgetAll(RedisKey.USER_SERVER_INFO, openId, UserServerInfo.class,
|
||||
RedisKey.COMMON);
|
||||
List<KSServerInfo> serverInfoList = new ArrayList<>();
|
||||
for (Map.Entry<String, UserServerInfo> entry : userServerInfoMap.entrySet()) {
|
||||
KSServerInfo info = new KSServerInfo();
|
||||
UserServerInfo userServerInfo = entry.getValue();
|
||||
info.server_id = entry.getKey();
|
||||
String serverName = "";
|
||||
for (DBObject data : servers) {
|
||||
if (entry.getKey().equals(data.get("server_id").toString())) {
|
||||
serverName = data.get("name").toString();
|
||||
}
|
||||
}
|
||||
info.server_name = serverName;
|
||||
KSRole ksRole = new KSRole();
|
||||
ksRole.role_id = userServerInfo.getId();
|
||||
ksRole.role_name = userServerInfo.getName();
|
||||
ksRole.recent_login_time = userServerInfo.getLoginTime();
|
||||
info.roles.add(ksRole);
|
||||
serverInfoList.add(info);
|
||||
}
|
||||
return serverInfoList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.pojo.KSConstant;
|
||||
import com.ljsd.pojo.KSPay;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.RSAUtil;
|
||||
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.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @ClassName: KSPayController
|
||||
* @Package com.ljsd.controller
|
||||
* @Description: ${快手支付回调}
|
||||
* @Author: zw
|
||||
* @date: 2020/7/28 18:04
|
||||
*/
|
||||
public class KSPayNotifyController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KSPayNotifyController.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
String data = HttpUtil.requestToStr(req);
|
||||
data = URLDecoder.decode(data, "utf-8");
|
||||
LOGGER.info("payData--- " + data);
|
||||
PrintWriter out = resp.getWriter();
|
||||
if (data.equals("")) {
|
||||
out.print("success");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
Map<String, String> orderData = new HashMap<>();
|
||||
String[] str = data.split("&");
|
||||
for (String s : str) {
|
||||
String[] payData = s.split("=");
|
||||
System.out.println("key: " + payData[0] + " value: " + payData[1]);
|
||||
orderData.put(payData[0], payData[1]);
|
||||
}
|
||||
String sign = orderData.remove("sign");
|
||||
String content = RSAUtil.getSignStringFromMap(orderData);
|
||||
|
||||
//验签
|
||||
boolean flag = RSAUtil.check(content, sign, KSConstant.KS_PAY_PUBLIC_KEY, "utf-8");
|
||||
LOGGER.info("充值flag: " + flag);
|
||||
//验签失败
|
||||
if (!flag) {
|
||||
out.print("sign error");
|
||||
out.flush();
|
||||
LOGGER.info("充值验签失败");
|
||||
return;
|
||||
}
|
||||
//init pay
|
||||
KSPay pay = new KSPay();
|
||||
pay.app_id = orderData.get("app_id");
|
||||
pay.allin_trade_no = orderData.get("allin_trade_no");
|
||||
pay.product_id = orderData.get("product_id");
|
||||
pay.role_id = orderData.get("role_id");
|
||||
pay.server_id = orderData.get("server_id");
|
||||
pay.data = orderData.get("data");
|
||||
pay.extension = orderData.get("extension");
|
||||
pay.money = orderData.get("money");
|
||||
Gson gson = new Gson();
|
||||
Map<String, String> json = gson.fromJson(orderData.get("extension"), Map.class);
|
||||
String orderId = json.get("orderId");
|
||||
//存入redis 存入成功就返回成功,后续在游戏服处理
|
||||
try {
|
||||
BaseGlobal.redisApp.hset("game", pay.server_id, "pay", KSConstant.KS_PAY, orderId, gson.toJson(pay), -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
out.print("data error");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
LOGGER.info("玩家充值成功,存入redis----roleId={},orderId={}", pay.role_id, pay.allin_trade_no);
|
||||
out.print("success");
|
||||
out.flush();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doPost(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.*;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @ClassName:
|
||||
* @Package com.ljsd.controller
|
||||
* @Description: ${发放礼包}
|
||||
* @Author: zw
|
||||
* @date: 2020/6/19 14:00
|
||||
*/
|
||||
public class KSPostGiftController extends HttpServlet {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KSPostGiftController.class);
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doPost(req, resp);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
String data = HttpUtil.requestToStr(req);
|
||||
LOGGER.info("reqData:--- " + data);
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
Gson gson = new Gson();
|
||||
KSGiftInfo giftInfo = gson.fromJson(data, KSGiftInfo.class);
|
||||
PrintWriter out = resp.getWriter();
|
||||
String sign = req.getHeader("sign");
|
||||
if (sign == null) {
|
||||
//非法请求
|
||||
jsonObject.addProperty("result", KSConstant.SIGN_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
long timeStamp = giftInfo.ts;
|
||||
long nowTime = System.currentTimeMillis();
|
||||
if (Math.abs(timeStamp - nowTime) > KSConstant.FIVE_MIN) {
|
||||
LOGGER.info("ksGetRoleList===>timeStamp:{},nowTime:{} " ,timeStamp,nowTime);
|
||||
jsonObject.addProperty("result", KSConstant.OTHER_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String resultSign = MyMD5Util.getSignature(data, KSConstant.APP_SECRET);
|
||||
if (!resultSign.equalsIgnoreCase(sign)) {
|
||||
LOGGER.error("签名错误: ----sdkSign ={},----resultSign={} ", sign, resultSign);
|
||||
//签名错误
|
||||
jsonObject.addProperty("result", KSConstant.SIGN_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String gift_pack_name = giftInfo.gift_pack_name;
|
||||
String game_id = giftInfo.game_id;
|
||||
KSGiftRoleInfo giftRoleInfo = giftInfo.role_info;
|
||||
String serverId = giftRoleInfo.server_id;
|
||||
String roleId = giftRoleInfo.role_id;
|
||||
|
||||
List<KSGiftPackItem> giftPackItems = giftInfo.pack_items;
|
||||
String timeStr = String.valueOf(System.currentTimeMillis());
|
||||
//生成mail对象
|
||||
KSMailInfo mail = new KSMailInfo();
|
||||
mail.type = 1;
|
||||
mail.gift_name = gift_pack_name;
|
||||
mail.pack_items = giftPackItems;
|
||||
//存入redis
|
||||
try {
|
||||
BaseGlobal.redisApp.hset("game", serverId, "mail", KSConstant.GIFT_KEY, roleId + "_" + timeStr, mail, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jsonObject.addProperty("result", KSConstant.OTHER_ERROR);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("发送礼包-------roleId={},serverId={},mail={}", roleId, serverId, gson.toJson(mail));
|
||||
jsonObject.addProperty("result", KSConstant.SUCCESS);
|
||||
out.print(jsonObject);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description bt 充值返利
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class Rebate9kController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Rebate9kController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String rebateType = parameterMap.get("rebate_type");
|
||||
String rebate_no = parameterMap.get("rebate_no");
|
||||
String gameOrderNo = parameterMap.get("game_order_no");
|
||||
String accountid = parameterMap.get("user_id");
|
||||
String payMoney = parameterMap.get("pay_money");
|
||||
String gold = parameterMap.get("gold");
|
||||
String gameId = parameterMap.get("game_id");
|
||||
String serviceId = parameterMap.get("service_id");
|
||||
String roleId = parameterMap.get("role_id");
|
||||
String roleName = parameterMap.get("role_name");
|
||||
String payTime = parameterMap.get("time");
|
||||
String payStatus = parameterMap.get("pay_status");
|
||||
String sign = parameterMap.get("sign");
|
||||
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info =rebateType + rebate_no + HttpUtil.getUrlEncoder(gameOrderNo) + HttpUtil.getUrlEncoder(accountid) + payMoney + gold + gameId + HttpUtil.getUrlEncoder(serviceId)
|
||||
+ HttpUtil.getUrlEncoder(roleId) +payTime + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
break;
|
||||
}
|
||||
LOGGER.info("rebate()info={}, 9k_md5Sign={},sig" + "={} sin derify fail !!!",info,sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
BaseGlobal.redisApp.hset( serviceId + ":" + RedisKey.BT_REBATE_KEY,"",rebate_no,gson.toJson(parameterMap),-1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
LOGGER.info("Rebate9kController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description bt 充值返利
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class RebateController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RebateController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String rebateType = parameterMap.get("rebate_type");
|
||||
String rebate_no = parameterMap.get("rebate_no");
|
||||
String gameOrderNo = parameterMap.get("game_order_no");
|
||||
String accountid = parameterMap.get("user_id");
|
||||
String payMoney = parameterMap.get("pay_money");
|
||||
String gold = parameterMap.get("gold");
|
||||
String gameId = parameterMap.get("game_id");
|
||||
String serviceId = parameterMap.get("service_id");
|
||||
String roleId = parameterMap.get("role_id");
|
||||
String roleName = parameterMap.get("role_name");
|
||||
String payTime = parameterMap.get("time");
|
||||
String payStatus = parameterMap.get("pay_status");
|
||||
String sign = parameterMap.get("sign");
|
||||
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info =rebateType + rebate_no + HttpUtil.getUrlEncoder(gameOrderNo) + HttpUtil.getUrlEncoder(accountid) + payMoney + gold + gameId + HttpUtil.getUrlEncoder(serviceId)
|
||||
+ HttpUtil.getUrlEncoder(roleId) +payTime + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
break;
|
||||
}
|
||||
LOGGER.info("rebate()info={}, md5Sign={},sig" + "={} sin derify fail !!!",info,sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
BaseGlobal.redisApp.hset( serviceId + ":" + RedisKey.BT_REBATE_KEY,"",rebate_no,gson.toJson(parameterMap),-1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
LOGGER.info("RebateController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.KSConstant;
|
||||
import com.ljsd.pojo.KSPay;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.GlobalSys;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description 一元 充值
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class Recharge9kController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Recharge9kController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String platformId = parameterMap.get("platformId");
|
||||
String uid = parameterMap.get("uid");
|
||||
String zoneId = parameterMap.get("zoneId");
|
||||
String roleId = parameterMap.get("roleId");
|
||||
String cpOrderId = parameterMap.get("cpOrderId");
|
||||
String orderId = parameterMap.get("orderId");
|
||||
String orderStatus = parameterMap.get("orderStatus");
|
||||
String amount = parameterMap.get("amount");
|
||||
String goodsInfo = parameterMap.get("extInfo");
|
||||
String payTime = parameterMap.get("payTime");
|
||||
String paySucTime = parameterMap.get("paySucTime");
|
||||
String notifyUrl = parameterMap.get("notifyUrl");
|
||||
String clientType = parameterMap.get("clientType");
|
||||
String sign = parameterMap.get("sign");
|
||||
parameterMap.remove("sign");
|
||||
String info = MyMD5Util.buildHttpQueryNoEncode(parameterMap) +GlobalSys.YY_APP_KEY;
|
||||
if (Integer.parseInt(orderStatus) != 1){
|
||||
LOGGER.info("callback()info={},9k_md5Sign={},orderStatus !=1");
|
||||
out.print("2");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (!sig.equals(sign)) {
|
||||
LOGGER.info("callback()info={},9k_md5Sign={},sig={} sin derify fail !!!",info,sign,sig);
|
||||
out.print("1");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
//init pay
|
||||
Gson gson = new Gson();
|
||||
String[] split = goodsInfo.split("\\|");
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("orderId", split[0]);
|
||||
jsonObject.addProperty("goodsId",split[1]);
|
||||
jsonObject.addProperty("welfareNum",split[2]);
|
||||
Map<String, String> json = gson.fromJson(jsonObject, Map.class);
|
||||
KSPay pay = new KSPay();
|
||||
pay.app_id = "zhj_yy";
|
||||
pay.allin_trade_no = orderId ;
|
||||
pay.goods_id = json.get("goodsId");
|
||||
pay.role_id = roleId;
|
||||
pay.server_id = zoneId;
|
||||
pay.data = orderStatus;
|
||||
pay.extension = jsonObject.toString() ;
|
||||
pay.money = amount;
|
||||
pay.couponAmount = amount;
|
||||
orderId = json.get("orderId");
|
||||
//存入redis 存入成功就返回成功,后续在游戏服处理
|
||||
try {
|
||||
BaseGlobal.redisApp.hset("game", pay.server_id, "pay", KSConstant.KS_PAY, orderId, gson.toJson(pay), -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
out.print("data error");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
LOGGER.info("玩家充值成功,存入redis----roleId={},orderId={},money={}", pay.role_id, pay.allin_trade_no,pay.money);
|
||||
String result = "0";
|
||||
LOGGER.info("Recharge9kController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String info = "";
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
System.out.println(sig);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.KSConstant;
|
||||
import com.ljsd.pojo.KSPay;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description bt 充值
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class RechargeController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RechargeController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String orderNo = parameterMap.get("order_sn");
|
||||
String goodName = parameterMap.get("good_name");
|
||||
String gameOrderSn = parameterMap.get("game_order_sn");
|
||||
String accountid = parameterMap.get("uuid");
|
||||
String amount = parameterMap.get("pay_money");
|
||||
String gameId = parameterMap.get("game_id");
|
||||
String serviceId = parameterMap.get("service_id");
|
||||
String serviceName = parameterMap.get("service_name");
|
||||
String roleId = parameterMap.get("role_id");
|
||||
String roleName = parameterMap.get("role_name");
|
||||
String payTime = parameterMap.get("time");
|
||||
String payStatus = parameterMap.get("pay_status");
|
||||
String goodsInfo = parameterMap.get("remark");
|
||||
String couponAmount = parameterMap.get("coupon_amount");
|
||||
String sign = parameterMap.get("sign");
|
||||
int isTest = Integer.parseInt(parameterMap.get("is_test"));
|
||||
|
||||
String version = "zhj_bt";
|
||||
boolean isSignSuccess = false;
|
||||
for (Map.Entry<String, String> entry : BaseGlobal.PAY_KEY.entrySet()) {
|
||||
String info = "good_name=" + HttpUtil.getUrlEncoder(goodName) + "&uuid="+accountid + "&order_sn="+orderNo + "&game_order_sn="+gameOrderSn + "&game_id="+gameId + "&service_id="
|
||||
+serviceId + "&service_name="+HttpUtil.getUrlEncoder(serviceName) + "&role_id=" + roleId + "&role_name=" + HttpUtil.getUrlEncoder(roleName) + "&pay_money=" + amount + "&pay_status=" + payStatus
|
||||
+"&remark=" + HttpUtil.getUrlEncoder(goodsInfo) + "&time=" + payTime + "&key=" + entry.getValue();
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
version = entry.getKey();
|
||||
break;
|
||||
}
|
||||
LOGGER.info("callback()info={}, md5Sign={},sig={} sin derify fail !!!",info,sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
//init pay
|
||||
Gson gson = new Gson();
|
||||
String[] split = goodsInfo.split("\\|");
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("orderId", split[0]);
|
||||
jsonObject.addProperty("goodsId",split[1]);
|
||||
jsonObject.addProperty("welfareNum",split[2]);
|
||||
Map<String, String> json = gson.fromJson(jsonObject, Map.class);
|
||||
KSPay pay = new KSPay();
|
||||
pay.app_id = version;
|
||||
pay.allin_trade_no = orderNo ;
|
||||
pay.goods_id = json.get("goodsId");
|
||||
pay.role_id = roleId;
|
||||
pay.server_id = serviceId;
|
||||
pay.data = payStatus;
|
||||
pay.extension = jsonObject.toString() ;
|
||||
pay.money = amount;
|
||||
pay.couponAmount = couponAmount;
|
||||
String orderId = json.get("orderId");
|
||||
//存入redis 存入成功就返回成功,后续在游戏服处理
|
||||
try {
|
||||
BaseGlobal.redisApp.hset("game", pay.server_id, "pay", KSConstant.KS_PAY, orderId, gson.toJson(pay), -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
out.print("data error");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
LOGGER.info("玩家充值成功,存入redis----roleId={},orderId={},money={}", pay.role_id, pay.allin_trade_no,pay.money);
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
LOGGER.info("RechargeController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String info = "";
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
System.out.println(sig);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
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.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description bt 发送道具
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
public class SendRewardController extends HttpServlet {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SendRewardController.class);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String title = parameterMap.get("title");
|
||||
String content = parameterMap.get("content");
|
||||
String uid = parameterMap.get("player_id");
|
||||
String serverId = parameterMap.get("server_id");
|
||||
String item = parameterMap.get("item");
|
||||
String activeId = parameterMap.get("active_id");
|
||||
String isFreee = parameterMap.get("is_freee");
|
||||
String money = parameterMap.get("money");
|
||||
String sign = parameterMap.get("sign");
|
||||
|
||||
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info =activeId + isFreee + money + title + content + uid + serverId + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
break;
|
||||
}
|
||||
LOGGER.info("sendReward()info={}, bt_md5Sign={},sig" + "={} sin derify fail !!!",info,sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
ResultVo resultVo = new ResultVo(200, "success");
|
||||
String id = UUID.randomUUID().toString();
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
parameterMap.put("item",HttpUtil.getReward(item));
|
||||
BaseGlobal.redisApp.hset( serverId + ":" + RedisKey.BT_SEND_REWARD_KEY,"",id,gson.toJson(parameterMap),-1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
resultVo = new ResultVo(100, "error");
|
||||
LOGGER.info("e={}",e);
|
||||
}
|
||||
String result = HttpUtil.getResult(resultVo);
|
||||
LOGGER.info("SendRewardController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.ljsd.listener;
|
||||
|
||||
import com.ljsd.netty.NettyClient;
|
||||
import com.ljsd.netty.impl.NettyTCPClientHandler;
|
||||
import com.ljsd.timer.ClientManager;
|
||||
import com.ljsd.timer.ServerManager;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.LogBackConfigLoader;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
/**
|
||||
* 创建的类名根据需要定义,但一定要实现ServletContextListener接口
|
||||
* @author gaojie
|
||||
*/
|
||||
public class WebContextListener implements ServletContextListener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ServletContextListener.class);
|
||||
private static final String DEFAULT_CONFIG_PATH = "/application.properties";
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
try {
|
||||
String path = System.getProperty("catalina.home");
|
||||
path += "/config/delivery/application.properties";
|
||||
FileInputStream inputStream = new FileInputStream(path);
|
||||
LogBackConfigLoader.load();
|
||||
BaseGlobal.properties.load(inputStream);
|
||||
BaseGlobal.init();
|
||||
new ServerManager().start();
|
||||
new ClientManager().start();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent arg0) {
|
||||
for (NettyTCPClientHandler handler : NettyClient.getHandlerMap().values()) {
|
||||
handler.getChannel().close();
|
||||
}
|
||||
for (EventLoopGroup group : NettyClient.getGroups()) {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.ljsd.netty;
|
||||
|
||||
import com.ljsd.netty.cocdex.Tea;
|
||||
|
||||
public class ClientData {
|
||||
//包长2 uid 4 msgid 4 result 4 index4
|
||||
private byte[] clientDate;
|
||||
|
||||
public int getMsgId() {
|
||||
return Tea.byteToInt(clientDate, 4);
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return Tea.byteToInt(clientDate, 0);
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return Tea.byteToInt(clientDate, 8);
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return Tea.byteToInt(clientDate, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只获取协议信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] parseProtoNetData() {
|
||||
byte[] data = new byte[clientDate.length - 16];
|
||||
System.arraycopy(clientDate, 16, data, 0, data.length);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getClientDate() {
|
||||
return clientDate;
|
||||
}
|
||||
|
||||
|
||||
public void setClientDate(byte[] clientDate) {
|
||||
this.clientDate = clientDate;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
package com.ljsd.netty;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.netty.cocdex.Tea;
|
||||
import com.ljsd.netty.impl.NettyTCPClientHandler;
|
||||
import com.ljsd.netty.impl.NettyTCPClientInitializer;
|
||||
import com.ljsd.timer.ServerManager;
|
||||
import com.mongodb.DBObject;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public class NettyClient {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
|
||||
|
||||
private static AtomicInteger requestId = new AtomicInteger(0);
|
||||
private static Map<Integer, NettyTCPClientHandler> handlerMap = new HashMap<>();
|
||||
|
||||
private static List<EventLoopGroup> groups = new ArrayList<>();
|
||||
|
||||
public static int getRequestId() {
|
||||
return requestId.addAndGet(1);
|
||||
}
|
||||
|
||||
|
||||
private static Channel getChannel(int serverId) {
|
||||
Channel channel = null;
|
||||
List<DBObject> serverInfoList = ServerManager.servers;
|
||||
DBObject server = null;
|
||||
for(DBObject data : serverInfoList) {
|
||||
if(Integer.parseInt(data.get("server_id").toString()) == serverId) {
|
||||
server = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(server == null) {
|
||||
return null;
|
||||
}
|
||||
String ip = server.get("ip").toString();
|
||||
int port = Integer.parseInt(server.get("port").toString());
|
||||
|
||||
Bootstrap bootstrap = null;
|
||||
try {
|
||||
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||
bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioSocketChannel.class)
|
||||
.handler(new NettyTCPClientInitializer())
|
||||
.option(ChannelOption.TCP_NODELAY, true);
|
||||
|
||||
channel = bootstrap.connect(ip, port).sync().channel();
|
||||
NettyTCPClientHandler handler = channel.pipeline().get(NettyTCPClientHandler.class);
|
||||
handlerMap.put(serverId, handler);
|
||||
groups.add(group);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("获取handler失败");
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static Result sendMessage(int routerId, int requestId, int serverId, int msgId,
|
||||
GeneratedMessage generatedMessage) throws InterruptedException {
|
||||
byte[] message = wrappedBytes(routerId, msgId, generatedMessage);
|
||||
return sendMessage(requestId, serverId, message);
|
||||
}
|
||||
|
||||
public static byte[] wrappedBytes(int uid, int msgId, GeneratedMessage generatedMessage) {
|
||||
byte[] byMessage;
|
||||
if (generatedMessage == null) {
|
||||
byMessage = new byte[0];
|
||||
} else {
|
||||
byMessage = generatedMessage.toByteArray();
|
||||
}
|
||||
byte[] bytes = new byte[byMessage.length + PackageConstant.UID_FIELD_LEN
|
||||
+ PackageConstant.ROUTERTYPE_LEN + PackageConstant.MSG_ID_FIELD_LEN
|
||||
+ PackageConstant.INDEXT_FIELD_LEN + PackageConstant.INDICATION_INDEX_FIELD_LEN
|
||||
+ PackageConstant.TOKEN_FIELD_LEN];
|
||||
int pos = 0;
|
||||
Tea.intToByte(bytes, pos, uid);
|
||||
pos += PackageConstant.UID_FIELD_LEN;
|
||||
bytes[pos] = 1;
|
||||
pos += PackageConstant.ROUTERTYPE_LEN;
|
||||
Tea.intToByte(bytes, pos, msgId);
|
||||
pos += PackageConstant.MSG_ID_FIELD_LEN;
|
||||
Tea.intToByte(bytes, pos, 0);
|
||||
pos += PackageConstant.INDEXT_FIELD_LEN;
|
||||
Tea.shortToByte(bytes, pos, 0);
|
||||
pos += PackageConstant.INDICATION_INDEX_FIELD_LEN;
|
||||
Tea.intToByte(bytes, pos, 0);
|
||||
pos += PackageConstant.TOKEN_FIELD_LEN;
|
||||
|
||||
System.arraycopy(byMessage, 0, bytes, pos, byMessage.length);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private static Result sendMessage(int requestId, int serverId, byte[] data) throws InterruptedException {
|
||||
NettyTCPClientHandler handler = handlerMap.get(serverId);
|
||||
if(handler == null || !handler.getChannel().isOpen()) {
|
||||
Channel channel = getChannel(serverId);
|
||||
if(channel == null) {
|
||||
return null;
|
||||
}
|
||||
handler = handlerMap.get(serverId);
|
||||
}
|
||||
SynchronousQueue<Result> queue = handler.sendMsg(requestId, data);
|
||||
Result result = queue.take();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<Integer, NettyTCPClientHandler> getHandlerMap() {
|
||||
return handlerMap;
|
||||
}
|
||||
|
||||
public static List<EventLoopGroup> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.ljsd.netty;
|
||||
|
||||
public class PackageConstant {
|
||||
public static final int LENGTH_FIELD_LEN = 2; //网络包的前两个字节是有效数据的长度
|
||||
public static final int UID_FIELD_LEN = 4; //从其他服务器回包到gateway时,长度后的四个字节是玩家ID
|
||||
public static final int MSG_ID_FIELD_LEN = 4; // 跟网络消息的消息号
|
||||
public static final int ROUTERTYPE_LEN = 1;//路由类型
|
||||
public static final int INDEXT_FIELD_LEN = 4;
|
||||
public static final int INDICATION_INDEX_FIELD_LEN = 2;//indication序列号
|
||||
public static final int TOKEN_FIELD_LEN = 4;//token检测
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.ljsd.netty;
|
||||
|
||||
public class Result {
|
||||
private int errorCode;
|
||||
private int errOrMsg;
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrOrMsg() {
|
||||
return errOrMsg;
|
||||
}
|
||||
|
||||
public void setErrOrMsg(int errOrMsg) {
|
||||
this.errOrMsg = errOrMsg;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.ljsd.netty.cocdex;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BaseDecoder extends ByteToMessageDecoder {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BaseDecoder.class);
|
||||
|
||||
public BaseDecoder(){
|
||||
}
|
||||
public short readLean(ByteBuf in){
|
||||
in.markReaderIndex();
|
||||
final byte[] buf = new byte[2];
|
||||
for (int i = 0; i < buf.length; i ++) {
|
||||
if (!in.isReadable()) {
|
||||
in.resetReaderIndex();
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf[i] = in.readByte();
|
||||
}
|
||||
int length = Tea.byteToShort(buf, 0);
|
||||
|
||||
return (short) length;
|
||||
}
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.ljsd.netty.cocdex;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ByteBufDecoder extends BaseDecoder {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ByteBufDecoder.class);
|
||||
|
||||
public ByteBufDecoder() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
|
||||
String secret_key = "";
|
||||
try {
|
||||
int length = readLean(in);
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
if (in.readableBytes() + 2 < length) {
|
||||
in.resetReaderIndex();
|
||||
} else {
|
||||
ByteBuf message = in.readBytes(length - 2);
|
||||
out.add(message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("decode->secret_key={},emsg={}", secret_key, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.ljsd.netty.cocdex;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class ByteBufEncoder extends MessageToByteEncoder<byte[]> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ByteBufDecoder.class);
|
||||
|
||||
public ByteBufEncoder(){
|
||||
}
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, byte[] msg, ByteBuf out) {
|
||||
try {
|
||||
//不加密
|
||||
out.writeShort((short) msg.length);
|
||||
out.writeBytes(msg, 0, msg.length);
|
||||
} catch (Exception e){
|
||||
LOGGER.error("encode->emsg={}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.ljsd.netty.cocdex;
|
||||
|
||||
public class PacketNetData {
|
||||
//
|
||||
private byte[] packetData;
|
||||
|
||||
public PacketNetData() {
|
||||
}
|
||||
|
||||
public void setPacketData(byte[] packetData) {
|
||||
this.packetData = packetData;
|
||||
}
|
||||
|
||||
public int getRouterId() {
|
||||
return Tea.byteToInt(packetData, 0);
|
||||
}
|
||||
|
||||
public byte getRouterType() {
|
||||
return (packetData[4]);
|
||||
}
|
||||
|
||||
|
||||
public int getMsgId() {
|
||||
return Tea.byteToInt(packetData, 5);
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return Tea.byteToInt(packetData, 9);
|
||||
}
|
||||
|
||||
public int getIndicationIndex() {
|
||||
return Tea.byteToShort(packetData, 13);
|
||||
}
|
||||
|
||||
public int getToken() {
|
||||
return Tea.byteToInt(packetData, 15);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 只获取协议信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] parseProtoNetData() {
|
||||
byte[] data = new byte[packetData.length - 19];
|
||||
System.arraycopy(packetData, 19, data, 0, data.length);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取协议加消息id字节数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] getMsgIdAndPBData() {
|
||||
byte[] data = new byte[packetData.length - 5];
|
||||
System.arraycopy(packetData, 5, data, 0, data.length);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取全部数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] getPacketData() {
|
||||
return packetData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package com.ljsd.netty.cocdex; /** */
|
||||
|
||||
import com.ljsd.netty.ClientData;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Tea算法
|
||||
* 每次操作可以处理8个字节数据
|
||||
* KEY为16字节,应为包含4个int型数的int[],一个int为4个字节
|
||||
* 加密解密轮数应为8的倍数,推荐加密轮数为64轮
|
||||
*/
|
||||
public class Tea {
|
||||
public static int[] KEY = new int[]{//加密解密所用的KEY
|
||||
0x789f5645, 0xf68bd5a4,
|
||||
0x81963ffa, 0x458fac58
|
||||
};
|
||||
private static int TIMES = 32;
|
||||
|
||||
public static Map<String, int[]> KEYS = new ConcurrentHashMap<>();
|
||||
|
||||
public static int[] generateSecretKey(){
|
||||
Random rand = new Random();
|
||||
int[] secretKey = new int[4];
|
||||
for(int i=0; i<4; i++){
|
||||
secretKey[i] = rand.nextInt();
|
||||
}
|
||||
return secretKey;
|
||||
}
|
||||
//若某字节被解释成负的则需将其转成无符号正数
|
||||
private static int transform(byte temp){
|
||||
int tempInt = (int)temp;
|
||||
if(tempInt < 0){
|
||||
tempInt += 256;
|
||||
}
|
||||
return tempInt;
|
||||
}
|
||||
|
||||
public static int byteToInt(byte[] content, int offset){
|
||||
int result = transform(content[offset+3]) | transform(content[offset+2]) << 8 |
|
||||
transform(content[offset+1]) << 16 | (int)content[offset] << 24;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void intToByte(byte[] bys, int offset, int content){
|
||||
bys[offset+3] = (byte)(content & 0xff);
|
||||
bys[offset+2] = (byte)((content >> 8) & 0xff);
|
||||
bys[offset+1] = (byte)((content >> 16) & 0xff);
|
||||
bys[offset] = (byte)((content >> 24) & 0xff);
|
||||
}
|
||||
|
||||
//加密
|
||||
public static byte[] encrypt(byte[] content, int offset, int[] key, int times){//times为加密轮数
|
||||
int delta=0x9e3779b9; //这是算法标准给的值
|
||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
||||
for(int m=offset; m<content.length; m+=8)
|
||||
{
|
||||
int y = byteToInt(content, m), z = byteToInt(content, m+4), sum = 0, i;
|
||||
for (i = 0; i < times; i++) {
|
||||
sum += delta;
|
||||
y += ((z<<4) + a) ^ (z + sum) ^ ((z>>5) + b);
|
||||
z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d);
|
||||
}
|
||||
intToByte(content, m, y);
|
||||
intToByte(content, m+4, z);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
//解密
|
||||
public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){
|
||||
int delta = 0x9e3779b9; //这是算法标准给的值
|
||||
int a = key[0], b = key[1], c = key[2], d = key[3];
|
||||
|
||||
for(int m=offset; m<encryptContent.length; m+=8) {
|
||||
int y = byteToInt(encryptContent, m), z = byteToInt(encryptContent, m+4), sum = 0xC6EF3720, i;
|
||||
for (i = 0; i < times; i++) {
|
||||
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
||||
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
||||
sum -= delta;
|
||||
}
|
||||
|
||||
intToByte(encryptContent, m, y);
|
||||
intToByte(encryptContent, m+4, z);
|
||||
}
|
||||
return encryptContent;
|
||||
}
|
||||
|
||||
public static void shortToByte(byte[] bys, int offset, int content){
|
||||
bys[offset+1] = (byte)(content & 0xff);
|
||||
bys[offset] = (byte)((content >> 8) & 0xff);
|
||||
}
|
||||
|
||||
public static int byteToShort(byte[] content, int offset){
|
||||
int result = transform(content[offset+1]) | transform(content[offset]) << 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] encrypt2(byte[] | ||||