commit b30615be0beb47d846b3f5bbb1880aa37abbb17b Author: BBIT-Kai <2911862937@qq.com> Date: Mon May 25 16:53:22 2026 +0800 初始化项目 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe07b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ +logs/ +.kotlin/ diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..584e1af --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,46 @@ + +val kotlin_version: String by project +val logback_version: String by project +val ktor_version: String by project + +plugins { + kotlin("jvm") version "2.0.20" + id("io.ktor.plugin") version "3.0.0-rc-1" + id("org.jetbrains.kotlin.plugin.serialization") version "2.0.20" +} +group = "com.bbitcn.shanxi.yqzl" +version = "1.0.15" + +application { + mainClass.set("io.ktor.server.tomcat.jakarta.EngineMain") + + val isDevelopment: Boolean = project.ext.has("development") + applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation(files("lib/signApi-3.1.5.2.jar")) + implementation(files("lib/linuxApi-1.0.jar")) + implementation(files("lib/windowsApi-1.0.jar")) + implementation(files("lib/IsecJSDK-3.0.1.0.jar")) + implementation(files("lib/xdsdk-1.0.jar")) + implementation("io.ktor:ktor-server-core-jvm") + implementation("io.ktor:ktor-server-tomcat-jakarta-jvm") + implementation("ch.qos.logback:logback-classic:$logback_version") + implementation("io.ktor:ktor-server-config-yaml") + testImplementation("io.ktor:ktor-server-test-host-jvm") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") + implementation("javax.xml.bind:jaxb-api:2.3.1") + implementation("org.glassfish.jaxb:jaxb-runtime:2.3.1") + // 序列化 + implementation("io.ktor:ktor-serialization-gson-jvm") + implementation("io.ktor:ktor-serialization-kotlinx-json-jvm") + implementation("io.ktor:ktor-server-content-negotiation-jvm") + // 状态页 + implementation("io.ktor:ktor-server-status-pages:$ktor_version") + implementation("io.ktor:ktor-server-cors:$ktor_version") +} diff --git a/config/config.properties b/config/config.properties new file mode 100644 index 0000000..e511f71 --- /dev/null +++ b/config/config.properties @@ -0,0 +1,32 @@ +# Mauth参数 +mauth.host=202.99.212.80 +mauth.port=9208 +mauth.enName=ycydjs +mauth.userPin=123456 +mauth.idCard=600601003 +mauth.protocol=0 +mauth.caFile=config/sm2_root2023.cer +mauth.businessId=d8d9085d3dd44e64bec47428629a3966 +mauth.businessKeyToken=YWRmMWE0OTk4Zjg5YjJjY2HPXlMog585ov4InwbI6WXnp14Ki43gHR1CAVHbuS+Y2tKKHnk7CEiduFcssmhKAKbTni0ZfZD/2HSfIO1MGqkQZlQMp2+nyKba59C9BZ+5Go34oLdPM7ctjnjQ7q8mt9yC2H0OsOLDnnrHH2ZQYmPi7ZD6oIZbWa2xqcc0gwzO4GYC89jKfQ4svwlP4/MgDu8WanAu6GCyNBsqXRqSErYSIfzHaFG0jSLFleakpWx2/TpsgJYKAMGX7A8GsXf7Yz31q3ry+kkgWNqHNM3kt6XGcbOcFZG3fJMxXSWG2RSx9AIaSNpstc+DBOi/tniuZi8cXgcaR/qV5UoBI6teJ6QiZV28Rzd0XoJxtMuoAqXG1BpITN6jWRhxJj9tdpeEEoZTeSmWKxbJDF8N7+o7Wo+wvJnOgndo3+Me9WM7QN/w+OWGBgjMKv3r1+ZTy5IorGMNW+KFVJ7SEC4iczoZnhYxVGOx4cYsxd8PT5x6/7kL2ll/CxvygPbHlPoIvqpPYQ/HRZV02asooy4zHE/ndIG7swGCd+SsErN5TnT5lo/SPlATKw2tGvU1Z8YtmQ4OLNRJL/MF55EuwQhDT1ypy1V/OPy42bMjMjzF/EGXF9a6BDu/mfyN1QyjW/rKC26Yww== + +# Request参数 +request.serviceIp=202.99.212.80 +request.servicePort=9202 +request.corpCode=C500504002 +request.email=fan@bbitcn.com + +# Mauth参数官方解释 +# enName 姓名拼音, 测试环境无需填写真实姓名, 生产环境需要填写真实姓名拼音, 签名验签时下载数字证书需要, 限长64个字符 +# userPin 本地加签验签的密码,请自己保密 +# mauthip, 签名验签时下载数字证书需要, 测试环境与生产环境不同, 由农信提供 +# mauthPort mauth端口, 签名验签时下载数字证书需要, 测试环境与生产环境不同, 由农信提供 +# idCard 身份证ID, 下载数字证书时使用, 测试环境无需填写真实号码, 但生产环境必须填写真实号码 +# protocol 下载证书的通讯方式: 2:https; 0:http; 专线使用http, 互联网使用https +# caFilePath 如果protocol为0,则此项不起作用,ca文件, 配置绝对路径, 下载数字证书使用https通讯时使用, 测试环境与生产环境不同, 由农信提供 +#windows: caFile=C:\\Temp\\sm2_root2023.cer +#linux: caFile=/home/eci/test/sm2_root.cer +# businessId 加解密使用, 测试环境生产环境不同 +# businessKeyToken 加解密使用, 测试环境生产环境不同 + +# Request参数官方解释 +# serviceIp, servicePort, corpCode, email是与银企直连平台通讯时连接的ip端口及企业编码, \ No newline at end of file diff --git a/config/sm2_root2023.cer b/config/sm2_root2023.cer new file mode 100644 index 0000000..8e99882 --- /dev/null +++ b/config/sm2_root2023.cer @@ -0,0 +1,12 @@ +-----BEGIN CERTIFICATE----- +MIIB0zCCAXmgAwIBAgIGAKLcs9liMAoGCCqBHM9VAYN1MD4xCzAJBgNVBAYTAkNO +MQwwCgYDVQQKDANURUMxDjAMBgNVBAsMBUNFU0hJMREwDwYDVQQDDAhTTTJfVEVT +VDAeFw0yMjEwMjgwNjE3MDhaFw0zMjEwMjgwNjE3MDhaMD4xCzAJBgNVBAYTAkNO +MQwwCgYDVQQKDANURUMxDjAMBgNVBAsMBUNFU0hJMREwDwYDVQQDDAhTTTJfVEVT +VDBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABNRgiD4a6PbNB9mVbkYtJCADL/oy +uLsuv89sV2PeSk4PHQcxg3BjM/oMXzimhza55LAsd5l59ivJj7WV/GmBUZCjYzBh +MB8GA1UdIwQYMBaAFAghFULyEyKiKuz0DEU0k0xfEQEiMA8GA1UdEwEB/wQFMAMB +Af8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBQIIRVC8hMioirs9AxFNJNMXxEB +IjAKBggqgRzPVQGDdQNIADBFAiAl+0c4GnRtZnEMofwsSsNpp4DA7ixj0vK1QBZs +mrcj2gIhANIsedg1puDX5octlr4iFBPwOahHxsZVYU6pc4mOta6C +-----END CERTIFICATE----- diff --git a/config/yqzl.bat b/config/yqzl.bat new file mode 100644 index 0000000..b59fdda --- /dev/null +++ b/config/yqzl.bat @@ -0,0 +1,76 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem yqzl 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=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME%.. + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and YQZL_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Dio.ktor.development=false" + +set JAVA_EXE=D:\java11\OpenJDK11U-jre_x64_windows_hotspot_11.0.24_8\jdk-11.0.24+8-jre\bin\java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +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 + + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\lib\yqzl-0.0.1.jar;%APP_HOME%\lib\signApi-3.1.4.jar;%APP_HOME%\lib\IsecJSDK-3.0.1.0.jar;%APP_HOME%\lib\xdsdk-1.0.jar;%APP_HOME%\lib\ktor-server-tomcat-jakarta-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-content-negotiation-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-status-pages-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-cors-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-config-yaml-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-servlet-jakarta-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-server-core-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-serialization-gson-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-serialization-kotlinx-json-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\kotlin-reflect-2.0.20.jar;%APP_HOME%\lib\ktor-serialization-kotlinx-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-serialization-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-events-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-http-cio-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-websockets-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-http-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-network-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\ktor-utils-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\yamlkt-jvm-0.13.0.jar;%APP_HOME%\lib\ktor-io-jvm-3.0.0-rc-1.jar;%APP_HOME%\lib\kotlin-stdlib-jdk8-2.0.20.jar;%APP_HOME%\lib\kotlin-stdlib-jdk7-2.0.20.jar;%APP_HOME%\lib\kotlinx-serialization-core-jvm-1.7.2.jar;%APP_HOME%\lib\kotlinx-serialization-json-jvm-1.7.2.jar;%APP_HOME%\lib\kotlinx-io-core-jvm-0.5.3.jar;%APP_HOME%\lib\kotlinx-io-bytestring-jvm-0.5.3.jar;%APP_HOME%\lib\kotlin-stdlib-2.0.20.jar;%APP_HOME%\lib\logback-classic-1.4.14.jar;%APP_HOME%\lib\jaxb-runtime-2.3.1.jar;%APP_HOME%\lib\jaxb-api-2.3.1.jar;%APP_HOME%\lib\kotlinx-coroutines-jdk8-1.8.1.jar;%APP_HOME%\lib\kotlinx-coroutines-core-jvm-1.8.1.jar;%APP_HOME%\lib\annotations-23.0.0.jar;%APP_HOME%\lib\logback-core-1.4.14.jar;%APP_HOME%\lib\slf4j-api-2.0.16.jar;%APP_HOME%\lib\javax.activation-api-1.2.0.jar;%APP_HOME%\lib\txw2-2.3.1.jar;%APP_HOME%\lib\istack-commons-runtime-3.0.7.jar;%APP_HOME%\lib\stax-ex-1.8.jar;%APP_HOME%\lib\FastInfoset-1.2.15.jar;%APP_HOME%\lib\config-1.4.3.jar;%APP_HOME%\lib\jansi-2.4.1.jar;%APP_HOME%\lib\tomcat-catalina-10.1.28.jar;%APP_HOME%\lib\tomcat-embed-core-10.1.28.jar;%APP_HOME%\lib\gson-2.11.0.jar;%APP_HOME%\lib\tomcat-jsp-api-10.1.28.jar;%APP_HOME%\lib\tomcat-util-scan-10.1.28.jar;%APP_HOME%\lib\tomcat-api-10.1.28.jar;%APP_HOME%\lib\tomcat-coyote-10.1.28.jar;%APP_HOME%\lib\tomcat-servlet-api-10.1.28.jar;%APP_HOME%\lib\tomcat-util-10.1.28.jar;%APP_HOME%\lib\tomcat-juli-10.1.28.jar;%APP_HOME%\lib\tomcat-annotations-api-10.1.28.jar;%APP_HOME%\lib\tomcat-jni-10.1.28.jar;%APP_HOME%\lib\tomcat-jaspic-api-10.1.28.jar;%APP_HOME%\lib\error_prone_annotations-2.27.0.jar;%APP_HOME%\lib\tomcat-el-api-10.1.28.jar + + +@rem Execute yqzl +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %YQZL_OPTS% -classpath "%CLASSPATH%" io.ktor.server.tomcat.jakarta.EngineMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable YQZL_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%YQZL_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5275062 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +kotlin.code.style=official +ktor_version=3.0.0-rc-1 +kotlin_version=2.0.20 +logback_version=1.4.14 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..39c8893 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@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 Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@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="-Xmx64m" "-Xms64m" + +@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 execute + +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 execute + +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 + +: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 %* + +: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 diff --git a/lib/IsecJSDK-3.0.1.0.jar b/lib/IsecJSDK-3.0.1.0.jar new file mode 100644 index 0000000..5c6a146 Binary files /dev/null and b/lib/IsecJSDK-3.0.1.0.jar differ diff --git a/lib/linuxApi-1.0.jar b/lib/linuxApi-1.0.jar new file mode 100644 index 0000000..6c15c8d Binary files /dev/null and b/lib/linuxApi-1.0.jar differ diff --git a/lib/signApi-3.1.5.2.jar b/lib/signApi-3.1.5.2.jar new file mode 100644 index 0000000..0e2df85 Binary files /dev/null and b/lib/signApi-3.1.5.2.jar differ diff --git a/lib/windowsApi-1.0.jar b/lib/windowsApi-1.0.jar new file mode 100644 index 0000000..26bd017 Binary files /dev/null and b/lib/windowsApi-1.0.jar differ diff --git a/lib/xdsdk-1.0.jar b/lib/xdsdk-1.0.jar new file mode 100644 index 0000000..803bf3f Binary files /dev/null and b/lib/xdsdk-1.0.jar differ diff --git a/net_mauth.store_yqzl b/net_mauth.store_yqzl new file mode 100644 index 0000000..cbd6a8c Binary files /dev/null and b/net_mauth.store_yqzl differ diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..2ef4b05 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "yqzl" diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/Application.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/Application.kt new file mode 100644 index 0000000..81180eb --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/Application.kt @@ -0,0 +1,117 @@ +package com.bbitcn.shanxi.yqzl + +import com.bbitcn.shanxi.yqzl.router.bankRouting +import com.bbitcn.shanxi.yqzl.utils.configure +import io.ktor.server.application.* +import com.bbitcn.shanxi.yqzl.router.oldRouting +import com.bbitcn.shanxi.yqzl.utils.MyUtils +import com.bbitcn.shanxi.yqzl.utils.MyUtils.logger +import com.srcu.SignApi +import java.io.File +import java.util.Properties + +/** + * 部署说明: + * 1.将项目目录的config文件夹复制到install dist生产的bin目录下 + * + * 2.(可选)如果需要自定义Java路径,则删除bin目录下yqzl.bat中以下代码 + * if defined JAVA_HOME goto findJavaFromJavaHome + * + * 和 + * + * :findJavaFromJavaHome + * set JAVA_HOME=%JAVA_HOME:"=% + * set JAVA_EXE=%JAVA_HOME%/bin/java.exe + * + * if exist "%JAVA_EXE%" goto execute + * + * 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 + */ + + +fun main(args: Array) { + io.ktor.server.tomcat.jakarta.EngineMain.main(args) +} + + +fun Application.module() { + init() + configure() + oldRouting() + bankRouting() + log.info( + "✅ Ktor 服务启动成功,监听端口:${ + environment.config.propertyOrNull("ktor.deployment.port")?.getString() ?: "默认" + }" + ) +} + +private fun init() { + // 加载配置文件 + val properties = Properties() + val configFile = File("config/config.properties") + + if (configFile.exists()) { + properties.load(configFile.inputStream()) + } + // 打印所有属性值 + logger.info("=================================================================") + logger.info("程序启动:读取Config配置文件") + if (properties.isEmpty) { + logger.info("未找到Config配置文件") + } else { + properties.forEach { key, value -> + logger.info("$key = $value") + } + } + logger.info("=================================================================") + try { + // 获取Mauth参数 + val mauthHost = properties.getProperty("mauth.host", "202.99.212.80") + val mauthPort = properties.getProperty("mauth.port", "9208").toInt() + val mauthEnName = properties.getProperty("mauth.enName", "ycydjs") + val mauthUserPin = properties.getProperty("mauth.userPin", "123456") + val mauthIdCard = properties.getProperty("mauth.idCard", "600601003") + val mauthProtocol = properties.getProperty("mauth.protocol", "0").toInt() + val mauthCertPath = properties.getProperty("mauth.caFile", "config\\sm2_root2023.cer") + val mauthBusinessId = properties.getProperty("mauth.businessId", "d8d9085d3dd44e64bec47428629a3966") + val mauthBusinessKeyToken = properties.getProperty( + "mauth.businessKeyToken", + "YWRmMWE0OTk4Zjg5YjJjY2HPXlMog585ov4InwbI6WXnp14Ki43gHR1CAVHbuS+Y2tKKHnk7CEiduFcssmhKAKbTni0ZfZD/2HSfIO1MGqkQZlQMp2+nyKba59C9BZ+5Go34oLdPM7ctjnjQ7q8mt9yC2H0OsOLDnnrHH2ZQYmPi7ZD6oIZbWa2xqcc0gwzO4GYC89jKfQ4svwlP4/MgDu8WanAu6GCyNBsqXRqSErYSIfzHaFG0jSLFleakpWx2/TpsgJYKAMGX7A8GsXf7Yz31q3ry+kkgWNqHNM3kt6XGcbOcFZG3fJMxXSWG2RSx9AIaSNpstc+DBOi/tniuZi8cXgcaR/qV5UoBI6teJ6QiZV28Rzd0XoJxtMuoAqXG1BpITN6jWRhxJj9tdpeEEoZTeSmWKxbJDF8N7+o7Wo+wvJnOgndo3+Me9WM7QN/w+OWGBgjMKv3r1+ZTy5IorGMNW+KFVJ7SEC4iczoZnhYxVGOx4cYsxd8PT5x6/7kL2ll/CxvygPbHlPoIvqpPYQ/HRZV02asooy4zHE/ndIG7swGCd+SsErN5TnT5lo/SPlATKw2tGvU1Z8YtmQ4OLNRJL/MF55EuwQhDT1ypy1V/OPy42bMjMjzF/EGXF9a6BDu/mfyN1QyjW/rKC26Yww==" + ) + // 获取Request参数 + val requestHost = properties.getProperty("request.serviceIp", "202.99.212.80") + val requestPort = properties.getProperty("request.servicePort", "9202").toInt() + MyUtils.requestHost = requestHost + MyUtils.requestPort = requestPort + val requestCorpCode = properties.getProperty("request.corpCode", "C500504002") + val requestEmail = properties.getProperty("request.email", "fan@bbitcn.com") + + // 调用SignApi.setMauthParam + SignApi.setMauthParam( + mauthHost, + mauthPort, + mauthEnName, + mauthUserPin, + mauthIdCard, + mauthProtocol, + mauthCertPath, + mauthBusinessId, + mauthBusinessKeyToken + ) + SignApi.setRequestParam( + requestHost, + requestPort, + requestCorpCode, + requestEmail + ) + } catch (e: Exception) { + e.printStackTrace() + } +} diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/Test.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/Test.kt new file mode 100644 index 0000000..a23beb1 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/Test.kt @@ -0,0 +1,49 @@ +package com.bbitcn.shanxi.yqzl + +import com.bbitcn.shanxi.yqzl.router.sendSocketRequestSync +import java.net.ServerSocket +import kotlin.concurrent.thread + +fun main() { + // 启动本地服务端 + startLocalSocketServer() + + // 等待服务端启动 + Thread.sleep(1000) + + // 发起请求 + val response = sendSocketRequestSync("HelloSocket", "127.0.0.1") + println("Client received: $response") +} +fun startLocalSocketServer(port: Int = 60000) { + thread { + try { + val serverSocket = ServerSocket(port) + println("Server started on port $port") + while (true) { + val client = serverSocket.accept() + thread { + try { + val input = client.getInputStream() + val output = client.getOutputStream() + val buffer = ByteArray(1024) + val bytesRead = input.read(buffer) + val received = String(buffer, 0, bytesRead, Charsets.UTF_8) + println("Server received: $received") + + // 简单处理,直接回写相同内容 + output.write(received.toByteArray(Charsets.UTF_8)) + output.flush() + } catch (e: Exception) { + println("Server client error: ${e.message}") + } finally { + client.close() + } + } + } + } catch (e: Exception) { + println("Server error: ${e.message}") + } + } +} + diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/BaseResponse.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/BaseResponse.kt new file mode 100644 index 0000000..d4a3dad --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/BaseResponse.kt @@ -0,0 +1,12 @@ +package ink.snowflake.server.model.response + +import kotlinx.serialization.Serializable + + +@Serializable +open class BaseResponse( + val status: Boolean = true, + val message: String = if(status) "操作成功" else "操作失败", + val data: String? = null, +) + diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/CommonRequest.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/CommonRequest.kt new file mode 100644 index 0000000..5fb8cc3 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/CommonRequest.kt @@ -0,0 +1,8 @@ +package com.bbitcn.shanxi.yqzl.model + +import kotlinx.serialization.Serializable + +@Serializable +data class CommonRequest ( + val str :String = "" +) \ No newline at end of file diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NewResponse.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NewResponse.kt new file mode 100644 index 0000000..1cb6e55 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NewResponse.kt @@ -0,0 +1,20 @@ +package com.bbitcn.shanxi.yqzl.model +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class NewResponse( + @SerialName("BusiCode") + val busiCode: String = "", + @SerialName("CorpTermId") + val corpTermId: String = "", + @SerialName("Errocode") + val erroCode: String = "", + @SerialName("Erromsg") + val erromsg: String = "", + @SerialName("ReciveXmlText") + val reciveXmlText: String = "", + @SerialName("Status") + val status: String = "" +) + diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NoSignRequest.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NoSignRequest.kt new file mode 100644 index 0000000..89c2bdd --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/NoSignRequest.kt @@ -0,0 +1,11 @@ +package com.bbitcn.shanxi.yqzl.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + + +@Serializable +data class NoSignRequest( + @SerialName("msg") + val msg: String = "" +) diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/PayRequest.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/PayRequest.kt new file mode 100644 index 0000000..3e20809 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/PayRequest.kt @@ -0,0 +1,23 @@ +package com.bbitcn.shanxi.yqzl.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class PayRequest( + // 业务代码 + @SerialName("BusiCode") + val busiCode: String = "", + // 请求业务编号 唯一值,响应报文时返回 + @SerialName("CorpTermId") + val corpTermId: String = "", + // 请求xml明文报文 + @SerialName("SendXmlText") + val sendXmlText: String = "", + // 加签字段拼接字符串 + @SerialName("SignData") + val signData: String = "", + // 是否加签 1 加签,0不加签 + @SerialName("SignTrue") + val signTrue: String = "0" +) \ No newline at end of file diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/SignRequest.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/SignRequest.kt new file mode 100644 index 0000000..b5524ff --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/SignRequest.kt @@ -0,0 +1,16 @@ +package com.bbitcn.shanxi.yqzl.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SignRequest( + @SerialName("msg") + val msg: String = "", + @SerialName("signData") + val signData: String = "", + @SerialName("versignData") + val versignData: String = "" +) + + diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/VerifyRequest.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/VerifyRequest.kt new file mode 100644 index 0000000..3d5403a --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/model/VerifyRequest.kt @@ -0,0 +1,6 @@ +package com.bbitcn.shanxi.yqzl.model + +import kotlinx.serialization.Serializable + +@Serializable +data class VerifyRequest(val testPlain: String, val sign: String) \ No newline at end of file diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Bank.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Bank.kt new file mode 100644 index 0000000..32bee16 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Bank.kt @@ -0,0 +1,192 @@ +package com.bbitcn.shanxi.yqzl.router + +import com.bbitcn.shanxi.yqzl.model.NewResponse +import com.bbitcn.shanxi.yqzl.model.NoSignRequest +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import com.bbitcn.shanxi.yqzl.model.PayRequest +import com.bbitcn.shanxi.yqzl.model.SignRequest +import com.bbitcn.shanxi.yqzl.utils.MyUtils +import com.bbitcn.shanxi.yqzl.utils.MyUtils.logger +import com.srcu.SignApi +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import java.io.ByteArrayOutputStream +import java.net.InetSocketAddress +import java.net.Socket + +fun Application.bankRouting() { + routing { + post("/bridgePay") { + val request = call.receive() + val logStart = request.busiCode + "-" + request.corpTermId + ":" + logger.info(logStart + "调用bridgePay接口") + call.respond( run { + try { + logger.info(logStart + "参数:" + Json.encodeToString(request)) + val requestStr: String? = if (request.signTrue != "1") { + // 不需要加签 + val noSignRequest = NoSignRequest(request.sendXmlText) + val res = Json.encodeToString(noSignRequest) + logger.info(logStart + "不需要加签,拼装请求:" + res) + res + } else { + // 需要加签 + logger.info(logStart + "需要加签,拼装加签请求:") + val afterSigned: String? = SignApi.signatureWithRegister(request.signData) + if (afterSigned != null) { + // 组装加签请求 + val signRequest = SignRequest( + msg = request.sendXmlText, + signData = request.signData, + versignData = afterSigned + ) + val res = Json.encodeToString(signRequest) + logger.info(logStart + "需要加签,拼装加签请求:" + res) + res + } else { + null + } + } + if (requestStr == null) { + logger.info(logStart + "加签失败,结束接口") + NewResponse( + status = "0", + corpTermId = request.corpTermId, + busiCode = request.busiCode, + erroCode = "JQ0001", + erromsg = "加签失败", + reciveXmlText = "" + ) + } else { + logger.info(logStart + "开始加密:" + requestStr) + // 加密 + val encryptedStr: String? = SignApi.encryptBytes(requestStr) + if (encryptedStr != null) { + logger.info(logStart + "加密成功,密文:" + encryptedStr) + // 加密成功,在头部增加长度 + val sth = wrapWithLength(encryptedStr) + // 请求银行得到密文 + logger.info(logStart + "请求Socket(${MyUtils.requestHost}:${MyUtils.requestPort}),参数:$sth") + val encryptedStr2 = + sendSocketRequestSync(sth, MyUtils.requestHost, MyUtils.requestPort) + if (encryptedStr2 == null || encryptedStr2 == "") { + // socket请求失败 + logger.info(logStart + "socket请求失败,收到的数据为空") + NewResponse( + status = "2", + corpTermId = request.corpTermId, + busiCode = request.busiCode, + erroCode = "666666", + erromsg = "socket请求失败,收到的数据为空", + reciveXmlText = "" + ) + } else { + logger.info(logStart + "socket请求成功:$encryptedStr2") + // 将收到的密文去除前8位 + val cutStr = parseLengthFromStr(encryptedStr2) + // 对密文解密 + logger.info(logStart + "开始解密:$cutStr") + val decryptedStr: String? = SignApi.decryptBytes(cutStr) + if (decryptedStr != null) { + logger.info(logStart + "解密成功,结束接口:" + decryptedStr) + // 将明文返回 + NewResponse( + status = "1", + corpTermId = request.corpTermId, + erroCode = "000000", + erromsg = "交互成功", + busiCode = request.busiCode, + reciveXmlText = decryptedStr + ) + } else { + logger.info(logStart + "解密失败,结束接口") + NewResponse( + status = "2", + corpTermId = request.corpTermId, + busiCode = request.busiCode, + erroCode = "JM0002", + erromsg = "国密解密失败", + reciveXmlText = "" + ) + } + } + } else { + logger.info(logStart + "加密失败,结束接口") + // 加密失败 + NewResponse( + status = "0", + corpTermId = request.corpTermId, + busiCode = request.busiCode, + erroCode = "JM0001", + erromsg = "国密加密失败", + reciveXmlText = "" + ) + } + } + } catch (ex: Exception) { + ex.printStackTrace() + logger.error(logStart + ex.message) + logger.error(logStart + "抛出异常,结束接口") + NewResponse( + busiCode = request.busiCode, + status = "2", + corpTermId = request.corpTermId, + erroCode = "E00000", + erromsg = "未知异常错误", + reciveXmlText = "" + ) + } + }) + } + } +} + +fun sendSocketRequestSync( + dataToSend: String, + ip: String, + port: Int = 60000 +): String? { + return try { + val socket = Socket() + socket.soTimeout = 3000 // 设置读取超时 + socket.connect(InetSocketAddress(ip, port), 3000) // 设置连接超时 + val outputStream = socket.getOutputStream() + outputStream.write(dataToSend.toByteArray(Charsets.UTF_8)) + outputStream.flush() + + val inputStream = socket.getInputStream() + val resultStream = ByteArrayOutputStream() + val buffer = ByteArray(8192) + var bytesRead: Int + while (true) { + bytesRead = inputStream.read(buffer) + if (bytesRead == -1) break + resultStream.write(buffer, 0, bytesRead) + } + socket.close() + resultStream.toString(Charsets.UTF_8.name()).trim().replace(" ", "") + } catch (e: Exception) { + e.printStackTrace() + null + } +} + + +/** + * 获取截掉前8位后的字符串 + */ +fun parseLengthFromStr(str: String): String { + return if (str.length > 8) str.drop(8) else "" +} + +/** + * 在字符串头部增加8位数字 + */ +fun wrapWithLength(str: String): String { + val length = str.length + val lengthStr = length.toString().padStart(8, '0') + return lengthStr + str +} diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Routing.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Routing.kt new file mode 100644 index 0000000..9037f7b --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/router/Routing.kt @@ -0,0 +1,136 @@ +package com.bbitcn.shanxi.yqzl.router + +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.server.routing.* +import com.bbitcn.shanxi.yqzl.model.CommonRequest +import com.bbitcn.shanxi.yqzl.model.VerifyRequest +import com.bbitcn.shanxi.yqzl.utils.MyUtils.logger +import com.srcu.SignApi +import ink.snowflake.server.model.response.BaseResponse + +fun Application.oldRouting() { + routing { + // 加密接口 + post("/encryptBytes") { + try { + logger.info("调用加密接口") + val request = call.receive() + val requestStr = request.str + logger.info("收到ERP加密明文:" + requestStr) + call.respond( + if (requestStr.isBlank()) { + BaseResponse(status = false, message = "参数requestStr不可为空") + } else { + logger.info("开始加密") + val res: String? = SignApi.encryptBytes(requestStr) + if (res != null) { + logger.info("加密成功") + logger.info("返回:$res") + BaseResponse(data = res) + } else { + logger.info("加密失败,详情查看C:\\Users\\<用户名>\\AppData\\Local\\Temp\\yqzl_info.log") + BaseResponse(status = false, message = "加密失败") + } + } + ) + } catch (ex: Exception) { + ex.printStackTrace() + logger.error("加密接口抛出异常") + logger.error(ex.message) + call.respond(BaseResponse(status = false, message = "解析错误")) + } + } + + // 解密接口 + post("/decryptBytes") { + try { + val request = call.receive() + val responseStr = request.str + logger.info("调用解密接口") + logger.info("收到待解密内容:" + responseStr) + call.respond( + if (responseStr.isEmpty()) { + BaseResponse(status = false, message = "参数responseStr不可为空") + } else { + logger.info("开始解密") + val result: String? = SignApi.decryptBytes(responseStr) + if (result == null) { + logger.info("解密失败,详情查看C:\\Users\\<用户名>\\AppData\\Local\\Temp\\yqzl_info.log") + BaseResponse(status = false, message = "解密失败") + } else { + logger.info("解密成功") + logger.info("返回:$result") + BaseResponse(data = result) + } + } + ) + } catch (ex: Exception) { + ex.printStackTrace() + logger.error("解密接口抛出异常") + logger.error(ex.message) + call.respond(BaseResponse(status = false, message = "解析错误")) + } + } + // 签名接口 + post("/signature") { + try { + val request = call.receive() + logger.info("调用签名接口") + logger.info("收到str:" + request.str) + val responseStr = request.str + call.respond( + if (responseStr.isEmpty()) { + BaseResponse(status = false, message = "参数responseStr不可为空") + } else { + logger.info("开始加签") + val result: String? = SignApi.signatureWithRegister(request.str) + if (result == null) { + logger.info("加签失败,详情查看C:\\Users\\<用户名>\\AppData\\Local\\Temp\\yqzl_info.log") + BaseResponse(status = false, message = "签名失败") + } else { + logger.info("加签成功") + logger.info("返回:$result") + BaseResponse(data = result) + } + } + ) + } catch (ex: Exception) { + ex.printStackTrace() + logger.error("加签接口抛出异常") + logger.error(ex.message) + call.respond(BaseResponse(status = false, message = "解析错误")) + } + } + // 验证接口 + post("/verify") { + try { + val request = call.receive() + logger.info("调用验签接口") + logger.info("收到testPlain:\n" + request.testPlain) + logger.info("收到sign:\n" + request.sign) + call.respond( + if (request.testPlain.isEmpty() || request.sign.isEmpty()) { + BaseResponse(status = false, message = "参数testPlain与sign不可为空") + } else { + logger.info("开始验签") + val result = SignApi.verify(request.testPlain, request.sign) + if (result) { + logger.info("签名验证成功") + BaseResponse(data = result.toString()) + } else { + logger.info("签名验证失败,详情查看C:\\Users\\<用户名>\\AppData\\Local\\Temp\\yqzl_info.log") + BaseResponse(status = false, message = "签名失败") + } + } + ) + } catch (ex: Exception) { + ex.printStackTrace() + logger.error("签名验证抛出异常") + logger.error(ex.message) + call.respond(BaseResponse(status = false, message = "解析错误")) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/MyUtils.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/MyUtils.kt new file mode 100644 index 0000000..15ce3a4 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/MyUtils.kt @@ -0,0 +1,9 @@ +package com.bbitcn.shanxi.yqzl.utils + +import org.slf4j.LoggerFactory + +object MyUtils{ + val logger = LoggerFactory.getLogger("RoutingLogger") + var requestHost = "" + var requestPort = 0 +} \ No newline at end of file diff --git a/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/Plugins.kt b/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/Plugins.kt new file mode 100644 index 0000000..5a83189 --- /dev/null +++ b/src/main/kotlin/com/bbitcn/shanxi/yqzl/utils/Plugins.kt @@ -0,0 +1,117 @@ +package com.bbitcn.shanxi.yqzl.utils + +import com.bbitcn.shanxi.yqzl.utils.MyUtils.logger +import ink.snowflake.server.model.response.BaseResponse +import io.ktor.http.* +import io.ktor.serialization.gson.* +import io.ktor.serialization.kotlinx.json.* +import io.ktor.server.application.* +import io.ktor.server.plugins.contentnegotiation.* +import io.ktor.server.plugins.cors.routing.CORS +import io.ktor.server.plugins.statuspages.StatusPages +import io.ktor.server.request.uri +import io.ktor.server.response.respond +import io.ktor.server.response.respondText + +fun Application.configure() { + install(ContentNegotiation) { + json() + gson{ + setPrettyPrinting() + } + } + install(CORS) { + anyHost() + allowHost("localhost:8089") + allowHost("127.0.0.1:8089") + allowHost("171.212.101.201:8089") + allowHost("debug.scaitcn.com:8089") + + // 进一步配置 CORS + allowMethod(HttpMethod.Get) + allowMethod(HttpMethod.Post) + allowHeader(HttpHeaders.ContentType) + allowHeader(HttpHeaders.Authorization) + } + + install(StatusPages) { + // 处理特定的异常 + exception { call, cause -> + logger.error("IllegalStateException 捕获:${cause.message}", cause) + call.respondText("App in illegal state as ${cause.message}", status = HttpStatusCode.InternalServerError) + } + exception { call, cause -> + logger.error("Exception 捕获:${cause.message}", cause) + call.respond( + HttpStatusCode.InternalServerError, BaseResponse( + status = false, + message = cause.localizedMessage + ) + ) + } + status(HttpStatusCode.Unauthorized) { call, status -> + logger.error("收到未授权请求:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Unauthorized," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.BadRequest) { call, status -> + logger.error("收到错误请求:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Bad Request," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.NotFound) { call, status -> + logger.error("请求未匹配路径:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Not Found," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.Forbidden) { call, status -> + logger.error("权限不足、资源受限:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Forbidden," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.MethodNotAllowed) { call, status -> + logger.error("请求未匹配路径:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Method Not Allowed," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.Conflict) { call, status -> + logger.error("语义层的逻辑冲突:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Conflict," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.InternalServerError) { call, status -> + logger.error("未被捕获的异常:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Internal Server Error," + status.description + ) + call.respond(status, response) + } + status(HttpStatusCode.ServiceUnavailable) { call, status -> + logger.error("服务不可用:${call.request.uri}") + val response = BaseResponse( + status = false, + message = "${status.value} Service Unavailable," + status.description + ) + call.respond(status, response) + } + } +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 0000000..0ab477e --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,6 @@ +ktor: + application: + modules: + - com.bbitcn.shanxi.yqzl.ApplicationKt.module + deployment: + port: 8091 diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..1d95720 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + logs/info.log + + logs/info.%d{yyyy-MM-dd}.log + + + ERROR + DENY + NEUTRAL + + + UTF-8 + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + logs/error.log + + logs/error.%d{yyyy-MM-dd}.log + + + ERROR + ACCEPT + DENY + + + UTF-8 + %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n + + + + + + + + + + + + + + +