From 5c59454c8a12b1a19846c23c99cff612db037e4f Mon Sep 17 00:00:00 2001 From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn> Date: 星期三, 23 九月 2020 11:47:28 +0800 Subject: [PATCH] 初始化 --- src/main/java/com/hx/mp/util/HttpXmlUtils.java | 63 src/main/java/com/hx/util/MD5.java | 64 .idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml | 13 .idea/libraries/Maven__com_google_code_gson_gson_2_8_5.xml | 13 src/main/java/com/hx/util/StringUtils.java | 306 + .idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml | 13 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_0_5_RELEASE.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_6.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml | 13 src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java | 404 + .idea/libraries/Maven__com_aliyun_oss_aliyun_sdk_oss_2_8_3.xml | 13 .idea/libraries/Maven__org_jdom_jdom_1_1_3.xml | 13 .idea/misc.xml | 13 .idea/libraries/Maven__com_github_jsqlparser_jsqlparser_2_0.xml | 13 src/main/java/com/qq/weixin/mp/aes/XMLParse.java | 106 src/main/java/com/hx/util/TengXunMapUtil.java | 191 .idea/libraries/Maven__commons_io_commons_io_2_6.xml | 13 src/main/java/com/hx/util/MyRedisTemplate.java | 139 .idea/libraries/Maven__com_alibaba_fastjson_1_2_47.xml | 13 src/main/java/com/hx/util/ThreadPoolUtils.java | 42 src/main/java/com/hx/exception/ParamException.java | 12 src/main/java/com/hx/mp/util/HttpClientUtil.java | 340 + hx-common.iml | 108 src/main/java/com/hx/util/TempltUtil.java | 150 .idea/libraries/Maven__com_gitee_sunchenbin_mybatis_actable_mybatis_enhance_actable_1_1_1_RELEASE.xml | 13 .idea/libraries/Maven__commons_logging_commons_logging_1_2.xml | 13 src/main/java/com/hx/util/EmailUtil.java | 120 src/main/java/com/hx/util/FileUtils.java | 342 + .idea/libraries/Maven__org_apache_commons_commons_pool2_2_5_0.xml | 13 src/main/java/com/hx/mp/util/MpUtil.java | 357 + .idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_5_RELEASE.xml | 13 .idea/libraries/Maven__org_apache_poi_poi_3_9.xml | 13 src/main/java/com/hx/util/QRCodeUtil.java | 238 + .idea/libraries/Maven__org_springframework_data_spring_data_commons_2_0_10_RELEASE.xml | 13 .idea/libraries/Maven__org_springframework_spring_web_5_0_9_RELEASE.xml | 13 .idea/libraries/Maven__io_jsonwebtoken_jjwt_0_9_1.xml | 13 src/main/java/com/hx/exception/ServiceException.java | 34 .idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_12_Final.xml | 13 .idea/compiler.xml | 21 src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java | 67 src/main/java/com/hx/util/FileUtil.java | 74 .idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_6.xml | 13 src/main/java/com/hx/util/RequestMethod.java | 152 src/main/java/com/hx/util/WebUtil.java | 53 .idea/libraries/Maven__com_github_pagehelper_pagehelper_5_1_11.xml | 13 .idea/libraries/Maven__org_springframework_spring_jcl_5_0_9_RELEASE.xml | 13 .idea/libraries/Maven__org_springframework_spring_jdbc_5_0_9_RELEASE.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml | 13 .idea/libraries/Maven__com_google_zxing_javase_3_0_0.xml | 13 src/main/java/com/hx/mp/util/TenpayHttpClient.java | 559 ++ pom.xml | 268 + .idea/libraries/Maven__com_sun_mail_javax_mail_1_6_2.xml | 13 .idea/libraries/Maven__commons_beanutils_commons_beanutils_1_9_3.xml | 13 .idea/libraries/Maven__net_sf_ezmorph_ezmorph_1_0_3.xml | 13 src/main/java/com/hx/util/BASE64.java | 51 .idea/libraries/Maven__org_projectlombok_lombok_1_16_22.xml | 13 .idea/libraries/Maven__cglib_cglib_3_1.xml | 13 .idea/libraries/Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/mp/util/ResponseHandler.java | 225 + .idea/libraries/Maven__commons_collections_commons_collections_3_2_2.xml | 13 .idea/libraries/Maven__junit_junit_4_12.xml | 13 .idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml | 13 .idea/libraries/Maven__org_springframework_data_spring_data_redis_2_0_10_RELEASE.xml | 13 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_0_5_RELEASE.xml | 13 .idea/libraries/Maven__org_springframework_spring_beans_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/resultTool/ResponseCode.java | 27 .idea/libraries/Maven__net_sf_json_lib_json_lib_jdk15_2_4.xml | 13 src/main/java/com/hx/util/SimpleEncrypt.java | 104 src/main/java/com/hx/mp/util/CorpMpClientUtil.java | 169 src/main/java/com/hx/mp/util/CertUtil.java | 31 .idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_12.xml | 13 .idea/libraries/Maven__org_springframework_spring_oxm_5_0_9_RELEASE.xml | 13 .idea/libraries/Maven__org_springframework_spring_webmvc_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/util/StreamUtils.java | 266 + src/main/java/com/hx/util/ExcelUtil.java | 201 .idea/libraries/Maven__org_ow2_asm_asm_4_2.xml | 13 src/main/java/com/hx/mp/util/WXPayUtil.java | 458 ++ .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 .idea/libraries/Maven__javax_activation_activation_1_1.xml | 13 src/main/java/com/hx/mp/util/CorpMpUtil.java | 294 + .idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_2_0_10_RELEASE.xml | 13 src/main/java/com/hx/util/GsonUtils.java | 29 src/main/java/com/hx/util/Aes.java | 113 .idea/libraries/Maven__org_springframework_spring_core_5_0_9_RELEASE.xml | 13 .idea/encodings.xml | 6 src/main/java/com/hx/mybatisTool/SqlSentence.java | 161 .idea/libraries/Maven__org_yaml_snakeyaml_1_19.xml | 13 .idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_66.xml | 13 src/main/java/com/hx/mybatisTool/SqlParam.java | 75 .idea/libraries/Maven__javax_servlet_jstl_1_2.xml | 13 .idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml | 13 src/main/java/com/hx/util/HttpUtil.java | 546 ++ src/main/java/com/hx/mp/util/WechatUtil.java | 77 src/main/java/com/hx/util/DateUtil.java | 346 + src/main/java/com/hx/common/CommonInit.java | 97 .idea/libraries/Maven__log4j_log4j_1_2_14.xml | 13 src/main/java/com/hx/resultTool/Result.java | 84 src/main/java/com/hx/util/MD5Util.java | 48 .idea/libraries/Maven__commons_codec_commons_codec_1_11.xml | 13 .idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml | 13 .idea/libraries/Maven__redis_clients_jedis_2_9_0.xml | 13 src/main/java/com/hx/mp/util/ClientResponseHandler.java | 228 + src/main/java/com/hx/util/NumberUtil.java | 340 + src/main/java/com/hx/util/Base64Util.java | 65 .idea/.gitignore | 2 src/main/java/com/hx/util/SerializeUtil.java | 72 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_0_5_RELEASE.xml | 13 .idea/libraries/Maven__com_auth0_java_jwt_3_10_3.xml | 13 .idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_1_1.xml | 13 src/main/java/com/hx/util/ImagesAddDomain.java | 84 .idea/libraries/Maven__org_dom4j_dom4j_2_1_3.xml | 13 .idea/libraries/Maven__org_springframework_boot_spring_boot_2_0_5_RELEASE.xml | 13 src/main/java/com/hx/util/JwtTool.java | 93 src/main/java/com/hx/mp/util/HttpUtil.java | 31 src/main/java/com/hx/util/CreateNoTool.java | 46 src/main/java/com/qq/weixin/mp/aes/WXBizMsgCrypt.java | 296 + src/main/java/com/hx/mp/util/XMLUtil.java | 109 src/main/java/com/hx/util/AesUtil.java | 126 .gitignore | 1 .idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml | 13 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_redis_1_4_2_RELEASE.xml | 13 src/main/java/com/hx/util/JwtConstant.java | 54 .idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_1.xml | 13 src/main/java/com/hx/util/OSSUtil.java | 126 src/main/java/com/hx/mp/util/WXSignUtils.java | 33 .idea/libraries/Maven__commons_lang_commons_lang_2_5.xml | 13 src/main/java/com/hx/util/RegValidatorUtil.java | 254 + .idea/libraries/Maven__com_google_zxing_core_3_3_0.xml | 13 .idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_0_5_RELEASE.xml | 13 .idea/libraries/hx_demoboot.xml | 9 .idea/vcs.xml | 6 .idea/modules.xml | 9 .idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml | 13 src/main/java/com/hx/mp/util/MD5Util.java | 43 .idea/libraries/Maven__com_zaxxer_HikariCP_2_7_9.xml | 13 src/main/java/com/hx/util/SimpleTool.java | 1053 +++++ .idea/libraries/Maven__org_springframework_spring_expression_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/util/HttpResponse.java | 32 .idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_13.xml | 13 .idea/libraries/Maven__net_glxn_qrgen_1_4.xml | 13 src/main/java/com/hx/annotation/Jurisdiction.java | 25 src/main/java/com/hx/exception/TipsException.java | 35 src/main/java/com/qq/weixin/mp/aes/SHA1.java | 61 .idea/$PRODUCT_WORKSPACE_FILE$ | 19 .idea/libraries/Maven__com_alibaba_druid_1_1_9.xml | 13 .idea/libraries/Maven__org_springframework_spring_context_support_5_0_9_RELEASE.xml | 13 .idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml | 13 .idea/libraries/Maven__org_apache_commons_commons_lang3_3_9.xml | 13 .idea/libraries/Maven__org_springframework_spring_context_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/mp/util/TenpayUtil.java | 132 src/main/java/com/qq/weixin/mp/aes/ByteGroup.java | 26 src/main/java/com/hx/mp/util/RequestHandler.java | 273 + .idea/libraries/Maven__com_belerweb_pinyin4j_2_5_1.xml | 13 .idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_1_1.xml | 13 src/main/java/com/qq/weixin/mp/aes/AesException.java | 59 src/main/main.iml | 12 .idea/libraries/Maven__mysql_mysql_connector_java_5_1_47.xml | 13 .idea/libraries/Maven__net_sourceforge_jexcelapi_jxl_2_6_12.xml | 13 .idea/libraries/Maven__org_mybatis_mybatis_3_4_0.xml | 13 .idea/libraries/Maven__org_springframework_spring_tx_5_0_9_RELEASE.xml | 13 src/main/java/com/hx/util/CheckCodeImageUtil.java | 96 .idea/libraries/Maven__javax_servlet_jsp_jstl_jstl_api_1_2.xml | 13 164 files changed, 12,586 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index a1c2a23..c836fce 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/target/ diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..3733e0d --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="masterDetails"> + <states> + <state key="ProjectJDKs.UI"> + <settings> + <last-edited>1.8</last-edited> + <splitter-proportions> + <option name="proportions"> + <list> + <option value="0.2" /> + </list> + </option> + </splitter-proportions> + </settings> + </state> + </states> + </component> +</project> \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..13e47b3 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <annotationProcessing> + <profile name="Maven default annotation processors profile" enabled="true"> + <sourceOutputDir name="target/generated-sources/annotations" /> + <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> + <outputRelativeToContentRoot value="true" /> + <module name="hx-common" /> + </profile> + </annotationProcessing> + <bytecodeTargetLevel> + <module name="hx-common" target="1.8" /> + </bytecodeTargetLevel> + </component> + <component name="JavacSettings"> + <option name="ADDITIONAL_OPTIONS_OVERRIDE"> + <module name="hx-common" options="-parameters" /> + </option> + </component> +</project> \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b26911b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding"> + <file url="file://$PROJECT_DIR$" charset="UTF-8" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/libraries/Maven__cglib_cglib_3_1.xml b/.idea/libraries/Maven__cglib_cglib_3_1.xml new file mode 100644 index 0000000..bd3cddd --- /dev/null +++ b/.idea/libraries/Maven__cglib_cglib_3_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: cglib:cglib:3.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib/3.1/cglib-3.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib/3.1/cglib-3.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/cglib/cglib/3.1/cglib-3.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_alibaba_druid_1_1_9.xml b/.idea/libraries/Maven__com_alibaba_druid_1_1_9.xml new file mode 100644 index 0000000..344bd1f --- /dev/null +++ b/.idea/libraries/Maven__com_alibaba_druid_1_1_9.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.alibaba:druid:1.1.9"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/druid/1.1.9/druid-1.1.9.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/druid/1.1.9/druid-1.1.9-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/druid/1.1.9/druid-1.1.9-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_alibaba_fastjson_1_2_47.xml b/.idea/libraries/Maven__com_alibaba_fastjson_1_2_47.xml new file mode 100644 index 0000000..dcd6ee5 --- /dev/null +++ b/.idea/libraries/Maven__com_alibaba_fastjson_1_2_47.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.alibaba:fastjson:1.2.47"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/fastjson/1.2.47/fastjson-1.2.47.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/fastjson/1.2.47/fastjson-1.2.47-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/fastjson/1.2.47/fastjson-1.2.47-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_aliyun_oss_aliyun_sdk_oss_2_8_3.xml b/.idea/libraries/Maven__com_aliyun_oss_aliyun_sdk_oss_2_8_3.xml new file mode 100644 index 0000000..910f84b --- /dev/null +++ b/.idea/libraries/Maven__com_aliyun_oss_aliyun_sdk_oss_2_8_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.aliyun.oss:aliyun-sdk-oss:2.8.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/aliyun/oss/aliyun-sdk-oss/2.8.3/aliyun-sdk-oss-2.8.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/aliyun/oss/aliyun-sdk-oss/2.8.3/aliyun-sdk-oss-2.8.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/aliyun/oss/aliyun-sdk-oss/2.8.3/aliyun-sdk-oss-2.8.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_auth0_java_jwt_3_10_3.xml b/.idea/libraries/Maven__com_auth0_java_jwt_3_10_3.xml new file mode 100644 index 0000000..7265d03 --- /dev/null +++ b/.idea/libraries/Maven__com_auth0_java_jwt_3_10_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.auth0:java-jwt:3.10.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/auth0/java-jwt/3.10.3/java-jwt-3.10.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/auth0/java-jwt/3.10.3/java-jwt-3.10.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/auth0/java-jwt/3.10.3/java-jwt-3.10.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_belerweb_pinyin4j_2_5_1.xml b/.idea/libraries/Maven__com_belerweb_pinyin4j_2_5_1.xml new file mode 100644 index 0000000..00b4ede --- /dev/null +++ b/.idea/libraries/Maven__com_belerweb_pinyin4j_2_5_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.belerweb:pinyin4j:2.5.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/belerweb/pinyin4j/2.5.1/pinyin4j-2.5.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/belerweb/pinyin4j/2.5.1/pinyin4j-2.5.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/belerweb/pinyin4j/2.5.1/pinyin4j-2.5.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml b/.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml new file mode 100644 index 0000000..33c30b4 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml:classmate:1.3.4"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/classmate/1.3.4/classmate-1.3.4.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/classmate/1.3.4/classmate-1.3.4-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/classmate/1.3.4/classmate-1.3.4-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml new file mode 100644 index 0000000..06441f4 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_6.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_6.xml new file mode 100644 index 0000000..eebe10d --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.6/jackson-core-2.9.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.6/jackson-core-2.9.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.9.6/jackson-core-2.9.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_6.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_6.xml new file mode 100644 index 0000000..51087da --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.6/jackson-databind-2.9.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.6/jackson-databind-2.9.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.6/jackson-databind-2.9.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml b/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml new file mode 100644 index 0000000..fa50d95 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.6/jackson-datatype-jdk8-2.9.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.6/jackson-datatype-jdk8-2.9.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.9.6/jackson-datatype-jdk8-2.9.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml b/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml new file mode 100644 index 0000000..7e20e35 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.6/jackson-datatype-jsr310-2.9.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.6/jackson-datatype-jsr310-2.9.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.9.6/jackson-datatype-jsr310-2.9.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml b/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml new file mode 100644 index 0000000..345adf8 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.6/jackson-module-parameter-names-2.9.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.6/jackson-module-parameter-names-2.9.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/module/jackson-module-parameter-names/2.9.6/jackson-module-parameter-names-2.9.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_gitee_sunchenbin_mybatis_actable_mybatis_enhance_actable_1_1_1_RELEASE.xml b/.idea/libraries/Maven__com_gitee_sunchenbin_mybatis_actable_mybatis_enhance_actable_1_1_1_RELEASE.xml new file mode 100644 index 0000000..f1308ec --- /dev/null +++ b/.idea/libraries/Maven__com_gitee_sunchenbin_mybatis_actable_mybatis_enhance_actable_1_1_1_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.gitee.sunchenbin.mybatis.actable:mybatis-enhance-actable:1.1.1.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/gitee/sunchenbin/mybatis/actable/mybatis-enhance-actable/1.1.1.RELEASE/mybatis-enhance-actable-1.1.1.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/gitee/sunchenbin/mybatis/actable/mybatis-enhance-actable/1.1.1.RELEASE/mybatis-enhance-actable-1.1.1.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/gitee/sunchenbin/mybatis/actable/mybatis-enhance-actable/1.1.1.RELEASE/mybatis-enhance-actable-1.1.1.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_2_0.xml b/.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_2_0.xml new file mode 100644 index 0000000..93b26b4 --- /dev/null +++ b/.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_2_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.github.jsqlparser:jsqlparser:2.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/github/jsqlparser/jsqlparser/2.0/jsqlparser-2.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/github/jsqlparser/jsqlparser/2.0/jsqlparser-2.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/github/jsqlparser/jsqlparser/2.0/jsqlparser-2.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_github_pagehelper_pagehelper_5_1_11.xml b/.idea/libraries/Maven__com_github_pagehelper_pagehelper_5_1_11.xml new file mode 100644 index 0000000..9760f7b --- /dev/null +++ b/.idea/libraries/Maven__com_github_pagehelper_pagehelper_5_1_11.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.github.pagehelper:pagehelper:5.1.11"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/github/pagehelper/pagehelper/5.1.11/pagehelper-5.1.11.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/github/pagehelper/pagehelper/5.1.11/pagehelper-5.1.11-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/github/pagehelper/pagehelper/5.1.11/pagehelper-5.1.11-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_code_gson_gson_2_8_5.xml b/.idea/libraries/Maven__com_google_code_gson_gson_2_8_5.xml new file mode 100644 index 0000000..2888f96 --- /dev/null +++ b/.idea/libraries/Maven__com_google_code_gson_gson_2_8_5.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.google.code.gson:gson:2.8.5"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_zxing_core_3_3_0.xml b/.idea/libraries/Maven__com_google_zxing_core_3_3_0.xml new file mode 100644 index 0000000..c44fbe8 --- /dev/null +++ b/.idea/libraries/Maven__com_google_zxing_core_3_3_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.google.zxing:core:3.3.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/core/3.3.0/core-3.3.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/core/3.3.0/core-3.3.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/core/3.3.0/core-3.3.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_zxing_javase_3_0_0.xml b/.idea/libraries/Maven__com_google_zxing_javase_3_0_0.xml new file mode 100644 index 0000000..e5a753c --- /dev/null +++ b/.idea/libraries/Maven__com_google_zxing_javase_3_0_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.google.zxing:javase:3.0.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/javase/3.0.0/javase-3.0.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/javase/3.0.0/javase-3.0.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/google/zxing/javase/3.0.0/javase-3.0.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_mail_javax_mail_1_6_2.xml b/.idea/libraries/Maven__com_sun_mail_javax_mail_1_6_2.xml new file mode 100644 index 0000000..f5980e4 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_mail_javax_mail_1_6_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.sun.mail:javax.mail:1.6.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/sun/mail/javax.mail/1.6.2/javax.mail-1.6.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/sun/mail/javax.mail/1.6.2/javax.mail-1.6.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/sun/mail/javax.mail/1.6.2/javax.mail-1.6.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__com_zaxxer_HikariCP_2_7_9.xml b/.idea/libraries/Maven__com_zaxxer_HikariCP_2_7_9.xml new file mode 100644 index 0000000..6d6865c --- /dev/null +++ b/.idea/libraries/Maven__com_zaxxer_HikariCP_2_7_9.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: com.zaxxer:HikariCP:2.7.9"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/2.7.9/HikariCP-2.7.9.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/2.7.9/HikariCP-2.7.9-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/2.7.9/HikariCP-2.7.9-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_9_3.xml b/.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_9_3.xml new file mode 100644 index 0000000..687a60e --- /dev/null +++ b/.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_9_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-beanutils:commons-beanutils:1.9.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_codec_commons_codec_1_11.xml b/.idea/libraries/Maven__commons_codec_commons_codec_1_11.xml new file mode 100644 index 0000000..4c8ff54 --- /dev/null +++ b/.idea/libraries/Maven__commons_codec_commons_codec_1_11.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-codec:commons-codec:1.11"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.11/commons-codec-1.11.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.11/commons-codec-1.11-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.11/commons-codec-1.11-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_collections_commons_collections_3_2_2.xml b/.idea/libraries/Maven__commons_collections_commons_collections_3_2_2.xml new file mode 100644 index 0000000..13afda2 --- /dev/null +++ b/.idea/libraries/Maven__commons_collections_commons_collections_3_2_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-collections:commons-collections:3.2.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_io_commons_io_2_6.xml b/.idea/libraries/Maven__commons_io_commons_io_2_6.xml new file mode 100644 index 0000000..d722698 --- /dev/null +++ b/.idea/libraries/Maven__commons_io_commons_io_2_6.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-io:commons-io:2.6"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.6/commons-io-2.6.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.6/commons-io-2.6-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.6/commons-io-2.6-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_lang_commons_lang_2_5.xml b/.idea/libraries/Maven__commons_lang_commons_lang_2_5.xml new file mode 100644 index 0000000..055afe5 --- /dev/null +++ b/.idea/libraries/Maven__commons_lang_commons_lang_2_5.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-lang:commons-lang:2.5"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.5/commons-lang-2.5.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.5/commons-lang-2.5-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.5/commons-lang-2.5-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml b/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml new file mode 100644 index 0000000..eab40b3 --- /dev/null +++ b/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: commons-logging:commons-logging:1.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__io_jsonwebtoken_jjwt_0_9_1.xml b/.idea/libraries/Maven__io_jsonwebtoken_jjwt_0_9_1.xml new file mode 100644 index 0000000..f25b99b --- /dev/null +++ b/.idea/libraries/Maven__io_jsonwebtoken_jjwt_0_9_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: io.jsonwebtoken:jjwt:0.9.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/io/jsonwebtoken/jjwt/0.9.1/jjwt-0.9.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/io/jsonwebtoken/jjwt/0.9.1/jjwt-0.9.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/io/jsonwebtoken/jjwt/0.9.1/jjwt-0.9.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_activation_activation_1_1.xml b/.idea/libraries/Maven__javax_activation_activation_1_1.xml new file mode 100644 index 0000000..180d587 --- /dev/null +++ b/.idea/libraries/Maven__javax_activation_activation_1_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.activation:activation:1.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/activation/activation/1.1/activation-1.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/activation/activation/1.1/activation-1.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/activation/activation/1.1/activation-1.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml b/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml new file mode 100644 index 0000000..e74f3ab --- /dev/null +++ b/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.annotation:javax.annotation-api:1.3.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_1.xml b/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_1.xml new file mode 100644 index 0000000..4b5f67f --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.servlet.jsp:jsp-api:2.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jsp_jstl_jstl_api_1_2.xml b/.idea/libraries/Maven__javax_servlet_jsp_jstl_jstl_api_1_2.xml new file mode 100644 index 0000000..075b025 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jsp_jstl_jstl_api_1_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.servlet.jsp.jstl:jstl-api:1.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jstl/jstl-api/1.2/jstl-api-1.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jstl/jstl-api/1.2/jstl-api-1.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jsp/jstl/jstl-api/1.2/jstl-api-1.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml b/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml new file mode 100644 index 0000000..f329893 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.servlet:jstl:1.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jstl/1.2/jstl-1.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jstl/1.2/jstl-1.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/jstl/1.2/jstl-1.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml b/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml new file mode 100644 index 0000000..679e09a --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.servlet:servlet-api:2.5"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/servlet-api/2.5/servlet-api-2.5-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml b/.idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml new file mode 100644 index 0000000..6978c0b --- /dev/null +++ b/.idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: javax.validation:validation-api:2.0.1.Final"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/javax/validation/validation-api/2.0.1.Final/validation-api-2.0.1.Final-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: junit:junit:4.12"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__log4j_log4j_1_2_14.xml b/.idea/libraries/Maven__log4j_log4j_1_2_14.xml new file mode 100644 index 0000000..2825a67 --- /dev/null +++ b/.idea/libraries/Maven__log4j_log4j_1_2_14.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: log4j:log4j:1.2.14"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_47.xml b/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_47.xml new file mode 100644 index 0000000..8ed561b --- /dev/null +++ b/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_47.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: mysql:mysql-connector-java:5.1.47"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__net_glxn_qrgen_1_4.xml b/.idea/libraries/Maven__net_glxn_qrgen_1_4.xml new file mode 100644 index 0000000..75d0911 --- /dev/null +++ b/.idea/libraries/Maven__net_glxn_qrgen_1_4.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: net.glxn:qrgen:1.4"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/net/glxn/qrgen/1.4/qrgen-1.4.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/net/glxn/qrgen/1.4/qrgen-1.4-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/net/glxn/qrgen/1.4/qrgen-1.4-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__net_sf_ezmorph_ezmorph_1_0_3.xml b/.idea/libraries/Maven__net_sf_ezmorph_ezmorph_1_0_3.xml new file mode 100644 index 0000000..9812d38 --- /dev/null +++ b/.idea/libraries/Maven__net_sf_ezmorph_ezmorph_1_0_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: net.sf.ezmorph:ezmorph:1.0.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.3/ezmorph-1.0.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.3/ezmorph-1.0.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.3/ezmorph-1.0.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__net_sf_json_lib_json_lib_jdk15_2_4.xml b/.idea/libraries/Maven__net_sf_json_lib_json_lib_jdk15_2_4.xml new file mode 100644 index 0000000..7c6b3e6 --- /dev/null +++ b/.idea/libraries/Maven__net_sf_json_lib_json_lib_jdk15_2_4.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: net.sf.json-lib:json-lib:jdk15:2.4"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__net_sourceforge_jexcelapi_jxl_2_6_12.xml b/.idea/libraries/Maven__net_sourceforge_jexcelapi_jxl_2_6_12.xml new file mode 100644 index 0000000..19e6af8 --- /dev/null +++ b/.idea/libraries/Maven__net_sourceforge_jexcelapi_jxl_2_6_12.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: net.sourceforge.jexcelapi:jxl:2.6.12"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_9.xml b/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_9.xml new file mode 100644 index 0000000..9050e00 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_9.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apache.commons:commons-lang3:3.9"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_5_0.xml b/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_5_0.xml new file mode 100644 index 0000000..440e770 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_5_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apache.commons:commons-pool2:2.5.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.5.0/commons-pool2-2.5.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.5.0/commons-pool2-2.5.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.5.0/commons-pool2-2.5.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_12.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_12.xml new file mode 100644 index 0000000..9cb68a2 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_12.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apache.httpcomponents:httpclient:4.5.12"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.12/httpclient-4.5.12.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.12/httpclient-4.5.12-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.12/httpclient-4.5.12-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_13.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_13.xml new file mode 100644 index 0000000..b475675 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_13.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apache.httpcomponents:httpcore:4.4.13"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_poi_poi_3_9.xml b/.idea/libraries/Maven__org_apache_poi_poi_3_9.xml new file mode 100644 index 0000000..a0ffd89 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_poi_poi_3_9.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.apache.poi:poi:3.9"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/poi/poi/3.9/poi-3.9.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/poi/poi/3.9/poi-3.9-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/apache/poi/poi/3.9/poi-3.9-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_66.xml b/.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_66.xml new file mode 100644 index 0000000..fd9556c --- /dev/null +++ b/.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_66.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.bouncycastle:bcprov-jdk15on:1.66"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/bouncycastle/bcprov-jdk15on/1.66/bcprov-jdk15on-1.66.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/bouncycastle/bcprov-jdk15on/1.66/bcprov-jdk15on-1.66-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/bouncycastle/bcprov-jdk15on/1.66/bcprov-jdk15on-1.66-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_dom4j_dom4j_2_1_3.xml b/.idea/libraries/Maven__org_dom4j_dom4j_2_1_3.xml new file mode 100644 index 0000000..10fb46a --- /dev/null +++ b/.idea/libraries/Maven__org_dom4j_dom4j_2_1_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.dom4j:dom4j:2.1.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/dom4j/dom4j/2.1.3/dom4j-2.1.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/dom4j/dom4j/2.1.3/dom4j-2.1.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/dom4j/dom4j/2.1.3/dom4j-2.1.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml b/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml new file mode 100644 index 0000000..3471c5b --- /dev/null +++ b/.idea/libraries/Maven__org_freemarker_freemarker_2_3_28.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.freemarker:freemarker:2.3.28"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/freemarker/freemarker/2.3.28/freemarker-2.3.28.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/freemarker/freemarker/2.3.28/freemarker-2.3.28-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/freemarker/freemarker/2.3.28/freemarker-2.3.28-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.hamcrest:hamcrest-core:1.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_12_Final.xml b/.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_12_Final.xml new file mode 100644 index 0000000..c019431 --- /dev/null +++ b/.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_12_Final.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.hibernate.validator:hibernate-validator:6.0.12.Final"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/validator/hibernate-validator/6.0.12.Final/hibernate-validator-6.0.12.Final.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/validator/hibernate-validator/6.0.12.Final/hibernate-validator-6.0.12.Final-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/hibernate/validator/hibernate-validator/6.0.12.Final/hibernate-validator-6.0.12.Final-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml b/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml new file mode 100644 index 0000000..5f7dd01 --- /dev/null +++ b/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_jdom_jdom_1_1_3.xml b/.idea/libraries/Maven__org_jdom_jdom_1_1_3.xml new file mode 100644 index 0000000..f7f5b46 --- /dev/null +++ b/.idea/libraries/Maven__org_jdom_jdom_1_1_3.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.jdom:jdom:1.1.3"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/jdom/jdom/1.1.3/jdom-1.1.3.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/jdom/jdom/1.1.3/jdom-1.1.3-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/jdom/jdom/1.1.3/jdom-1.1.3-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_mybatis_3_4_0.xml b/.idea/libraries/Maven__org_mybatis_mybatis_3_4_0.xml new file mode 100644 index 0000000..655ae2e --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_mybatis_3_4_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.mybatis:mybatis:3.4.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis/3.4.0/mybatis-3.4.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis/3.4.0/mybatis-3.4.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis/3.4.0/mybatis-3.4.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml b/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml new file mode 100644 index 0000000..bd108d5 --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.mybatis:mybatis-spring:1.3.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis-spring/1.3.0/mybatis-spring-1.3.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis-spring/1.3.0/mybatis-spring-1.3.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/mybatis-spring/1.3.0/mybatis-spring-1.3.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_1_1.xml b/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_1_1.xml new file mode 100644 index 0000000..218b48a --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_1_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.1.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-autoconfigure/1.1.1/mybatis-spring-boot-autoconfigure-1.1.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-autoconfigure/1.1.1/mybatis-spring-boot-autoconfigure-1.1.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-autoconfigure/1.1.1/mybatis-spring-boot-autoconfigure-1.1.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_1_1.xml b/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_1_1.xml new file mode 100644 index 0000000..77694f1 --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_1_1.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-starter/1.1.1/mybatis-spring-boot-starter-1.1.1.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-starter/1.1.1/mybatis-spring-boot-starter-1.1.1-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/mybatis/spring/boot/mybatis-spring-boot-starter/1.1.1/mybatis-spring-boot-starter-1.1.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_4_2.xml b/.idea/libraries/Maven__org_ow2_asm_asm_4_2.xml new file mode 100644 index 0000000..b5e3748 --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_4_2.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.ow2.asm:asm:4.2"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/4.2/asm-4.2.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/4.2/asm-4.2-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/4.2/asm-4.2-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_projectlombok_lombok_1_16_22.xml b/.idea/libraries/Maven__org_projectlombok_lombok_1_16_22.xml new file mode 100644 index 0000000..763e50d --- /dev/null +++ b/.idea/libraries/Maven__org_projectlombok_lombok_1_16_22.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.projectlombok:lombok:1.16.22"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.22/lombok-1.16.22.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.22/lombok-1.16.22-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.22/lombok-1.16.22-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml new file mode 100644 index 0000000..20e8163 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.slf4j:slf4j-api:1.7.25"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_2_0_5_RELEASE.xml new file mode 100644 index 0000000..694ace0 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.5.RELEASE/spring-boot-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.5.RELEASE/spring-boot-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot/2.0.5.RELEASE/spring-boot-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_5_RELEASE.xml new file mode 100644 index 0000000..487c520 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.5.RELEASE/spring-boot-autoconfigure-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.5.RELEASE/spring-boot-autoconfigure-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-autoconfigure/2.0.5.RELEASE/spring-boot-autoconfigure-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_0_5_RELEASE.xml new file mode 100644 index 0000000..dc46324 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-starter:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter/2.0.5.RELEASE/spring-boot-starter-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter/2.0.5.RELEASE/spring-boot-starter-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter/2.0.5.RELEASE/spring-boot-starter-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_redis_1_4_2_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_redis_1_4_2_RELEASE.xml new file mode 100644 index 0000000..c30cc3d --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_redis_1_4_2_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-starter-data-redis:1.4.2.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-data-redis/1.4.2.RELEASE/spring-boot-starter-data-redis-1.4.2.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-data-redis/1.4.2.RELEASE/spring-boot-starter-data-redis-1.4.2.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-data-redis/1.4.2.RELEASE/spring-boot-starter-data-redis-1.4.2.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_0_5_RELEASE.xml new file mode 100644 index 0000000..76d2fe0 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-jdbc/2.0.5.RELEASE/spring-boot-starter-jdbc-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-jdbc/2.0.5.RELEASE/spring-boot-starter-jdbc-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-jdbc/2.0.5.RELEASE/spring-boot-starter-jdbc-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_0_5_RELEASE.xml new file mode 100644 index 0000000..7e50280 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-starter-json:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-json/2.0.5.RELEASE/spring-boot-starter-json-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-json/2.0.5.RELEASE/spring-boot-starter-json-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-json/2.0.5.RELEASE/spring-boot-starter-json-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_0_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_0_5_RELEASE.xml new file mode 100644 index 0000000..454ee43 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_0_5_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-web/2.0.5.RELEASE/spring-boot-starter-web-2.0.5.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-web/2.0.5.RELEASE/spring-boot-starter-web-2.0.5.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-web/2.0.5.RELEASE/spring-boot-starter-web-2.0.5.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_commons_2_0_10_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_commons_2_0_10_RELEASE.xml new file mode 100644 index 0000000..a634019 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_data_spring_data_commons_2_0_10_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.data:spring-data-commons:2.0.10.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-commons/2.0.10.RELEASE/spring-data-commons-2.0.10.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-commons/2.0.10.RELEASE/spring-data-commons-2.0.10.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-commons/2.0.10.RELEASE/spring-data-commons-2.0.10.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_2_0_10_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_2_0_10_RELEASE.xml new file mode 100644 index 0000000..f277e85 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_2_0_10_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.data:spring-data-keyvalue:2.0.10.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-keyvalue/2.0.10.RELEASE/spring-data-keyvalue-2.0.10.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-keyvalue/2.0.10.RELEASE/spring-data-keyvalue-2.0.10.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-keyvalue/2.0.10.RELEASE/spring-data-keyvalue-2.0.10.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_data_spring_data_redis_2_0_10_RELEASE.xml b/.idea/libraries/Maven__org_springframework_data_spring_data_redis_2_0_10_RELEASE.xml new file mode 100644 index 0000000..9646d84 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_data_spring_data_redis_2_0_10_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework.data:spring-data-redis:2.0.10.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-redis/2.0.10.RELEASE/spring-data-redis-2.0.10.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-redis/2.0.10.RELEASE/spring-data-redis-2.0.10.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/data/spring-data-redis/2.0.10.RELEASE/spring-data-redis-2.0.10.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml new file mode 100644 index 0000000..d72ff5a --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-aop:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.9.RELEASE/spring-aop-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.9.RELEASE/spring-aop-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-aop/5.0.9.RELEASE/spring-aop-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_beans_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_beans_5_0_9_RELEASE.xml new file mode 100644 index 0000000..f606e1f --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_beans_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-beans:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.9.RELEASE/spring-beans-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.9.RELEASE/spring-beans-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-beans/5.0.9.RELEASE/spring-beans-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_context_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_context_5_0_9_RELEASE.xml new file mode 100644 index 0000000..1444af1 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_context_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-context:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.9.RELEASE/spring-context-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.9.RELEASE/spring-context-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/5.0.9.RELEASE/spring-context-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_context_support_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_context_support_5_0_9_RELEASE.xml new file mode 100644 index 0000000..5df5664 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_context_support_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-context-support:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/5.0.9.RELEASE/spring-context-support-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/5.0.9.RELEASE/spring-context-support-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-context-support/5.0.9.RELEASE/spring-context-support-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_core_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_core_5_0_9_RELEASE.xml new file mode 100644 index 0000000..15a89a5 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_core_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-core:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.9.RELEASE/spring-core-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.9.RELEASE/spring-core-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-core/5.0.9.RELEASE/spring-core-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_expression_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_expression_5_0_9_RELEASE.xml new file mode 100644 index 0000000..b5c312e --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_expression_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-expression:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.9.RELEASE/spring-expression-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.9.RELEASE/spring-expression-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-expression/5.0.9.RELEASE/spring-expression-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_jcl_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_jcl_5_0_9_RELEASE.xml new file mode 100644 index 0000000..847069e --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_jcl_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-jcl:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.9.RELEASE/spring-jcl-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.9.RELEASE/spring-jcl-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jcl/5.0.9.RELEASE/spring-jcl-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_9_RELEASE.xml new file mode 100644 index 0000000..59978cc --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-jdbc:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.9.RELEASE/spring-jdbc-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.9.RELEASE/spring-jdbc-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-jdbc/5.0.9.RELEASE/spring-jdbc-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_oxm_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_oxm_5_0_9_RELEASE.xml new file mode 100644 index 0000000..d466a05 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_oxm_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-oxm:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-oxm/5.0.9.RELEASE/spring-oxm-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-oxm/5.0.9.RELEASE/spring-oxm-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-oxm/5.0.9.RELEASE/spring-oxm-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_tx_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_tx_5_0_9_RELEASE.xml new file mode 100644 index 0000000..79735e2 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_tx_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-tx:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-tx/5.0.9.RELEASE/spring-tx-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-tx/5.0.9.RELEASE/spring-tx-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-tx/5.0.9.RELEASE/spring-tx-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_web_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_web_5_0_9_RELEASE.xml new file mode 100644 index 0000000..6700b12 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_web_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-web:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-web/5.0.9.RELEASE/spring-web-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-web/5.0.9.RELEASE/spring-web-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-web/5.0.9.RELEASE/spring-web-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_9_RELEASE.xml new file mode 100644 index 0000000..392a5f3 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_9_RELEASE.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.springframework:spring-webmvc:5.0.9.RELEASE"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-webmvc/5.0.9.RELEASE/spring-webmvc-5.0.9.RELEASE.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-webmvc/5.0.9.RELEASE/spring-webmvc-5.0.9.RELEASE-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/springframework/spring-webmvc/5.0.9.RELEASE/spring-webmvc-5.0.9.RELEASE-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_19.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_19.xml new file mode 100644 index 0000000..33ccf19 --- /dev/null +++ b/.idea/libraries/Maven__org_yaml_snakeyaml_1_19.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: org.yaml:snakeyaml:1.19"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.19/snakeyaml-1.19.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.19/snakeyaml-1.19-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/org/yaml/snakeyaml/1.19/snakeyaml-1.19-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml b/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml new file mode 100644 index 0000000..77144ff --- /dev/null +++ b/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="Maven: redis.clients:jedis:2.9.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0.jar!/" /> + </CLASSES> + <JAVADOC> + <root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0-javadoc.jar!/" /> + </JAVADOC> + <SOURCES> + <root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file diff --git a/.idea/libraries/hx_demoboot.xml b/.idea/libraries/hx_demoboot.xml new file mode 100644 index 0000000..0f3f912 --- /dev/null +++ b/.idea/libraries/hx_demoboot.xml @@ -0,0 +1,9 @@ +<component name="libraryTable"> + <library name="hx-demoboot"> + <CLASSES> + <root url="jar://$PROJECT_DIR$/target/hx-demoboot.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e8942bd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="MavenProjectsManager"> + <option name="originalFiles"> + <list> + <option value="$PROJECT_DIR$/pom.xml" /> + </list> + </option> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4800ad9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/hx-common.iml" filepath="$PROJECT_DIR$/hx-common.iml" /> + <module fileurl="file://$PROJECT_DIR$/src/main/main.iml" filepath="$PROJECT_DIR$/src/main/main.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/hx-common.iml b/hx-common.iml new file mode 100644 index 0000000..e2d5751 --- /dev/null +++ b/hx-common.iml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> + <component name="FacetManager"> + <facet type="Spring" name="Spring"> + <configuration /> + </facet> + <facet type="web" name="Web"> + <configuration> + <webroots /> + </configuration> + </facet> + </component> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" /> + <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" /> + <orderEntry type="library" name="Maven: com.aliyun.oss:aliyun-sdk-oss:2.8.3" level="project" /> + <orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.66" level="project" /> + <orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.3" level="project" /> + <orderEntry type="library" name="Maven: org.jdom:jdom:1.1.3" level="project" /> + <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" /> + <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.12" level="project" /> + <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> + <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" /> + <orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" /> + <orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" /> + <orderEntry type="library" name="Maven: com.google.zxing:core:3.3.0" level="project" /> + <orderEntry type="library" name="Maven: net.glxn:qrgen:1.4" level="project" /> + <orderEntry type="library" name="Maven: com.google.zxing:javase:3.0.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" /> + <orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" /> + <orderEntry type="library" name="Maven: org.apache.poi:poi:3.9" level="project" /> + <orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.5.0" level="project" /> + <orderEntry type="library" name="Maven: com.auth0:java-jwt:3.10.3" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" /> + <orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt:0.9.1" level="project" /> + <orderEntry type="library" name="Maven: javax.servlet.jsp.jstl:jstl-api:1.2" level="project" /> + <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" /> + <orderEntry type="library" name="Maven: javax.servlet.jsp:jsp-api:2.1" level="project" /> + <orderEntry type="library" name="Maven: javax.servlet:jstl:1.2" level="project" /> + <orderEntry type="library" name="Maven: com.gitee.sunchenbin.mybatis.actable:mybatis-enhance-actable:1.1.1.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.28" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:1.4.2.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.0.10.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.0.10.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.0.10.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-tx:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.22" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.19" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.6" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.6" level="project" /> + <orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.12.Final" level="project" /> + <orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" /> + <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-web:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1" level="project" /> + <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.1.1" level="project" /> + <orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.0" level="project" /> + <orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.0" level="project" /> + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.0.5.RELEASE" level="project" /> + <orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.7.9" level="project" /> + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> + <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.0.9.RELEASE" level="project" /> + <orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:5.1.47" level="project" /> + <orderEntry type="library" name="Maven: com.alibaba:druid:1.1.9" level="project" /> + <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.47" level="project" /> + <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" /> + <orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" /> + <orderEntry type="library" name="Maven: com.belerweb:pinyin4j:2.5.1" level="project" /> + <orderEntry type="library" name="Maven: net.sourceforge.jexcelapi:jxl:2.6.12" level="project" /> + <orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" /> + <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.3" level="project" /> + <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" /> + <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" /> + <orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.3" level="project" /> + <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" /> + <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> + <orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.1.11" level="project" /> + <orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:2.0" level="project" /> + </component> +</module> \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..66d0d15 --- /dev/null +++ b/pom.xml @@ -0,0 +1,268 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>com.hx.gitee</groupId> + <artifactId>hx-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>hx-common</artifactId> + <packaging>jar</packaging> + + + <dependencies> + + <!--鍙戦�侀偖浠�--> + <dependency> + <groupId>com.sun.mail</groupId> + <artifactId>javax.mail</artifactId> + </dependency> + + <dependency> + <groupId>com.aliyun.oss</groupId> + <artifactId>aliyun-sdk-oss</artifactId> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on --> + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-jdk15on</artifactId> + </dependency> + + <!--寰俊鏀粯鐢ㄥ埌鐨勫寘--> + <dependency> + <groupId>org.dom4j</groupId> + <artifactId>dom4j</artifactId> + </dependency> + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom</artifactId> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> + + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </dependency> + <!--<dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency>--> + + <!--鐢熸垚浜岀淮鐮佹敮鎸佸寘--> + <dependency> + <groupId>com.google.zxing</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> + <groupId>net.glxn</groupId> + <artifactId>qrgen</artifactId> + </dependency> + + <!-- 瀛楃涓插伐鍏风被jar:StringUtils --> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <!-- excel2003浣跨敤鐨刯ar --> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + </dependency> + <dependency> + <groupId>redis.clients</groupId> + <artifactId>jedis</artifactId> + </dependency> + + <dependency> + <groupId>com.auth0</groupId> + <artifactId>java-jwt</artifactId> + </dependency> + <dependency> + <groupId>io.jsonwebtoken</groupId> + <artifactId>jjwt</artifactId> + </dependency> + + <dependency> + <groupId>javax.servlet.jsp.jstl</groupId> + <artifactId>jstl-api</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + </dependency> + + <!-- mybatis鑷姩鐢熸垚 --> + <dependency> + <groupId>com.gitee.sunchenbin.mybatis.actable</groupId> + <artifactId>mybatis-enhance-actable</artifactId> + </dependency> + + <!-- 妯℃澘鐢熸垚jar --> + <dependency> + <groupId>org.freemarker</groupId> + <artifactId>freemarker</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.mybatis.spring.boot</groupId> + <artifactId>mybatis-spring-boot-starter</artifactId><exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> + </exclusion> + </exclusions> + + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>druid</artifactId> + </dependency> + + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>fastjson</artifactId> + </dependency> + + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <classifier>jdk15</classifier> + </dependency> + + <dependency> + <groupId>com.belerweb</groupId> + <artifactId>pinyin4j</artifactId> + </dependency> + + <dependency> + <groupId>net.sourceforge.jexcelapi</groupId> + <artifactId>jxl</artifactId> + </dependency> + + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <exclusions> + <exclusion> + <artifactId>commons-logging</artifactId> + <groupId>commons-logging</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>net.sf.ezmorph</groupId> + <artifactId>ezmorph</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>com.github.pagehelper</groupId> + <artifactId>pagehelper</artifactId> + </dependency> + </dependencies> + + <build> + <finalName>hx-demoboot</finalName> + <resources> + <resource> + <directory>src/main/java</directory> + <includes> + <include>**/*.properties</include> + <include>**/*.xml</include> + <include>**/*.tld</include> + <include>**/*.tpl</include> + </includes> + <filtering>false</filtering> + </resource> + <resource> + <directory>src/main/resources</directory> + <excludes> + <exclude>profile-active/**</exclude> + </excludes> + </resource> + <resource> + <directory>${runtime.env}</directory> + </resource> + </resources> + </build> + +</project> \ No newline at end of file diff --git a/src/main/java/com/hx/annotation/Jurisdiction.java b/src/main/java/com/hx/annotation/Jurisdiction.java new file mode 100644 index 0000000..764d680 --- /dev/null +++ b/src/main/java/com/hx/annotation/Jurisdiction.java @@ -0,0 +1,25 @@ +package com.hx.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/**鏉冮檺娉ㄨВ + * @author chenjiahe + * @version 2019骞�09鏈�14鏃� 涓嬪崍6:13:37 + */ +//琛ㄧず娉ㄨВ鍔犲湪鎺ュ彛銆佺被銆佹灇涓剧瓑 +@Target(ElementType.METHOD) +//VM灏嗗湪杩愯鏈熶篃淇濈暀娉ㄩ噴锛屽洜姝ゅ彲浠ラ�氳繃鍙嶅皠鏈哄埗璇诲彇娉ㄨВ鐨勪俊鎭� +@Retention(RetentionPolicy.RUNTIME) +//灏嗘娉ㄨВ鍖呭惈鍦╦avadoc涓� +@Documented +//鍏佽瀛愮被缁ф壙鐖剁被涓殑娉ㄨВ +@Inherited +public @interface Jurisdiction { + /**鏉冮檺鍚�*/ + String privilege(); +} diff --git a/src/main/java/com/hx/common/CommonInit.java b/src/main/java/com/hx/common/CommonInit.java new file mode 100644 index 0000000..5caaf8f --- /dev/null +++ b/src/main/java/com/hx/common/CommonInit.java @@ -0,0 +1,97 @@ +package com.hx.common; + +import com.hx.exception.ParamException; +import com.hx.exception.ServiceException; +import com.hx.mybatisTool.SqlParam; +import com.hx.mybatisTool.SqlSentence; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.context.request.WebRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +/**鍏叡鍒濆鍖� + * @author ChenJiaHe + * @Date 2020-06-11 + */ + +public class CommonInit { + + /*璇蜂笉瑕佸0鏄庡彉閲忥紝浼氬鑷翠笉瀹夊叏锛屽洜涓鸿繖涓槸鍗曞垪*/ + + protected HttpServletRequest request = null; + protected HttpSession session = null; + + + //鍙渶瑕佸姞涓婁笅闈㈣繖娈靛嵆鍙紝娉ㄦ剰涓嶈兘蹇樿娉ㄨВ + @InitBinder + public void initBinder(WebDataBinder binder, WebRequest request) { + //杞崲鏃ユ湡 娉ㄦ剰杩欓噷鐨勮浆鍖栬鍜屼紶杩涙潵鐨勫瓧绗︿覆鐨勬牸寮忎竴鐩� 濡�2015-9-9 灏卞簲璇ヤ负yyyy-MM-dd + DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor涓鸿嚜瀹氫箟鏃ユ湡缂栬緫鍣� + } + + public HttpServletRequest getRequest() { + //鑾峰彇鍙傛暟瀵硅薄 + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + request = attributes.getRequest(); + return request; + } + + public HttpSession getSession() { + //鑾峰彇鍙傛暟瀵硅薄 + session = getRequest() .getSession(); + return session; + } + + /** + * 鑾峰彇request閲屾煇涓睘鎬� + * @param attrName 灞炴�у悕绉� + * @return 瀵硅薄 + */ + public Object getRequestAttribute(String attrName) + { + return getRequest().getAttribute(attrName); + } + + /** + * 璁剧疆涓�涓猺equest灞炴�� + * @param attrName 灞炴�у悕绉� + * @param attrObject 灞炴�у�� + */ + public void setRequestAttribute(String attrName, Object attrObject) { + getRequest().setAttribute(attrName, attrObject); + } + + + + /** + * 鎶涘嚭鏈嶅姟寮傚父 + * @param msg 閿欒淇℃伅 + */ + public void throwServiceException(String msg) + { + throw new ServiceException(msg); + } + + /** + * 鎶涘嚭鍙傛暟寮傚父 + * @param msg 閿欒淇℃伅 + */ + public void throwParamException(String msg) + { + throw new ParamException(msg); + } + + +} diff --git a/src/main/java/com/hx/exception/ParamException.java b/src/main/java/com/hx/exception/ParamException.java new file mode 100644 index 0000000..1aa3f39 --- /dev/null +++ b/src/main/java/com/hx/exception/ParamException.java @@ -0,0 +1,12 @@ +package com.hx.exception; + +/** 鍙傛暟寮傚父 + * @author ChenJiaHe + * @Date 2020-06-19 + */ +public class ParamException extends RuntimeException { + + public ParamException(String message) { + super(message); + } +} diff --git a/src/main/java/com/hx/exception/ServiceException.java b/src/main/java/com/hx/exception/ServiceException.java new file mode 100644 index 0000000..f76edde --- /dev/null +++ b/src/main/java/com/hx/exception/ServiceException.java @@ -0,0 +1,34 @@ +package com.hx.exception; + +/** 鍒ゆ柇寮傚父/涓氬姟寮傚父 + * @author ChenJiaHe + * @Date 2020-06-19 + */ +public class ServiceException extends RuntimeException { + + private Integer code; + + public ServiceException(String message) { + super(message); + } + + public ServiceException(String message, Integer code) { + super(message); + this.code = code; + } + + public ServiceException(String message, Throwable cause, Integer code) { + super(message, cause); + this.code = code; + } + + public ServiceException(Throwable cause, Integer code) { + super(cause); + this.code = code; + } + + //@Override + public int getCode() { + return this.code; + } +} diff --git a/src/main/java/com/hx/exception/TipsException.java b/src/main/java/com/hx/exception/TipsException.java new file mode 100644 index 0000000..6bfdc44 --- /dev/null +++ b/src/main/java/com/hx/exception/TipsException.java @@ -0,0 +1,35 @@ +package com.hx.exception; + +/** + * 鍓嶇鎻愮ず寮傚父 + * @author ChenJiaHe + * @Date 2020-06-19 + */ +public class TipsException extends RuntimeException { + + private Integer code; + + public TipsException(String message) { + super(message); + } + + public TipsException(String message, Integer code) { + super(message); + this.code = code; + } + + public TipsException(String message, Throwable cause, Integer code) { + super(message, cause); + this.code = code; + } + + public TipsException(Throwable cause, Integer code) { + super(cause); + this.code = code; + } + + //@Override + public int getCode() { + return this.code; + } +} diff --git a/src/main/java/com/hx/mp/util/CertUtil.java b/src/main/java/com/hx/mp/util/CertUtil.java new file mode 100644 index 0000000..2483d1c --- /dev/null +++ b/src/main/java/com/hx/mp/util/CertUtil.java @@ -0,0 +1,31 @@ +package com.hx.mp.util; + +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContexts; + +import javax.net.ssl.SSLContext; +import java.io.File; +import java.io.FileInputStream; +import java.security.KeyStore; + +@SuppressWarnings("deprecation") +public class CertUtil { + /** + * 鍔犺浇璇佷功 + */ + public static SSLConnectionSocketFactory initCert(String certPath, String mchId) throws Exception { + FileInputStream instream = null; + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + instream = new FileInputStream(new File(certPath)); + keyStore.load(instream, mchId.toCharArray()); + + if (null != instream) { + instream.close(); + } + + SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,mchId.toCharArray()).build(); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + + return sslsf; + } +} diff --git a/src/main/java/com/hx/mp/util/ClientResponseHandler.java b/src/main/java/com/hx/mp/util/ClientResponseHandler.java new file mode 100644 index 0000000..0d03f4a --- /dev/null +++ b/src/main/java/com/hx/mp/util/ClientResponseHandler.java @@ -0,0 +1,228 @@ +package com.hx.mp.util; + +import org.jdom.JDOMException; + +import java.io.IOException; +import java.util.*; + +/** + * 锟斤拷台应锟斤拷锟斤拷<br/> + * ========================================================================<br/> + * api说锟斤拷锟斤拷<br/> + * getKey()/setKey(),锟斤拷取/锟斤拷锟斤拷锟斤拷钥<br/> + * getContent() / setContent(), 锟斤拷取/锟斤拷锟斤拷原始锟斤拷锟斤拷<br/> + * getParameter()/setParameter(),锟斤拷取/锟斤拷锟矫诧拷锟斤拷值<br/> + * getAllParameters(),锟斤拷取锟斤拷锟叫诧拷锟斤拷<br/> + * isTenpaySign(),锟角凤拷聘锟酵ㄇ╋拷锟�,true:锟斤拷 false:锟斤拷<br/> + * getDebugInfo(),锟斤拷取debug锟斤拷息<br/> + * + * ========================================================================<br/> + * + */ +public class ClientResponseHandler { + + /** 应锟斤拷原始锟斤拷锟斤拷 */ + private String content; + + /** 应锟斤拷牟锟斤拷锟� */ + @SuppressWarnings("rawtypes") + private SortedMap parameters; + + /** debug锟斤拷息 */ + private String debugInfo; + + /** 锟斤拷钥 */ + private String key; + + /** 锟街凤拷 */ + private String charset; + + /*@SuppressWarnings("rawtypes") + public ClientResponseHandler() { + this.content = ""; + this.parameters = new TreeMap(); + this.debugInfo = ""; + this.key = ""; + this.charset = "UTF-8"; + }*/ + + public ClientResponseHandler() { + this.content = ""; + this.parameters = new TreeMap(); + this.debugInfo = ""; + this.key = ""; + this.charset = "UTF-8"; + } + + public String getContent() { + return content; + } + + public void setContent(String content) throws Exception { + this.content = content; + + this.doParse(); + } + + /** + * 锟斤拷取锟斤拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @return String + */ + public String getParameter(String parameter) { + String s = (String) this.parameters.get(parameter); + return (null == s) ? "" : s; + } + + /** + * 锟斤拷锟矫诧拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @param parameterValue + * 锟斤拷锟斤拷值 + */ + @SuppressWarnings("unchecked") + public void setParameter(String parameter, String parameterValue) { + String v = ""; + if (null != parameterValue) { + v = parameterValue.trim(); + } + this.parameters.put(parameter, v); + } + + /** + * 锟斤拷锟斤拷锟斤拷锟叫的诧拷锟斤拷 + * + * @return SortedMap + */ + @SuppressWarnings("rawtypes") + public SortedMap getAllParameters() { + return this.parameters; + } + + public String getDebugInfo() { + return debugInfo; + } + + /** + * 锟斤拷取锟斤拷钥 + */ + public String getKey() { + return key; + } + + /** + * 锟斤拷锟斤拷锟斤拷钥 + */ + public void setKey(String key) { + this.key = key; + } + + public String getCharset() { + return this.charset; + } + + public void setCharset(String charset) { + this.charset = charset; + } + + /** + * 锟角凤拷聘锟酵ㄇ╋拷锟�,锟斤拷锟斤拷锟斤拷:锟斤拷锟斤拷锟斤拷锟斤拷锟絘-z锟斤拷锟斤拷,锟斤拷锟斤拷锟斤拷值锟侥诧拷锟斤拷渭锟角╋拷锟� + * + * @return boolean + */ + @SuppressWarnings("rawtypes") + public boolean isTenpaySign() { + StringBuffer sb = new StringBuffer(); + Set es = this.parameters.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + if (!"sign".equals(k) && null != v && !"".equals(v)) { + sb.append(k + "=" + v + "&"); + } + } + + sb.append("key=" + this.getKey()); + + System.out.println("杩斿洖鐨勫弬鏁�:" + sb); + // 锟斤拷锟秸� + String sign = MD5Util.MD5Encode(sb.toString(), this.charset) + .toUpperCase(); + + String tenpaySign = this.getParameter("sign").toUpperCase(); + + // debug锟斤拷息 + this.setDebugInfo(sb.toString() + " => sign:" + sign + " tenpaySign:" + + tenpaySign); + + Boolean b = tenpaySign.equals(sign); + + System.out.println("楠岃瘉杩斿洖鏉ョ殑鏁版嵁鏄惁寰俊杩斿洖鐨�:" + b); + + return b; + } + + /** + * 锟角凤拷聘锟酵ㄇ╋拷锟� + * + * @param signParameterArray + * 签锟斤拷牟锟斤拷锟斤拷锟斤拷锟� + * @return boolean + */ + protected boolean isTenpaySign(String signParameterArray[]) { + + StringBuffer signPars = new StringBuffer(); + for (int index = 0; index < signParameterArray.length; index++) { + String k = signParameterArray[index]; + String v = this.getParameter(k); + if (null != v && !"".equals(v)) { + signPars.append(k + "=" + v + "&"); + } + } + + signPars.append("key=" + this.getKey()); + + // 锟斤拷锟秸� + String sign = MD5Util.MD5Encode(signPars.toString(), this.charset) + .toLowerCase(); + + String tenpaySign = this.getParameter("sign").toLowerCase(); + + // debug锟斤拷息 + this.setDebugInfo(signPars.toString() + " => sign:" + sign + + " tenpaySign:" + tenpaySign); + + return tenpaySign.equals(sign); + } + + protected void setDebugInfo(String debugInfo) { + this.debugInfo = debugInfo; + } + + /** + * 锟斤拷锟斤拷XML锟斤拷锟斤拷 + */ + @SuppressWarnings("rawtypes") + protected void doParse() throws JDOMException, IOException, JDOMException { + String xmlContent = this.getContent(); + + // 锟斤拷锟斤拷xml,锟矫碉拷map + Map m = XMLUtil.doXMLParse(xmlContent); + + // 锟斤拷锟矫诧拷锟斤拷 + Iterator it = m.keySet().iterator(); + while (it.hasNext()) { + String k = (String) it.next(); + String v = (String) m.get(k); + this.setParameter(k, v); + } + + } + +} diff --git a/src/main/java/com/hx/mp/util/CorpMpClientUtil.java b/src/main/java/com/hx/mp/util/CorpMpClientUtil.java new file mode 100644 index 0000000..41d7cf7 --- /dev/null +++ b/src/main/java/com/hx/mp/util/CorpMpClientUtil.java @@ -0,0 +1,169 @@ +package com.hx.mp.util; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import org.apache.commons.io.IOUtils; + +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.text.MessageFormat; + +/** + * 浼佷笟寰俊瀹㈡埛宸ュ叿 + */ +public class CorpMpClientUtil { + + /**鐢熸垚鑱旂郴鎴戞寜閽弬鏁扮殑閾炬帴锛堢敓鎴恈onfig_id锛�*/ + public static final String CREATE_CONTACT_ID_URL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_contact_way?access_token="; + /**鑾峰彇浼佷笟瀹㈡埛璇︽儏閾炬帴*/ + public static final String GET_CLIENT_DETAIL_URL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get"; + /**娣诲姞瀹㈡埛鑱旂郴浜烘爣绛�*/ + public static final String ADD_TAG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token="; + /**鍒犻櫎瀹㈡埛鑱旂郴浜烘爣绛�*/ + public static final String DEL_TAG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token="; + /**瀹㈡埛鍏宠仈浼佷笟寰俊鐨勬爣绛緐rl*/ + public static final String RELATION_TAG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token="; + + + /**鐢熸垚浼佷笟鎴愬憳鑱旂郴鎴戠殑id-鍗曚汉 + * @param accessToken 浼佷笟鐨刟ccessToken + * @param userId 浼佷笟鎴愬憳鐨剈serId + * @param state 浼佷笟鑷畾涔夌殑state鍙傛暟锛岀敤浜庡尯鍒嗕笉鍚岀殑娣诲姞娓犻亾锛屽湪璋冪敤鈥滆幏鍙栧閮ㄨ仈绯讳汉璇︽儏鈥濇椂浼氳繑鍥炶鍙傛暟鍊硷紝涓嶈秴杩�30涓瓧绗� + * @param remark 鑱旂郴鏂瑰紡鐨勫娉ㄤ俊鎭紝鐢ㄤ簬鍔╄锛屼笉瓒呰繃30涓瓧绗� + * @return + */ + public static JSONObject createContactId(String accessToken,String userId,String state,String remark){ + + String configId = null; + JSONObject data = new JSONObject(); + data.put("type",1); + data.put("scene",1); + data.put("state",state); + data.put("remark",remark); + JSONArray userIds = new JSONArray(); + userIds.add(userId); + data.put("user",userIds); + + //璇锋眰锛岃繑鍥炴牸寮� + /*{ + "errcode": 0, + "errmsg": "ok", + "config_id":"42b34949e138eb6e027c123cba77fAAA"銆�銆� + }*/ + + return HttpURLUtil(CREATE_CONTACT_ID_URL+accessToken,data.toString()); + } + + /**鑾峰彇浼佷笟瀹㈡埛璇︽儏淇℃伅 + * @param accessToken 浼佷笟鐨刟ccessToken + * @param externalUserId 澶栭儴浜哄憳鐨剈serId + * @return + */ + public static JSONObject getClientData(String accessToken,String externalUserId){ + + return HttpURLUtil(GET_CLIENT_DETAIL_URL+"?access_token="+accessToken+"&external_userid="+externalUserId,null); + } + + /** 娣诲姞瀹㈡埛鑱旂郴浜烘爣绛撅紝 + *濡傛灉瑕佸悜鎸囧畾鐨勬爣绛剧粍涓嬫坊鍔犳爣绛撅紝闇�瑕佸~鍐檊roup_id鍙傛暟锛涘鏋滆鍒涘缓涓�涓叏鏂扮殑鏍囩缁勪互鍙婃爣绛撅紝 + *鍒欓渶瑕侀�氳繃group_name鍙傛暟鎸囧畾鏂版爣绛剧粍鍚嶇О锛屽鏋滃~鍐欑殑groupname宸茬粡瀛樺湪锛屽垯浼氬湪姝ゆ爣绛剧粍涓嬫柊寤烘爣绛� + * @param accessToken 浼佷笟鐨刟ccessToken + * @param groupId 缁刬d锛堢粍鍚嶇О鍜岀粍id蹇呭~涓�涓級 + * @param groupName 缁勫悕绉� 缁勫悕绉板拰缁刬d蹇呭~涓�涓級 + * @param groupOrder 缁勬帓搴忥紝涓嶅~榛樿浼佷笟寰俊鐢熸垚瑙勫垯 + * @param tagArray 鏁扮粍锛屾牸寮忥細[{ "name": "TAG_NAME_1", "order": 1 }] + * @return + */ + public static JSONObject addTable(String accessToken,String groupId,String groupName,String groupOrder,JSONArray tagArray){ + JSONObject data = new JSONObject(); + data.put("group_id",groupId); + data.put("group_name",groupName); + data.put("order",groupOrder); + data.put("tag",tagArray); + return HttpURLUtil(ADD_TAG+accessToken,data.toString()); + } + + /**鍒犻櫎瀹㈡埛鑱旂郴浜烘爣绛� + * groupArr鍜宼agArr涓嶅彲鍚屾椂涓虹┖銆� + * 濡傛灉涓�涓爣绛剧粍涓嬫墍鏈夌殑鏍囩鍧囪鍒犻櫎锛屽垯鏍囩缁勪細琚嚜鍔ㄥ垹闄ゃ�� + * @param accessToken 浼佷笟鐨刟ccessToken + * @param groupArr 缁刬d鏁扮粍 + * @param tagArr 鏍囩id鏁扮粍 + * @return + */ + public static JSONObject delTable(String accessToken,JSONArray groupArr,String tagArr){ + JSONObject data = new JSONObject(); + data.put("tag_id",tagArr); + data.put("group_id",groupArr); + return HttpURLUtil(DEL_TAG+accessToken,data.toString()); + } + + /** + * 瀹㈡埛鍏宠仈浼佷笟寰俊鐨勬爣绛� + * 娉ㄦ剰锛氳纭繚external_userid鏄痷serid鐨勫閮ㄨ仈绯讳汉銆� + * add_tag鍜宺emove_tag涓嶅彲鍚屾椂涓虹┖銆� + * @param accessToken 浼佷笟鐨刟ccessToken + * @param userId 浼佷笟鎴愬憳鐨剈serid + * @param externalUserId 澶栭儴鑱旂郴浜虹殑id + * @param addTag 鏂板鐨勬爣绛緄d锛堜紒涓氭爣绛剧殑id锛夋暟缁� + * @param removeTag 鍒犻櫎鐨勬爣绛緄d锛堜紒涓氭爣绛剧殑id锛夋暟缁� + * @return + */ + public static JSONObject relationTag(String accessToken,String userId,String externalUserId + ,JSONArray addTag,JSONArray removeTag){ + JSONObject data = new JSONObject(); + data.put("userid",userId); + data.put("external_userid",externalUserId); + data.put("add_tag",addTag); + data.put("remove_tag",removeTag); + return HttpURLUtil(RELATION_TAG+accessToken,data.toString()); + } + + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static JSONObject HttpURLUtil(String url, String data) { + HttpURLConnection con = null; + URL u = null; + String wxMsgXml = null; + JSONObject obj = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); + obj = JSONObject.fromObject(wxMsgXml); + // //System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } +} diff --git a/src/main/java/com/hx/mp/util/CorpMpUtil.java b/src/main/java/com/hx/mp/util/CorpMpUtil.java new file mode 100644 index 0000000..bd83c76 --- /dev/null +++ b/src/main/java/com/hx/mp/util/CorpMpUtil.java @@ -0,0 +1,294 @@ +package com.hx.mp.util; + +import com.hx.exception.TipsException; +import com.hx.util.StringUtils; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import org.apache.commons.io.IOUtils; +import org.apache.poi.util.SystemOutLogger; + +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.text.MessageFormat; + +/** + * 浼佷笟寰俊宸ュ叿绫� + */ +public class CorpMpUtil { + + /**閾炬帴-鑾峰彇搴旂敤accessToken*/ + public static final String URL_GET_ACCESS_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}"; + /**閾炬帴-鑾峰彇session淇℃伅*/ + public static final String URL_CODE_2_SESSION = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token={0}&js_code={1}&grant_type=authorization_code"; + /**閾炬帴-娣诲姞鏍囩*/ + public static final String URL_ADD_LABEL = "https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token={0}"; + /**閾炬帴-娣诲姞閮ㄩ棬*/ + public static final String URL_ADD_DEPARTMENT = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token={0}"; + /**閾炬帴-淇敼閮ㄩ棬*/ + public static final String URL_UPDATE_DEPARTMENT = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token={0}"; + /**閾炬帴-鍒犻櫎閮ㄩ棬*/ + public static final String URL_DELETE_DEPARTMENT = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token={0}&id={1}"; + /**閾炬帴-娣诲姞鎴愬憳*/ + public static final String URL_ADD_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token={0}"; + /**閾炬帴-鏇存柊鎴愬憳*/ + public static final String URL_UPDATE_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={0}"; + /**閾炬帴-鍒犻櫎鎴愬憳*/ + public static final String URL_DELETE_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token={0}&userid={1}"; + /**閾炬帴-鎴愬憳璇︽儏*/ + public static final String URL_INFO_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={0}&userid={1}"; + /**鍙戦�佹秷鎭�*/ + public static final String URL_MESSAGE_SEND = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="; + + /** + * 娣诲姞宸ヤ綔浜哄憳 + * @param at 璁块棶at + * @param userId 鐢ㄦ埛id + * @param name 鍚嶇О + * @param depId 閮ㄩ棬id + * @param position 鑱屼綅 + * @param tel 鐢佃瘽 + * @param email 閭 + * @return 杩斿洖 + */ + public static int addUser(String at, String userId, String name, int depId + , String position,String tel,String email) { + + if(StringUtils.isEmpty(tel)&&StringUtils.isEmpty(email)){ + throw new TipsException("娣诲姞浼佷笟寰俊鎵嬫満鍙峰拰閭涓嶈兘閮戒负绌猴紒"); + } + + JSONObject obj = new JSONObject(); + obj.put("userid", userId); + obj.put("name", name); + obj.put("department", depId); + obj.put("position", position); + obj.put("mobile", tel); + obj.put("email", email); + obj = HttpURLUtil(MessageFormat.format(URL_ADD_USER, at), obj.toString()); + if(obj != null) { + return obj.optInt("errcode", -1); + } + return -1; + } + /** + * 鏇存柊宸ヤ綔浜哄憳 + * @param at 璁块棶at + * @param userId 鐢ㄦ埛id + * @param name 鍚嶇О + * @param depId 閮ㄩ棬id + * @param position 鑱屼綅 + * @param tel 鐢佃瘽 + * @param email 閭 + * @return 杩斿洖 + */ + public static int updateUser(String at, String userId, String name, int depId + , String position,String tel,String email) { + JSONObject obj = new JSONObject(); + obj.put("userid", userId); + obj.put("name", name); + obj.put("department", depId); + obj.put("position", position); + obj.put("mobile", tel); + obj.put("email", email); + + obj = HttpURLUtil(MessageFormat.format(URL_UPDATE_USER, at), obj.toString()); + if(obj != null && obj.optInt("errcode", -1) == 0) { + return obj.optInt("errcode", -1); + } + + return -1; + } + + /** + * 鍒犻櫎宸ヤ綔浜哄憳 + * @param at 璁块棶at + * @param userId 鐢ㄦ埛id + * @return 杩斿洖 + */ + public static int deleteUser(String at, String userId) { + JSONObject obj = new JSONObject(); + obj.put("userid", userId); + + obj = HttpURLUtil(MessageFormat.format(URL_DELETE_USER, at,userId), obj.toString()); + if(obj != null) { + return obj.optInt("errcode", -1); + } + return -1; + } + + /** + * 宸ヤ綔浜哄憳鍒ゆ柇鏄惁瀛樺湪浼佷笟寰俊 + * @param at 璁块棶at + * @param userId 鐢ㄦ埛id + * @return 杩斿洖 + */ + public static int infoUser(String at, String userId) { + JSONObject obj = new JSONObject(); + obj.put("userid", userId); + + obj = HttpURLUtil(MessageFormat.format(URL_INFO_USER, at,userId), obj.toString()); + System.out.println("userId:"+userId); + System.out.println("obj:"+obj.toString()); + if(obj != null) { + return obj.optInt("errcode", -1); + } + return -1; + } + + + /** + * 娣诲姞閮ㄩ棬 + * @param name 閮ㄩ棬鍚嶇О + * @return id + */ + public static int addDepartment(String at, String name, int parentId) { + JSONObject obj = new JSONObject(); + obj.put("name", name); + obj.put("parentid", parentId); + + obj = HttpURLUtil(MessageFormat.format(URL_ADD_DEPARTMENT, at), obj.toString()); + + if(obj != null && obj.optInt("errcode", -1) == 0) { + return obj.optInt("id", -1); + } + return -1; + } + + /** + * 鏇存柊閮ㄩ棬 + * @param name 閮ㄩ棬鍚嶇О + * @param deaprtId 閮ㄩ棬id + * @param parentid 鐖剁被閮ㄩ棬id锛屽彲浠ヤ负绌� + * @return 鐘舵�侊紝0鎴愬姛 + */ + public static int updateDepartment(String at, String name, int deaprtId,int parentid) { + JSONObject obj = new JSONObject(); + obj.put("name", name); + obj.put("id", deaprtId); + obj.put("parentid", parentid); + + obj = HttpURLUtil(MessageFormat.format(URL_UPDATE_DEPARTMENT, at), obj.toString()); + return obj.optInt("errcode", -1); + } + + /**鍒犻櫎閮ㄩ棬 + * 鍒犻櫎鐨勯儴闂ㄤ笉鑳芥槸鏍归儴闂ㄤ笖娌℃湁鎴愬憳 + * @param deaprtId 閮ㄩ棬id + * @return 鐘舵�侊紝0鎴愬姛 + */ + public static int deleteDepartment(String at,int deaprtId) { + JSONObject obj = new JSONObject(); + obj.put("id", deaprtId); + + obj = HttpURLUtil(MessageFormat.format(URL_DELETE_DEPARTMENT,at,deaprtId), obj.toString()); + System.out.println("鍒犻櫎閮ㄩ棬:"+obj.toString()); + return obj.optInt("errcode", -1); + } + + /**鍙戦�佷紒涓氬簲鐢ㄦ秷鎭� + * @param accessToken 浼佷笟accessToken + * @param data 鍙戦�佹暟鎹粨鏋� + * @return + */ + public static JSONObject messageSend(String accessToken,String data){ + return HttpURLUtil(URL_MESSAGE_SEND+accessToken,data); + } + + /**娣诲姞鐢ㄦ埛鏍囩锛屾爣绛惧悕绉颁笉鑳介噸澶� + * @param at 璁块棶at + * @param label 鏍囩鍚嶇О + * @return 杩斿洖 -1澶辫触,0鎴愬姛锛�1宸插瓨鍦� + */ + public static int addLabel(String at, String label) { + String url = MessageFormat.format(URL_ADD_LABEL, at); + JSONObject obj = new JSONObject(); + obj.put("tagname", label); + obj = HttpURLUtil(url, obj.toString()); + System.out.println("obj....:"+obj.toString()); + if(obj != null ) { + int errcode = obj.optInt("errcode", -1); + if( errcode== 0){ + //涓婁紶鎴愬姛 + return obj.optInt("tagid", -1); + }if(errcode == 40071){ + //鏍囩宸茬粡瀛樺湪 + return 1; + } + } + return -1; + } + + + /** + * 鑾峰彇搴旂敤accessToken + * @param corpId 浼佷笟id + * @param appSecret 搴旂敤瀵嗛挜 + * @return + * @throws Exception + */ + public static JSONObject getApplicationAccessToken(String corpId, String appSecret) { + String url = MessageFormat.format(URL_GET_ACCESS_TOKEN, corpId, appSecret); + JSONObject obj = HttpURLUtil(url, null); + return obj; + } + + /** + * 浣跨敤涓存椂鐧诲綍鍑瘉code鑾峰彇 session_key銆佺敤鎴穟serId浠ュ強鐢ㄦ埛鎵�鍦ㄤ紒涓氱殑corpId绛変俊鎭� + * @param accessToken 璁块棶token + * @param code 涓存椂code + * @return + */ + public static JSONObject code2Session(String accessToken, String code) { + String url = MessageFormat.format(URL_CODE_2_SESSION, accessToken, code); + JSONObject obj = HttpURLUtil(url, null); + return obj; + } + + + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static JSONObject HttpURLUtil(String url, String data) { + HttpURLConnection con = null; + URL u = null; + String wxMsgXml = null; + JSONObject obj = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); + obj = JSONObject.fromObject(wxMsgXml); + // //System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } +} diff --git a/src/main/java/com/hx/mp/util/HttpClientUtil.java b/src/main/java/com/hx/mp/util/HttpClientUtil.java new file mode 100644 index 0000000..5f99f59 --- /dev/null +++ b/src/main/java/com/hx/mp/util/HttpClientUtil.java @@ -0,0 +1,340 @@ +package com.hx.mp.util; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.UnrecoverableKeyException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.util.HashMap; +import java.util.Map; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManagerFactory; + +/** + * Http锟酵伙拷锟剿癸拷锟斤拷锟斤拷<br/> + * 锟斤拷锟斤拷锟节诧拷锟斤拷锟斤拷锟洁,锟诫不要锟斤拷锟解部锟斤拷锟矫★拷 + * @author miklchen + * + */ +public class HttpClientUtil { + + public static final String SunX509 = "SunX509"; + public static final String JKS = "JKS"; + public static final String PKCS12 = "PKCS12"; + public static final String TLS = "TLS"; + + /** + * get HttpURLConnection + * @param strUrl url锟斤拷址 + * @return HttpURLConnection + * @throws IOException + */ + public static HttpURLConnection getHttpURLConnection(String strUrl) + throws IOException { + URL url = new URL(strUrl); + HttpURLConnection httpURLConnection = (HttpURLConnection) url + .openConnection(); + return httpURLConnection; + } + + /** + * get HttpsURLConnection + * @param strUrl url锟斤拷址 + * @return HttpsURLConnection + * @throws IOException + */ + public static HttpsURLConnection getHttpsURLConnection(String strUrl) + throws IOException { + URL url = new URL(strUrl); + HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url + .openConnection(); + return httpsURLConnection; + } + + /** + * 锟斤拷取锟斤拷锟斤拷锟窖拷锟斤拷锟絬rl + * @param strUrl + * @return String + */ + public static String getURL(String strUrl) { + + if(null != strUrl) { + int indexOf = strUrl.indexOf("?"); + if(-1 != indexOf) { + return strUrl.substring(0, indexOf); + } + + return strUrl; + } + + return strUrl; + + } + + /** + * 锟斤拷取锟斤拷询锟斤拷 + * @param strUrl + * @return String + */ + public static String getQueryString(String strUrl) { + + if(null != strUrl) { + int indexOf = strUrl.indexOf("?"); + if(-1 != indexOf) { + return strUrl.substring(indexOf+1, strUrl.length()); + } + + return ""; + } + + return strUrl; + } + + /** + * 锟斤拷询锟街凤拷转锟斤拷锟斤拷Map<br/> + * name1=key1&name2=key2&... + * @param queryString + * @return + */ + @SuppressWarnings("rawtypes") + public static Map queryString2Map(String queryString) { + if(null == queryString || "".equals(queryString)) { + return null; + } + + Map m = new HashMap(); + String[] strArray = queryString.split("&"); + for(int index = 0; index < strArray.length; index++) { + String pair = strArray[index]; + HttpClientUtil.putMapByPair(pair, m); + } + + return m; + + } + + /** + * 锟窖硷拷值锟斤拷锟斤拷锟組ap<br/> + * pair:name=value + * @param pair name=value + * @param m + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static void putMapByPair(String pair, Map m) { + + if(null == pair || "".equals(pair)) { + return; + } + + int indexOf = pair.indexOf("="); + if(-1 != indexOf) { + String k = pair.substring(0, indexOf); + String v = pair.substring(indexOf+1, pair.length()); + if(null != k && !"".equals(k)) { + m.put(k, v); + } + } else { + m.put(pair, ""); + } + } + + /** + * BufferedReader转锟斤拷锟斤拷String<br/> + * 注锟斤拷:锟斤拷锟截憋拷锟斤拷要锟斤拷锟叫达拷锟斤拷 + * @param reader + * @return String + * @throws IOException + */ + public static String bufferedReader2String(BufferedReader reader) throws IOException { + StringBuffer buf = new StringBuffer(); + String line = null; + while( (line = reader.readLine()) != null) { + buf.append(line); + buf.append("\r\n"); + } + + return buf.toString(); + } + + /** + * 锟斤拷锟斤拷锟斤拷锟�<br/> + * 注锟斤拷:锟斤拷锟截憋拷锟斤拷要锟斤拷锟叫达拷锟斤拷 + * @param out + * @param data + * @param len + * @throws IOException + */ + public static void doOutput(OutputStream out, byte[] data, int len) + throws IOException { + int dataLen = data.length; + int off = 0; + while (off < data.length) { + if (len >= dataLen) { + out.write(data, off, dataLen); + off += dataLen; + } else { + out.write(data, off, len); + off += len; + dataLen -= len; + } + + // 刷锟铰伙拷锟斤拷锟斤拷 + out.flush(); + } + + } + + /** + * 锟斤拷取SSLContext + * @param trustFile + * @param trustPasswd + * @param keyFile + * @param keyPasswd + * @return + * @throws NoSuchAlgorithmException + * @throws KeyStoreException + * @throws IOException + * @throws CertificateException + * @throws UnrecoverableKeyException + * @throws KeyManagementException + */ + public static SSLContext getSSLContext( + FileInputStream trustFileInputStream, String trustPasswd, + FileInputStream keyFileInputStream, String keyPasswd) + throws NoSuchAlgorithmException, KeyStoreException, + CertificateException, IOException, UnrecoverableKeyException, + KeyManagementException { + + // ca + TrustManagerFactory tmf = TrustManagerFactory.getInstance(HttpClientUtil.SunX509); + KeyStore trustKeyStore = KeyStore.getInstance(HttpClientUtil.JKS); + trustKeyStore.load(trustFileInputStream, HttpClientUtil + .str2CharArray(trustPasswd)); + tmf.init(trustKeyStore); + + final char[] kp = HttpClientUtil.str2CharArray(keyPasswd); + KeyManagerFactory kmf = KeyManagerFactory.getInstance(HttpClientUtil.SunX509); + KeyStore ks = KeyStore.getInstance(HttpClientUtil.PKCS12); + ks.load(keyFileInputStream, kp); + kmf.init(ks, kp); + + SecureRandom rand = new SecureRandom(); + SSLContext ctx = SSLContext.getInstance(HttpClientUtil.TLS); + ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), rand); + + return ctx; + } + + /** + * 锟斤拷取CA证锟斤拷锟斤拷息 + * @param cafile CA证锟斤拷锟侥硷拷 + * @return Certificate + * @throws CertificateException + * @throws IOException + */ + public static Certificate getCertificate(File cafile) + throws CertificateException, IOException { + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + FileInputStream in = new FileInputStream(cafile); + Certificate cert = cf.generateCertificate(in); + in.close(); + return cert; + } + + /** + * 锟街凤拷转锟斤拷锟斤拷char锟斤拷锟斤拷 + * @param str + * @return char[] + */ + public static char[] str2CharArray(String str) { + if(null == str) return null; + + return str.toCharArray(); + } + + /** + * 锟芥储ca证锟斤拷锟絁KS锟斤拷式 + * @param cert + * @param alias + * @param password + * @param out + * @throws KeyStoreException + * @throws NoSuchAlgorithmException + * @throws CertificateException + * @throws IOException + */ + public static void storeCACert(Certificate cert, String alias, + String password, OutputStream out) throws KeyStoreException, + NoSuchAlgorithmException, CertificateException, IOException { + KeyStore ks = KeyStore.getInstance("JKS"); + + ks.load(null, null); + + ks.setCertificateEntry(alias, cert); + + // store keystore + ks.store(out, HttpClientUtil.str2CharArray(password)); + + } + + public static InputStream String2Inputstream(String str) { + return new ByteArrayInputStream(str.getBytes()); + } + + /** + * InputStream转锟斤拷锟斤拷Byte + * 注锟斤拷:锟斤拷锟截憋拷锟斤拷要锟斤拷锟叫达拷锟斤拷 + * @param in + * @return byte + * @throws Exception + */ + public static byte[] InputStreamTOByte(InputStream in) throws IOException{ + + int BUFFER_SIZE = 4096; + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] data = new byte[BUFFER_SIZE]; + int count = -1; + + while((count = in.read(data,0,BUFFER_SIZE)) != -1) + outStream.write(data, 0, count); + + data = null; + byte[] outByte = outStream.toByteArray(); + outStream.close(); + + return outByte; + } + + /** + * InputStream转锟斤拷锟斤拷String + * 注锟斤拷:锟斤拷锟截憋拷锟斤拷要锟斤拷锟叫达拷锟斤拷 + * @param in + * @param encoding 锟斤拷锟斤拷 + * @return String + * @throws Exception + */ + public static String InputStreamTOString(InputStream in,String encoding) throws IOException{ + + return new String(InputStreamTOByte(in),encoding); + + } + + +} diff --git a/src/main/java/com/hx/mp/util/HttpUtil.java b/src/main/java/com/hx/mp/util/HttpUtil.java new file mode 100644 index 0000000..7ccb979 --- /dev/null +++ b/src/main/java/com/hx/mp/util/HttpUtil.java @@ -0,0 +1,31 @@ +package com.hx.mp.util; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClients; + +public class HttpUtil { + /** + * 鍙戦�乸ost璇锋眰 + * + * @param url + * 璇锋眰鍦板潃 + * @param outputEntity + * 鍙戦�佸唴瀹� + * @param isLoadCert + * 鏄惁鍔犺浇璇佷功 + */ + public static CloseableHttpResponse Post(String url, String outputEntity, boolean isLoadCert, String certPath, String mchId) throws Exception { + HttpPost httpPost = new HttpPost(url); + // 寰楁寚鏄庝娇鐢║TF-8缂栫爜锛屽惁鍒欏埌API鏈嶅姟鍣╔ML鐨勪腑鏂囦笉鑳借鎴愬姛璇嗗埆 + httpPost.addHeader("Content-Type", "text/xml"); + httpPost.setEntity(new StringEntity(outputEntity, "UTF-8")); + if (isLoadCert) { + // 鍔犺浇鍚湁璇佷功鐨刪ttp璇锋眰 + return HttpClients.custom().setSSLSocketFactory(CertUtil.initCert(certPath, mchId)).build().execute(httpPost); + } else { + return HttpClients.custom().build().execute(httpPost); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/hx/mp/util/HttpXmlUtils.java b/src/main/java/com/hx/mp/util/HttpXmlUtils.java new file mode 100644 index 0000000..ac31380 --- /dev/null +++ b/src/main/java/com/hx/mp/util/HttpXmlUtils.java @@ -0,0 +1,63 @@ +package com.hx.mp.util; + +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.xml.sax.InputSource; + +import java.io.IOException; +import java.io.StringReader; +import java.util.*; + +public class HttpXmlUtils { + + @SuppressWarnings("rawtypes") + public static String transferXml(SortedMap<Object, Object> parameters) { + + Document document = DocumentHelper.createDocument(); + Element root = document.addElement("xml"); + + Set es = parameters.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + + Element ToUserName = root.addElement(k); + ToUserName.addText(v); + } + + String queryString = document.asXML();// 杞负String + + queryString = queryString.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").trim(); + + // System.out.println("浼佷笟绔粯娆惧弬鏁帮細"+queryString); + return queryString; + } + + @SuppressWarnings("unchecked") + public static Map<String, String> parseRefundXml(String refundXml) throws JDOMException, IOException { + + StringReader read = new StringReader(refundXml); + // 鍒涘缓鏂扮殑杈撳叆婧怱AX 瑙f瀽鍣ㄥ皢浣跨敤 InputSource 瀵硅薄鏉ョ‘瀹氬浣曡鍙� XML 杈撳叆 + InputSource source = new InputSource(read); + // 鍒涘缓涓�涓柊鐨凷AXBuilder + SAXBuilder sb = new SAXBuilder(); + // 閫氳繃杈撳叆婧愭瀯閫犱竴涓狣ocument + Document doc; + doc = (Document) sb.build(source); + Element root = doc.getRootElement();// 鎸囧悜鏍硅妭鐐� + List<Element> list = root.elements(); + Map<String, String> refundOrderMap = new HashMap<String, String>(); + if (list != null && list.size() > 0) { + for (Element element : list) { + refundOrderMap.put(element.getName(), element.getText()); + } + return refundOrderMap; + } + return null; + } +} diff --git a/src/main/java/com/hx/mp/util/MD5Util.java b/src/main/java/com/hx/mp/util/MD5Util.java new file mode 100644 index 0000000..08e76a4 --- /dev/null +++ b/src/main/java/com/hx/mp/util/MD5Util.java @@ -0,0 +1,43 @@ +package com.hx.mp.util; + +import java.security.MessageDigest; + +public class MD5Util { + + private static String byteArrayToHexString(byte b[]) { + StringBuffer resultSb = new StringBuffer(); + for (int i = 0; i < b.length; i++) + resultSb.append(byteToHexString(b[i])); + + return resultSb.toString(); + } + + private static String byteToHexString(byte b) { + int n = b; + if (n < 0) + n += 256; + int d1 = n / 16; + int d2 = n % 16; + return hexDigits[d1] + hexDigits[d2]; + } + + public static String MD5Encode(String origin, String charsetname) { + String resultString = null; + try { + resultString = new String(origin); + MessageDigest md = MessageDigest.getInstance("MD5"); + if (charsetname == null || "".equals(charsetname)) + resultString = byteArrayToHexString(md.digest(resultString + .getBytes())); + else + resultString = byteArrayToHexString(md.digest(resultString + .getBytes(charsetname))); + } catch (Exception exception) { + } + return resultString; + } + + private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + +} diff --git a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java new file mode 100644 index 0000000..fcec5f9 --- /dev/null +++ b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java @@ -0,0 +1,404 @@ +package com.hx.mp.util; + +import com.hx.util.OSSUtil; +import com.hx.util.SimpleTool; +import com.hx.util.StringUtils; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; +import org.springframework.stereotype.Component; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 寰俊鑾峰彇鏉冮檺鍩烘湰宸ュ叿绫� + * @author ChenJiaHe + * @Date 2020-07-14 + */ +@Component +public class MPWeixinBaseUtil { + + // 绫诲瀷 + private static final String GRANT_TYPE = "client_credential"; + + /**鑾峰彇access_token閾炬帴*/ + private static final String GETACCESS_TOKENURL = "https://api.weixin.qq.com/cgi-bin/token?grant_type="; + /**閫氳繃code鑾峰彇灏忕▼搴忎俊鎭摼鎺�*/ + private static final String JSCODE2SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?"; + /**鍙戦�佽闃呮秷鎭�氱煡閾炬帴*/ + private static final String SEND_SUBSCRIBE_MESSAGE = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="; + //鐢熸垚灏忕▼搴忎簩缁寸爜鍦板潃锛堟柟褰級 + public static final String MAKE_TWOCODE_SQUARE_URL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="; + //鐢熸垚灏忕▼搴忎簩缁寸爜鍦板潃锛堝渾褰級 + public static final String MAKE_TWOCODE_ROUND_URL = "https://api.weixin.qq.com/wxa/getwxacode?access_token="; + //鐢熸垚鏃犻檺浜岀淮鐮� + public static final String URL_UNLIMIT_SQUARE = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}"; + ////////////////////////////////////////////////// + + /** (灏忕▼搴�)閫氳繃code鎹㈠彇缃戦〉鎺堟潈access_token/濡傛灉鏄痵nsapi_base妯″紡鐨勬巿鏉冿紝杩欓噷灏卞彲浠ユ嬁鍒皁penId浜� ***/ + public static JSONObject getJscode2session(String appid,String secret,String code) { + + return HttpURLUtil(JSCODE2SESSION_URL+"appid="+appid+"&secret="+secret + +"&grant_type=authorization_code&js_code=" + code,null); + } + + /**鍙戦�佽闃呮秷鎭�氱煡**/ + public static JSONObject sendSubscribeMessage(String data,String accessToken){ + return HttpURLUtil(SEND_SUBSCRIBE_MESSAGE+accessToken,data); + } + + /** 鑾峰彇access_token */ + public static JSONObject getAccessToken(String appid,String secret) throws Exception { + String access_token; + // 閫氳繃WX鎺ュ彛鑾峰彇access_token + JSONObject obj = getApplication_Access_tokenForUrl(appid,secret); + return obj; + } + + /** 浠巜eixin鎺ュ彛鑾峰彇Access_token **/ + public static JSONObject getApplication_Access_tokenForUrl(String appid,String secret) { + return HttpURLUtil(GETACCESS_TOKENURL+GRANT_TYPE +"&appid="+appid +"&secret="+secret,null); + } + + /**鐢熸垚鏃犻檺浜岀淮鐮侊紝骞朵笂浼犲埌OSS*/ + public static String createUnlimitQrCode(String at, String scene, String page, int width, boolean autoColor, + JSONObject lineColor, boolean isHyaline, String fileName, String keyId, + String keySecret, String endPoint, String bucket) + { + String imgUrl = null; + InputStream in = null; + HttpURLConnection conn = null; + + try { + //鐢熸垚鍙戦�佹暟鎹� + JSONObject obj = new JSONObject(); + obj.put("scene", scene); + obj.put("width", width); + obj.put("page", page); + obj.put("auto_color", autoColor); + obj.put("line_color", lineColor); + obj.put("is_hyaline", isHyaline); + + // 鍒涘缓url璧勬簮 + URL url = new URL(StringUtils.format(URL_UNLIMIT_SQUARE, at)); + // 寤虹珛http杩炴帴 + conn = (HttpURLConnection) url.openConnection(); + // 璁剧疆鍏佽杈撳嚭 + conn.setDoOutput(true); + conn.setDoInput(true); + // 璁剧疆涓嶇敤缂撳瓨 + conn.setUseCaches(false); + // 璁剧疆浼犻�掓柟寮� + conn.setRequestMethod("POST"); + // 璁剧疆缁存寔闀胯繛鎺� + conn.setRequestProperty("Connection", "Keep-Alive"); + // 璁剧疆鏂囦欢瀛楃闆�: + conn.setRequestProperty("Charset", "UTF-8"); + // 璁剧疆鏂囦欢绫诲瀷: + conn.setRequestProperty("contentType", "application/json"); + // 寮�濮嬭繛鎺ヨ姹� + conn.connect(); + OutputStream out = conn.getOutputStream(); + // 鍐欏叆璇锋眰鐨勫瓧绗︿覆 + out.write((obj.toString()).getBytes()); + out.flush(); + out.close(); + + // 璇锋眰杩斿洖鐨勭姸鎬� + if (conn.getResponseCode() == 200) { + // 璇锋眰杩斿洖鐨勬暟鎹� + in = conn.getInputStream(); + imgUrl = OSSUtil.uploadImg(fileName, in, keyId, keySecret, endPoint, bucket); + conn.disconnect(); + conn = null; + } + + if (in != null) { + in.close(); + in = null; + } + + if (conn != null) { + conn.disconnect(); + conn = null; + } + }catch (Exception e) + { + e.printStackTrace(); + + if (in != null) { + try { + in.close(); + }catch (Exception ep) + { + ep.printStackTrace(); + } + in = null; + } + + if (conn != null) { + conn.disconnect(); + conn = null; + } + } + + return imgUrl; + } + + /**鐢熸垚灏忕▼搴忎簩缁寸爜宸ュ叿锛堟柟褰級 + * path 浜岀淮鐮佽烦杞摼鎺� + * width 浜岀淮鐮佸搴�,榛樿鏄�430 + * saveUrl 淇濆瓨鍥剧墖鐨勫叏璺緞 + * seeUrl 鏄剧ず鍥剧墖璺緞 + * appid 灏忕▼搴忛厤缃� + * secret 灏忕▼搴忛厤缃� + * return 浜岀淮鐮佹樉绀哄浘鐗囬摼鎺� + * @throws Exception + * */ + public static String twoCodeImgSquare(String at, String path,Integer width,String saveUrl, + String seeUrl,String appid,String secret) throws Exception { + + if(!SimpleTool.checkNotNull(width)) { + width = 430; + } + //鐢熸垚鍙戦�佹暟鎹� + JSONObject obj = new JSONObject(); + obj.put("path", path); + obj.put("width", width); + + //浜岀淮鐮佸浘鐗囪矾寰� + String codeUrl = ""; + codeUrl = HttpURLUtilMakeCodeImg(MAKE_TWOCODE_SQUARE_URL+at,obj,saveUrl,seeUrl); + if(SimpleTool.checkNotNull(codeUrl)){ + if(!codeUrl.startsWith("/")){ + codeUrl = "/"+codeUrl; + } + } + return codeUrl; + } + + public static String twoCodeImgSquare(String at, String path,Integer width, String fileName, String keyId, + String keySecret, String endPoint, String bucket) throws Exception { + + if(!SimpleTool.checkNotNull(width)) { + width = 430; + } + //鐢熸垚鍙戦�佹暟鎹� + JSONObject obj = new JSONObject(); + obj.put("path", path); + obj.put("width", width); + + String imgUrl = null; + InputStream in = null; + HttpURLConnection conn = null; + + try { + + // 鍒涘缓url璧勬簮 + URL url = new URL(MAKE_TWOCODE_SQUARE_URL + at); + // 寤虹珛http杩炴帴 + conn = (HttpURLConnection) url.openConnection(); + // 璁剧疆鍏佽杈撳嚭 + conn.setDoOutput(true); + conn.setDoInput(true); + // 璁剧疆涓嶇敤缂撳瓨 + conn.setUseCaches(false); + // 璁剧疆浼犻�掓柟寮� + conn.setRequestMethod("POST"); + // 璁剧疆缁存寔闀胯繛鎺� + conn.setRequestProperty("Connection", "Keep-Alive"); + // 璁剧疆鏂囦欢瀛楃闆�: + conn.setRequestProperty("Charset", "UTF-8"); + // 璁剧疆鏂囦欢绫诲瀷: + conn.setRequestProperty("contentType", "application/json"); + // 寮�濮嬭繛鎺ヨ姹� + conn.connect(); + OutputStream out = conn.getOutputStream(); + // 鍐欏叆璇锋眰鐨勫瓧绗︿覆 + out.write((obj.toString()).getBytes()); + out.flush(); + out.close(); + + // 璇锋眰杩斿洖鐨勭姸鎬� + if (conn.getResponseCode() == 200) { + // 璇锋眰杩斿洖鐨勬暟鎹� + in = conn.getInputStream(); + imgUrl = OSSUtil.uploadImg(fileName, in, keyId, keySecret, endPoint, bucket); + conn.disconnect(); + conn = null; + } + + if (in != null) { + in.close(); + in = null; + } + + if (conn != null) { + conn.disconnect(); + conn = null; + } + }catch (Exception e) + { + e.printStackTrace(); + + if (in != null) { + try { + in.close(); + }catch (Exception ep) + { + ep.printStackTrace(); + } + in = null; + } + + if (conn != null) { + conn.disconnect(); + conn = null; + } + } + + return imgUrl; + + + } + + /** 鐢熸垚浜岀淮鐮佺殑鍥剧墖 杩斿洖鍥剧墖璺緞 + * urlx 鎵ц閾炬帴 + * objx 鏁版嵁 + * saveUrl 淇濆瓨鍥剧墖璺緞 + * seeUrl 鏄剧ず鍥剧墖璺緞 + * + * **/ + public static String HttpURLUtilMakeCodeImg(String urlx,JSONObject objx,String saveUrl,String seeUrl) throws IOException { + String realpath = null; + + // 鍒涘缓url璧勬簮 + URL url = new URL(urlx); + // 寤虹珛http杩炴帴 + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + // 璁剧疆鍏佽杈撳嚭 + conn.setDoOutput(true); + + conn.setDoInput(true); + + // 璁剧疆涓嶇敤缂撳瓨 + conn.setUseCaches(false); + // 璁剧疆浼犻�掓柟寮� + conn.setRequestMethod("POST"); + // 璁剧疆缁存寔闀胯繛鎺� + conn.setRequestProperty("Connection", "Keep-Alive"); + // 璁剧疆鏂囦欢瀛楃闆�: + conn.setRequestProperty("Charset", "UTF-8"); + // 杞崲涓哄瓧鑺傛暟缁� + // byte[] data = (objx.toString()).getBytes(); + // 璁剧疆鏂囦欢闀垮害 + // conn.setRequestProperty("Content-Length",String.valueOf(data.length)); + + // 璁剧疆鏂囦欢绫诲瀷: + conn.setRequestProperty("contentType", "application/json"); + // 寮�濮嬭繛鎺ヨ姹� + conn.connect(); + OutputStream out = conn.getOutputStream(); + // 鍐欏叆璇锋眰鐨勫瓧绗︿覆 + out.write((objx.toString()).getBytes()); + out.flush(); + out.close(); + + // 璇锋眰杩斿洖鐨勭姸鎬� + if (conn.getResponseCode() == 200) { + System.out.println("杩炴帴鎴愬姛"); + // 璇锋眰杩斿洖鐨勬暟鎹� + InputStream in = conn.getInputStream(); + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] temp = new byte[1024]; + int rc = 0; + while ((rc = in.read(temp, 0, 100)) > 0) { + swapStream.write(temp, 0, rc); + } + byte[] buffer2 = swapStream.toByteArray(); + String base64 = Base64.encodeBase64String(buffer2); + + //鐢熸垚鍚嶇О + java.util.Random r=new java.util.Random(); + StringBuilder str=new StringBuilder();//瀹氫箟鍙橀暱瀛楃涓� + for(int i=0;i<8;i++){ + str.append(r.nextInt(10)); + } + Date date = new Date(); + SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); + String imgName = sf.format(date); + imgName = imgName+str.toString(); + + //鏂囦欢淇濆瓨浣嶇疆 + File saveDir = new File(saveUrl); + if(!saveDir.exists()){ + saveDir.mkdir(); + } + File file = new File(saveDir+"/"+imgName+".png"); + FileOutputStream fos = new FileOutputStream(file); + fos.write(buffer2); + if(fos!=null){ + fos.close(); + } + if(in!=null){ + in.close(); + } + realpath = seeUrl+"/"+imgName+".png"; + } else { + System.out.println("no++"); + } + return realpath; + } + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + private static JSONObject HttpURLUtil(String url,String data) { + HttpURLConnection con = null; + URL u; + String wxMsgXml; + JSONObject obj; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", + "application/x-www-form-urlencoded"); + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), StandardCharsets.UTF_8); + // 鍒ゆ柇杩斿洖鍙傛暟鏄惁姝g‘/鎴愬姛 + obj = JSONObject.fromObject(wxMsgXml); + // System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } + +} diff --git a/src/main/java/com/hx/mp/util/MpUtil.java b/src/main/java/com/hx/mp/util/MpUtil.java new file mode 100644 index 0000000..cad3924 --- /dev/null +++ b/src/main/java/com/hx/mp/util/MpUtil.java @@ -0,0 +1,357 @@ +package com.hx.mp.util; + +import com.hx.util.StringUtils; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.sql.Timestamp; +import java.text.MessageFormat; +import java.util.Date; + +/** + * 寰俊灏忕▼搴忓伐鍏风被 + */ +public class MpUtil { + + /** 璇锋眰access_token */ + public static final String URL_ACCESS_TOKEN = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; + /** 璇锋眰鏈嶅姟鍣↖P鍦板潃 */ + public static final String URL_SERVER_ADDR = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token="; + /** 寰俊js鐨刢ode鎹㈠幓sessionKey */ + public static final String JSCODE2SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&grant_type=authorization_code&js_code="; + /** 璇锋眰灏忕▼搴忕爜 **/ + public static final String URL_WXACODE = "https://api.weixin.qq.com/wxa/getwxacode?access_token="; + /** 璇锋眰灏忕▼搴忕爜-鏃犳暟閲忛檺鍒� **/ + public static final String URL_WXACODEUNLIMIT = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="; + /** 璇锋眰灏忕▼搴忎簩缁寸爜 */ + public static final String URL_QRCODE = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="; + /** 鍙戞ā鐗堟秷鎭� */ + public static final String URL_SEND_TEMP_MSG = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="; + /** 璁剧疆鍙戠エ鎺堟潈瀛楁 */ + public static final String URL_SET_TICKET_FIELD = "https://api.weixin.qq.com/card/invoice/setbizattr?action=set_auth_field&access_token="; + /** 鑾峰彇鍙戠エticket */ + public static final String URL_GET_TICKET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card&access_token="; + /** 鑾峰彇鍙戠エ鎺堟潈椤甸摼鎺� */ + public static final String URL_GET_TICKET_AUTH_LINK = "https://api.weixin.qq.com/card/invoice/getauthurl?access_token="; + /** 鏌ヨ鍙戠エ鎺堟潈瀛楁 */ + public static final String URL_GET_AUTH_FIELD = "https://api.weixin.qq.com/card/invoice/getauthdata?access_token="; + /** 璁剧疆 鏀粯鍚庡紑鍙戠エ */ + public static final String URL_SET_PAY_INVOICE = "https://api.weixin.qq.com/card/invoice/setbizattr?action=set_pay_mch&access_token="; + /** 鏌ヨ鏀粯鍚庡紑鍙戠エ */ + public static final String URL_GET_PAY_INVOICE = "https://api.weixin.qq.com/card/invoice/setbizattr?action=get_pay_mch&access_token="; + /** 鍙戦�佸鏈嶆秷鎭� */ + public static final String URL_SEND_KF_MSG = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="; + + /************************************************* + * 灏忕▼搴� + *************************/ + /** 鍒╃敤code鎹㈠彇sessionKey */ + public static JSONObject jsCode2session(String code, String appId, String appSecret) { + JSONObject obj = new JSONObject(); + String url = StringUtils.format(JSCODE2SESSION_URL, appId, appSecret) + code; + obj = HttpURLUtil(url, null); + return obj; + } + + /** 鑾峰彇灏忕▼搴忎簩缁寸爜鍥剧墖 */ + public static String getQrCode(String accessToken, String jsonParam) + throws Exception { + JSONObject obj = HttpURLUtilJson(URL_QRCODE + accessToken, jsonParam); + String qrStr = obj.optString("data"); + return qrStr; + } + + /** 浠巜eixin鎺ュ彛鑾峰彇Access_token **/ + public static JSONObject getApplication_Access_tokenForUrl(String appId, String appSecret) + throws Exception { + String url = MessageFormat.format(URL_ACCESS_TOKEN, appId, appSecret); + JSONObject obj = HttpURLUtil(url, null); + return obj; + } + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static InputStream HttpURLUtilStream(String url, String data) { + HttpURLConnection con = null; + URL u = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(200000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + + return con.getInputStream(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (con != null) { + con.disconnect(); + } + } + return null; + } + + /** 鑾峰彇浜岀淮鐮佸浘鐗� **/ + public static JSONObject HttpURLUtilJson(String urlx, String objx) { + JSONObject jo = new JSONObject(); + try { + // 鍒涘缓url璧勬簮 + URL url = new URL(urlx); + // 寤虹珛http杩炴帴 + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + // 璁剧疆鍏佽杈撳嚭 + conn.setDoOutput(true); + + conn.setDoInput(true); + + // 璁剧疆涓嶇敤缂撳瓨 + conn.setUseCaches(false); + // 璁剧疆浼犻�掓柟寮� + conn.setRequestMethod("POST"); + // 璁剧疆缁存寔闀胯繛鎺� + conn.setRequestProperty("Connection", "Keep-Alive"); + // 璁剧疆鏂囦欢瀛楃闆�: + conn.setRequestProperty("Charset", "UTF-8"); + // 璁剧疆鏂囦欢绫诲瀷: + conn.setRequestProperty("contentType", "application/json"); + // 寮�濮嬭繛鎺ヨ姹� + conn.connect(); + OutputStream out = conn.getOutputStream(); + // 鍐欏叆璇锋眰鐨勫瓧绗︿覆 + out.write(objx.getBytes()); + out.flush(); + out.close(); + + // 璇锋眰杩斿洖鐨勭姸鎬� + if (conn.getResponseCode() == 200) { + // 璇锋眰杩斿洖鐨勬暟鎹� + InputStream in = conn.getInputStream(); + try { + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] temp = new byte[1024]; + int rc = 0; + while ((rc = in.read(temp, 0, 100)) > 0) { + swapStream.write(temp, 0, rc); + } + byte[] buffer = swapStream.toByteArray(); + String base64 = Base64.encodeBase64String(buffer); + jo.put("data", base64); + } catch (Exception e1) { + e1.printStackTrace(); + } + } else { + // System.out.println("no++"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return jo; + } + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static JSONObject HttpURLUtil(String url, String data) { + HttpURLConnection con = null; + URL u = null; + String wxMsgXml = null; + JSONObject obj = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); + obj = JSONObject.fromObject(wxMsgXml); + // //System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } + + /** 鍙戦�佹ā鐗堟秷鎭� **/ + public static JSONObject sendTempMsg(String accessToken, String jsonStr) { + JSONObject obj = HttpURLUtil(URL_SEND_TEMP_MSG + accessToken, jsonStr); + return obj; + } + + public static Integer DateToTimestamp(Date time) { + Timestamp ts = new Timestamp(time.getTime()); + return (int) ((ts.getTime()) / 1000); + } + + /** + * 鍙戦�侀摼鎺ュ鏈嶆秷鎭� + * + * @throws JSONException + */ + public static String sendKfLinkMsg(String at, String openId, String title, String description, String url, + String imgUrl) throws JSONException { + String result = "fail"; + + JSONObject obj = new JSONObject(); + obj.put("touser", openId); + obj.put("msgtype", "link"); + + JSONObject pObj = new JSONObject(); + pObj.put("title", title); + pObj.put("description", description); + pObj.put("url", url); + pObj.put("thumb_url", imgUrl); + obj.put("link", pObj); + + JSONObject rObj = HttpURLUtil(URL_SEND_KF_MSG + at, obj.toString()); + // System.out.println("rObj==="+rObj); + if (rObj != null) { + if (rObj.optInt("errcode", -1) == 0) { + result = "suc"; + } else { + result = rObj.optString("errmsg"); + } + } + rObj = null; + obj = null; + + return result; + } + + /** + * 鍙戦�佸浘鐗囧鎴锋秷鎭� + * + * @param access_token + * access_token + * @param toUser + * 鐢ㄦ埛openid + * @param media_id + * 绱犳潗id + * @return + */ + public static String sendKfImageMsg(String access_token, String toUser, String media_id) { + String result = "fail"; + + try { + JSONObject obj = new JSONObject(); + obj.put("touser", toUser); + obj.put("msgtype", "image"); + + JSONObject pObj = new JSONObject(); + pObj.put("media_id", media_id); + obj.put("image", pObj); + + JSONObject rObj = HttpURLUtil(URL_SEND_KF_MSG + access_token, obj.toString()); + System.out.println("rObj==" + rObj.toString()); + if (rObj != null) { + if (rObj.optInt("errcode", -1) == 0) { + result = "suc"; + } else { + result = rObj.optString("errmsg"); + } + } + rObj = null; + obj = null; + } catch (Exception e) { + e.printStackTrace(); + } + + return result; + } + + /** + * 鍙戦�佹枃鏈鎴锋秷鎭� + * + * @param access_token + * access_token + * @param toUser + * 鐢ㄦ埛openid + * @return + */ + public static String sendKfTextMsg(String access_token, String toUser, String content) { + String result = "fail"; + + try { + JSONObject obj = new JSONObject(); + obj.put("touser", toUser); + obj.put("msgtype", "text"); + + JSONObject pObj = new JSONObject(); + pObj.put("content", content); + obj.put("text", pObj); + + JSONObject rObj = HttpURLUtil(URL_SEND_KF_MSG + access_token, obj.toString()); + if (rObj != null) { + if (rObj.optInt("errcode", -1) == 0) { + result = "suc"; + } else { + result = rObj.optString("errmsg"); + } + } + rObj = null; + obj = null; + } catch (Exception e) { + e.printStackTrace(); + } + + return result; + } + + /** 鑾峰彇灏忕▼搴忕爜鍥剧墖 */ + public static String getWXACode(String accessToken, String jsonParam, String path) + throws Exception { + JSONObject obj = HttpURLUtilJson(URL_WXACODE + accessToken, jsonParam); + String qrStr = obj.optString("data"); + return qrStr; + } + + /** 鑾峰彇灏忕▼搴忕爜鍥剧墖 */ + public static String getWXACodeUnlimit(String accessToken, String jsonParam, String path) + throws Exception { + JSONObject obj = HttpURLUtilJson(URL_WXACODEUNLIMIT + accessToken, jsonParam); + String qrStr = obj.optString("data"); + return qrStr; + } + +} diff --git a/src/main/java/com/hx/mp/util/RequestHandler.java b/src/main/java/com/hx/mp/util/RequestHandler.java new file mode 100644 index 0000000..5fa8a6f --- /dev/null +++ b/src/main/java/com/hx/mp/util/RequestHandler.java @@ -0,0 +1,273 @@ +package com.hx.mp.util; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷坛写锟斤拷啵拷锟叫碿reateSign锟斤拷锟斤拷锟斤拷锟缴★拷 + *JX + *linhan + */ +public class RequestHandler { + + /** 锟斤拷锟絬rl锟斤拷址 */ + private String gateUrl; + + /** 锟斤拷钥 */ + private String key; + + /** 锟斤拷锟斤拷牟锟斤拷锟� */ + @SuppressWarnings("rawtypes") + private SortedMap parameters; + + /** debug锟斤拷息 */ + private String debugInfo; + + private HttpServletRequest request; + + private HttpServletResponse response; + + /** + * 锟斤拷锟届函锟斤拷 + * + * @param request + * @param response + */ + /*@SuppressWarnings("rawtypes") + public RequestHandler(HttpServletRequest request, + HttpServletResponse response) { + this.request = request; + this.response = response; + + this.gateUrl = "https://gw.tenpay.com/gateway/pay.htm"; + this.key = ""; + this.parameters = new TreeMap(); + this.debugInfo = ""; + }*/ + + /** + * 锟斤拷锟届函锟斤拷 + * @param request + * @param response + */ + public RequestHandler(HttpServletRequest request, HttpServletResponse response) { + this.request = request; + this.response = response; + + this.gateUrl = "https://gw.tenpay.com/gateway/pay.htm"; + this.key = ""; + this.parameters = new TreeMap(); + this.debugInfo = ""; + } + + /** + * 锟斤拷始锟斤拷锟斤拷锟斤拷 + */ + public void init() { + // nothing to do + } + + /** + * 锟斤拷取锟斤拷诘锟街�,锟斤拷锟斤拷锟斤拷锟街� + */ + public String getGateUrl() { + return gateUrl; + } + + /** + * 锟斤拷锟斤拷锟斤拷诘锟街�,锟斤拷锟斤拷锟斤拷锟街� + */ + public void setGateUrl(String gateUrl) { + this.gateUrl = gateUrl; + } + + /** + * 锟斤拷取锟斤拷钥 + */ + public String getKey() { + return key; + } + + /** + * 绉橀挜 + */ + public void setKey(String key) { + this.key = key; + } + + /** + * 锟斤拷取锟斤拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @return String + */ + public String getParameter(String parameter) { + String s = (String) this.parameters.get(parameter); + return (null == s) ? "" : s; + } + + /** + * 锟斤拷锟矫诧拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @param parameterValue + * 锟斤拷锟斤拷值 + */ + @SuppressWarnings("unchecked") + public void setParameter(String parameter, String parameterValue) { + String v = ""; + if (null != parameterValue) { + v = parameterValue.trim(); + } + this.parameters.put(parameter, v); + } + + /** + * 锟斤拷锟斤拷锟斤拷锟叫的诧拷锟斤拷 + * + * @return SortedMap + */ + @SuppressWarnings("rawtypes") + public SortedMap getAllParameters() { + return this.parameters; + } + + /** + * 锟斤拷取debug锟斤拷息 + */ + public String getDebugInfo() { + return debugInfo; + } + + /** + * 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷URL + * + * @return String + * @throws UnsupportedEncodingException + */ + /*@SuppressWarnings("rawtypes") + public String getRequestURL() throws UnsupportedEncodingException { + + this.createSign(); + + StringBuffer sb = new StringBuffer(); + String enc = TenpayUtil.getCharacterEncoding(this.request, + this.response); + Set es = this.parameters.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + + if (!"spbill_create_ip".equals(k)) { + sb.append(k + "=" + URLEncoder.encode(v, enc) + "&"); + } else { + sb.append(k + "=" + v.replace(".", "%2E") + "&"); + + } + } + + // 去锟斤拷锟斤拷锟揭伙拷锟�& + String reqPars = sb.substring(0, sb.lastIndexOf("&")); + + return this.getGateUrl() + "?" + reqPars; + + }*/ + + /** + * 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷URL + * @return String + * @throws UnsupportedEncodingException + */ + public String getRequestURL() throws UnsupportedEncodingException { + + this.createSign(); + + StringBuffer sb = new StringBuffer(); + String enc = TenpayUtil.getCharacterEncoding(this.request, this.response); + Set es = this.parameters.entrySet(); + Iterator it = es.iterator(); + while(it.hasNext()) { + Map.Entry entry = (Map.Entry)it.next(); + String k = (String)entry.getKey(); + String v = (String)entry.getValue(); + + if(!"spbill_create_ip".equals(k)) { + sb.append(k + "=" + URLEncoder.encode(v, enc) + "&"); + } else { + sb.append(k + "=" + v.replace(".", "%2E") + "&"); + + + } + } + + //去锟斤拷锟斤拷锟揭伙拷锟�& + String reqPars = sb.substring(0, sb.lastIndexOf("&")); + + return this.getGateUrl() + "?" + reqPars; + + } + + public void doSend() throws UnsupportedEncodingException, IOException { + this.response.sendRedirect(this.getRequestURL()); + } + + /** + * TODO 鐢熸垚绛惧悕 + */ + @SuppressWarnings("rawtypes") + public String createSign() { + StringBuffer sb = new StringBuffer(); + Set es = this.parameters.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + if (null != v && !"".equals(v) && !"sign".equals(k) + && !"key".equals(k)) { + sb.append(k + "=" + v + "&"); + } + } + sb.append("key=" + this.getKey()); +System.out.println("sb="+sb); + String enc = TenpayUtil.getCharacterEncoding(this.request, + this.response); + String sign = MD5Util.MD5Encode(sb.toString(), enc).toUpperCase(); + + this.setParameter("sign", sign); + + // debug锟斤拷息 + this.setDebugInfo(sb.toString() + " => sign:" + sign); + + return sign; + } + + /** + * 锟斤拷锟斤拷debug锟斤拷息 + */ + protected void setDebugInfo(String debugInfo) { + this.debugInfo = debugInfo; + } + + protected HttpServletRequest getHttpServletRequest() { + return this.request; + } + + protected HttpServletResponse getHttpServletResponse() { + return this.response; + } + +} diff --git a/src/main/java/com/hx/mp/util/ResponseHandler.java b/src/main/java/com/hx/mp/util/ResponseHandler.java new file mode 100644 index 0000000..4a573a3 --- /dev/null +++ b/src/main/java/com/hx/mp/util/ResponseHandler.java @@ -0,0 +1,225 @@ +package com.hx.mp.util; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 应锟斤拷锟斤拷锟斤拷 应锟斤拷锟斤拷锟斤拷坛写锟斤拷啵拷锟叫磇sTenpaySign锟斤拷锟斤拷锟斤拷锟缴★拷 + *JX + *linhan + */ +public class ResponseHandler { + + /** 锟斤拷钥 */ + private String key; + + /** 应锟斤拷牟锟斤拷锟� */ + @SuppressWarnings("rawtypes") + private SortedMap parameters; + + /** debug锟斤拷息 */ + private String debugInfo; + + private HttpServletRequest request; + + private HttpServletResponse response; + + private String uriEncoding; + + /** + * 锟斤拷锟届函锟斤拷 + * + * @param request + * @param response + */ + @SuppressWarnings("rawtypes") + public ResponseHandler(HttpServletRequest request, + HttpServletResponse response) { + this.request = request; + this.response = response; + + this.key = ""; + this.parameters = new TreeMap(); + this.debugInfo = ""; + + this.uriEncoding = ""; + + Map m = this.request.getParameterMap(); + Iterator it = m.keySet().iterator(); + while (it.hasNext()) { + String k = (String) it.next(); + String v = ((String[]) m.get(k))[0]; + this.setParameter(k, v); + } + + } + + /** + * 锟斤拷取锟斤拷钥 + */ + public String getKey() { + return key; + } + + /** + * 锟斤拷锟斤拷锟斤拷钥 + */ + public void setKey(String key) { + this.key = key; + } + + /** + * 锟斤拷取锟斤拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @return String + */ + public String getParameter(String parameter) { + String s = (String) this.parameters.get(parameter); + return (null == s) ? "" : s; + } + + /** + * 锟斤拷锟矫诧拷锟斤拷值 + * + * @param parameter + * 锟斤拷锟斤拷锟斤拷锟� + * @param parameterValue + * 锟斤拷锟斤拷值 + */ + @SuppressWarnings("unchecked") + public void setParameter(String parameter, String parameterValue) { + String v = ""; + if (null != parameterValue) { + v = parameterValue.trim(); + } + this.parameters.put(parameter, v); + } + + /** + * 锟斤拷锟斤拷锟斤拷锟叫的诧拷锟斤拷 + * + * @return SortedMap + */ + @SuppressWarnings("rawtypes") + public SortedMap getAllParameters() { + return this.parameters; + } + + /** + * 锟角凤拷聘锟酵ㄇ╋拷锟�,锟斤拷锟斤拷锟斤拷:锟斤拷锟斤拷锟斤拷锟斤拷锟絘-z锟斤拷锟斤拷,锟斤拷锟斤拷锟斤拷值锟侥诧拷锟斤拷渭锟角╋拷锟� + * + * @return boolean + */ + @SuppressWarnings("rawtypes") + public boolean isTenpaySign() { + StringBuffer sb = new StringBuffer(); + Set es = this.parameters.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + if (!"sign".equals(k) && null != v && !"".equals(v)) { + sb.append(k + "=" + v + "&"); + } + } + + sb.append("key=" + this.getKey()); + + // 锟斤拷锟秸� + String enc = TenpayUtil.getCharacterEncoding(this.request, + this.response); + String sign = MD5Util.MD5Encode(sb.toString(), enc).toLowerCase(); + + String tenpaySign = this.getParameter("sign").toLowerCase(); + + // debug锟斤拷息 + this.setDebugInfo(sb.toString() + " => sign:" + sign + " tenpaySign:" + + tenpaySign); + + return tenpaySign.equals(sign); + } + + /** + * 锟斤拷锟截达拷锟斤拷锟斤拷锟狡革拷通锟斤拷锟斤拷锟斤拷锟斤拷 + * + * @param msg + * : Success or fail锟斤拷 + * @throws IOException + */ + public void sendToCFT(String msg) throws IOException { + String strHtml = msg; + PrintWriter out = this.getHttpServletResponse().getWriter(); + out.println(strHtml); + out.flush(); + out.close(); + + } + + /** + * 锟斤拷取uri锟斤拷锟斤拷 + * + * @return String + */ + public String getUriEncoding() { + return uriEncoding; + } + + /** + * 锟斤拷锟斤拷uri锟斤拷锟斤拷 + * + * @param uriEncoding + * @throws UnsupportedEncodingException + */ + @SuppressWarnings("rawtypes") + public void setUriEncoding(String uriEncoding) + throws UnsupportedEncodingException { + if (!"".equals(uriEncoding.trim())) { + this.uriEncoding = uriEncoding; + + // 锟斤拷锟斤拷转锟斤拷 + String enc = TenpayUtil.getCharacterEncoding(request, response); + Iterator it = this.parameters.keySet().iterator(); + while (it.hasNext()) { + String k = (String) it.next(); + String v = this.getParameter(k); + v = new String(v.getBytes(uriEncoding.trim()), enc); + this.setParameter(k, v); + } + } + } + + /** + * 锟斤拷取debug锟斤拷息 + */ + public String getDebugInfo() { + return debugInfo; + } + + /** + * 锟斤拷锟斤拷debug锟斤拷息 + */ + protected void setDebugInfo(String debugInfo) { + this.debugInfo = debugInfo; + } + + protected HttpServletRequest getHttpServletRequest() { + return this.request; + } + + protected HttpServletResponse getHttpServletResponse() { + return this.response; + } + +} diff --git a/src/main/java/com/hx/mp/util/TenpayHttpClient.java b/src/main/java/com/hx/mp/util/TenpayHttpClient.java new file mode 100644 index 0000000..24ad9be --- /dev/null +++ b/src/main/java/com/hx/mp/util/TenpayHttpClient.java @@ -0,0 +1,559 @@ +package com.hx.mp.util; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; + +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; + +/** + * 锟狡革拷通http锟斤拷锟斤拷https锟斤拷锟斤拷通锟脚客伙拷锟斤拷<br/> + * ========================================================================<br/> + * api说锟斤拷锟斤拷<br/> + * setReqContent($reqContent),锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷o拷锟斤拷锟斤拷post锟斤拷get锟斤拷锟斤拷锟斤拷get锟斤拷式锟结供<br/> + * getResContent(), 锟斤拷取应锟斤拷锟斤拷锟斤拷<br/> + * setMethod(method),锟斤拷锟斤拷锟斤拷锟襟方凤拷,post锟斤拷锟斤拷get<br/> + * getErrInfo(),锟斤拷取锟斤拷锟斤拷锟斤拷息<br/> + * setCertInfo(certFile, certPasswd),锟斤拷锟斤拷证锟介,双锟斤拷https时锟斤拷要使锟斤拷<br/> + * setCaInfo(caFile), 锟斤拷锟斤拷CA锟斤拷锟斤拷式未pem锟斤拷锟斤拷锟斤拷锟斤拷锟津不硷拷锟�<br/> + * setTimeOut(timeOut)锟斤拷 锟斤拷锟矫筹拷时时锟戒,锟斤拷位锟斤拷<br/> + * getResponseCode(), 取锟斤拷锟截碉拷http状态锟斤拷<br/> + * call(),锟斤拷锟斤拷锟斤拷媒涌锟�<br/> + * getCharset()/setCharset(),锟街凤拷锟斤拷锟�<br/> + * + * ========================================================================<br/> + * + */ +public class TenpayHttpClient { + + private static final String USER_AGENT_VALUE = + "Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)"; + + private static final String JKS_CA_FILENAME = + "tenpay_cacert.jks"; + + private static final String JKS_CA_ALIAS = "tenpay"; + + private static final String JKS_CA_PASSWORD = ""; + + /** ca证锟斤拷锟侥硷拷 */ + private File caFile; + + /** 证锟斤拷锟侥硷拷 */ + private File certFile; + + /** 证锟斤拷锟斤拷锟斤拷 */ + private String certPasswd; + + /** 锟斤拷锟斤拷锟斤拷锟捷o拷锟斤拷锟斤拷post锟斤拷get锟斤拷锟斤拷锟斤拷get锟斤拷式锟结供 */ + private String reqContent; + + /** 应锟斤拷锟斤拷锟斤拷 */ + private String resContent; + + /** 锟斤拷锟襟方凤拷 */ + private String method; + + /** 锟斤拷锟斤拷锟斤拷息 */ + private String errInfo; + + /** 锟斤拷时时锟斤拷,锟斤拷锟斤拷为锟斤拷位 */ + private int timeOut; + + /** http应锟斤拷锟斤拷锟� */ + private int responseCode; + + /** 锟街凤拷锟斤拷锟� */ + private String charset; + + private InputStream inputStream; + + private RequestHandler reqHandler;//鏂逛究鍙栧�兼墍鐢�(quan) + + /*public TenpayHttpClient() { + this.caFile = null; + this.certFile = null; + this.certPasswd = ""; + + this.reqContent = ""; + this.resContent = ""; + this.method = "POST"; + this.errInfo = ""; + this.timeOut = 30;//30锟斤拷 + + this.responseCode = 0; + this.charset = "UTF-8"; + + this.inputStream = null; + }*/ + + public TenpayHttpClient() { + this.caFile = null; + this.certFile = null; + this.certPasswd = ""; + + this.reqContent = ""; + this.resContent = ""; + this.method = "POST"; + this.errInfo = ""; + this.timeOut = 30;//30锟斤拷 + + this.responseCode = 0; + this.charset = "UTF-8"; + + this.inputStream = null; + } + + /** + * 锟斤拷锟斤拷证锟斤拷锟斤拷息 + * @param certFile 证锟斤拷锟侥硷拷 + * @param certPasswd 证锟斤拷锟斤拷锟斤拷 + */ + public void setCertInfo(File certFile, String certPasswd) { + this.certFile = certFile; + this.certPasswd = certPasswd; + } + + /** + * 锟斤拷锟斤拷ca + * @param caFile + */ + public void setCaInfo(File caFile) { + this.caFile = caFile; + } + + /** + * 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 + * @param reqContent 锟斤拷锟斤拷锟斤拷锟斤拷 + */ + public void setReqContent(String reqContent) { + this.reqContent = reqContent; + } + + /** + * 锟斤拷取锟斤拷锟斤拷锟斤拷锟� + * @return String + * @throws IOException + */ + public String getResContent() { + try { + this.doResponse(); + } catch (IOException e) { + this.errInfo = e.getMessage(); + //return ""; + } + + return this.resContent; + } + + /** + * 锟斤拷锟斤拷锟斤拷锟襟方凤拷post锟斤拷锟斤拷get + * @param method 锟斤拷锟襟方凤拷post/get + */ + public void setMethod(String method) { + this.method = method; + } + + /** + * 锟斤拷取锟斤拷锟斤拷锟斤拷息 + * @return String + */ + public String getErrInfo() { + return this.errInfo; + } + + /** + * 锟斤拷锟矫筹拷时时锟斤拷,锟斤拷锟斤拷为锟斤拷位 + * @param timeOut 锟斤拷时时锟斤拷,锟斤拷锟斤拷为锟斤拷位 + */ + public void setTimeOut(int timeOut) { + this.timeOut = timeOut; + } + + /** + * 锟斤拷取http状态锟斤拷 + * @return int + */ + public int getResponseCode() { + return this.responseCode; + } + + /** + * 执锟斤拷http锟斤拷锟矫★拷true:锟缴癸拷 false:失锟斤拷 + * @return boolean + */ +/* public boolean call() { + + boolean isRet = false; + + + //http + if(null == this.caFile && null == this.certFile) { + System.out.println("娌℃湁CA"); + try { + this.callHttp(); + isRet = true; + } catch (IOException e) { + this.errInfo = e.getMessage(); + } + return isRet; + } + + //https + try { + this.callHttps(); + isRet = true; + } catch (UnrecoverableKeyException e) { + this.errInfo = e.getMessage(); + } catch (KeyManagementException e) { + this.errInfo = e.getMessage(); + } catch (CertificateException e) { + this.errInfo = e.getMessage(); + } catch (KeyStoreException e) { + this.errInfo = e.getMessage(); + } catch (NoSuchAlgorithmException e) { + this.errInfo = e.getMessage(); + } catch (IOException e) { + this.errInfo = e.getMessage(); + } + + return isRet; + + }*/ + + /** + * 执锟斤拷http锟斤拷锟矫★拷true:锟缴癸拷 false:失锟斤拷 + * @return boolean + */ + public boolean call() { + + boolean isRet = false; + + + //http + if(null == this.caFile && null == this.certFile) { + System.out.println("娌℃湁CA"); + try { + this.callHttp(); + isRet = true; + } catch (IOException e) { + this.errInfo = e.getMessage(); + } + return isRet; + } + + //https + try { + this.callHttps(); + isRet = true; + } catch (UnrecoverableKeyException e) { + this.errInfo = e.getMessage(); + } catch (KeyManagementException e) { + this.errInfo = e.getMessage(); + } catch (CertificateException e) { + this.errInfo = e.getMessage(); + } catch (KeyStoreException e) { + this.errInfo = e.getMessage(); + } catch (NoSuchAlgorithmException e) { + this.errInfo = e.getMessage(); + } catch (IOException e) { + this.errInfo = e.getMessage(); + } + + return isRet; + + } + + protected void callHttp() throws IOException { + + if("POST".equals(this.method.toUpperCase())) { + String url = HttpClientUtil.getURL(this.reqContent); + System.out.println("tenpayHttpClient:url:"+url); + //String queryString = HttpClientUtil.getQueryString(this.reqContent); + //byte[] postData = queryString.getBytes(this.charset); + + String queryString = createXmlPosData(); + byte[] postData = queryString.getBytes(this.charset); + this.httpPostMethod(url, postData); + + return ; + } + + this.httpGetMethod(this.reqContent); + + } + + protected void callHttps() throws IOException, CertificateException, + KeyStoreException, NoSuchAlgorithmException, + UnrecoverableKeyException, KeyManagementException { + // ca目录 + String caPath = this.caFile.getParent(); + + System.out.println("caPath:"+caPath); + File jksCAFile = new File(caPath + "/" + + TenpayHttpClient.JKS_CA_FILENAME); + if (!jksCAFile.isFile()) { + X509Certificate cert = (X509Certificate) HttpClientUtil + .getCertificate(this.caFile); + + FileOutputStream out = new FileOutputStream(jksCAFile); + + // store jks file + HttpClientUtil.storeCACert(cert, TenpayHttpClient.JKS_CA_ALIAS, + TenpayHttpClient.JKS_CA_PASSWORD, out); + + out.close(); + + } + + FileInputStream trustStream = new FileInputStream(jksCAFile); + FileInputStream keyStream = new FileInputStream(this.certFile); + + SSLContext sslContext = HttpClientUtil.getSSLContext(trustStream, + TenpayHttpClient.JKS_CA_PASSWORD, keyStream, this.certPasswd); + + //锟截憋拷锟斤拷 + keyStream.close(); + trustStream.close(); + + if("POST".equals(this.method.toUpperCase())) { + String url = HttpClientUtil.getURL(this.reqContent); + + //鍘熸湰鏄洿鎺ュ弬鏁拌浆涓哄瓧鑺傛暟缁勭殑锛岀幇鍦ㄧ粍鎷紉ml + //String queryString = HttpClientUtil.getQueryString(this.reqContent);//鑾峰彇閾炬帴涓嬮潰鐨勫唴瀹� + //byte[] postData = queryString.getBytes(this.charset);//鎶婂弬鏁拌浆涓哄瓧鑺傛暟缁� + + //鍏堣幏鍙栧弬鏁� + String queryString = createXmlPosData(); + + byte[] postData = queryString.getBytes(this.charset);//鎶婂弬鏁拌浆涓哄瓧鑺傛暟缁� + + this.httpsPostMethod(url, postData, sslContext); + + return ; + } + + this.httpsGetMethod(this.reqContent, sslContext); + + } + + /** + * 锟斤拷http post锟斤拷式通锟斤拷 + * @param url + * @param postData + * @throws IOException + */ + protected void httpPostMethod(String url, byte[] postData) + throws IOException { + + HttpURLConnection conn = HttpClientUtil.getHttpURLConnection(url); + + this.doPost(conn, postData); + } + + /** + * 锟斤拷http get锟斤拷式通锟斤拷 + * + * @param url + * @throws IOException + */ + protected void httpGetMethod(String url) throws IOException { + + HttpURLConnection httpConnection = + HttpClientUtil.getHttpURLConnection(url); + + this.setHttpRequest(httpConnection); + + httpConnection.setRequestMethod("GET"); + + this.responseCode = httpConnection.getResponseCode(); + + this.inputStream = httpConnection.getInputStream(); + + } + + /** + * 锟斤拷https get锟斤拷式通锟斤拷 + * @param url + * @param sslContext + * @throws IOException + */ + protected void httpsGetMethod(String url, SSLContext sslContext) + throws IOException { + + SSLSocketFactory sf = sslContext.getSocketFactory(); + + HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url); + + conn.setSSLSocketFactory(sf); + + this.doGet(conn); + + } + + //鎻愪氦https post 鏁版嵁 s + protected void httpsPostMethod(String url, byte[] postData, + SSLContext sslContext) throws IOException { + + SSLSocketFactory sf = sslContext.getSocketFactory(); + + HttpsURLConnection conn = HttpClientUtil.getHttpsURLConnection(url); + + conn.setSSLSocketFactory(sf); + + this.doPost(conn, postData); + + } + + /** + * 锟斤拷锟斤拷http锟斤拷锟斤拷默锟斤拷锟斤拷锟斤拷 + * @param httpConnection + */ + protected void setHttpRequest(HttpURLConnection httpConnection) { + + //锟斤拷锟斤拷锟斤拷锟接筹拷时时锟斤拷 + httpConnection.setConnectTimeout(this.timeOut * 1000); + + //User-Agent + httpConnection.setRequestProperty("User-Agent", + TenpayHttpClient.USER_AGENT_VALUE); + + //锟斤拷使锟矫伙拷锟斤拷 + httpConnection.setUseCaches(false); + + //锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� + httpConnection.setDoInput(true); + httpConnection.setDoOutput(true); + + } + + /** + * 锟斤拷锟斤拷应锟斤拷 + * @throws IOException + */ + protected void doResponse() throws IOException { + + if(null == this.inputStream) { + return; + } + + //锟斤拷取应锟斤拷锟斤拷锟斤拷 + this.resContent=HttpClientUtil.InputStreamTOString(this.inputStream,this.charset); + + // System.out.println("tenpayHttpClinet:385:"+resContent); + //锟截憋拷锟斤拷锟斤拷锟斤拷 + this.inputStream.close(); + + } + + /** + * post锟斤拷式锟斤拷锟斤拷 + * @param conn + * @param postData + * @throws IOException + */ + protected void doPost(HttpURLConnection conn, byte[] postData) + throws IOException { + + // 锟斤拷post锟斤拷式通锟斤拷 + conn.setRequestMethod("POST"); + + // 锟斤拷锟斤拷锟斤拷锟斤拷默锟斤拷锟斤拷锟斤拷 + this.setHttpRequest(conn); + + // Content-Type + conn.setRequestProperty("Content-Type", + "application/x-www-form-urlencoded"); + + BufferedOutputStream out = new BufferedOutputStream(conn + .getOutputStream()); + + final int len = 1024; // 1KB + HttpClientUtil.doOutput(out, postData, len); + + // 锟截憋拷锟斤拷 + out.close(); + + // 锟斤拷取锟斤拷应锟斤拷锟斤拷状态锟斤拷 + this.responseCode = conn.getResponseCode(); + + // 锟斤拷取应锟斤拷锟斤拷锟斤拷锟斤拷 + this.inputStream = conn.getInputStream(); + + } + + /** + * get锟斤拷式锟斤拷锟斤拷 + * @param conn + * @throws IOException + */ + protected void doGet(HttpURLConnection conn) throws IOException { + + //锟斤拷GET锟斤拷式通锟斤拷 + conn.setRequestMethod("GET"); + + //锟斤拷锟斤拷锟斤拷锟斤拷默锟斤拷锟斤拷锟斤拷 + this.setHttpRequest(conn); + + //锟斤拷取锟斤拷应锟斤拷锟斤拷状态锟斤拷 + this.responseCode = conn.getResponseCode(); + + //锟斤拷取应锟斤拷锟斤拷锟斤拷锟斤拷 + this.inputStream = conn.getInputStream(); + } + + public void setRequestHandler(RequestHandler reqHandler) { + this.reqHandler = reqHandler; + } + + + //缁勫缓xml鏍煎紡浼犻�掑弬鏁� + @SuppressWarnings({ "rawtypes", "unused" }) + public String createXmlPosData(){ + //鍏堣幏鍙栧弬鏁� + Document document = DocumentHelper.createDocument(); + Element root = document.addElement("xml"); + + if(reqHandler==null)throw new RuntimeException("璇峰厛璁惧叆reqHandler"); + + SortedMap parameters = reqHandler.getAllParameters(); + Set es = reqHandler.getAllParameters().entrySet(); + Iterator it = es.iterator(); + while(it.hasNext()) { + Map.Entry entry = (Map.Entry)it.next(); + String k = (String)entry.getKey(); + String v = (String)entry.getValue(); + + Element ToUserName = root.addElement(k); + ToUserName.addText(v); + } + + String queryString = document.asXML();//杞负String + + queryString = queryString.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").trim(); + + System.out.println("xml锛�"+queryString); + return queryString; + } + +} diff --git a/src/main/java/com/hx/mp/util/TenpayUtil.java b/src/main/java/com/hx/mp/util/TenpayUtil.java new file mode 100644 index 0000000..8d6758a --- /dev/null +++ b/src/main/java/com/hx/mp/util/TenpayUtil.java @@ -0,0 +1,132 @@ +package com.hx.mp.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +public class TenpayUtil { + + /** + * 锟窖讹拷锟斤拷转锟斤拷锟斤拷锟街凤拷 + * @param obj + * @return String 转锟斤拷锟斤拷锟街凤拷,锟斤拷锟斤拷锟斤拷为null,锟津返回匡拷锟街凤拷. + */ + public static String toString(Object obj) { + if(obj == null) + return ""; + + return obj.toString(); + } + + /** + * 锟窖讹拷锟斤拷转锟斤拷为int锟斤拷值. + * + * @param obj + * 锟斤拷锟斤拷锟街的讹拷锟斤拷. + * @return int 转锟斤拷锟斤拷锟斤拷锟街�,锟皆诧拷锟斤拷转锟斤拷锟侥讹拷锟襟返伙拷0锟斤拷 + */ + public static int toInt(Object obj) { + int a = 0; + try { + if (obj != null) + a = Integer.parseInt(obj.toString()); + } catch (Exception e) { + + } + return a; + } + + /** + * 锟斤拷取锟斤拷前时锟斤拷 yyyyMMddHHmmss + * @return String + */ + public static String getCurrTime() { + Date now = new Date(); + SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String s = outFormat.format(now); + return s; + } + + /** + * 锟斤拷取锟斤拷前锟斤拷锟斤拷 yyyyMMdd + * @param date + * @return String + */ + public static String formatDate(Date date) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); + String strDate = formatter.format(date); + return strDate; + } + + /** + * 取锟斤拷一锟斤拷指锟斤拷锟斤拷锟饺达拷小锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�. + * + * @param length + * int 锟借定锟斤拷取锟斤拷锟斤拷锟斤拷锟侥筹拷锟饺★拷length小锟斤拷11 + * @return int 锟斤拷锟斤拷锟斤拷傻锟斤拷锟斤拷锟斤拷 + */ + public static int buildRandom(int length) { + int num = 1; + double random = Math.random(); + if (random < 0.1) { + random = random + 0.1; + } + for (int i = 0; i < length; i++) { + num = num * 10; + } + return (int) ((random * num)); + } + + /** + * 锟斤拷取锟斤拷锟斤拷锟街凤拷 + * @param request + * @param response + * @return String + */ + public static String getCharacterEncoding(HttpServletRequest request, + HttpServletResponse response) { + + if(null == request || null == response) { + return "utf-8"; + } + + String enc = request.getCharacterEncoding(); + if(null == enc || "".equals(enc)) { + enc = response.getCharacterEncoding(); + } + + if(null == enc || "".equals(enc)) { + enc = "utf-8"; + } + + return enc; + } + + /** + * 锟斤拷取unix时锟戒,锟斤拷1970-01-01 00:00:00锟斤拷始锟斤拷锟斤拷锟斤拷 + * @param date + * @return long + */ + public static long getUnixTime(Date date) { + if( null == date ) { + return 0; + } + + return date.getTime()/1000; + } + + /** + * 时锟斤拷转锟斤拷锟斤拷锟街凤拷 + * @param date 时锟斤拷 + * @param formatType 锟斤拷式锟斤拷锟斤拷锟斤拷 + * @return String + */ + public static String date2String(Date date, String formatType) { + SimpleDateFormat sdf = new SimpleDateFormat(formatType); + return sdf.format(date); + } + +} diff --git a/src/main/java/com/hx/mp/util/WXPayUtil.java b/src/main/java/com/hx/mp/util/WXPayUtil.java new file mode 100644 index 0000000..8a3eb50 --- /dev/null +++ b/src/main/java/com/hx/mp/util/WXPayUtil.java @@ -0,0 +1,458 @@ +package com.hx.mp.util; + +import com.hx.exception.ServiceException; +import com.hx.util.SimpleTool; +import net.sf.json.JSONObject; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import javax.net.ssl.SSLContext; +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.FileInputStream; +import java.security.KeyStore; +import java.util.*; + + +/** 寰俊鏀粯/閫�娆� + * @author ChenJiaHe + */ +public class WXPayUtil { + + // 閫�娆炬帴鍙h繛鎺� + private static final String REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund"; + /**鏌ヨ璁㈠崟閾炬帴*/ + @SuppressWarnings("unused") + private static final String QUERY_URL = "https://api.mch.weixin.qq.com/pay/orderquery"; + + /**鍚屾剰涓嬪崟閾炬帴*/ + private static final String FIRST_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder"; + + // 浼佷笟浠樻 + private static final String CORP_PAY_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; + + + /** 浼佷笟浠樻*/ + public static JSONObject qdCorpPay(String appId, String orderNo, String certPath, String mchid, String mchKey, String openId, String payFee, String desc) + throws Exception { + + SortedMap<Object, Object> parameters = new TreeMap<Object, Object>(); + parameters.put("mch_appid", appId); + parameters.put("mchid", mchid); + parameters.put("partner_trade_no", orderNo); + parameters.put("nonce_str", UUID.randomUUID().toString().substring(0, 30)); + parameters.put("openid", openId); + parameters.put("check_name", "NO_CHECK"); + parameters.put("amount", payFee); + parameters.put("spbill_create_ip", "8.8.8.8"); + parameters.put("desc", desc); + + String sign = WXSignUtils.createSign("UTF-8", parameters, mchKey); + + parameters.put("sign", sign); + String xmlInfo = HttpXmlUtils.transferXml(parameters); + + JSONObject returnObj = new JSONObject(); + + try { + CloseableHttpResponse response = HttpUtil.Post(CORP_PAY_URL, xmlInfo, true, certPath, mchid); + String transfersXml = EntityUtils.toString(response.getEntity(), "utf-8"); + // System.out.println("娓犻亾绔紒涓氫粯娆撅細" + transfersXml); + Map<String, String> transferMap = HttpXmlUtils.parseRefundXml(transfersXml); + boolean bl = false; + if (transferMap.size() > 0) { + if (transferMap.get("return_code").equals("SUCCESS")) { + // 閫氳鎴愬姛 + if (transferMap.get("result_code").equals("SUCCESS")) { + // 鎴愬姛闇�瑕佽繘琛岀殑閫昏緫鎿嶄綔 + returnObj.put("status", "suc"); + } else { + bl = true; + returnObj.put("status", "fail"); + returnObj.put("errMsg", transferMap.get("err_code") + "|" + transferMap.get("err_code_des")); + } + } else { + bl = true; + // 閫氳涓嶆垚鍔� + returnObj.put("status", "fail"); + returnObj.put("errMsg", transferMap.get("return_msg")); + } + } else { + bl = true; + returnObj.put("status", "fail"); + returnObj.put("errMsg", "杩斿洖涓虹┖"); + } + if (bl) { + System.out.println("浼佷笟浠樻澶辫触锛�" + transfersXml); + } + } catch (Exception e) { + e.printStackTrace(); + returnObj.put("status", "fail"); + returnObj.put("errMsg", e.getMessage()); + } + + return returnObj; + } + + /**缁熶竴鏀粯 + * @param request 鏂规硶鑾峰彇 + * @param appId 灏忕▼搴忓彿 + * @param partner 鍟嗘埛鍙� + * @param key 绉橀挜 + * @param notifyUrl 鍥炶皟閾炬帴 + * @param out_trade_no 璁㈠崟鍙� + * @param body 鍟嗗搧鎻忚堪 + * @param total_fee 鏀粯閲戦 + * @param openid 鐢ㄦ埛openId + * @param attach 闄勫甫鏁版嵁鍖� + * @param notifyUrl 鍥炶皟閫氱煡鍦板潃 + * @param trade_type 浜ゆ槗绫诲瀷 + * @return JSON status = "SUC"涓烘垚鍔� + */ + public static JSONObject unifiedPay(HttpServletRequest request,String appId,String partner,String key,String notifyUrl,String out_trade_no, String body, String total_fee, String openid, + String attach,String trade_type) throws Exception { + + if (!SimpleTool.checkNotNull(notifyUrl)) { + throw new ServiceException("鏀粯鍔熻兘鏁呴殰锛�"); + } + + // 鍒涘缓鏌ヨ璇锋眰瀵硅薄 + RequestHandler reqHandler = new RequestHandler(null, null); + // 閫氫俊瀵硅薄 + TenpayHttpClient httpClient = new TenpayHttpClient(); + // 搴旂瓟瀵硅薄 + ClientResponseHandler resHandler = new ClientResponseHandler(); + + // ----------------------------- + // 璁剧疆璇锋眰鍙傛暟 + // ----------------------------- + // reqHandler.init(); + reqHandler.setKey(key); + reqHandler.setGateUrl(FIRST_ORDER_URL);// 璇锋眰URL + + // ----------------------------- + // 璁剧疆鎺ュ彛鍙傛暟(sign鍚庡彴鑷姩鐢熸垚) + // ----------------------------- + reqHandler.setParameter("appid", appId); // 鍏紬鍙�/灏忕▼搴� + reqHandler.setParameter("mch_id", partner); // 鍟嗘埛鍙� + reqHandler.setParameter("nonce_str", SimpleTool.getUUIDName().substring(0, 30));// 闅忔満涔辩爜 + reqHandler.setParameter("body", body);// 鍟嗗搧鎻忚堪 + reqHandler.setParameter("out_trade_no", out_trade_no);// 鍟嗘埛璁㈠崟鍙� + reqHandler.setParameter("total_fee", total_fee);// 鎬婚噾棰� + reqHandler.setParameter("spbill_create_ip", "8.8.8.8");// 缁堢IP + reqHandler.setParameter("notify_url",notifyUrl);// 閫氱煡鍦板潃 + reqHandler.setParameter("trade_type", trade_type);// 浜ゆ槗绫诲瀷 + // JSAPI锛孨ATIVE锛孉PP + reqHandler.setParameter("openid", openid);// openId + reqHandler.setParameter("attach", attach);// 闄勫甫鏁版嵁鍖� + + // ----------------------------- + // 璁剧疆閫氫俊鍙傛暟 + // ----------------------------- + // 璁剧疆璇锋眰杩斿洖鐨勭瓑寰呮椂闂� + httpClient.setTimeOut(5); + + // 璁剧疆ca璇佷功 + // httpClient.setCaInfo(new File(CA_PATH)); + + // 璁剧疆涓汉(鍟嗘埛)璇佷功 + // httpClient.setCertInfo(new File(CERT_PATH), CERT_PWD); + + // 璁剧疆鍙戦�佺被鍨婸OST + httpClient.setMethod("POST"); + + // 璁剧疆璇锋眰鍐呭(鐢熸垚sign) + String requestUrl = reqHandler.getRequestURL();// 缁勬嫾https://www.baidu.com?a=x&b=xx + + httpClient.setReqContent(requestUrl);// https://www.baidu.com?a=x&b=xx + String rescontent = "null"; + + httpClient.setRequestHandler(reqHandler);// 鎶婂鐞嗗璞★紝鍍忔槸鍙傛暟鍚勭涓滆タ閮借缃繘鍘绘柟渚胯幏鍙�(quan) + + // 杩斿洖鍑哄幓鐨勫璞�(鐘舵�侊紝閿欒鍘熷洜锛岃鎿嶄綔鐩稿叧淇℃伅(鍙傛暟,杩斿洖鍊�)) + JSONObject returnObj = new JSONObject(); + + // 鍚庡彴璋冪敤 + if (httpClient.call()) { + System.out.println("缁熶竴涓嬪崟,鎴愬姛cll浜�::"); + + // 璁剧疆缁撴灉鍙傛暟 + rescontent = httpClient.getResContent(); + System.out.println("缁熶竴涓嬪崟杩斿洖缁撴灉:" + rescontent); + resHandler.setContent(rescontent);// 瑙f瀽xml + resHandler.setKey(key); + + // 鑾峰彇杩斿洖鍙傛暟 + String return_code = resHandler.getParameter("return_code"); + String return_msg = resHandler.getParameter("return_msg"); + + // 鍒ゆ柇绛惧悕鍙婄粨鏋� + if (resHandler.isTenpaySign() && "SUCCESS".equals(return_code)) { + String prepay_id = resHandler.getParameter("prepay_id");// 棰勬敮浠樹氦鏄撲細璇濇爣璇� + String code_url = resHandler.getParameter("code_url");// 浜岀淮鐮侀摼鎺� + + String result_code = resHandler.getParameter("result_code");// 涓氬姟缁撴灉 + String appid = resHandler.getParameter("appid");// 鍏紬璐﹀彿ID + String mch_id = resHandler.getParameter("mch_id");// 鍟嗘埛鍙� + String nonce_str = resHandler.getParameter("nonce_str");// 闅忔満鐮� + String sign = resHandler.getParameter("sign");// 绛惧悕 + + if (result_code.equals("SUCCESS")) { + returnObj.put("status", "suc"); + returnObj.put("sign", sign); + returnObj.put("nonce_str", nonce_str); + returnObj.put("mch_id", mch_id); + returnObj.put("appid", appid); + returnObj.put("prepay_id", prepay_id); + returnObj.put("code_url", code_url); + returnObj.put("out_trade_no", out_trade_no); + } else { + String errMsg = "[ERROR]result_code:" + resHandler.getParameter("result_code") + " err_code:" + + resHandler.getParameter("err_code") + "err_code_des:" + + resHandler.getParameter("err_code_des"); + + // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫�� + returnObj.put("status", "ERROR-C"); + returnObj.put("errMsg", errMsg); + } + } else { + String errMsg = "return_code:" + return_code + "err_code:" + resHandler.getParameter("err_code") + + " return_msg:" + return_msg; + // 閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫�� + returnObj.put("status", "ERROR-B"); + returnObj.put("errMsg", errMsg); + } + } else { + // 鏈夊彲鑳藉洜涓虹綉缁滃師鍥狅紝璇锋眰宸茬粡澶勭悊锛屼絾鏈敹鍒板簲绛斻�� + returnObj.put("status", "ERROR-A"); + returnObj.put("errMsg", httpClient.getResponseCode() + ":" + httpClient.getErrInfo()); + } + + // 鑾峰彇debug淇℃伅,寤鸿鎶婅姹傘�佸簲绛斿唴瀹广�乨ebug淇℃伅锛岄�氫俊杩斿洖鐮佸啓鍏ユ棩蹇楋紝鏂逛究瀹氫綅闂 + String detail = "http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + ";" + "req url:" + + requestUrl + ";" + ";" + "req debug:" + reqHandler.getDebugInfo() + ";" + "res content:" + rescontent + + ";" + "res debug:" + resHandler.getDebugInfo() + ";"; + + returnObj.put("detail", detail); + + + return returnObj; + } + + /**澶勭悊淇℃伅 + */ + public static JSONObject paymentData(JSONObject payObj,String key){ + JSONObject wxObj = new JSONObject(); + /**缁熶竴涓嬪崟*/ + String payStatus = payObj.getString("status"); + if (payStatus.equals("suc")) { + // JSONObject payObj = po.getJSONObject("inf"); + String appId = payObj.getString("appid"); + String nonceStr = payObj.getString("nonce_str"); + String prepay_id = payObj.getString("prepay_id"); + // JSAPI璋冪敤鏀粯杩斿洖鐨勬暟鎹� + String timeStamp = SimpleTool.getTenTime(new Date()).toString(); + String signType = "MD5"; + String packagef = "prepay_id=" + prepay_id; + RequestHandler reqHandler = new RequestHandler(null, null); + reqHandler.setParameter("appId", appId); + reqHandler.setParameter("nonceStr", nonceStr); + reqHandler.setParameter("timeStamp", timeStamp); + reqHandler.setParameter("package", packagef); + reqHandler.setParameter("signType", signType); + reqHandler.setKey(key); + String paySign = reqHandler.createSign();// 鐢熸垚绛惧悕 + wxObj.put("orderNo", payObj.getString("out_trade_no")); + wxObj.put("paySign", paySign); + wxObj.put("appId", appId); + wxObj.put("nonceStr", nonceStr); + wxObj.put("package", packagef); + wxObj.put("timeStamp", timeStamp); + } else { + throw new RuntimeException(payObj.toString()); + } + return wxObj; + } + + /** + * 閫�娆� + * @param appId 灏忕▼搴�/鍏紬鍙� appId + * @param partner 鍟嗘埛鍙� + * @param key 鍟嗘埛鍙风閽� + * @param certPath 涓汉鍟嗘埛璇佷功 + * @param out_trade_no 鍟嗘埛璁㈠崟鍙� + * @param transaction_id 璐粯閫氳鍗曞彿锛堝井淇¤鍗曞彿锛� + * @param out_refund_no 鍟嗘埛閫�鍗曞彿 + * @param total_fee 璁㈠崟鎬婚(鍗曚綅:鍒�) + * @param refund_fee 閫�娆鹃噾棰�(鍗曚綅:鍒�) + * @return JSON status="SUCCESS"(鎴愬姛) (鐘舵�侊紝閿欒鍘熷洜锛岃鎿嶄綔鐩稿叧淇℃伅(鍙傛暟,杩斿洖鍊�)) + */ + public static JSONObject refund(String appId,String partner,String key,String certPath,String out_trade_no, String transaction_id, String out_refund_no, String total_fee, + String refund_fee) { + try{ + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + FileInputStream instream = new FileInputStream(new File(certPath)); + try { + keyStore.load(instream,partner.toCharArray()); + }finally { + instream.close(); + } + // Trust own CA and all self-signed certs + SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,partner.toCharArray()).build(); + // Allow TLSv1 protocol only + SSLConnectionSocketFactory sslsf; + sslsf = new SSLConnectionSocketFactory( + sslcontext, new String[] { "TLSv1" }, null, + SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + CloseableHttpClient httpclient = HttpClients.custom() + .setSSLSocketFactory(sslsf).build(); + HttpPost httppost = new HttpPost(REFUND_URL); + String xml = wxPayRefundData(appId,partner,key,out_trade_no, transaction_id, total_fee, out_refund_no, refund_fee); + try { + StringEntity se = new StringEntity(xml); + httppost.setEntity(se); + System.out.println("executing request" + httppost.getRequestLine()); + CloseableHttpResponse responseEntry = httpclient.execute(httppost); + try { + HttpEntity entity = responseEntry.getEntity(); + System.out.println(responseEntry.getStatusLine()); + if (entity != null) { + SAXReader saxReader = new SAXReader(); + Document document = saxReader.read(entity.getContent()); + Element rootElt = document.getRootElement(); + String resultCode = rootElt.elementText("result_code"); + JSONObject result = new JSONObject(); + + if(resultCode.equals("SUCCESS")){ + result.put("weixinPayUrl", rootElt.elementText("code_url")); + result.put("prepayId", rootElt.elementText("prepay_id")); + result.put("msg","success"); + + String refund_id = rootElt.elementText("refund_id");//寰俊閫�娆惧崟鍙� + String r_out_refund_no=rootElt.elementText("out_refund_no"); + String errMsg = "鍟嗘埛鍙�"+r_out_refund_no+"鐨勯��娆炬祦姘村彿鏄細"+refund_id; + result.put("status", "SUCCESS"); + result.put("errMsg", errMsg); + result.put("refund_id", refund_id); + }else{ + String errMsg = "[ERROR]result_code:" + rootElt.elementText("result_code")+ + " err_code:" + rootElt.elementText("err_code"); + + //閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫�� + result.put("errMsg", errMsg); + result.put("status","false"); + result.put("msg",rootElt.elementText("err_code_des")); + } + return result; + } + EntityUtils.consume(entity); + } + finally { + responseEntry.close(); + } + } + finally { + httpclient.close(); + } + return null; + }catch(Exception e){ + e.printStackTrace(); + JSONObject result = new JSONObject(); + result.put("status","error"); + result.put("msg",e.getMessage()); + return result; + } + } + + /** 灏佽鍙傛暟鏁版嵁 + * @param appId 灏忕▼搴�/鍏紬鍙� appId + * @param partner 鍟嗘埛鍙� + * @param key 鍟嗘埛鍙风閽� + * @param out_trade_no 鍟嗘埛璁㈠崟鍙� + * @param transaction_id 璐粯閫氳鍗曞彿锛堝井淇¤鍗曞彿锛� + * @param out_refund_no 鍟嗘埛閫�鍗曞彿 + * @param total_fee 璁㈠崟鎬婚(鍗曚綅:鍒�) + * @param refund_fee 閫�娆鹃噾棰�(鍗曚綅:鍒�) + * @return + */ + public static String wxPayRefundData(String appId,String partner,String key,String out_trade_no, String transaction_id,String out_refund_no,String total_fee,String refund_fee) { + StringBuffer xml = new StringBuffer(); + String data = null; + try { + String nonceStr = SimpleTool.getUUIDName().substring(0,30); + xml.append("</xml>"); + SortedMap<String,String> parameters = new TreeMap<String,String>(); + parameters.put("appid",appId); + parameters.put("mch_id",partner); + parameters.put("nonce_str", nonceStr); + parameters.put("out_trade_no", out_trade_no); + parameters.put("transaction_id", transaction_id); + parameters.put("out_refund_no", out_refund_no); + parameters.put("fee_type", "CNY"); + parameters.put("total_fee", total_fee);//鎬婚噾棰� + parameters.put("refund_fee", refund_fee);//閫�娆鹃噾棰� + parameters.put("op_user_id",partner); + parameters.put("sign", createSign(parameters,key)); + + data =SortedMaptoXml(parameters); + } catch (Exception e) { + System.err.println(e.getMessage()); + return null; + } + return data; + } + + /** + * 鍒涘缓md5鎽樿,瑙勫垯鏄�:鎸夊弬鏁板悕绉癮-z鎺掑簭,閬囧埌绌哄�肩殑鍙傛暟涓嶅弬鍔犵鍚嶃�� + */ + public static String createSign(SortedMap<String, String> packageParams, String AppKey) { + StringBuffer sb; + sb = new StringBuffer(); + Set es = packageParams.entrySet(); + Iterator it = es.iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + String k = (String) entry.getKey(); + String v = (String) entry.getValue(); + if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) { + sb.append(k + "=" + v + "&"); + } + } + sb.append("key=" + AppKey); + String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase(); + return sign; + } + + /** + * @Author: HONGLINCHEN + * @Description:璇锋眰鍊艰浆鎹负xml鏍煎紡 SortedMap杞瑇ml + * @param params + * @Date: 2017-9-7 17:18 + */ + private static String SortedMaptoXml(SortedMap<String,String> params) { + StringBuilder sb = new StringBuilder(); + Set es = params.entrySet(); + Iterator it = es.iterator(); + sb.append("<xml>\n"); + while(it.hasNext()) { + Map.Entry entry = (Map.Entry)it.next(); + String k = (String)entry.getKey(); + Object v = entry.getValue(); + sb.append("<"+k+">"); + sb.append(v); + sb.append("</"+k+">\n"); + } + sb.append("</xml>"); + return sb.toString(); + } +} diff --git a/src/main/java/com/hx/mp/util/WXSignUtils.java b/src/main/java/com/hx/mp/util/WXSignUtils.java new file mode 100644 index 0000000..8e921c5 --- /dev/null +++ b/src/main/java/com/hx/mp/util/WXSignUtils.java @@ -0,0 +1,33 @@ +package com.hx.mp.util; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; + +public class WXSignUtils { + /** + * 寰俊鏀粯绛惧悕绠楁硶sign + * @param characterEncoding + * @param parameters + * @return + */ + @SuppressWarnings("rawtypes") + public static String createSign(String characterEncoding, SortedMap<Object,Object> parameters, String key){ + StringBuffer sb = new StringBuffer(); + Set es = parameters.entrySet();//鎵�鏈夊弬涓庝紶鍙傜殑鍙傛暟鎸夌収accsii鎺掑簭锛堝崌搴忥級 + Iterator it = es.iterator(); + while(it.hasNext()) { + Map.Entry entry = (Map.Entry)it.next(); + String k = (String)entry.getKey(); + Object v = entry.getValue(); + if(null != v && !"".equals(v) + && !"sign".equals(k) && !"key".equals(k)) { + sb.append(k + "=" + v + "&"); + } + } + sb.append("key=" + key); + String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase(); + return sign; + } +} diff --git a/src/main/java/com/hx/mp/util/WechatUtil.java b/src/main/java/com/hx/mp/util/WechatUtil.java new file mode 100644 index 0000000..9d6406e --- /dev/null +++ b/src/main/java/com/hx/mp/util/WechatUtil.java @@ -0,0 +1,77 @@ +package com.hx.mp.util; + +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; +import net.sf.json.JSONObject; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.UnsupportedEncodingException; +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Security; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + + +public class WechatUtil { + public static boolean initialized = false; + + //log4j鏃ュ織 + private static Logger logger = LoggerFactory.getLogger(WechatUtil.class.getName()); + + public static JSONObject encryptedData(String encryptedData, String session_key, String iv) throws Exception { + JSONObject encrypted_obj = null; + byte[] resultByte =decrypt(Base64.decode(encryptedData), + Base64.decode(session_key), + Base64.decode(iv)); + if(null != resultByte && resultByte.length > 0){ + String userInfo = new String(resultByte, "UTF-8"); + encrypted_obj = JSONObject.fromObject(userInfo); + }else{ + logger.error("鑾峰彇unionid瑙e瘑澶辫触锛歟ncryptedData="+encryptedData+";session_key="+session_key+";iv="+iv); + } + return encrypted_obj; + } + + + /** + * AES瑙e瘑 + * @param content 瀵嗘枃 + * @return + * @throws InvalidAlgorithmParameterException + * @throws NoSuchProviderException + */ + public static byte[] decrypt(byte[] content, byte[] keyByte, byte[] ivByte) throws Exception { + initialize(); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); + Key sKeySpec = new SecretKeySpec(keyByte, "AES"); + + cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(ivByte));// 鍒濆鍖� + byte[] result = cipher.doFinal(content); + return result; + } + + public static void initialize(){ + if (initialized) return; + Security.addProvider(new BouncyCastleProvider()); + initialized = true; + } + //鐢熸垚iv + public static AlgorithmParameters generateIV(byte[] iv) throws Exception{ + AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); + params.init(new IvParameterSpec(iv)); + return params; + } + + +} diff --git a/src/main/java/com/hx/mp/util/XMLUtil.java b/src/main/java/com/hx/mp/util/XMLUtil.java new file mode 100644 index 0000000..120edff --- /dev/null +++ b/src/main/java/com/hx/mp/util/XMLUtil.java @@ -0,0 +1,109 @@ +package com.hx.mp.util; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * xml锟斤拷锟斤拷锟斤拷 + *JX + *linhan + */ +public class XMLUtil { + + /** + * 锟斤拷锟斤拷xml,锟斤拷锟截碉拷一锟斤拷元锟截硷拷值锟皆★拷锟斤拷锟斤拷一锟斤拷元锟斤拷锟斤拷锟接节点,锟斤拷私诘锟斤拷值锟斤拷锟接节碉拷锟絰ml锟斤拷荨锟� + * @param strxml + * @return + * @throws JDOMException + * @throws IOException + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Map doXMLParse(String strxml) throws JDOMException, IOException { + strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\""); + + if(null == strxml || "".equals(strxml)) { + return null; + } + + Map m = new HashMap(); + + InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8")); + SAXBuilder builder = new SAXBuilder(); + Document doc = builder.build(in); + Element root = doc.getRootElement(); + List list = root.getChildren(); + Iterator it = list.iterator(); + while(it.hasNext()) { + Element e = (Element) it.next(); + String k = e.getName(); + String v = ""; + List children = e.getChildren(); + if(children.isEmpty()) { + v = e.getTextNormalize(); + } else { + v = XMLUtil.getChildrenText(children); + } + + m.put(k, v); + } + + //锟截憋拷锟斤拷 + in.close(); + + return m; + } + + /** + * 锟斤拷取锟接斤拷锟斤拷xml + * @param children + * @return String + */ + @SuppressWarnings("rawtypes") + public static String getChildrenText(List children) { + StringBuffer sb = new StringBuffer(); + if(!children.isEmpty()) { + Iterator it = children.iterator(); + while(it.hasNext()) { + Element e = (Element) it.next(); + String name = e.getName(); + String value = e.getTextNormalize(); + List list = e.getChildren(); + sb.append("<" + name + ">"); + if(!list.isEmpty()) { + sb.append(XMLUtil.getChildrenText(list)); + } + sb.append(value); + sb.append("</" + name + ">"); + } + } + + return sb.toString(); + } + + /** + * 锟斤拷取xml锟斤拷锟斤拷锟街凤拷 + * @param strxml + * @return + * @throws IOException + * @throws JDOMException + */ + public static String getXMLEncoding(String strxml) throws JDOMException, IOException { + InputStream in = HttpClientUtil.String2Inputstream(strxml); + SAXBuilder builder = new SAXBuilder(); + Document doc = builder.build(in); + in.close(); + return (String)doc.getProperty("encoding"); + } + + +} diff --git a/src/main/java/com/hx/mybatisTool/SqlParam.java b/src/main/java/com/hx/mybatisTool/SqlParam.java new file mode 100644 index 0000000..0757522 --- /dev/null +++ b/src/main/java/com/hx/mybatisTool/SqlParam.java @@ -0,0 +1,75 @@ +package com.hx.mybatisTool; + +import java.util.Map; + +import com.hx.exception.TipsException; +import com.hx.util.SimpleTool; +/** + * mybatis 鑷畾涔夊鐞唖ql璇彞 + * @author chenjiahe + * @Data: 2020-06-08 + */ +public class SqlParam { + + private String whereSentence = "1=1"; + private String updateSentence; + private Map<String,Object> m; + + /********************mother****************************/ + /** + * 鏌ヨ鐨勮鍙� + * @param sql 濡傦細id = #{m.userId} order by age + * @param values 瀛樻斁鐨勫�煎锛歷alues.put("userId","123456") + */ + public void sqlWhere(String sql,Map<String,Object> values) { + if(!SimpleTool.checkNotNull(values)){ + throw new TipsException("values is null"); + } + if(!SimpleTool.checkNotNull(sql)) { + sql = "1=1"; + } + whereSentence = sql; + m = values; + } + + /** + * 鏇存柊璇彞鐨勮鍙� + * @param sql 濡傦細name = #{m.name},age = ? Where id = #{m.id} + * @param values 瀛樻斁鐨勫�� + */ + public void sqlUpdate(String sql,Map<String,Object> values) { + if(!SimpleTool.checkNotNull(values)){ + throw new TipsException("values is null"); + } + m = values; + updateSentence = sql; + } + + /************************************************************************/ + + public String getWhereSentence() { + return whereSentence; + } + + public void setWhereSentence(String whereSentence) { + this.whereSentence = whereSentence; + } + + public String getUpdateSentence() { + return updateSentence; + } + + public void setUpdateSentence(String updateSentence) { + this.updateSentence = updateSentence; + } + + public Map<String, Object> getM() { + return m; + } + + public void setM(Map<String, Object> m) { + this.m = m; + } + +} + diff --git a/src/main/java/com/hx/mybatisTool/SqlSentence.java b/src/main/java/com/hx/mybatisTool/SqlSentence.java new file mode 100644 index 0000000..280ef0a --- /dev/null +++ b/src/main/java/com/hx/mybatisTool/SqlSentence.java @@ -0,0 +1,161 @@ +package com.hx.mybatisTool; + +import com.hx.exception.TipsException; +import com.hx.util.StringUtils; + +import java.util.Map; + +/** + * mybatis 鑷畾涔夊鐞唖ql璇彞 + * @author chenjiahe + * @Data: 2020-06-08 + */ +public class SqlSentence { + + private String sqlSentence; + + private Map<String,Object> m; + /**绫诲瀷*/ + private Integer type = TYPE_NORMAL; + /**鎺掑簭*/ + private String orderBy; + /**寮�濮嬮〉鏁�*/ + private Integer startPage = 0; + /**姣忛〉鏁伴噺*/ + private Integer pageNum = 0; + + ////////////////////////////////////////////////////////////// + /**姝e父*/ + public static final int TYPE_NORMAL = 0; + /**鍔ㄦ��*/ + public static final int TYPE_DYN = 1; + + /********************mother****************************/ + + public SqlSentence() + { + + } + + public SqlSentence(Class c, String where, Map<String, Object> values) + { + if(StringUtils.isEmpty(where)) + { + throw new TipsException("sql is null"); + } + + if(values == null) + { + throw new TipsException("values is null"); + } + + sqlSentence = "select * from " + c.getSimpleName()+ " where " + where; + m = values; + } + + public SqlSentence(String where, Map<String, Object> values) + { + if(StringUtils.isEmpty(where)) + { + throw new TipsException("sql is null"); + } + + if(values == null) + { + throw new TipsException("values is null"); + } + + sqlSentence = where; + m = values; + } + + + /** + * sql鏁存潯璇彞 + * @param sql 濡傦細select * from user Where name = #{m.userName} order by age desc + * @param values 瀛樻斁鐨勫�煎锛歷alues.put("userName","ChenJiaHe") + */ + public void sqlSentence(String sql,Map<String,Object> values) { + if(StringUtils.isEmpty(sql)) + { + throw new TipsException("sql is null"); + } + + if(values == null) + { + throw new TipsException("values is null"); + } + + sqlSentence = sql; + m = values; + } + + /** + * 璁剧疆鍔ㄦ�佹煡璇� + * @param map 鏌ヨ + */ + public void setDynSql(Map<String, Object> map) + { + this.type = TYPE_DYN; + this.m = map; + } + + + /************************************************************************/ + + public Map<String, Object> getM() { + return m; + } + + public void setM(Map<String, Object> m) { + this.m = m; + } + + public String getSqlSentence() { + return sqlSentence; + } + + public void setSqlSentence(String sqlSentence) { + this.sqlSentence = sqlSentence; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getOrderBy() { + return orderBy; + } + + public void setOrderBy(String orderBy) { + this.orderBy = orderBy; + } + + public Integer getStartPage() { + return startPage; + } + + public void setStartPage(Integer startPage) { + this.startPage = startPage; + } + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getStartIndex() + { + return (startPage - 1) * pageNum; + } + +} + + diff --git a/src/main/java/com/hx/resultTool/ResponseCode.java b/src/main/java/com/hx/resultTool/ResponseCode.java new file mode 100644 index 0000000..303bf2d --- /dev/null +++ b/src/main/java/com/hx/resultTool/ResponseCode.java @@ -0,0 +1,27 @@ +package com.hx.resultTool; + +/** + * 缁熶竴鐘舵�佺爜 + * @author chenjiahe + * @Data: 2020-06-20 + */ +public final class ResponseCode { + /*鎴愬姛*/ + public static final String SUCCESS = "100"; + /*閿欒鎻愮ず锛屽墠绔牴鎹繖涓爜寮瑰嚭鎻愮ず*/ + public static final String ERROR_TIPS="200"; + /*鍙傛暟楠岃瘉閿欒*/ + public static final String ERROR_PARAMS_VALIDATOR="205"; + /*涓氬姟楠岃瘉閿欒*/ + public static final String ERROR_SERVICE_VALIDATOR="300"; + /*绯荤粺鏁版嵁閿欒*/ + public static final String ERROR_DATA_VALIDATOR="400"; + /*鐧诲綍鏈夎*/ + public static final String ERROR_LOGIN="603"; + /*绯荤粺寮傚父*/ + public static final String ERROR_SYSTEM = "999"; + + + +} + diff --git a/src/main/java/com/hx/resultTool/Result.java b/src/main/java/com/hx/resultTool/Result.java new file mode 100644 index 0000000..32f35c9 --- /dev/null +++ b/src/main/java/com/hx/resultTool/Result.java @@ -0,0 +1,84 @@ +package com.hx.resultTool; + +import java.io.Serializable; + +/** + * 缁熶竴杩斿洖鏍煎紡 + * @author chenjiahe + * @Data: 2020-06-20 + */ +public class Result implements Serializable { + + private static final long serialVersionUID = -3948389268046368059L; + + private String code; + + private String msg; + + private Object data; + + public Result() {} + + public Result(String code, String msg) { + this.code = code; + this.msg = msg; + } + + public static Result success() { + Result Result = new Result(); + Result.setCode(ResponseCode.SUCCESS); + Result.setMsg("SUCCESS"); + return Result; + } + + public static Result success(Object data) { + Result Result = new Result(); + Result.setCode(ResponseCode.SUCCESS); + Result.setData(data); + Result.setMsg("SUCCESS"); + return Result; + } + + public static Result failure(String code, String msg) { + Result Result = new Result(); + Result.setCode(code); + Result.setMsg(msg); + return Result; + } + + public static Result failure(String code, String msg, Object data) { + Result Result = new Result(); + Result.setCode(code); + Result.setMsg(msg); + Result.setData(data); + return Result; + } + + /*******************************************************************************/ + + public String getCode() { + return this.code; + } + + public void setCode(final String code) { + this.code = code; + } + + public String getMsg() { + return this.msg; + } + + public void setMsg(final String msg) { + this.msg = msg; + } + + public Object getData() { + return this.data; + } + + public void setData(final Object data) { + this.data = data; + } + +} + diff --git a/src/main/java/com/hx/util/Aes.java b/src/main/java/com/hx/util/Aes.java new file mode 100644 index 0000000..2a25c9e --- /dev/null +++ b/src/main/java/com/hx/util/Aes.java @@ -0,0 +1,113 @@ +package com.hx.util; + +import org.apache.commons.codec.binary.Base64; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; + +/** + * AES鍔犲瘑宸ュ叿绫� + */ +public class Aes { + + /** + * 灏嗕簩杩涘埗杞崲鎴�16杩涘埗 + * + * @param buf 瀛楄妭鏁扮粍 + * @return + */ + public static String parseByte2HexStr(byte buf[]) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < buf.length; i++) { + String hex = Integer.toHexString(buf[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sb.append(hex.toUpperCase()); + } + return sb.toString(); + } + + /** + * 灏�16杩涘埗杞崲涓轰簩杩涘埗 + * + * @param hexStr 16杩涘埗瀛楃 + * @return + */ + public static byte[] parseHexStr2Byte(String hexStr) { + if (hexStr.length() < 1) + return null; + byte[] result = new byte[hexStr.length() / 2]; + for (int i = 0; i < hexStr.length() / 2; i++) { + int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); + int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); + result[i] = (byte) (high * 16 + low); + } + return result; + } + + /** + * 鍔犲瘑 + * @param str 寰呭姞瀵嗗瓧绗︿覆 + * @param secret 瀵嗛挜 + * @return + */ + public static byte[] encrypt(String str, String secret) { + if (null != str) { + byte[] bytes = null; + + try { + Base64 base64 = new Base64(); + String ALGORITHM = "AES"; + SecretKey desKey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c; + c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.ENCRYPT_MODE, desKey); + bytes = c.doFinal(str.getBytes("UTF-8")); + return bytes; + } catch (Exception e) { + e.printStackTrace(); + } + + } + return null; + } + + /** + * 瑙e瘑 + * @param str 寰呰В瀵嗗瓧绗︿覆 + * @param secret 瀵嗛挜 + * @return + */ + public static byte[] decrypt(byte[] str, String secret) { + try { + String ALGORITHM = "AES"; + SecretKey desKey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.DECRYPT_MODE, desKey); + return c.doFinal(str); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static void main(String[] args) throws UnsupportedEncodingException { + + String content = "apiKey=phitabfaceapi&userId=o5W1it6Pvqn6vPX6E1BGERH8J1lw"; + String password = "phitabfacesecret"; + + byte[] encode = encrypt(content, password); + String code = parseByte2HexStr(encode); + System.out.println("瀵嗘枃瀛楃涓诧細" + code); + + //16杩涘埗瀛楃涓茶浆鎴愬瓧鑺傛暟缁� + byte[] decode = parseHexStr2Byte(code); + // 瑙e瘑 + byte[] decryptResult = decrypt(decode, password); + System.out.println("瑙e瘑鍚庯細" + new String(decryptResult, "UTF-8")); //涓嶈浆鐮佷細涔辩爜 + + } +} diff --git a/src/main/java/com/hx/util/AesUtil.java b/src/main/java/com/hx/util/AesUtil.java new file mode 100644 index 0000000..d5b869c --- /dev/null +++ b/src/main/java/com/hx/util/AesUtil.java @@ -0,0 +1,126 @@ +package com.hx.util; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.commons.codec.binary.Base64; + +/** + * AES鍔犺В瀵嗗伐鍏� + * 浣跨敤璇ョ被锛岄渶瑕佽鏇挎崲local_policy.jar鍙妘s_export_policy.jar + * @author ChenJiaHe + * + */ +public class AesUtil { + + /**16浣嶅姞瀵嗙閽�*/ + public static final String SECRET = "huoXiong16816888"; + + /** + * AES鍔犲瘑 + * + * @param str + * 闇�瑕佸姞瀵嗙殑鏄庢枃 + * @param secret + * 绉橀挜 + * @return 鍔犲瘑鍚庣殑瀵嗘枃(base64缂栫爜瀛楃涓�) + */ + public static String aesEncryp(String str, String secret) { + if (null != str) { + byte[] bytes = null; + + try { + Base64 base64 = new Base64(); + String ALGORITHM = "AES"; + SecretKey deskey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c; + c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.ENCRYPT_MODE, deskey); + bytes = c.doFinal(str.getBytes("UTF-8")); + if (bytes != null) { + return new String(base64.encode(bytes)); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + return null; + } + + /** + * AES瑙e瘑 + * + * @param str + * 闇�瑕佽В瀵嗙殑绉樻枃 + * @param secret + * 绉橀挜 + * @return 瑙e瘑鍚庣殑鏄庢枃 + */ + public static String aesDecryp(String str, String secret) { + try { + Base64 base64 = new Base64(); + String ALGORITHM = "AES"; + SecretKey deskey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.DECRYPT_MODE, deskey); + return new String(c.doFinal(base64.decode(str.getBytes("UTF-8"))), "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * AES鍔犲瘑锛堝浐瀹氱閽ワ級 + * + * @param str 闇�瑕佸姞瀵嗙殑鏄庢枃 + * @return 鍔犲瘑鍚庣殑瀵嗘枃(base64缂栫爜瀛楃涓�) + */ + public static String aesEncryp(String str) { + String secret = SECRET; + if (null != str) { + byte[] bytes = null; + + try { + Base64 base64 = new Base64(); + String ALGORITHM = "AES"; + SecretKey deskey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c; + c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.ENCRYPT_MODE, deskey); + bytes = c.doFinal(str.getBytes("UTF-8")); + if (bytes != null) { + return new String(base64.encode(bytes)); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + return null; + } + + /** + * AES瑙e瘑锛堝浐瀹氱閽ワ級 + * + * @param str 闇�瑕佽В瀵嗙殑绉樻枃 + * @return 瑙e瘑鍚庣殑鏄庢枃 + */ + public static String aesDecryp(String str) { + String secret = SECRET; + try { + Base64 base64 = new Base64(); + String ALGORITHM = "AES"; + SecretKey deskey = new SecretKeySpec(secret.getBytes("UTF-8"), ALGORITHM);// 鐢熸垚瀵嗛挜 + Cipher c = Cipher.getInstance(ALGORITHM); + c.init(Cipher.DECRYPT_MODE, deskey); + return new String(c.doFinal(base64.decode(str.getBytes("UTF-8"))), "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/main/java/com/hx/util/BASE64.java b/src/main/java/com/hx/util/BASE64.java new file mode 100644 index 0000000..dddd636 --- /dev/null +++ b/src/main/java/com/hx/util/BASE64.java @@ -0,0 +1,51 @@ +package com.hx.util; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +/** + * BASE64鍔犲瘑瑙e瘑 + */ +public class BASE64 +{ + + /** + * BASE64瑙e瘑 + * @param key + * @return + * @throws Exception + */ + public static byte[] decryptBASE64(String key) { + byte[] t = new byte[]{}; + try{ + t = (new BASE64Decoder()).decodeBuffer(key); + }catch (Exception e) { + e.printStackTrace(); + } + return t; + } + + /** + * BASE64鍔犲瘑 + * @param key + * @return + * @throws Exception + */ + public static String encryptBASE64(byte[] key){ + String s = ""; + try{ + s = (new BASE64Encoder()).encodeBuffer(key); + }catch (Exception e) { + e.printStackTrace(); + } + return s; + } + + + public static void main(String[] args) throws Exception + { + String data = BASE64.encryptBASE64("123456789".getBytes()); + System.out.println("鍔犲瘑鍓嶏細"+data); + byte[] byteArray = BASE64.decryptBASE64(data); + System.out.println("瑙e瘑鍚庯細"+new String(byteArray)); + } +} diff --git a/src/main/java/com/hx/util/Base64Util.java b/src/main/java/com/hx/util/Base64Util.java new file mode 100644 index 0000000..f7e312e --- /dev/null +++ b/src/main/java/com/hx/util/Base64Util.java @@ -0,0 +1,65 @@ +package com.hx.util; + +/** + * Base64 宸ュ叿绫� + */ +public class Base64Util { + private static final char last2byte = (char) Integer.parseInt("00000011", 2); + private static final char last4byte = (char) Integer.parseInt("00001111", 2); + private static final char last6byte = (char) Integer.parseInt("00111111", 2); + private static final char lead6byte = (char) Integer.parseInt("11111100", 2); + private static final char lead4byte = (char) Integer.parseInt("11110000", 2); + private static final char lead2byte = (char) Integer.parseInt("11000000", 2); + private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + + public Base64Util() { + } + + public static String encode(byte[] from) { + StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3); + int num = 0; + char currentByte = 0; + + int i; + for (i = 0; i < from.length; ++i) { + for (num %= 8; num < 8; num += 6) { + switch (num) { + case 0: + currentByte = (char) (from[i] & lead6byte); + currentByte = (char) (currentByte >>> 2); + case 1: + case 3: + case 5: + default: + break; + case 2: + currentByte = (char) (from[i] & last6byte); + break; + case 4: + currentByte = (char) (from[i] & last4byte); + currentByte = (char) (currentByte << 2); + if (i + 1 < from.length) { + currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6); + } + break; + case 6: + currentByte = (char) (from[i] & last2byte); + currentByte = (char) (currentByte << 4); + if (i + 1 < from.length) { + currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4); + } + } + + to.append(encodeTable[currentByte]); + } + } + + if (to.length() % 4 != 0) { + for (i = 4 - to.length() % 4; i > 0; --i) { + to.append("="); + } + } + + return to.toString(); + } +} diff --git a/src/main/java/com/hx/util/CheckCodeImageUtil.java b/src/main/java/com/hx/util/CheckCodeImageUtil.java new file mode 100644 index 0000000..e934a4d --- /dev/null +++ b/src/main/java/com/hx/util/CheckCodeImageUtil.java @@ -0,0 +1,96 @@ +package com.hx.util; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Base64; + +import javax.imageio.ImageIO; + +/** + * 楠岃瘉鐮佺敓鎴愬櫒 + * @author ChenJiaHe + * @Date 2020-06-17 + */ +public class CheckCodeImageUtil { + + private final static int WIDTH = 60; + private final static int HEIGHT = 20; + + private static char[] generateCheckCode() { + // 锟斤拷锟斤拷锟斤拷证锟斤拷锟斤拷址锟斤拷 + String chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char[] rands = new char[4]; + for (int i = 0; i < 4; i++) { + int rand = (int) (Math.random() * 35); + rands[i] = chars.charAt(rand); + } + return rands; + } + + private static void drawRands(Graphics g, char[] rands) { + g.setColor(Color.BLACK); + g.setFont(new Font(null, Font.ITALIC | Font.BOLD, 18)); + // 锟节诧拷同锟侥高讹拷锟斤拷锟斤拷锟斤拷锟街わ拷锟斤拷每锟斤拷锟街凤拷 + g.drawString("" + rands[0], 1, 17); + g.drawString("" + rands[1], 16, 15); + g.drawString("" + rands[2], 31, 18); + g.drawString("" + rands[3], 46, 16); + } + + private static void drawBackground(Graphics g) { + // 锟斤拷锟斤拷锟斤拷 + g.setColor(new Color(0xDCDCDC)); + g.fillRect(0, 0, WIDTH, HEIGHT); + // 锟斤拷锟斤拷锟斤拷120锟斤拷锟斤拷锟脚碉拷 + for (int i = 0; i < 120; i++) { + int x = (int) (Math.random() * WIDTH); + int y = (int) (Math.random() * HEIGHT); + int red = (int) (Math.random() * 255); + int green = (int) (Math.random() * 255); + int blue = (int) (Math.random() * 255); + g.setColor(new Color(red, green, blue)); + g.drawOval(x, y, 1, 0); + } + } + + public static String[] createImage(String id) + { + ByteArrayOutputStream bos = null; + String reStr = ""; + char[] rands = null; + try { + BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); + Graphics g = image.getGraphics(); + + rands = generateCheckCode(); + + drawBackground(g); + drawRands(g, rands); + + g.dispose(); + + bos = new ByteArrayOutputStream(); + ImageIO.write(image, "JPEG", bos); + byte[] buf = bos.toByteArray(); + reStr = Base64.getEncoder().encodeToString(buf); + + }catch (Exception e) { + e.printStackTrace(); + }finally { + if(bos != null) + { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + bos = null; + } + } + return new String[] {new String(rands),reStr}; + } +} diff --git a/src/main/java/com/hx/util/CreateNoTool.java b/src/main/java/com/hx/util/CreateNoTool.java new file mode 100644 index 0000000..93ac0c6 --- /dev/null +++ b/src/main/java/com/hx/util/CreateNoTool.java @@ -0,0 +1,46 @@ +package com.hx.util; + +import java.util.Random; + +public class CreateNoTool { + + /**鑾峰彇闅忔満绉橀挜(鏁板瓧涓庡ぇ鍐欏瓧姣嶇粍鍚�) + * + * @param y + * 闅忔満鏁颁綅鏁� + * @return + */ + public static String randomKey(Integer y) { + String[] data = new String[] { + "0","1","2","3","4","5","6","7","8","9" + ,"A","B","C","D","E","F","G","H","I","J" + ,"K","L","M","N","O","P","Q","R","S","T" + ,"U","V","W","S","Y","Z" + }; + String no = ""; + Random r = new Random(); + for (int i = 0; i < y; i++) { + no += data[r.nextInt(data.length-1)]; + } + return no; + } + + /**鑾峰彇闅忔満绉橀挜(鏁板瓧) + * + * @param y + * 闅忔満鏁颁綅鏁� + * @return + */ + public static String randomKeyNumber(Integer y) { + String[] data = new String[] { + "0","1","2","3","4","5","6","7","8","9" + }; + String no = ""; + Random r = new Random(); + for (int i = 0; i < y; i++) { + no += data[r.nextInt(data.length-1)]; + } + return no; + } + +} diff --git a/src/main/java/com/hx/util/DateUtil.java b/src/main/java/com/hx/util/DateUtil.java new file mode 100644 index 0000000..f06d7eb --- /dev/null +++ b/src/main/java/com/hx/util/DateUtil.java @@ -0,0 +1,346 @@ +package com.hx.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +public class DateUtil { + + private static SimpleDateFormat Format_1 = new SimpleDateFormat("yyyyMMdd"); + private static SimpleDateFormat Format_2 = new SimpleDateFormat("yyyyMMddHHmmss"); + private static SimpleDateFormat Format_3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static SimpleDateFormat Format_4 = new SimpleDateFormat("yyyy-MM-dd"); + private static SimpleDateFormat Format_5 = new SimpleDateFormat("HH:mm:ss"); + private static SimpleDateFormat Format_6 = new SimpleDateFormat("yyyyMM"); + private static SimpleDateFormat Format_7 = new SimpleDateFormat("MM鏈坉d鏃� HH:mm"); + private static SimpleDateFormat Format_8 = new SimpleDateFormat("yyyy骞碝M鏈�"); + private static SimpleDateFormat Format_9 = new SimpleDateFormat("MM-dd"); + private static SimpleDateFormat Format_10 = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�"); + private static SimpleDateFormat Format_11 = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃� HH:mm:ss"); + private static SimpleDateFormat Format_12 = new SimpleDateFormat("yyyyMMddHHmm"); + private static SimpleDateFormat Format_13 = new SimpleDateFormat("yyyy/MM/dd"); + private static SimpleDateFormat Format_14 = new SimpleDateFormat("yyyy-MM"); + private static SimpleDateFormat Format_15 = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + private static SimpleDateFormat Format_16 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); + private static SimpleDateFormat Format_17 = new SimpleDateFormat("HH:mm"); + + /**鏃堕棿鏍煎紡杞寲 + * @param date 鏃堕棿 + * @param format 鏃堕棿鏍煎紡 + * @return 杩斿洖鐨勬椂闂存牸寮忓瓧绗︿覆 + */ + public static String dateFormat(Date date, String format) { + if(!SimpleTool.checkNotNull(date)){ + return ""; + } + SimpleDateFormat df = new SimpleDateFormat(format);//璁剧疆鏃ユ湡鏍煎紡 + return df.format(date); + } + + /** + * 杞崲鎴恲yyyMMdd鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate(Date date) { + return Format_1.format(date); + } + + /** + * 杞崲鎴恲yyyMMddHHmmss鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_1(Date date) { + return Format_2.format(date); + } + + /** + * 杞崲鎴恲yyy-MM-dd HH:mm:ss鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_2(Date date) { + return date == null ? null : Format_3.format(date); + } + + /** + * 杞崲鎴恲yyy-MM-dd鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_3(Date date) { + return date != null ? Format_4.format(date) : null; + } + + /** + * 杞崲鎴怘H:mm:ss鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_4(Date date) { + return Format_5.format(date); + } + + /** + * 杞崲鎴恲yyyMM鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_5(Date date) { + return Format_6.format(date); + } + + /** + * 杞崲鎴恗m鏈坉d鏃� HH:mm鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_6(Date date) { + return Format_7.format(date); + } + + /** + * 杞崲鎴恲yyy骞磎m鏈堟牸寮忕殑鏃ユ湡瀛楃涓� + * + * @param date + * @return + */ + public static String formatDate_7(Date date) { + return Format_8.format(date); + } + + /** + * 杞崲鎴恗m-dd鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_8(Date date) { + return Format_9.format(date); + } + + /** + * 杞崲鎴恲yyy骞碝M鏈坉d鏃ユ牸寮忕殑鏃ユ湡瀛楃涓� + * + * @param date + * @return + */ + public static String formatDate_9(Date date) { + return Format_10.format(date); + } + + /** + * 杞崲鎴恲yyyMMddHHmm鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_11(Date date) { + return Format_12.format(date); + } + + /** + * 杞崲鎴恲yyy骞碝M鏈坉d鏃� HH:mm:ss鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_10(Date date) { + return Format_11.format(date); + } + + /** + * 杞崲鎴恲yyy/MM/dd 鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_13(Date date) { + return Format_13.format(date); + } + + /** + * 杞崲鎴恲yyy-MM 鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_14(Date date) { + return Format_14.format(date); + } + + /** + * 杞崲鎴恲yyyMMddHHmmssSSS鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_15(Date date) { + return Format_15.format(date); + } + + /** + * 杞崲鎴恲yyy/MM/dd HH:mm鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_16(Date date) { + return Format_16.format(date); + } + + /** + * 杞崲鎴怘H:mm鏍煎紡鐨勬棩鏈熷瓧绗︿覆 + * + * @param date + * @return + */ + public static String formatDate_17(Date date) { + return Format_17.format(date); + } + + /** + * 杞崲鎴愬瓧绗︿覆yyyyMMddHHmmss鎴愭棩锟�? + * + * @param str + * @return + * @throws Exception + */ + public static Date parseString(String str) throws Exception { + return Format_2.parse(str); + } + + /** + * 杞崲鎴愬瓧绗︿覆鍒版寚瀹氱殑鏃ユ湡 + * + * @param str + * @param format + * @return + * @throws Exception + */ + public static Date parseString(String str, String format) throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.parse(str); + } + + /**鏃堕棿涓婂垎閽熷彔鍔� + * @Author: ChenJiaHe + * @param dateTime 鏃堕棿 + * @param min 鍒嗛挓 + * @return + */ + public static Date addMin(Date dateTime,int min){ + Calendar c = Calendar.getInstance(); + c.setTime(dateTime); + c.add(Calendar.MINUTE, min); + return c.getTime(); + } + + /**鏃堕棿涓婂皬鏃跺彔鍔� + * @Author: ChenJiaHe + * @param dateTime 鏃堕棿 + * @param hour 灏忔椂 + * @return + */ + public static Date addhour(Date dateTime,int hour){ + Calendar c = Calendar.getInstance(); + c.setTime(dateTime); + c.add(Calendar.HOUR, hour); + return c.getTime(); + } + + /**鏃堕棿涓婂ぉ鏁板彔鍔� + * @Author: ChenJiaHe + * @param dateTime 鏃堕棿 + * @param dayNum 澶╂暟 + * @return + */ + public static Date addDay(Date dateTime,int dayNum){ + Calendar c = Calendar.getInstance(); + c.setTime(dateTime); + c.add(Calendar.DATE, dayNum); + return c.getTime(); + } + + /** + * 杞崲鎴愬瓧绗︿覆鍒版寚瀹氱殑鏃ユ湡 + * + * @param date + * @param format + * @return + * @throws Exception + */ + public static String formatDate(Date date, String format) { + if (date == null) { + return null; + } + + SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA); + return sdf.format(date); + } + + /**鏃ユ湡杞槦鏈� + * @param dateTime 瀛楃涓叉椂闂� + * @param format 瀛楃涓叉椂闂存牸寮� + * @param returnType 杩斿洖绫诲瀷 0鏄熸湡鍑�1鍛ㄥ嚑 + * @return 鏁版嵁 + */ + public static String dateToWeek(String dateTime,String format,Integer returnType) throws ParseException { + SimpleDateFormat f = new SimpleDateFormat(format); + String[] weekDays = { "鏄熸湡鏃�", "鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�" }; + if(SimpleTool.checkNotNull(returnType)&&returnType==1){ + weekDays = new String[]{"鍛ㄦ棩", "鍛ㄤ竴", "鍛ㄤ簩", "鍛ㄤ笁", "鍛ㄥ洓", "鍛ㄤ簲", "鍛ㄥ叚"}; + } + Calendar cal = Calendar.getInstance(); // 鑾峰緱涓�涓棩鍘� + Date datet = null; + datet = f.parse(dateTime); + cal.setTime(datet); + + int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 鎸囩ず涓�涓槦鏈熶腑鐨勬煇澶┿�� + if (w < 0) + w = 0; + return weekDays[w]; + } + + /**鏃ユ湡杞槦鏈� + * @param dateTime 鏃堕棿 + * @param returnType 杩斿洖绫诲瀷 0鏄熸湡鍑�1鍛ㄥ嚑 + * @return 鏁版嵁 + */ + public static String dateToWeek(Date dateTime,Integer returnType) { + String[] weekDays = { "鏄熸湡鏃�", "鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�" }; + if(SimpleTool.checkNotNull(returnType)&&returnType==1){ + weekDays = new String[]{"鍛ㄦ棩", "鍛ㄤ竴", "鍛ㄤ簩", "鍛ㄤ笁", "鍛ㄥ洓", "鍛ㄤ簲", "鍛ㄥ叚"}; + } + Calendar cal = Calendar.getInstance(); // 鑾峰緱涓�涓棩鍘� + cal.setTime(dateTime); + + int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 鎸囩ず涓�涓槦鏈熶腑鐨勬煇澶┿�� + if (w < 0) + w = 0; + return weekDays[w]; + } + + /**鍒ゆ柇涓や釜鏃堕棿鏄笉鏄悓涓�澶�*/ + public static boolean timeEqual(Date startTime,Date endTime){ + if(startTime == null || endTime==null){ + return false; + } + boolean status = false; + if(formatDate(startTime,"yyyyMMdd").equals(formatDate(endTime,"yyyyMMdd"))){ + status = false; + } + return status; + } + +} diff --git a/src/main/java/com/hx/util/EmailUtil.java b/src/main/java/com/hx/util/EmailUtil.java new file mode 100644 index 0000000..4434af5 --- /dev/null +++ b/src/main/java/com/hx/util/EmailUtil.java @@ -0,0 +1,120 @@ +package com.hx.util; + +import com.sun.mail.util.MailSSLSocketFactory; + +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.mail.*; +import javax.mail.internet.*; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.util.Properties; + +/**閭欢澶勭悊宸ュ叿 + * @author ChenJiaHe + * @Date 2020-07-06 + */ +public class EmailUtil { + /** + * 鍙戦�佸甫闄勪欢鐨勯偖浠� + * + * @param receive + * 鏀朵欢浜� + * @param subject + * 閭欢涓婚 + * @param msg + * 閭欢鍐呭 + * @param filename + * 闄勪欢鍦板潃 + * @param from + * 鍙戜欢浜虹數瀛愰偖绠� + * @param pass + * 鍙戜欢浜虹數瀛愰偖绠卞瘑鐮� + * @return + * @throws GeneralSecurityException + */ + public static boolean sendMail(String receive, String subject, String msg, String filename, + String from,String pass) + throws GeneralSecurityException { + if (StringUtils.isEmpty(receive)) { + return false; + } + + // 鎸囧畾鍙戦�侀偖浠剁殑涓绘満涓� smtp.qq.com smtp.163.com + String host = "smtp.qq.com"; // 閭欢鏈嶅姟鍣� + + // 鑾峰彇绯荤粺灞炴�� + Properties properties = System.getProperties(); + + // 璁剧疆閭欢鏈嶅姟鍣� + properties.setProperty("mail.smtp.host", host); + + properties.put("mail.smtp.auth", "true"); + MailSSLSocketFactory sf = new MailSSLSocketFactory(); + sf.setTrustAllHosts(true); + properties.put("mail.smtp.ssl.enable", "true"); + properties.put("mail.smtp.ssl.socketFactory", sf); + // 鑾峰彇榛樿session瀵硅薄 + Session session = Session.getDefaultInstance(properties, new Authenticator() { + public PasswordAuthentication getPasswordAuthentication() { // qq閭鏈嶅姟鍣ㄨ处鎴枫�佺涓夋柟鐧诲綍鎺堟潈鐮� + return new PasswordAuthentication(from, pass); // 鍙戜欢浜洪偖浠剁敤鎴峰悕銆佸瘑鐮� + } + }); + + try { + // 鍒涘缓榛樿鐨� MimeMessage 瀵硅薄 + MimeMessage message = new MimeMessage(session); + + // Set From: 澶撮儴澶村瓧娈� + message.setFrom(new InternetAddress(from)); + + // Set To: 澶撮儴澶村瓧娈� + message.addRecipient(Message.RecipientType.TO, new InternetAddress(receive)); + + // Set Subject: 涓婚鏂囧瓧 + message.setSubject(subject); + + // 鍒涘缓娑堟伅閮ㄥ垎 + BodyPart messageBodyPart = new MimeBodyPart(); + + // 娑堟伅 + messageBodyPart.setText(msg); + + // 鍒涘缓澶氶噸娑堟伅 + Multipart multipart = new MimeMultipart(); + + // 璁剧疆鏂囨湰娑堟伅閮ㄥ垎 + multipart.addBodyPart(messageBodyPart); + + // 闄勪欢閮ㄥ垎 + messageBodyPart = new MimeBodyPart(); + // 璁剧疆瑕佸彂閫侀檮浠剁殑鏂囦欢璺緞 + if(SimpleTool.checkNotNull(filename)){ + DataSource source = new FileDataSource(filename); + if(!SimpleTool.checkNotNull(source)){ + throw new RuntimeException("鑾峰彇闄勪欢澶辫触锛�"); + } + messageBodyPart.setDataHandler(new DataHandler(source)); + // messageBodyPart.setFileName(filename); + // 澶勭悊闄勪欢鍚嶇О涓枃锛堥檮甯︽枃浠惰矾寰勶級涔辩爜闂 + //messageBodyPart.setFileName(MimeUtility.encodeText(source.getName())); + messageBodyPart.setFileName(new String(source.getName().toString().getBytes("UTF-8"))); + multipart.addBodyPart(messageBodyPart); + } + + // 鍙戦�佸畬鏁存秷鎭� + message.setContent(multipart); + + // 鍙戦�佹秷鎭� + Transport.send(message); + // System.out.println("Sent message successfully...."); + return true; + } catch (MessagingException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return false; + } +} diff --git a/src/main/java/com/hx/util/ExcelUtil.java b/src/main/java/com/hx/util/ExcelUtil.java new file mode 100644 index 0000000..3598df9 --- /dev/null +++ b/src/main/java/com/hx/util/ExcelUtil.java @@ -0,0 +1,201 @@ +package com.hx.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +import java.util.List; +import java.util.Map; + +import com.hx.exception.TipsException; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.Cell; +import org.springframework.web.multipart.MultipartFile; + + +/** + * + * @author hjr + */ +public final class ExcelUtil { + + /** + * @param excelName + * 鏂囦欢鍚嶇О + * @param outPath + * 淇濆瓨璺緞 + * @param headList + * Excel鏂囦欢Head鏍囬闆嗗悎 + * @param fieldList + * Excel鏂囦欢Field鏍囬闆嗗悎 鏍规嵁field鏉ュ鎵句綅缃~鍏呰〃鏍� + * @param dataList + * Excel鏂囦欢鏁版嵁鍐呭閮ㄥ垎 + * @throws Exception + */ + public static String createExcel(String outPath, String excelName, + String[] headList, String[] fieldList, + List<Map<String, Object>> dataList) throws Exception { + + String filePath = null; + // 鍒涘缓鏂扮殑Excel 宸ヤ綔绨� + HSSFWorkbook workbook = new HSSFWorkbook(); + + // 鍦‥xcel宸ヤ綔绨夸腑寤轰竴宸ヤ綔琛紝鍏跺悕涓虹己鐪佸�� + // 濡傝鏂板缓涓�鍚嶄负"鏁堢泭鎸囨爣"鐨勫伐浣滆〃锛屽叾璇彞涓猴細 + // HSSFSheet sheet = workbook.createSheet("鏁堢泭鎸囨爣"); + HSSFSheet sheet = workbook.createSheet(); + // 鍦ㄧ储寮�0鐨勪綅缃垱寤鸿锛堟渶椤剁鐨勮锛� + HSSFRow row = sheet.createRow(0); + // =============================================================== + for (int i = 0; i < headList.length; i++) { + + // 鍦ㄧ储寮�0鐨勪綅缃垱寤哄崟鍏冩牸锛堝乏涓婄锛� + HSSFCell cell = row.createCell(i); + // 瀹氫箟鍗曞厓鏍间负瀛楃涓茬被鍨� + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + // 鍦ㄥ崟鍏冩牸涓緭鍏ヤ竴浜涘唴瀹� + cell.setCellValue(headList[i]); + } + // =============================================================== + if (dataList != null) { + for (int n = 0; n < dataList.size(); n++) { + // 鍦ㄧ储寮�1鐨勪綅缃垱寤鸿 + HSSFRow row_value = sheet.createRow(n + 1); + Map<String, Object> dataMap = dataList.get(n); + // =============================================================== + for (int i = 0; i < fieldList.length; i++) { + // 鍦ㄧ储寮�0鐨勪綅缃垱寤哄崟鍏冩牸锛堝乏涓婄锛� + HSSFCell cell = row_value.createCell(i); + // 瀹氫箟鍗曞厓鏍间负瀛楃涓茬被鍨� + cell.setCellType(HSSFCell.CELL_TYPE_STRING); + // 鍦ㄥ崟鍏冩牸涓緭鍏ヤ竴浜涘唴瀹� + cell.setCellValue(objToString(dataMap.get(fieldList[i]))); + } + // =============================================================== + } + } + + // 鏂板缓涓�杈撳嚭鏂囦欢娴� + File file = SimpleTool.createFile(outPath,excelName); + FileOutputStream fOut = new FileOutputStream(file); + // 鎶婄浉搴旂殑Excel 宸ヤ綔绨垮瓨鐩� + workbook.write(fOut); + fOut.flush(); + // 鎿嶄綔缁撴潫锛屽叧闂枃浠� + fOut.close(); + + if(outPath.endsWith("/")){ + filePath = outPath + excelName; + }else{ + filePath = outPath +"/"+ excelName; + } + return filePath; + } + + private static String objToString(Object obj) { + if (obj == null) { + return ""; + } else { + if (obj instanceof String) { + return (String) obj; + } else if (obj instanceof Date) { + return null;// DateUtil.dateToString((Date) + // obj,DateUtil.DATESTYLE_SHORT_EX); + } else { + return obj.toString(); + } + } + } + + /** + * 璇诲彇 Excel鏂囦欢鍐呭 + * + * @param file + * @param header 鏄惁鍖呮嫭琛ㄥご + * @return + * @throws Exception + */ + public static List<List<String>> readExcelByeFileData(MultipartFile file, boolean header) throws Exception { + + String fileName = file.getOriginalFilename(); + if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { + throw new TipsException("涓婁紶鏂囦欢鏍煎紡涓嶆纭�"); + } + + // 缁撴灉闆� + List<List<String>> list = new ArrayList<>(); + + HSSFWorkbook hssfworkbook = new HSSFWorkbook(file.getInputStream()); + + // 閬嶅巻璇ヨ〃鏍间腑鎵�鏈夌殑宸ヤ綔琛紝i琛ㄧず宸ヤ綔琛ㄧ殑鏁伴噺 getNumberOfSheets琛ㄧず宸ヤ綔琛ㄧ殑鎬绘暟 + for(int s=0;s<hssfworkbook.getNumberOfSheets();s++) { + HSSFSheet hssfsheet = hssfworkbook.getSheetAt(s); + int col = 0; + // 閬嶅巻璇ヨ鎵�鏈夌殑琛�,j琛ㄧず琛屾暟 getPhysicalNumberOfRows琛岀殑鎬绘暟 鍘婚櫎鏍囬 + for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) { + HSSFRow hssfrow = hssfsheet.getRow(j); + if(hssfrow!=null){ + if(j == 0) { + col = hssfrow.getPhysicalNumberOfCells(); + if(!header) { + //涓嶅寘鎷〃澶� + continue; + } + } + // 鍗曡鏁版嵁 + List<String> arrayString = new ArrayList<>(); + for (int i = 0; i < col; i++) { + HSSFCell cell = hssfrow.getCell(i); + if (cell == null) { + arrayString.add(""); + } else if (cell.getCellType() == 0) { + // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); + if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { + short format = cell.getCellStyle().getDataFormat(); + if(format == 14 || format == 31 || format == 57 || format == 58){ + //鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛� + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString.add(formater.format(d)); + //arrayString[i] = formater.format(d); + }else if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date d = cell.getDateCellValue(); + //DateFormat formater = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃� HH鏃秏m鍒唖s绉�"); + DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + arrayString.add(formater.format(d)); + //arrayString[i] = formater.format(d); + } else { + if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){ + arrayString.add(cell.getStringCellValue()); + //arrayString[i] =cell.getStringCellValue(); + }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){ + arrayString.add(cell.getCellFormula()); + //arrayString[i] =cell.getCellFormula(); + }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){ + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); + arrayString.add(dataFormatter.formatCellValue(cell)); + //arrayString[i] =dataFormatter.formatCellValue(cell); + } + } + } + } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){ + arrayString.add(""); + //arrayString[i] = ""; + } else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� + arrayString.add(cell.getStringCellValue().trim()); + //arrayString[i] = cell.getStringCellValue().trim(); + } + } + list.add(arrayString); + } + } + } + return list; + } + +} diff --git a/src/main/java/com/hx/util/FileUtil.java b/src/main/java/com/hx/util/FileUtil.java new file mode 100644 index 0000000..03e7fee --- /dev/null +++ b/src/main/java/com/hx/util/FileUtil.java @@ -0,0 +1,74 @@ +package com.hx.util; + +import java.io.*; + +/** + * 鏂囦欢璇诲彇宸ュ叿绫� + * @author ChenJiaHe + * @Date 2020-06-17 + */ +public class FileUtil { + + /** + * 璇诲彇鏂囦欢鍐呭锛屼綔涓哄瓧绗︿覆杩斿洖 + */ + public static String readFileAsString(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + + if (file.length() > 1024 * 1024 * 1024) { + throw new IOException("File is too large"); + } + + StringBuilder sb = new StringBuilder((int) (file.length())); + // 鍒涘缓瀛楄妭杈撳叆娴� + FileInputStream fis = new FileInputStream(filePath); + // 鍒涘缓涓�涓暱搴︿负10240鐨凚uffer + byte[] bbuf = new byte[10240]; + // 鐢ㄤ簬淇濆瓨瀹為檯璇诲彇鐨勫瓧鑺傛暟 + int hasRead = 0; + while ( (hasRead = fis.read(bbuf)) > 0 ) { + sb.append(new String(bbuf, 0, hasRead)); + } + fis.close(); + return sb.toString(); + } + + /** + * 鏍规嵁鏂囦欢璺緞璇诲彇byte[] 鏁扮粍 + */ + public static byte[] readFileByBytes(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); + BufferedInputStream in = null; + + try { + in = new BufferedInputStream(new FileInputStream(file)); + short bufSize = 1024; + byte[] buffer = new byte[bufSize]; + int len1; + while (-1 != (len1 = in.read(buffer, 0, bufSize))) { + bos.write(buffer, 0, len1); + } + + byte[] var7 = bos.toByteArray(); + return var7; + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException var14) { + var14.printStackTrace(); + } + + bos.close(); + } + } + } +} diff --git a/src/main/java/com/hx/util/FileUtils.java b/src/main/java/com/hx/util/FileUtils.java new file mode 100644 index 0000000..0dc968c --- /dev/null +++ b/src/main/java/com/hx/util/FileUtils.java @@ -0,0 +1,342 @@ +package com.hx.util; + +import com.hx.exception.TipsException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** 鏂囦欢澶勭悊宸ュ叿 + * @author ChenJiaHe + * @Date 2020-06-17 + */ +public class FileUtils { + + private final static Logger logger = LoggerFactory.getLogger(FileUtils.class); + + private static int BUFFER_SIZE = 1024; + + /** + * @param path + * @MethodName fileIsExists + * @Description 鏂囦欢鏄惁瀛樺湪 + * @Author ChenJiaHe + * @Date 2019/9/7 9:13 + * @Since JDK 1.8 + */ + public static boolean fileIsExists(String path) { + File file = new File(path); + if (file.exists()) { + return true; + } else { + return false; + } + } + + /** + * @param sourceFile + * @param targetFile + * @MethodName copyFile + * @Description 澶嶅埗鏂囦欢 + * @Author ChenJiaHe + * @Date 2019/9/7 9:36 + * @Since JDK 1.8 + */ + public static void copyFile(File sourceFile, File targetFile) throws IOException { + BufferedInputStream inputStream = null; + BufferedOutputStream outputStream = null; + try { + inputStream = new BufferedInputStream(new FileInputStream(sourceFile)); + outputStream = new BufferedOutputStream(new FileOutputStream(targetFile)); + byte[] b = new byte[BUFFER_SIZE]; + int len; + while ((len = inputStream.read(b)) != -1) { + outputStream.write(b, 0, len); + } + outputStream.flush(); + } catch (Exception e) { + logger.error("copy file error", e); + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + } + } + + /** + * @param path + * @param fileType 鏂囦欢绫诲瀷锛�0 = 鏂囦欢澶� 1 = 鏂囦欢 + * @MethodName getAllFiles + * @Description 璁�鍙栨枃浠跺す涓嬬殑锛屼笉鍖呮嫭瀛愭枃浠跺す鍐� + * @Author ChenJiaHe + * @Date 2019/9/17 15:56 + * @Since JDK 1.8 + */ + public static List<String> getAllFiles(String path, String fileType) { + List<String> fileList = new ArrayList<>(); + File fileDic = new File(path); + File[] files = fileDic.listFiles(); + for (File file : files) { + if ("1".equals(fileType)) { + if (file.isFile()) { + fileList.add(file.toString()); + } + } + if ("0".equals(fileType)) { + if (file.isDirectory()) { + fileList.add(file.toString()); + } + } + } + return fileList; + } + + /** + * @param path + * @MethodName getFolderFiles + * @Description 閫掑綊鑾峰彇鎵�鏈夊寘鎷瓙鏂囦欢澶圭殑鏂囦欢 + * @Author ChenJiaHe + * @Date 2019/9/17 16:11 + * @Since JDK 1.8 + */ + public static void getAllFileName(String path, List<String> listFileName) { + try { + File file = new File(path); + File[] files = file.listFiles(); + String[] names = file.list(); + if (names != null) { + String[] completNames = new String[names.length]; + for (int i = 0; i < names.length; i++) { + completNames[i] = path + names[i]; + } + listFileName.addAll(Arrays.asList(completNames)); + } + for (File a : files) { + // 濡傛灉鏂囦欢澶逛笅鏈夊瓙鏂囦欢澶癸紝鑾峰彇瀛愭枃浠跺す涓嬬殑鎵�鏈夋枃浠跺叏璺緞銆� + if (a.isDirectory()) { + getAllFileName(a.getAbsolutePath() + "\\", listFileName); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 璇诲彇鏂囦欢鍐呭锛屼綔涓哄瓧绗︿覆杩斿洖 + */ + public static String readFileAsString(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + + if (file.length() > 1024 * 1024 * 1024) { + throw new IOException("File is too large"); + } + + StringBuilder sb = new StringBuilder((int) (file.length())); + // 鍒涘缓瀛楄妭杈撳叆娴� + FileInputStream fis = new FileInputStream(filePath); + // 鍒涘缓涓�涓暱搴︿负10240鐨凚uffer + byte[] bbuf = new byte[10240]; + // 鐢ㄤ簬淇濆瓨瀹為檯璇诲彇鐨勫瓧鑺傛暟 + int hasRead = 0; + while ( (hasRead = fis.read(bbuf)) > 0 ) { + sb.append(new String(bbuf, 0, hasRead)); + } + fis.close(); + return sb.toString(); + } + + /** + * 鏍规嵁鏂囦欢璺緞璇诲彇byte[] 鏁扮粍 + */ + public static byte[] readFileByBytes(String filePath) throws IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } else { + ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); + BufferedInputStream in = null; + + try { + in = new BufferedInputStream(new FileInputStream(file)); + short bufSize = 1024; + byte[] buffer = new byte[bufSize]; + int len1; + while (-1 != (len1 = in.read(buffer, 0, bufSize))) { + bos.write(buffer, 0, len1); + } + + byte[] var7 = bos.toByteArray(); + return var7; + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException var14) { + var14.printStackTrace(); + } + + bos.close(); + } + } + } + + + /** + * 2020-06-29 + * cjh + * 鍥剧墖鏍煎紡鍒ゆ柇 + * */ + public static boolean imageFormatJudge(MultipartFile firs) { + String imageName = firs.getOriginalFilename(); + //鎴彇鏍煎紡 + String suffix =imageName.substring(imageName.lastIndexOf(".") + 1); + //鏍煎紡瀛楁瘝杞皬鍐� + suffix = suffix.toLowerCase(); + //杩涜鍒ゆ柇 + if(suffix.equals("png")) { + return true; + }else if(suffix.equals("jpg")){ + return true; + }else if(suffix.equals("jpeg")){ + return true; + }else { + return false; + } + } + + /**鍥剧墖涓婁紶鐨勬柟娉� + * 淇濆瓨鍒版湇鍔″櫒閲岄潰鐨� + * @param platformIconFile 鍥剧墖鏂囦欢 + * @param unifiedFolder NG鎸囧悜鐨勫墠绔枃浠跺す(缁熶竴鏂囦欢澶�)锛屽锛歶ser/local/images/ + * @param saveFolder 淇濆瓨鍒扮殑鏂囦欢澶�,濡傦細/bananer/ + * @param autoDateFolder 鏄惁鐢熸垚鏃ユ湡鏂囦欢澶� + * @return 鍥剧墖璺緞 + * 2020-06-29 ChenJiaHe + */ + public static String handleFileUpload(MultipartFile platformIconFile,String unifiedFolder,String saveFolder + ,boolean autoDateFolder) { + String fileName = ""; + try { + if(platformIconFile == null) { + throw new TipsException("璇蜂笂浼犲浘鐗囷紒"); + } + if(!imageFormatJudge(platformIconFile)) { + throw new TipsException("璇蜂笂浼爌ng銆乯pg鍜宩peg鏍煎紡鐨勫浘鐗囷紒"); + } + + //璁剧疆鍥剧墖澶у皬 + // String.format("%.1f",platformIconFile.getSize()/1024.0); + if(autoDateFolder){ + if(saveFolder.endsWith("/")){ + saveFolder = saveFolder+dateFormat(new Date(),"yyyyMM")+"/"; + }else{ + saveFolder = saveFolder+"/"+dateFormat(new Date(),"yyyyMM")+"/"; + } + } + fileName = dateFormat(new Date(),"yyyyMMddHHmmssSSS"); + if(unifiedFolder.endsWith("/")){ + if(saveFolder.startsWith("/")){ + saveFolder = saveFolder.replaceFirst("/",""); + unifiedFolder = unifiedFolder + saveFolder; + }else{ + unifiedFolder = unifiedFolder+saveFolder; + } + }else{ + if(saveFolder.startsWith("/")){ + unifiedFolder = unifiedFolder + saveFolder; + }else{ + unifiedFolder = unifiedFolder+"/"+saveFolder; + } + } + fileName = saveFolder+fileUp(platformIconFile,unifiedFolder,fileName); + } catch (RuntimeException e) { + e.printStackTrace(); + } + return fileName; + } + + /** + * 2020-06-29 ChenJiaHe +聽聽 聽 * @param file 聽聽 聽聽聽 聽聽聽 聽//鏂囦欢瀵硅薄 +聽聽 聽 * @param filePath聽聽 聽聽聽 聽//涓婁紶璺緞 +聽聽 聽 * @param fileName聽聽 聽聽聽 聽//鏂囦欢鍚� +聽聽 聽 * @return聽 鏂囦欢鍚� +聽聽 聽 */ + public static String fileUp(MultipartFile file, String filePath, String fileName){ + String extName = ""; // 鎵╁睍鍚嶆牸寮忥細 + try { + if (file.getOriginalFilename().lastIndexOf(".") >= 0){ + extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + } + copyFile(file.getInputStream(), filePath, fileName+extName).replaceAll("-", ""); + } catch (IOException e) { + System.out.println(e); + } + return fileName+extName; + } + + /** + 聽聽 聽 * 鍐欐枃浠跺埌褰撳墠鐩綍鐨剈pload鐩綍涓� + 聽聽 聽 * + 聽聽 聽 * @param in + 聽聽 聽 * @param fileName + 聽聽 聽 * @throws IOException + 聽聽 聽 */ + private static String copyFile(InputStream in, String dir, String realName)throws IOException { + File file = new File(dir, realName); + file.setWritable(true); + if (!file.exists()) { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); + } + org.apache.commons.io.FileUtils.copyInputStreamToFile(in, file); + return realName; + } + + /** + * + * @param date 鏃堕棿 + * @param format 鏃堕棿鏍煎紡 + * @return 杩斿洖鐨勬椂闂存牸寮忓瓧绗︿覆 + */ + public static String dateFormat(Date date,String format) { + SimpleDateFormat df = new SimpleDateFormat(format);//璁剧疆鏃ユ湡鏍煎紡 + return df.format(date); + } + + + /** + * @param stream 鏂囦欢娴� + * @param saveUrl 淇濆瓨鍒扮殑鏂囦欢澶� + * @param fileName 鏂囦欢鍥剧墖 + * @return + * @throws IOException + */ + public static File inputStreamToFile(InputStream stream,String saveUrl,String fileName) throws IOException { + if(saveUrl.endsWith("/")){ + saveUrl = saveUrl + fileName; + }else{ + saveUrl = saveUrl +"/"+ fileName; + } + File targetFile = new File(saveUrl); + org.apache.commons.io.FileUtils.copyInputStreamToFile(stream, targetFile); + return targetFile; + } + +} diff --git a/src/main/java/com/hx/util/GsonUtils.java b/src/main/java/com/hx/util/GsonUtils.java new file mode 100644 index 0000000..3d725b4 --- /dev/null +++ b/src/main/java/com/hx/util/GsonUtils.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. + */ +package com.hx.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; + +import java.lang.reflect.Type; + +/** + * Json宸ュ叿绫�. + */ +public class GsonUtils { + private static Gson gson = new GsonBuilder().create(); + + public static String toJson(Object value) { + return gson.toJson(value); + } + + public static <T> T fromJson(String json, Class<T> classOfT) throws JsonParseException { + return gson.fromJson(json, classOfT); + } + + public static <T> T fromJson(String json, Type typeOfT) throws JsonParseException { + return (T) gson.fromJson(json, typeOfT); + } +} diff --git a/src/main/java/com/hx/util/HttpResponse.java b/src/main/java/com/hx/util/HttpResponse.java new file mode 100644 index 0000000..3edd3c2 --- /dev/null +++ b/src/main/java/com/hx/util/HttpResponse.java @@ -0,0 +1,32 @@ +package com.hx.util; + +public class HttpResponse { + private int code; + private String content; + + public HttpResponse(int status, String content) { + this.code = status; + this.content = content; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String toString(){ + return new StringBuilder("[ code = ").append(code) + .append(" , content = ").append(content).append(" ]").toString(); + } +} diff --git a/src/main/java/com/hx/util/HttpUtil.java b/src/main/java/com/hx/util/HttpUtil.java new file mode 100644 index 0000000..26caf6f --- /dev/null +++ b/src/main/java/com/hx/util/HttpUtil.java @@ -0,0 +1,546 @@ +package com.hx.util; + +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import org.apache.commons.io.IOUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.activation.MimetypesFileTypeMap; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * http 宸ュ叿绫� + */ +public class HttpUtil { + + /**multipart/form-data 鏍煎紡鍙戦�佹暟鎹椂鍚勪釜閮ㄥ垎鍒嗛殧绗︾殑鍓嶇紑,蹇呴』涓� --*/ + private static final String BOUNDARY_PREFIX = "--"; + /**鍥炶溅鎹㈣,鐢ㄤ簬涓�琛岀殑缁撳熬*/ + private static final String LINE_END = "\r\n"; + + + public static String post(String requestUrl, String accessToken, String params) + throws Exception { + String contentType = "application/x-www-form-urlencoded"; + return HttpUtil.post(requestUrl, accessToken, contentType, params); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params) + throws Exception { + String encoding = "UTF-8"; + if (requestUrl.contains("nlp")) { + encoding = "GBK"; + } + return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); + } + + public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) + throws Exception { + String url = requestUrl + "?access_token=" + accessToken; + return HttpUtil.postGeneralUrl(url, contentType, params, encoding); + } + + public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) + throws Exception { + URL url = new URL(generalUrl); + // 鎵撳紑鍜孶RL涔嬮棿鐨勮繛鎺� + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + // 璁剧疆閫氱敤鐨勮姹傚睘鎬� + connection.setRequestProperty("Content-Type", contentType); + connection.setRequestProperty("Connection", "Keep-Alive"); + connection.setUseCaches(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // 寰楀埌璇锋眰鐨勮緭鍑烘祦瀵硅薄 + DataOutputStream out = new DataOutputStream(connection.getOutputStream()); + out.write(params.getBytes(encoding)); + out.flush(); + out.close(); + + // 寤虹珛瀹為檯鐨勮繛鎺� + connection.connect(); + // 鑾峰彇鎵�鏈夊搷搴斿ご瀛楁 + Map<String, List<String>> headers = connection.getHeaderFields(); + // 閬嶅巻鎵�鏈夌殑鍝嶅簲澶村瓧娈� + for (String key : headers.keySet()) { + System.err.println(key + "--->" + headers.get(key)); + } + // 瀹氫箟 BufferedReader杈撳叆娴佹潵璇诲彇URL鐨勫搷搴� + BufferedReader in = null; + in = new BufferedReader( + new InputStreamReader(connection.getInputStream(), encoding)); + String result = ""; + String getLine; + while ((getLine = in.readLine()) != null) { + result += getLine; + } + in.close(); + System.err.println("result:" + result); + return result; + } + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static JSONObject HttpURLUtil(String url, String data) { + HttpURLConnection con = null; + URL u = null; + String wxMsgXml = null; + JSONObject obj = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); + obj = JSONObject.fromObject(wxMsgXml); + // //System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } + + + /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ + public static JSONObject HttpURLUtilJson(String url, String data) { + HttpURLConnection con = null; + URL u = null; + String wxMsgXml = null; + JSONObject obj = null; + try { + u = new URL(url); + con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod("POST"); + con.setDoOutput(true); + con.setDoInput(true); + con.setUseCaches(false); + con.setReadTimeout(5000); + con.setRequestProperty("Charset", "UTF-8"); + con.setRequestProperty("Content-Type", "application/json"); + + if (data != null) { + OutputStream os = con.getOutputStream(); + os.write(data.getBytes("utf-8")); + } + + if (con.getResponseCode() != 200) + throw new RuntimeException("璇锋眰url澶辫触"); + // 璇诲彇杩斿洖鍐呭 + wxMsgXml = IOUtils.toString(con.getInputStream(), "utf-8"); + obj = JSONObject.fromObject(wxMsgXml); + // //System.out.println("HttpURLUtil:"+wxMsgXml); + } catch (Exception e) { + e.printStackTrace(); + obj = new JSONObject(); + try { + obj.put("status", 1); + obj.put("errMsg", e.getMessage()); + } catch (JSONException e1) { + e1.printStackTrace(); + } + } finally { + if (con != null) { + con.disconnect(); + } + } + return obj; + } + + /** + * post 璇锋眰锛氫互琛ㄥ崟鏂瑰紡鎻愪氦鏁版嵁 + * <p> + * 鐢变簬 multipart/form-data 涓嶆槸 http 鏍囧噯鍐呭锛岃�屾槸灞炰簬鎵╁睍绫诲瀷锛� + * 鍥犳闇�瑕佽嚜宸辨瀯閫犳暟鎹粨鏋勶紝鍏蜂綋濡備笅锛� + * <p> + * 1銆侀鍏堬紝璁剧疆 Content-Type + * <p> + * Content-Type: multipart/form-data; boundary=${bound} + * <p> + * 鍏朵腑${bound} 鏄竴涓崰浣嶇锛屼唬琛ㄦ垜浠瀹氱殑鍒嗗壊绗︼紝鍙互鑷繁浠绘剰瑙勫畾锛� + * 浣嗕负浜嗛伩鍏嶅拰姝e父鏂囨湰閲嶅浜嗭紝灏介噺瑕佷娇鐢ㄥ鏉備竴鐐圭殑鍐呭 + * <p> + * 2銆佽缃富浣撳唴瀹� + * <p> + * --${bound} + * Content-Disposition: form-data; name="userName" + * <p> + * Andy + * --${bound} + * Content-Disposition: form-data; name="file"; filename="娴嬭瘯.excel" + * Content-Type: application/octet-stream + * <p> + * 鏂囦欢鍐呭 + * --${bound}-- + * <p> + * 鍏朵腑${bound}鏄箣鍓嶅ご淇℃伅涓殑鍒嗛殧绗︼紝濡傛灉澶翠俊鎭腑瑙勫畾鏄�123锛岄偅杩欓噷涔熻鏄�123锛� + * 鍙互寰堝鏄撶湅鍒帮紝杩欎釜璇锋眰鎻愭槸澶氫釜鐩稿悓閮ㄥ垎缁勬垚鐨勶細 + * 姣忎竴閮ㄥ垎閮芥槸浠�--鍔犲垎闅旂寮�濮嬬殑锛岀劧鍚庢槸璇ラ儴鍒嗗唴瀹圭殑鎻忚堪淇℃伅锛岀劧鍚庝竴涓洖杞︽崲琛岋紝鐒跺悗鏄弿杩颁俊鎭殑鍏蜂綋鍐呭锛� + * 濡傛灉浼犻�佺殑鍐呭鏄竴涓枃浠剁殑璇濓紝閭d箞杩樹細鍖呭惈鏂囦欢鍚嶄俊鎭互鍙婃枃浠跺唴瀹圭被鍨嬨�� + * 涓婇潰绗簩閮ㄥ垎鏄竴涓枃浠朵綋鐨勭粨鏋勶紝鏈�鍚庝互--鍒嗛殧绗�--缁撳熬锛岃〃绀鸿姹備綋缁撴潫 + * + * @param urlStr 璇锋眰鐨剈rl + * @param filePathMap key 鍙傛暟鍚嶏紝value 鏂囦欢鐨勮矾寰� + * @param keyValues 鏅�氬弬鏁扮殑閿�煎 + * @param headers + * @return + * @throws IOException + */ + public static HttpResponse postFormData(String urlStr, Map<String, String> filePathMap, Map<String, Object> keyValues, Map<String, Object> headers) throws IOException { + HttpResponse response; + HttpURLConnection conn = getHttpURLConnection(urlStr, headers); + //鍒嗛殧绗︼紝鍙互浠绘剰璁剧疆锛岃繖閲岃缃负 MyBoundary+ 鏃堕棿鎴筹紙灏介噺澶嶆潅鐐癸紝閬垮厤鍜屾鏂囬噸澶嶏級 + String boundary = "MyBoundary" + System.currentTimeMillis(); + //璁剧疆 Content-Type 涓� multipart/form-data; boundary=${boundary} + conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + + //鍙戦�佸弬鏁版暟鎹� + try (DataOutputStream out = new DataOutputStream(conn.getOutputStream())) { + //鍙戦�佹櫘閫氬弬鏁� + if (keyValues != null && !keyValues.isEmpty()) { + for (Map.Entry<String, Object> entry : keyValues.entrySet()) { + writeSimpleFormField(boundary, out, entry); + } + } + //鍙戦�佹枃浠剁被鍨嬪弬鏁� + if (filePathMap != null && !filePathMap.isEmpty()) { + for (Map.Entry<String, String> filePath : filePathMap.entrySet()) { + writeFile(filePath.getKey(), filePath.getValue(), boundary, out); + } + } + + //鍐欑粨灏剧殑鍒嗛殧绗�--${boundary}--,鐒跺悗鍥炶溅鎹㈣ + String endStr = BOUNDARY_PREFIX + boundary + BOUNDARY_PREFIX + LINE_END; + out.write(endStr.getBytes()); + } catch (Exception e) { + e.printStackTrace(); + response = new HttpResponse(500, e.getMessage()); + return response; + } + + return getHttpResponse(conn); + } + + public static HttpResponse postFormData(String urlStr, Map<String, MultipartFile> filePathMap, Map<String, Object> keyValues) throws IOException { + HttpResponse response; + HttpURLConnection conn = getHttpURLConnection(urlStr, null); + //鍒嗛殧绗︼紝鍙互浠绘剰璁剧疆锛岃繖閲岃缃负 MyBoundary+ 鏃堕棿鎴筹紙灏介噺澶嶆潅鐐癸紝閬垮厤鍜屾鏂囬噸澶嶏級 + String boundary = "MyBoundary" + System.currentTimeMillis(); + //璁剧疆 Content-Type 涓� multipart/form-data; boundary=${boundary} + conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + + //鍙戦�佸弬鏁版暟鎹� + try (DataOutputStream out = new DataOutputStream(conn.getOutputStream())) { + //鍙戦�佹櫘閫氬弬鏁� + if (keyValues != null && !keyValues.isEmpty()) { + for (Map.Entry<String, Object> entry : keyValues.entrySet()) { + writeSimpleFormField(boundary, out, entry); + } + } + //鍙戦�佹枃浠剁被鍨嬪弬鏁� + if (filePathMap != null && !filePathMap.isEmpty()) { + for (Map.Entry<String, MultipartFile> filePath : filePathMap.entrySet()) { + writeFile(filePath.getKey(), filePath.getValue(), boundary, out); + } + } + + //鍐欑粨灏剧殑鍒嗛殧绗�--${boundary}--,鐒跺悗鍥炶溅鎹㈣ + String endStr = BOUNDARY_PREFIX + boundary + BOUNDARY_PREFIX + LINE_END; + out.write(endStr.getBytes()); + } catch (Exception e) { + response = new HttpResponse(500, e.getMessage()); + return response; + } + + return getHttpResponse(conn); + } + + /** + * 鑾峰緱杩炴帴瀵硅薄 + * + * @param urlStr + * @param headers + * @return + * @throws IOException + */ + private static HttpURLConnection getHttpURLConnection(String urlStr, Map<String, Object> headers) throws IOException { + URL url = new URL(urlStr); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + //璁剧疆瓒呮椂鏃堕棿 + conn.setConnectTimeout(50000); + conn.setReadTimeout(50000); + //鍏佽杈撳叆娴� + conn.setDoInput(true); + //鍏佽杈撳嚭娴� + conn.setDoOutput(true); + //涓嶅厑璁镐娇鐢ㄧ紦瀛� + conn.setUseCaches(false); + //璇锋眰鏂瑰紡 + conn.setRequestMethod("POST"); + //璁剧疆缂栫爜 utf-8 + conn.setRequestProperty("Charset", "UTF-8"); + //璁剧疆涓洪暱杩炴帴 + conn.setRequestProperty("connection", "keep-alive"); + + //璁剧疆鍏朵粬鑷畾涔� headers + if (headers != null && !headers.isEmpty()) { + for (Map.Entry<String, Object> header : headers.entrySet()) { + conn.setRequestProperty(header.getKey(), header.getValue().toString()); + } + } + + return conn; + } + + private static HttpResponse getHttpResponse(HttpURLConnection conn) { + HttpResponse response; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { + int responseCode = conn.getResponseCode(); + StringBuilder responseContent = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + responseContent.append(line); + } + response = new HttpResponse(responseCode, responseContent.toString()); + } catch (Exception e) { + e.printStackTrace(); + response = new HttpResponse(500, e.getMessage()); + } + return response; + } + + /** + * 鍐欐枃浠剁被鍨嬬殑琛ㄥ崟鍙傛暟 + * + * @param paramName 鍙傛暟鍚� + * @param filePath 鏂囦欢璺緞 + * @param boundary 鍒嗛殧绗� + * @param out + * @throws IOException + */ + private static void writeFile(String paramName, String filePath, String boundary, + DataOutputStream out) { + try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) { + /** + * 鍐欏垎闅旂--${boundary}锛屽苟鍥炶溅鎹㈣ + */ + String boundaryStr = BOUNDARY_PREFIX + boundary + LINE_END; + out.write(boundaryStr.getBytes()); + /** + * 鍐欐弿杩颁俊鎭�(鏂囦欢鍚嶈缃负涓婁紶鏂囦欢鐨勬枃浠跺悕)锛� + * 鍐� Content-Disposition: form-data; name="鍙傛暟鍚�"; filename="鏂囦欢鍚�"锛屽苟鍥炶溅鎹㈣ + * 鍐� Content-Type: application/octet-stream锛屽苟涓や釜鍥炶溅鎹㈣ + */ + String fileName = new File(filePath).getName(); + String contentDispositionStr = String.format("Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"", paramName, fileName) + LINE_END; + out.write(contentDispositionStr.getBytes()); + String contentType = "Content-Type: application/octet-stream" + LINE_END + LINE_END; + out.write(contentType.getBytes()); + + String line; + while ((line = fileReader.readLine()) != null) { + out.write(line.getBytes()); + } + //鍥炶溅鎹㈣ + out.write(LINE_END.getBytes()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 鍐欐枃浠剁被鍨嬬殑琛ㄥ崟鍙傛暟 + * + * @param paramName 鍙傛暟鍚� + * @param multipartFile 鏂囦欢 + * @param boundary 鍒嗛殧绗� + * @param out + * @throws IOException + */ + private static void writeFile(String paramName, MultipartFile multipartFile, String boundary, + DataOutputStream out) { + + try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(multipartFile.getInputStream()))) { + /** + * 鍐欏垎闅旂--${boundary}锛屽苟鍥炶溅鎹㈣ + */ + String boundaryStr = BOUNDARY_PREFIX + boundary + LINE_END; + out.write(boundaryStr.getBytes()); + /** + * 鍐欐弿杩颁俊鎭�(鏂囦欢鍚嶈缃负涓婁紶鏂囦欢鐨勬枃浠跺悕)锛� + * 鍐� Content-Disposition: form-data; name="鍙傛暟鍚�"; filename="鏂囦欢鍚�"锛屽苟鍥炶溅鎹㈣ + * 鍐� Content-Type: application/octet-stream锛屽苟涓や釜鍥炶溅鎹㈣ + */ + String fileName = multipartFile.getName(); + String contentDispositionStr = String.format("Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"", paramName, fileName) + LINE_END; + out.write(contentDispositionStr.getBytes()); + String contentType = "Content-Type: application/octet-stream" + LINE_END + LINE_END; + out.write(contentType.getBytes()); + + String line; + while ((line = fileReader.readLine()) != null) { + out.write(line.getBytes()); + } + //鍥炶溅鎹㈣ + out.write(LINE_END.getBytes()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 鍐欐櫘閫氱殑琛ㄥ崟鍙傛暟 + * + * @param boundary 鍒嗛殧绗� + * @param out + * @param entry 鍙傛暟鐨勯敭鍊煎 + * @throws IOException + */ + private static void writeSimpleFormField(String boundary, DataOutputStream out, Map.Entry<String, Object> entry) throws IOException { + //鍐欏垎闅旂--${boundary}锛屽苟鍥炶溅鎹㈣ + String boundaryStr = BOUNDARY_PREFIX + boundary + LINE_END; + out.write(boundaryStr.getBytes()); + //鍐欐弿杩颁俊鎭細Content-Disposition: form-data; name="鍙傛暟鍚�"锛屽苟涓や釜鍥炶溅鎹㈣ + String contentDispositionStr = String.format("Content-Disposition: form-data; name=\"%s\"", entry.getKey()) + LINE_END + LINE_END; + out.write(contentDispositionStr.getBytes()); + //鍐欏叿浣撳唴瀹癸細鍙傛暟鍊硷紝骞跺洖杞︽崲琛� + String valueStr = entry.getValue().toString() + LINE_END; + out.write(valueStr.getBytes()); + } + + public static String formUpload(String urlStr, Map<String, String> textMap, + Map<String, String> fileMap,String contentType) { + String res = ""; + HttpURLConnection conn = null; + // boundary灏辨槸request澶村拰涓婁紶鏂囦欢鍐呭鐨勫垎闅旂 + String BOUNDARY = "---------------------------123821742118716"; + try { + URL url = new URL(urlStr); + conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(5000); + conn.setReadTimeout(30000); + conn.setDoOutput(true); + conn.setDoInput(true); + conn.setUseCaches(false); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Connection", "Keep-Alive"); + // conn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)"); + conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + BOUNDARY); + OutputStream out = new DataOutputStream(conn.getOutputStream()); + // text + if (textMap != null) { + StringBuffer strBuf = new StringBuffer(); + Iterator iter = textMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry) iter.next(); + String inputName = (String) entry.getKey(); + String inputValue = (String) entry.getValue(); + if (inputValue == null) { + continue; + } + strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n"); + strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n"); + strBuf.append(inputValue); + } + out.write(strBuf.toString().getBytes()); + } + // file + if (fileMap != null) { + Iterator iter = fileMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry) iter.next(); + String inputName = (String) entry.getKey(); + String inputValue = (String) entry.getValue(); + if (inputValue == null) { + continue; + } + File file = new File(inputValue); + String filename = file.getName(); + + //娌℃湁浼犲叆鏂囦欢绫诲瀷锛屽悓鏃舵牴鎹枃浠惰幏鍙栦笉鍒扮被鍨嬶紝榛樿閲囩敤application/octet-stream + contentType = new MimetypesFileTypeMap().getContentType(file); + //contentType闈炵┖閲囩敤filename鍖归厤榛樿鐨勫浘鐗囩被鍨� + if(!"".equals(contentType)){ + if (filename.endsWith(".png")) { + contentType = "image/png"; + }else if (filename.endsWith(".jpg") || filename.endsWith(".jpeg") || filename.endsWith(".jpe")) { + contentType = "image/jpeg"; + }else if (filename.endsWith(".gif")) { + contentType = "image/gif"; + }else if (filename.endsWith(".ico")) { + contentType = "image/image/x-icon"; + } + } + if (contentType == null || "".equals(contentType)) { + contentType = "application/octet-stream"; + } + StringBuffer strBuf = new StringBuffer(); + strBuf.append("\r\n").append("--").append(BOUNDARY).append("\r\n"); + strBuf.append("Content-Disposition: form-data; name=\"" + inputName + "\"; filename=\"" + filename + "\"\r\n"); + strBuf.append("Content-Type:" + contentType + "\r\n\r\n"); + out.write(strBuf.toString().getBytes()); + DataInputStream in = new DataInputStream(new FileInputStream(file)); + int bytes = 0; + byte[] bufferOut = new byte[1024]; + while ((bytes = in.read(bufferOut)) != -1) { + out.write(bufferOut, 0, bytes); + } + in.close(); + } + } + byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes(); + out.write(endData); + out.flush(); + out.close(); + // 璇诲彇杩斿洖鏁版嵁 + StringBuffer strBuf = new StringBuffer(); + BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String line = null; + while ((line = reader.readLine()) != null) { + strBuf.append(line).append("\n"); + } + res = strBuf.toString(); + reader.close(); + reader = null; + } catch (Exception e) { + System.out.println("鍙戦�丳OST璇锋眰鍑洪敊銆�" + urlStr); + e.printStackTrace(); + } finally { + if (conn != null) { + conn.disconnect(); + conn = null; + } + } + return res; + } +} diff --git a/src/main/java/com/hx/util/ImagesAddDomain.java b/src/main/java/com/hx/util/ImagesAddDomain.java new file mode 100644 index 0000000..cfbfe27 --- /dev/null +++ b/src/main/java/com/hx/util/ImagesAddDomain.java @@ -0,0 +1,84 @@ +package com.hx.util; + +import net.sf.json.JSONArray; + +/**鍥剧墖璺緞鍔犱笂鍩熷悕 + * @author ChenJiaHe + * @Date 2020-07-07 + */ +public class ImagesAddDomain { + + /** + * 鍥剧墖璺緞鍔犱笂鍩熷悕 + * @param arrString 鍥剧墖JSON瀛楃涓叉暟缁� + * @param domainName 鍩熷悕 + * @return + */ + public static JSONArray imagesAddDomain(String arrString, String domainName){ + JSONArray arr = new JSONArray(); + if(SimpleTool.checkNotNull(arrString)){ + JSONArray images = JSONArray.fromObject(arrString); + for(int i = 0;i<images.size();i++){ + if(images.getString(i).indexOf("http")!=-1){ + arr.add(images.getString(i)); + }else{ + arr.add(urlAddDomain(images.getString(i),domainName)); + } + } + } + return arr; + } + + /** + * 鍥剧墖璺緞鍔犱笂鍩熷悕 + * @param imagesArr 鍥剧墖鏁扮粍 + * @param domainName 鍩熷悕 + * @return + */ + public static JSONArray imagesAddDomain(JSONArray imagesArr, String domainName){ + JSONArray arr = new JSONArray(); + if(SimpleTool.checkNotNull(imagesArr)){ + for(int i = 0;i<imagesArr.size();i++){ + if(imagesArr.getString(i).indexOf("http")!=-1){ + arr.add(imagesArr.getString(i)); + }else{ + arr.add(urlAddDomain(imagesArr.getString(i),domainName)); + } + } + } + return arr; + } + + /** + * 鍥剧墖璺緞鍔犱笂鍩熷悕 + * @param imagesUrl 鍥剧墖璺緞 + * @param domainName 鍩熷悕 + * @return + */ + public static String urlAddDomain(String imagesUrl, String domainName){ + if(StringUtils.isEmpty(domainName)){ + return imagesUrl; + } + if(SimpleTool.checkNotNull(imagesUrl)){ + if(imagesUrl.indexOf("http")!=-1){ + return imagesUrl; + } + if(domainName.endsWith("/")){ + if(imagesUrl.startsWith("/")){ + imagesUrl = imagesUrl.replaceFirst("/",""); + imagesUrl = domainName+imagesUrl; + }else{ + imagesUrl = domainName+imagesUrl; + } + }else{ + if(imagesUrl.startsWith("/")){ + imagesUrl = domainName+imagesUrl; + }else{ + imagesUrl = domainName+"/"+imagesUrl; + } + } + } + return imagesUrl; + } + +} diff --git a/src/main/java/com/hx/util/JwtConstant.java b/src/main/java/com/hx/util/JwtConstant.java new file mode 100644 index 0000000..be0eac5 --- /dev/null +++ b/src/main/java/com/hx/util/JwtConstant.java @@ -0,0 +1,54 @@ +package com.hx.util; + +import com.alibaba.fastjson.JSONObject; + +import io.jsonwebtoken.Claims; + +/** + * JWT 鍏峰閰嶇疆 + * @author chenjiahe + * @Data 2020-06-09 + */ +public class JwtConstant { + + public static void main(String[] args) { + //姣忔柊寮�涓�涓」鐩氨閲嶆柊鐢熸垚JWT_SECERT绉橀挜 + //String s = BASE64.encryptBASE64("hx-haoqi168".getBytes()); + //System.out.println("s:"+s); + JSONObject obj = new JSONObject(); + obj.put("id", "111"); + obj.put("adminRoleId", "22"); + String token = JwtTool.createJWT("111", obj.toString(), 300); + System.out.println("token:"+token); + //eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMTEiLCJzdWIiOiLkuprpurvot4wiLCJpc3MiOiJ1c2VyIiwiaWF0IjoxNTkxODY4NjAxLCJleHAiOjE1OTE4Njg5MDF9.8m_TgK8m49r35-qQRQ0cGjL4r_jBlaVqb318vM00qrE + } + + public static String JWT_ERRCODE_EXPIRE = "鐧诲綍鏈夋晥鏈熷凡杩囷紒"; + public static String JWT_ERRCODE_FAIL = "鐧诲綍鏃犳晥锛岃閲嶆柊鐧诲綍锛�"; + public static String JWT_SECERT = "aGFvcWkxNjg=";//鐢熸垚JWT鐨勭閽� + + private Claims claims; + private boolean success; + private String errCode; + + + /*************************************************************************/ + public Claims getClaims() { + return claims; + } + public void setClaims(Claims claims) { + this.claims = claims; + } + public boolean isSuccess() { + return success; + } + public void setSuccess(boolean success) { + this.success = success; + } + public String getErrCode() { + return errCode; + } + public void setErrCode(String errCode) { + this.errCode = errCode; + } +} diff --git a/src/main/java/com/hx/util/JwtTool.java b/src/main/java/com/hx/util/JwtTool.java new file mode 100644 index 0000000..873b27a --- /dev/null +++ b/src/main/java/com/hx/util/JwtTool.java @@ -0,0 +1,93 @@ +package com.hx.util; + +import java.util.Date; + +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.ExpiredJwtException; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.SignatureException; + +/** + * 鐢熸垚token 锛堢櫥褰曪紝鎴栬�呭叾浠栵級 + * @author chenjiahe + * @Data 20200609 + */ +public class JwtTool { + + /** + * 绛惧彂JWT + * @param id 鏍囪瘑 + * @param subject 鍙互鏄疛SON鏁版嵁 灏藉彲鑳藉皯 + * @param ttlMillis 鏈夋晥鏃堕棿闀垮害(绉�)锛屼负绌轰綘璁よ瘉鏃堕棿 + * @return String + * + */ + public static String createJWT(String id, String subject, long ttlMillis) { + SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; + long nowMillis = System.currentTimeMillis(); + Date now = new Date(nowMillis); + SecretKey secretKey = generalKey(); + JwtBuilder builder = Jwts.builder() + .setId(id) + .setSubject(subject) // 涓婚 + .setIssuer("user") // 绛惧彂鑰� + .setIssuedAt(now) // 绛惧彂鏃堕棿 + .signWith(signatureAlgorithm, secretKey); // 绛惧悕绠楁硶浠ュ強瀵嗗寵 + if (SimpleTool.checkNotNull(ttlMillis)&&ttlMillis >= 0) { + long expMillis = nowMillis + ttlMillis*1000; + Date expDate = new Date(expMillis); + builder.setExpiration(expDate); // 杩囨湡鏃堕棿 + } + return builder.compact(); + } + /** + * 楠岃瘉JWT + * @param jwtStr + * @return JwtConstant + */ + public static JwtConstant validateJWT(String jwtStr) { + JwtConstant checkResult = new JwtConstant(); + Claims claims = null; + try { + claims = parseJWT(jwtStr); + checkResult.setSuccess(true); + checkResult.setClaims(claims); + } catch (ExpiredJwtException e) { + checkResult.setErrCode(JwtConstant.JWT_ERRCODE_EXPIRE); + checkResult.setSuccess(false); + } catch (SignatureException e) { + checkResult.setErrCode(JwtConstant.JWT_ERRCODE_FAIL); + checkResult.setSuccess(false); + } catch (Exception e) { + checkResult.setErrCode(JwtConstant.JWT_ERRCODE_FAIL); + checkResult.setSuccess(false); + } + return checkResult; + } + + public static SecretKey generalKey() { + byte[] encodedKey = BASE64.decryptBASE64(JwtConstant.JWT_SECERT); + SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); + return key; + } + + /** + * + * 瑙f瀽JWT瀛楃涓� + * @param jwt + * @return + * @throws Exception + */ + public static Claims parseJWT(String jwt) throws Exception { + SecretKey secretKey = generalKey(); + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(jwt) + .getBody(); + } +} diff --git a/src/main/java/com/hx/util/MD5.java b/src/main/java/com/hx/util/MD5.java new file mode 100644 index 0000000..2196ad7 --- /dev/null +++ b/src/main/java/com/hx/util/MD5.java @@ -0,0 +1,64 @@ +package com.hx.util; + +import java.security.MessageDigest; + +public class MD5 { + private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + + public static String byteArrayToHexString(byte[] b) { + StringBuffer resultSb = new StringBuffer(); + for (int i = 0; i < b.length; i++) { + resultSb.append(byteToHexString(b[i])); + } + return resultSb.toString(); + } + + private static String byteToHexString(byte b) { + int n = b; + if (n < 0) + n = 256 + n; + int d1 = n / 16; + int d2 = n % 16; + return hexDigits[d1] + hexDigits[d2]; + } + + public static String MD5Encode(String origin) { + String resultString = null; + + try { + resultString = new String(origin); + MessageDigest md = MessageDigest.getInstance("MD5"); + resultString = byteArrayToHexString(md.digest(resultString + .getBytes())); + } catch (Exception ex) { + + } + return resultString; + } + + /**瀵嗙爜鍔犲瘑 **/ + public static String encryption(String str){ + try{ + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.update(str.getBytes()); + byte b[] = md5.digest(); + int i ; + StringBuffer buf = new StringBuffer(""); + for(int j = 0;j<b.length;j++){ + i = b[j]; + if(i<0) + i+=256; + if(i<116) + buf.append("0"); + buf.append(Integer.toHexString(i)); + } + str = buf.toString().substring(8, 24); //鍗佸叚浣� + }catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("鍔犲瘑绋嬪簭閿欒锛�"); + } + return str; + } + +} \ No newline at end of file diff --git a/src/main/java/com/hx/util/MD5Util.java b/src/main/java/com/hx/util/MD5Util.java new file mode 100644 index 0000000..f7eba43 --- /dev/null +++ b/src/main/java/com/hx/util/MD5Util.java @@ -0,0 +1,48 @@ +package com.hx.util; + +import java.security.MessageDigest; + +public class MD5Util { + + private static String byteArrayToHexString(byte b[]) { + StringBuffer resultSb = new StringBuffer(); + for (int i = 0; i < b.length; i++) + resultSb.append(byteToHexString(b[i])); + + return resultSb.toString(); + } + + private static String byteToHexString(byte b) { + int n = b; + if (n < 0) + n += 256; + int d1 = n / 16; + int d2 = n % 16; + return hexDigits[d1] + hexDigits[d2]; + } + + /** + * @param origin 鍔犲瘑淇℃伅 + * @param charsetname 鍔犲瘑淇℃伅鐨勫瓧绗︿覆鍚嶇О锛堝彲浠ヤ负绌猴級 + * @return + */ + public static String MD5Encode(String origin, String charsetname) { + String resultString = null; + try { + resultString = new String(origin); + MessageDigest md = MessageDigest.getInstance("MD5"); + if (charsetname == null || "".equals(charsetname)) + resultString = byteArrayToHexString(md.digest(resultString + .getBytes())); + else + resultString = byteArrayToHexString(md.digest(resultString + .getBytes(charsetname))); + } catch (Exception exception) { + } + return resultString; + } + + private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + +} diff --git a/src/main/java/com/hx/util/MyRedisTemplate.java b/src/main/java/com/hx/util/MyRedisTemplate.java new file mode 100644 index 0000000..5a081c7 --- /dev/null +++ b/src/main/java/com/hx/util/MyRedisTemplate.java @@ -0,0 +1,139 @@ +package com.hx.util; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.ListOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +/** + * @PackageName com.hx.util + * @ProjectName hx-parent + * @Author: ChenJiaHe + * @Date: Create in 16:51 2019/7/22 + * @Description: + * @Copyright Copyright (c) 2019, hx01@163.com All Rights Reserved. + */ +@Component +public class MyRedisTemplate<E> { + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private SerializeUtil<E> serialize; + + public static ListOperations<String, String> list; + + /** + * 鏍规嵁閿�艰幏鍙杤alue + * @param key + * @return + */ + public E get(String key) { + ValueOperations<String, String> opsForValue = redisTemplate.opsForValue(); + return key == null ? null : serialize.unserialize(opsForValue.get(key)); + } + + /** + * 璁剧疆閿�煎(鏃犺秴鏃舵椂闂�) + * @param key + * @param value + * @return + */ + public boolean set(String key, E value) { + ValueOperations<String, String> opsForValue = redisTemplate.opsForValue(); + try { + opsForValue.set(key, serialize.serialize(value)); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 璁剧疆閿�煎 (璁剧疆鏈夋晥鏃堕棿,浠ョ涓哄崟浣�) + * + * @param key + * @param value + * @param expire + * @return boolean + */ + public boolean set(String key, E value, long expire) { + ValueOperations<String, String> opsForValue = redisTemplate.opsForValue(); + try { + opsForValue.set(key, serialize.serialize(value), expire, TimeUnit.SECONDS); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 鏍规嵁key鍒犻櫎閿�煎 + * + * @param key + * @return + */ + public boolean delete(String key) { + try { + redisTemplate.delete(key); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + /* + * 妯℃嫙闃熷垪 + */ + + /** + * lpush 杩涢槦鍒� + * + * @param key + * @param value + * @return + */ + public Long lpush(String key, String value) { + list = redisTemplate.opsForList(); + try { + Long leftPush = list.leftPush(key, value); + return leftPush; + } catch (Exception e) { + e.printStackTrace(); + return Long.valueOf(-1); + } + } + + /** + * rpop 鍑洪槦鍒� + * + * @param key + * @return + */ + public String rpop(String key) { + list = redisTemplate.opsForList(); + try { + return list.rightPop(key); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 杩斿洖鎸囧畾闃熷垪(list)鍚嶉槦鍒楅暱搴� + * + * @param key + * @return + */ + public Long llen(String key) { + list = redisTemplate.opsForList(); + return list.size(key); + } +} diff --git a/src/main/java/com/hx/util/NumberUtil.java b/src/main/java/com/hx/util/NumberUtil.java new file mode 100644 index 0000000..708ac35 --- /dev/null +++ b/src/main/java/com/hx/util/NumberUtil.java @@ -0,0 +1,340 @@ +package com.hx.util; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; + +/** + * 鏁板瓧宸ュ叿 + * + * @author mgchen + * + */ +public class NumberUtil { + + private static DecimalFormat fmt = new DecimalFormat("0.00"); + + private static DecimalFormat fmtOne = new DecimalFormat("0.0"); + + private static DecimalFormat fmtThree = new DecimalFormat("0.000"); + + /** + * 鑾峰彇鎸囧畾鏍煎紡鐨凞ouble 绫诲瀷鏁版嵁 + * @param e + * 瑕佽浆鎹㈢殑鏁版嵁婧� + **/ + public static Double getTypeDouble(Double e) { + fmt.setRoundingMode(RoundingMode.HALF_UP); // 淇濈暀灏忔暟鐐瑰悗涓や綅骞跺洓鑸嶄簲鍏ワ紝纭繚浠烽挶鍑嗙‘ + Double d = Double.valueOf(fmt.format(e)); + return d; + } + + /** + * 鑾峰彇鎸囧畾鏍煎紡鐨凞ouble 绫诲瀷鏁版嵁 + * + * @param e + * 瑕佽浆鎹㈢殑鏁版嵁婧� + **/ + public static Double getTypeDouble1(Double e) { + fmtOne.setRoundingMode(RoundingMode.HALF_UP); // 淇濈暀灏忔暟鐐瑰悗涓や綅骞跺洓鑸嶄簲鍏ワ紝纭繚浠烽挶鍑嗙‘ + Double d = Double.valueOf(fmtOne.format(e)); + return d; + } + + public static Double getTypeDouble2(Double e) { + fmtThree.setRoundingMode(RoundingMode.HALF_UP); // 淇濈暀灏忔暟鐐瑰悗涓や綅骞跺洓鑸嶄簲鍏ワ紝纭繚浠烽挶鍑嗙‘ + Double d = Double.valueOf(fmtThree.format(e)); + return d; + } + + /** + * 鎶婂瓨鍌ㄧ殑鍒嗗瓧绗︿覆杞垚鍏冪殑娴偣鏁� 渚嬪100鍒�1.0 + */ + public static Double getYunFromFenStr(String fenStr) { + return getTypeDouble(Integer.parseInt(fenStr) * 1.0 / 100); + } + + /** + * 鎶婂瓨鍌ㄧ殑鍒嗚浆鎴愬厓鐨勬诞鐐规暟 渚嬪100鍒�1.0 + */ + public static Double getYunFromFen(Integer fen) { + if (fen == null) { + return 0D; + } + return getTypeDouble(fen * 1.0 / 100); + } + + /** + * 鎶婂瓨鍌ㄧ殑鍘樿浆鎴愬厓鐨勬诞鐐规暟 渚嬪1000鍒�1.0 + */ + public static Double getYunFromLi(int li) { + return getTypeDouble2(li * 1.0 / 1000); + } + + /** + * 鎶婂瓨鍌ㄧ殑鏁板�艰浆涓虹櫨鍒嗘瘮 + * + * @param rate + * @return + */ + public static Double getRateFromInt(int rate) { + return getTypeDouble(rate * 1.0 / 100); + } + + /** 娴偣鏁板洓鑸嶄簲鍏ュ彇鏁� */ + public static int getRoundHalfUp(double tar) { + return new BigDecimal(tar).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); + } + + /** 娴偣鏁板洓鑸嶄簲鍏ュ彇鏁� */ + public static int getRoundHalfDown(double tar) { + Double d = Math.floor(tar); + return d.intValue(); + } + + /** + * 鎶婁竴涓猟ouble鐨勫瓧绗︿覆涔�100 杩斿洖鏁存暟 + * + * @return int 鏁存暟 + */ + public static int getYunFromFen(String str) { + // BigDecimal b1 = new BigDecimal(str); + // BigDecimal b2 = new BigDecimal("100"); + // return b1.multiply(b2).intValue(); + return multiply(str, "100").intValue(); + } + + /** 鑾峰彇涓や綅灏忔暟鐨勬暣鏁� */ + public static int getTwoDecimalInt(Double d) { + return Double.valueOf(fmt.format(d)).intValue(); + } + + /** + * num1 闄や互num2 寰楀埌鐧惧垎鐧� 淇濈暀涓�浣嶅皬鏁� + * + * @param num1 + * @param num2 + * @return + */ + public static Double getPercentage(Integer num1, Integer num2) { + Double reNum = 0d; + if (num1 == null || num2 == null || num1 == 0 || num2 == 0) { + return reNum; + } + BigDecimal b1 = new BigDecimal(num1 * 100); + BigDecimal b2 = new BigDecimal(num2); + reNum = b1.divide(b2, 1, BigDecimal.ROUND_HALF_UP).doubleValue(); + return reNum; + } + + /** + * 灏嗕竴涓暟闄や互100 + * + * @param fen + * @return Double + */ + public static Double fenForYuan(int fen) { + // BigDecimal b1 = new BigDecimal(fen); + // BigDecimal b2 = new BigDecimal(100); + // return b1.divide(b2).doubleValue(); + return divide(fen, 100); + } + + /** + * 灏嗕竴涓暟闄や互100 + * + * @param fen + * @return Double + */ + public static Double fenForYuan(String fen) { + // BigDecimal b1 = new BigDecimal(fen); + // BigDecimal b2 = new BigDecimal(100); + // return b1.divide(b2).doubleValue(); + return divide(fen, "100"); + } + + public static void main(String[] args) { + double d = 299999d; + System.out.println(getTwoOfDouble(d)); + } + + /** + * 涓や釜鏁扮浉闄� + * + * @param num1 + * 鏁板瓧1 + * @param num2 + * 鏁板瓧2 + * @return + */ + public static Double divide(int num1, int num2) { + return divide(num1 * 1D, num2 * 1D); + } + + /** + * 涓や釜鏁扮浉闄�- 淇濈暀涓や綅灏忔暟鐐� + * + * @param num1 + * 鏁板瓧1 + * @param num2 + * 鏁板瓧2 + * @return + */ + public static Double divide(String num1, String num2) { + return divide(Double.parseDouble(num1), Double.parseDouble(num1), 2); + } + + /** + * 涓や釜鏁扮浉闄�- 淇濈暀涓や綅灏忔暟鐐� + * + * @param num1 + * 鏁板瓧1 + * @param num2 + * 鏁板瓧2 + * @return + */ + public static Double divide(Double num1, Double num2) { + return divide(num1, num2, 2); + } + + /** + * 涓や釜鏁扮浉闄� + * + * @param num1 + * 鏁板瓧1 + * @param num2 + * 鏁板瓧2 + * @param scale + * 灏忔暟浣嶆暟锛� 榛樿淇濈暀2浣� + * @return + */ + public static Double divide(Double num1, Double num2, Integer scale) { + if (scale == null || scale < 0) { + scale = 2; + } + BigDecimal b1 = new BigDecimal(num1); + BigDecimal b2 = new BigDecimal(num2); + return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * + * 涓や釜鏁扮浉闄� + * + * @param num1 + * 鏁板瓧1 + * @param num2 + * 鏁板瓧2 + * @param scale + * 灏忔暟浣嶆暟锛� 榛樿淇濈暀2浣� + * @return + */ + public static Double divideDown(Double num1, Double num2, Integer scale) { + if (scale == null || scale < 0) { + scale = 2; + } + BigDecimal b1 = new BigDecimal(num1); + BigDecimal b2 = new BigDecimal(num2); + + return b1.divide(b2, scale, BigDecimal.ROUND_DOWN).doubleValue(); + } + + /** + * 涓や釜Double鏁扮浉涔� + * + * @param num1 + * @param num2 + * @return Double + * + */ + public static Double multiply(Double num1, Double num2) { + return multiply(num1.toString(), num2.toString()); + } + + /** + * 涓や釜Double鏁扮浉涔� + * + * @param num1 + * @param num2 + * @return Double + * + */ + public static Double multiply(String num1, String num2) { + BigDecimal b1 = new BigDecimal(num1); + BigDecimal b2 = new BigDecimal(num2); + return b1.multiply(b2).doubleValue(); + } + + /** + * 涓や釜Double鏁扮浉鍑� + * + * @param v1 + * @param v2 + * @return Double + */ + public static Double subtract(Double v1, Double v2) { + return subtract(v2.toString(), v2.toString()); + } + + /** + * 涓や釜Double鏁扮浉鍑� + * + * @param v1 + * @param v2 + * @return Double + */ + public static Double subtract(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.subtract(b2).doubleValue(); + } + + /** + * 涓や釜Double鏁扮浉鍔� + * + * @param v1 + * @param v2 + * @return Double + */ + public static Double add(Double v1, Double v2) { + return add(v1.toString(), v2.toString()); + } + + /** + * 涓や釜Double鏁扮浉鍔� + * + * @param v1 + * @param v2 + * @return Double + */ + public static Double add(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.add(b2).doubleValue(); + } + + /** 浠庡厓杞寲涓哄垎锛屽厓涓�2浣嶅皬鏁� */ + public static int getFenFromYun(String doubleStr) { + return getRoundHalfUp(Double.parseDouble(doubleStr) * 100); + } + + /**鑾峰彇涓や綅灏忔暟鐨勫瓧绗︿覆*/ + public static String getTwoOfDouble(double value) + { + String str = value + ""; + + //濡傛灉鏈夊皬鏁扮偣锛屽垯涓や綅灏忔暟 + int pointIndex = str.indexOf("."); + if(pointIndex != -1) + { + int len = str.length(); + if(len - (pointIndex + 1) > 2) + { + return str.substring(0, pointIndex + 3); + } + } + + return str; + } + +} diff --git a/src/main/java/com/hx/util/OSSUtil.java b/src/main/java/com/hx/util/OSSUtil.java new file mode 100644 index 0000000..64228ec --- /dev/null +++ b/src/main/java/com/hx/util/OSSUtil.java @@ -0,0 +1,126 @@ +package com.hx.util; + +import com.aliyun.oss.OSSClient; +import com.aliyun.oss.model.OSSObject; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +public class OSSUtil { + + private static OSSClient ossClient; + + public static OSSClient getOSSClient(String keyId, String keySecret, String endPoint) + { + if(ossClient == null) + { + ossClient = new OSSClient(endPoint, keyId, keySecret); + } + + return ossClient; + } + + /** 鍚庣璋冪敤涓婁紶鍥剧墖 */ + public static String uploadImg(String fileName, File imgFile, String keyId, String keySecret, String endPoint, String bucket) throws IOException { + + // // 鍘嬬缉鍒版枃浠跺す + // Thumbnails.of(imgFile).scale(1f).outputQuality(0.8f).toFile(SimpleToof.getRealpath("/upload/image/") + // + imgName); + // File file = new File(SimpleToof.getRealpath("/upload/image/") + imgName); + + // 鍒涘缓OSSClient瀹炰緥銆� + OSSClient ossClient = new OSSClient("https://" + endPoint, keyId, keySecret); + // 涓婁紶鏂囦欢銆�<yourLocalFile>鐢辨湰鍦版枃浠惰矾寰勫姞鏂囦欢鍚嶅寘鎷悗缂�缁勬垚锛屼緥濡�/users/local/myfile.txt銆� + // 鍒ゆ柇鍘嬬缉鍚庣殑澶у皬 + // if (file.length() > imgFile.length()) { + ossClient.putObject(bucket, fileName, imgFile); + // } else { + // ossClient.putObject(BUCKET, fileName, file); + // } + // 鍏抽棴OSSClient銆� + ossClient.shutdown(); + + return "https://" + bucket + "." + endPoint + "/" + fileName; + } + + /** 鍚庣璋冪敤涓婁紶鍥剧墖 */ + public static String uploadImg(String fileName, MultipartFile imgFile, String keyId, String keySecret, String endPoint, String bucket) { + + try { + // 鍒涘缓OSSClient瀹炰緥銆� + OSSClient ossClient = new OSSClient("https://" + endPoint, keyId, keySecret); + ossClient.putObject(bucket, fileName, imgFile.getInputStream()); + ossClient.shutdown(); + + return "https://" + bucket + "." + endPoint + "/" + fileName; + }catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + /** 鍚庣璋冪敤涓婁紶鍥剧墖 */ + public static String uploadImg(String fileName, InputStream is, String keyId, String keySecret, String endPoint, String bucket) { + + try { + // 鍒涘缓OSSClient瀹炰緥銆� + OSSClient ossClient = new OSSClient("https://" + endPoint, keyId, keySecret); + ossClient.putObject(bucket, fileName, is); + ossClient.shutdown(); + + return "https://" + bucket + "." + endPoint + "/" + fileName; + }catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public static byte[] getObject(String key, String keyId, String keySecret, String endPoint, String bucket) { + + byte[] resultByte = null; + InputStream is = null; + ByteArrayOutputStream swapStream = null; + try { + OSSObject ossObject = getOSSClient(keyId, keySecret, endPoint).getObject(bucket, key); + is = ossObject.getObjectContent(); + swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[1024]; //buff鐢ㄤ簬瀛樻斁寰幆璇诲彇鐨勪复鏃舵暟鎹� + int rc = 0; + while ((rc = is.read(buff, 0, 1024)) > 0) { + swapStream.write(buff, 0, rc); + } + + resultByte = swapStream.toByteArray(); //in_b涓鸿浆鎹箣鍚庣殑缁撴灉 + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if(is != null) + { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + is = null; + } + + if(swapStream != null) + { + try { + swapStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + swapStream = null; + } + } + + return resultByte; + } +} diff --git a/src/main/java/com/hx/util/QRCodeUtil.java b/src/main/java/com/hx/util/QRCodeUtil.java new file mode 100644 index 0000000..4ed2f62 --- /dev/null +++ b/src/main/java/com/hx/util/QRCodeUtil.java @@ -0,0 +1,238 @@ +package com.hx.util; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.List; + +import javax.imageio.ImageIO; + +import com.google.zxing.*; + +import com.google.zxing.client.j2se.BufferedImageLuminanceSource; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +public class QRCodeUtil { + + // 浜岀淮鐮侀鑹�==榛戣壊 + private static final int BLACK = 0xFF000000; + // 浜岀淮鐮侀鑹�==鐧借壊 + private static final int WHITE = 0xFFFFFFFF; + // 浜岀淮鐮佸浘鐗囨牸寮�==jpg鍜宲ng涓ょ + private static final List<String> IMAGE_TYPE = new ArrayList<>(); + + static { + IMAGE_TYPE.add("jpg"); + IMAGE_TYPE.add("png"); + } + + /** + * zxing鏂瑰紡鐢熸垚浜岀淮鐮� + * 娉ㄦ剰锛� + * 1,鏂囨湰鐢熸垚浜岀淮鐮佺殑鏂规硶鐙珛鍑烘潵,杩斿洖image娴佺殑褰㈠紡,鍙互杈撳嚭鍒伴〉闈� + * 2,璁剧疆瀹归敊鐜囦负鏈�楂�,涓�鑸閿欑巼瓒婇珮,鍥剧墖瓒婁笉娓呮櫚, 浣嗘槸鍙湁灏嗗閿欑巼璁剧疆楂樹竴鐐规墠鑳藉吋瀹筶ogo鍥剧墖 + * 3,logo鍥剧墖榛樿鍗犱簩缁寸爜鍥剧墖鐨�20%,璁剧疆澶ぇ浼氬鑷存棤娉曡В鏋� + * + * @param content 浜岀淮鐮佸寘鍚殑鍐呭锛屾枃鏈垨缃戝潃 + * @param path 鐢熸垚鐨勪簩缁寸爜鍥剧墖瀛樻斁浣嶇疆 + * @param size 鐢熸垚鐨勪簩缁寸爜鍥剧墖灏哄 鍙互鑷畾涔夋垨鑰呴粯璁わ紙250锛� + * @param logoPath logo鐨勫瓨鏀句綅缃� + * @param autoDateFolder 鍦ㄥ瓨鏀鹃摼鎺ヤ笂鐢熸垚鏃ユ湡鏂囦欢澶癸紝鏍煎紡鏄痽yyyMM + */ + public static String QRCodeCreate(String content, String path, Integer size, String logoPath,Boolean autoDateFolder) { + try { + Date newDate = new Date(); + if(autoDateFolder){ + if(autoDateFolder){ + if(path.endsWith("/")){ + path = path+dateFormat(newDate,"yyyyMM")+"/"; + }else{ + path = path+"/"+dateFormat(newDate,"yyyyMM")+"/"; + } + } + } + + path = path+newDate.getTime()+".jpg"; + + //鍥剧墖绫诲瀷 + String imageType = "jpg"; + //鑾峰彇浜岀淮鐮佹祦鐨勫舰寮忥紝鍐欏叆鍒扮洰褰曟枃浠朵腑 + BufferedImage image = getBufferedImage(content, size, logoPath); + //鑾峰緱闅忔満鏁� + Random random = new Random(); + //鐢熸垚浜岀淮鐮佸瓨鏀炬枃浠� + File file = new File(path); + if (!file.exists()) { + file.mkdirs(); + } + ImageIO.write(image, imageType, file); + } catch (IOException e) { + e.printStackTrace(); + } + return path; + } + + /** + * 浜岀淮鐮佹祦鐨勫舰寮忥紝鍖呭惈鏂囨湰鍐呭 + * + * @param content 浜岀淮鐮佹枃鏈唴瀹� + * @param size 浜岀淮鐮佸昂瀵� + * @param logoPath logo鐨勫瓨鏀句綅缃� + * @return + */ + public static BufferedImage getBufferedImage(String content, Integer size, String logoPath) { + if (size == null || size <= 0) { + size = 250; + } + BufferedImage image = null; + try { + // 璁剧疆缂栫爜瀛楃闆� + Map<EncodeHintType, Object> hints = new HashMap<>(); + //璁剧疆缂栫爜 + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + //璁剧疆瀹归敊鐜囨渶楂� + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + hints.put(EncodeHintType.MARGIN, 1); + // 1銆佺敓鎴愪簩缁寸爜 + MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); + BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, size, size, hints); + // 2銆佽幏鍙栦簩缁寸爜瀹介珮 + int codeWidth = bitMatrix.getWidth(); + int codeHeight = bitMatrix.getHeight(); + // 3銆佸皢浜岀淮鐮佹斁鍏ョ紦鍐叉祦 + image = new BufferedImage(codeWidth, codeHeight, BufferedImage.TYPE_INT_RGB); + for (int i = 0; i < codeWidth; i++) { + for (int j = 0; j < codeHeight; j++) { + // 4銆佸惊鐜皢浜岀淮鐮佸唴瀹瑰畾鍏ュ浘鐗� + image.setRGB(i, j, bitMatrix.get(i, j) ? BLACK : WHITE); + } + } + //鍒ゆ柇鏄惁鍐欏叆logo鍥剧墖 + if (logoPath != null && !"".equals(logoPath)) { + File logoPic = new File(logoPath); + if (logoPic.exists()) { + Graphics2D g = image.createGraphics(); + BufferedImage logo = ImageIO.read(logoPic); + int widthLogo = logo.getWidth(null) > image.getWidth() * 2 / 10 ? (image.getWidth() * 2 / 10) : logo.getWidth(null); + int heightLogo = logo.getHeight(null) > image.getHeight() * 2 / 10 ? (image.getHeight() * 2 / 10) : logo.getHeight(null); + int x = (image.getWidth() - widthLogo) / 2; + int y = (image.getHeight() - heightLogo) / 2; + // 寮�濮嬬粯鍒跺浘鐗� + g.drawImage(logo, x, y, widthLogo, heightLogo, null); + g.drawRoundRect(x, y, widthLogo, heightLogo, 15, 15); + //杈规瀹藉害 + g.setStroke(new BasicStroke(2)); + //杈规棰滆壊 + g.setColor(Color.WHITE); + g.drawRect(x, y, widthLogo, heightLogo); + g.dispose(); + logo.flush(); + image.flush(); + } + } + } catch (WriterException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return image; + } + + /** + * 缁欎簩缁寸爜鍥剧墖娣诲姞Logo + * + * @param qrPic 浜岀淮鐮佸浘鐗� + * @param logoPic logo鍥剧墖 + * @param path 鍚堟垚鍚庣殑鍥剧墖瀛樺偍鐩綍 + */ + public static boolean zxingCodeCreate(File qrPic, File logoPic, String path) { + try { + String imageType = path.substring(path.lastIndexOf(".") + 1).toLowerCase(); + if (!IMAGE_TYPE.contains(imageType)) { + return false; + } + + if (!qrPic.isFile() && !logoPic.isFile()) { + return false; + } + + //璇诲彇浜岀淮鐮佸浘鐗囷紝骞舵瀯寤虹粯鍥惧璞� + BufferedImage image = ImageIO.read(qrPic); + Graphics2D g = image.createGraphics(); + //璇诲彇Logo鍥剧墖 + BufferedImage logo = ImageIO.read(logoPic); + //璁剧疆logo鐨勫ぇ灏�,鏈�澶�20%0 + int widthLogo = logo.getWidth(null) > image.getWidth() * 2 / 10 ? (image.getWidth() * 2 / 10) : logo.getWidth(null); + int heightLogo = logo.getHeight(null) > image.getHeight() * 2 / 10 ? (image.getHeight() * 2 / 10) : logo.getHeight(null); + // 璁$畻鍥剧墖鏀剧疆浣嶇疆锛岄粯璁ゅ湪涓棿 + int x = (image.getWidth() - widthLogo) / 2; + int y = (image.getHeight() - heightLogo) / 2; + // 寮�濮嬬粯鍒跺浘鐗� + g.drawImage(logo, x, y, widthLogo, heightLogo, null); + g.drawRoundRect(x, y, widthLogo, heightLogo, 15, 15); + //杈规瀹藉害 + g.setStroke(new BasicStroke(2)); + //杈规棰滆壊 + g.setColor(Color.WHITE); + g.drawRect(x, y, widthLogo, heightLogo); + g.dispose(); + logo.flush(); + image.flush(); + File newFile = new File(path); + if (!newFile.exists()) { + newFile.mkdirs(); + } + ImageIO.write(image, imageType, newFile); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + /** + * 浜岀淮鐮佺殑瑙f瀽鏂规硶 + * + * @param path 浜岀淮鐮佸浘鐗囩洰褰� + * @return + */ + public static Result zxingCodeAnalyze(String path) { + try { + MultiFormatReader formatReader = new MultiFormatReader(); + File file = new File(path); + if (file.exists()) { + BufferedImage image = ImageIO.read(file); + LuminanceSource source = new BufferedImageLuminanceSource(image); + Binarizer binarizer = new HybridBinarizer(source); + BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer); + Map hints = new HashMap(); + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + Result result = formatReader.decode(binaryBitmap, hints); + return result; + } + } catch (IOException e) { + e.printStackTrace(); + } catch (NotFoundException e) { + e.printStackTrace(); + } + return null; + } + + /** + * + * @param date 鏃堕棿 + * @param format 鏃堕棿鏍煎紡 + * @return 杩斿洖鐨勬椂闂存牸寮忓瓧绗︿覆 + */ + public static String dateFormat(Date date,String format) { + SimpleDateFormat df = new SimpleDateFormat(format);//璁剧疆鏃ユ湡鏍煎紡 + return df.format(date); + } + +} diff --git a/src/main/java/com/hx/util/RegValidatorUtil.java b/src/main/java/com/hx/util/RegValidatorUtil.java new file mode 100644 index 0000000..4c89a09 --- /dev/null +++ b/src/main/java/com/hx/util/RegValidatorUtil.java @@ -0,0 +1,254 @@ +package com.hx.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 姝e垯琛ㄨ揪寮忛獙璇佸伐锟�? + * @author mgchen + * + */ +public class RegValidatorUtil { + + /** + * 楠岃瘉閭 + * + * @param str 寰呴獙璇佺殑瀛楃 + * @return 濡傛灉鏄鍚堢殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean isEmail(String str) { + String regex = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; + return match(regex, str); + } + + /** + * 楠岃瘉IP鍦板潃 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean isIP(String str) { + String num = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)"; + String regex = "^" + num + "\\." + num + "\\." + num + "\\." + num + "$"; + return match(regex, str); + } + + /** + * 楠岃瘉缃戝潃Url + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsUrl(String str) { + String regex = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"; + return match(regex, str); + } + + /** + * 楠岃瘉鐢佃瘽鍙风爜 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsTelephone(String str) { + String regex = "^(\\d{3,4}-)?\\d{6,8}$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆瀵嗙爜鏉′欢(瀛楃涓庢暟鎹悓鏃跺嚭锟�?) + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsPassword(String str) { + String regex = "[A-Za-z0-9]+"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆瀵嗙爜闀垮害 (6-18锟�?) + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsPasswLength(String str) { + String regex = "^\\d{6,18}$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆閭斂缂栧彿 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsPostalcode(String str) { + String regex = "^\\d{6}$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆鎵嬫満鍙风爜 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsHandset(String str) { + String regex = "^[1]+[3,5]+\\d{9}$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆韬唤璇佸彿 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsIDcard(String str) { + String regex = "(^\\d{18}$)|(^\\d{15}$)"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆涓や綅灏忔暟 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsDecimal(String str) { + String regex = "^[0-9]+(.[0-9]{2})?$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆锟�?骞寸殑12涓湀 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsMonth(String str) { + String regex = "^(0?[[1-9]|1[0-2])$"; + return match(regex, str); + } + + /** + * 楠岃瘉杈撳叆锟�?涓湀锟�?31锟�? + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsDay(String str) { + String regex = "^((0?[1-9])|((1|2)[0-9])|30|31)$"; + return match(regex, str); + } + + /** + * 楠岃瘉鏃ユ湡鏃堕棿 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堢綉锟�?鏍煎紡鐨勫瓧绗︿覆,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean isDate(String str) { + // 涓ユ牸楠岃瘉鏃堕棿鏍煎紡锟�?(鍖归厤[2002-01-31], [1997-04-30], + // [2004-01-01])涓嶅尮锟�?([2002-01-32], [2003-02-29], [04-01-01]) + // String regex = + // "^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((01,3-9])|(1[0-2]))-(29|30)))))$"; + // 娌″姞鏃堕棿楠岃瘉鐨刌YYY-MM-DD + // String regex = + // "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$"; + // 鍔犱簡鏃堕棿楠岃瘉鐨刌YYY-MM-DD 00:00:00 + String regex = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d$"; + return match(regex, str); + } + + /** + * 楠岃瘉鏁板瓧杈撳叆 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsNumber(String str) { + String regex = "^[0-9]*$"; + return match(regex, str); + } + + /** + * 楠岃瘉闈為浂鐨勬鏁存暟 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsIntNumber(String str) { + String regex = "^[1-9][0-9]*$"; + return match(regex, str); + } + + /** + * 楠岃瘉澶у啓瀛楁瘝 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsUpChar(String str) { + String regex = "^[A-Z]+$"; + return match(regex, str); + } + + /** + * 楠岃瘉灏忓啓瀛楁瘝 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsLowChar(String str) { + String regex = "^[a-z]+$"; + return match(regex, str); + } + + /** + * 楠岃瘉楠岃瘉杈撳叆瀛楁瘝 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsLetter(String str) { + String regex = "^[A-Za-z]+$"; + return match(regex, str); + } + + /** + * 楠岃瘉楠岃瘉杈撳叆姹夊瓧 + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsChinese(String str) { + String regex = "^[\u4e00-\u9fa5],{0,}$"; + return match(regex, str); + } + + /** + * 楠岃瘉楠岃瘉杈撳叆瀛楃锟�? + * + * @param str 寰呴獙璇佺殑瀛楃锟�? + * @return 濡傛灉鏄鍚堟牸寮忕殑瀛楃锟�?,杩斿洖 <b>true </b>,鍚﹀垯锟�? <b>false </b> + */ + public static boolean IsLength(String str) { + String regex = "^.{8,}$"; + return match(regex, str); + } + + /** + * @param regex + * 姝e垯琛ㄨ揪寮忓瓧绗︿覆 + * @param str + * 瑕佸尮閰嶇殑瀛楃锟�? + * @return 濡傛灉str 绗﹀悎 regex鐨勬鍒欒〃杈惧紡鏍煎紡,杩斿洖true, 鍚﹀垯杩斿洖 false; + */ + private static boolean match(String regex, String str) { + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(str); + return matcher.matches(); + } +} diff --git a/src/main/java/com/hx/util/RequestMethod.java b/src/main/java/com/hx/util/RequestMethod.java new file mode 100644 index 0000000..9c0b36b --- /dev/null +++ b/src/main/java/com/hx/util/RequestMethod.java @@ -0,0 +1,152 @@ +package com.hx.util; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class RequestMethod { + + /** + * 鍙戦�丳ost璇锋眰 + * @param path 璇锋眰璺緞 + * @param params 璇锋眰鍙傛暟 + * @param encoding 缂栫爜 + * @return 鏈嶅姟鍣ㄧ鍐呭 + */ + public static String sendPOSTRequest(String path, Map<String, String> params, String encoding) throws Exception{ + StringBuilder data = new StringBuilder(); + if(params!=null && !params.isEmpty()){ + for(Map.Entry<String, String> entry : params.entrySet()){ + data.append(entry.getKey()).append("="); + data.append(URLEncoder.encode(entry.getValue(), encoding)); + data.append("&"); + } + data.deleteCharAt(data.length() - 1); + } + byte[] entity = data.toString().getBytes();//鐢熸垚瀹炰綋鏁版嵁 + HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection(); + conn.setConnectTimeout(5000); + conn.setRequestMethod("POST"); + conn.setDoOutput(true);//鍏佽瀵瑰杈撳嚭鏁版嵁 + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); + OutputStream outStream = conn.getOutputStream(); + outStream.write(entity); + if(conn.getResponseCode() == 200){ + return StreamUtils.InputStreamTOString(conn.getInputStream()) ; + } + return null; + } + + /** + * 鍙戦�丳ost璇锋眰 + * @param path 璇锋眰璺緞 + * @param content 鍙戦�佸唴瀹� + * @param encoding 缂栫爜 + * @return 鏈嶅姟鍣ㄧ鍐呭 + */ + public static String sendPOSTRequest(String path, String content, String encoding){ + //byte[] entity = content.toString().getBytes();//鐢熸垚瀹炰綋鏁版嵁 + try{ + HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection(); + conn.setConnectTimeout(5000); + conn.setRequestMethod("POST"); + conn.setDoOutput(true);//鍏佽瀵瑰杈撳嚭鏁版嵁 + conn.setDoInput(true); + conn.setUseCaches(false); + conn.setRequestProperty("Charset", "utf-8"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + //conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); + OutputStreamWriter outStream = new OutputStreamWriter(conn.getOutputStream(),"UTF-8"); + outStream.write(content); + outStream.flush(); + if(conn.getResponseCode() == 200){ + return StreamUtils.InputStreamTOString(conn.getInputStream()); + } + }catch(Exception e){ + e.printStackTrace(); + } + return null; + } + + /** + * 鍙戦�丳ost璇锋眰 + * @param path 璇锋眰璺緞 + * @param entity 鍙戦�佸唴瀹� + * @param encoding 缂栫爜 + * @return 鏈嶅姟鍣ㄧ鍐呭 + */ + public static String sendPOSTRequest(String path, byte[] entity, String encoding) throws Exception{ + System.out.println("entity:" + entity.length); + HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection(); + conn.setConnectTimeout(5000); + conn.setRequestMethod("POST"); + conn.setDoOutput(true);//鍏佽瀵瑰杈撳嚭鏁版嵁 + conn.setRequestProperty("Content-Type", "application/octet-stream"); + conn.setRequestProperty("Accept", "application/octet-stream"); + conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); + OutputStream outStream = conn.getOutputStream(); + outStream.write(entity); + if(conn.getResponseCode() == 200){ + return StreamUtils.InputStreamTOString(conn.getInputStream()); + } + return null; + } + + /** + * 鍙戦�丟ET璇锋眰 + * @param path 璇锋眰璺緞 + * @param params 璇锋眰鍙傛暟 + * @return 鏈嶅姟鍣ㄧ鍐呭 + */ + public static String sendGETRequest(String path, Map<String, String> params, String ecoding) throws Exception{ + // http://192.168.1.100:8080/web/ManageServlet?title=xxx&timelength=90 + StringBuilder url = new StringBuilder(path); + if(params!=null){ + url.append("?"); + for(Map.Entry<String, String> entry : params.entrySet()){ + url.append(entry.getKey()).append("="); + url.append(URLEncoder.encode(entry.getValue(), ecoding)); + url.append("&"); + } + url.deleteCharAt(url.length() - 1); + } + HttpURLConnection conn = (HttpURLConnection)new URL(url.toString()).openConnection(); + conn.setConnectTimeout(5000); + conn.setRequestMethod("GET"); + if(conn.getResponseCode() == 200){ + return StreamUtils.InputStreamTOString(conn.getInputStream()) ; + } + return null; + } + + + + public static String msg(InputStream in) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + String line; + List<String> lines = new ArrayList<String>(); + while((line = br.readLine())!=null){ + lines.add(line); + } + if(lines.size()>0){ + String f = lines.get(0); + if(f.indexOf("200")!=-1){ + String e = lines.get(lines.size()-1); + return e; + }else{ + return null; + } + }else{ + return null; + } + } +} diff --git a/src/main/java/com/hx/util/SerializeUtil.java b/src/main/java/com/hx/util/SerializeUtil.java new file mode 100644 index 0000000..07bbb47 --- /dev/null +++ b/src/main/java/com/hx/util/SerializeUtil.java @@ -0,0 +1,72 @@ +package com.hx.util; + +import org.springframework.stereotype.Component; + +import java.io.*; +import java.net.URLDecoder; +import java.net.URLEncoder; + +/** + * @PackageName com.hx.util + * @ProjectName hx-parent + * @Author: ChenJiaHe + * @Date: Create in 16:52 2019/7/22 + * @Description: + * @Copyright Copyright (c) 2019, hx01@163.com All Rights Reserved. + */ +@Component +public class SerializeUtil<E> { + + public String serialize(E object) { + ObjectOutputStream oos = null; + ByteArrayOutputStream baos = null; + try { + baos = new ByteArrayOutputStream(); + oos = new ObjectOutputStream(baos); + oos.writeObject(object); + + String str = baos.toString("ISO-8859-1"); + return URLEncoder.encode(str, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + baos.close(); + oos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + @SuppressWarnings("unchecked") + public E unserialize(String serializeStr) { + String readStr = ""; + if (serializeStr == null || "".equals(serializeStr)) { + return null; + } + try { + readStr = URLDecoder.decode(serializeStr, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + ObjectInputStream ois = null; + InputStream bais = null; + try { + bais = new ByteArrayInputStream(readStr.getBytes("ISO-8859-1")); + ois = new ObjectInputStream(bais); + return (E) ois.readObject(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + ois.close(); + bais.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/src/main/java/com/hx/util/SimpleEncrypt.java b/src/main/java/com/hx/util/SimpleEncrypt.java new file mode 100644 index 0000000..69909b0 --- /dev/null +++ b/src/main/java/com/hx/util/SimpleEncrypt.java @@ -0,0 +1,104 @@ +package com.hx.util; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +/*** + * 锟�?鍗曠殑鍔犲瘑绋嬪簭锛屽拰瑙e瘑绋嬪簭 + * + * @author mq.c + * + */ +public class SimpleEncrypt { + + /** + * 鑾峰彇鎸囧畾闀垮害闅忔満鐨勫瓧绗︿覆 + * + * @param getNum + * @return + */ + private static String generateCheckCode(Integer getNum) { + // abcdefghijklmnopqrstuvwxyz + // String chars = + // "123456789.AB2CD3EF7G;HI5JK5LMN/OPQR8ST.UVW7X9YZ?~!@#$%^&*()_+{}:>?<|/.,';][=-"; + // String chars = + // "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&*()_+{}|:<>?/.,';][\\=-"; + String chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz._?"; + String[] charsx = chars.split(""); + // String[] charsx = chars.split(""); + List<String> list = Arrays.asList(charsx); + Collections.shuffle(list); + StringBuffer buff = new StringBuffer(); + Random random = new Random(); + for (int i = 0; i < getNum; i++) { + int rand = random.nextInt(list.size()); + // buff.append(chars.charAt(rand)); + buff.append(list.get(rand)); + } + return buff.toString(); + } + + /** + * 瀵瑰瓧绗︿覆杩涜绠�鏄撳姞瀵�(涓嶈鍦ㄦ剰閭g寰堝鏄撹浜虹牬瑙g殑灏忕粏鑺�) + * 璇ュ姞瀵嗛噰鐢�"鍓嶉潰13浣嶉殢鏈虹爜"+dataString+"鍚�9浣嶉殢鏈虹爜"锛岀粍鎷兼垚涓�涓瓧绗︿覆锛岃繘琛孊ASE64鍔犲瘑寰楀嚭鐨勫姞瀵嗗�� + * + * @param dataString + * 瑕佽繘琛屽姞瀵嗙殑鏁版嵁婧� + * @return + */ + public static String simpleEnCode(String dataString) { + // 缁勬嫾闅忔満鍊� + String ranString = generateCheckCode(13).toString() + dataString + generateCheckCode(9).toString(); + + System.out.println(ranString); + // 杩涜鍔犲瘑 sun.misc.BASE64Encoder.BASE64Encoder() + String enCode = new BASE64Encoder().encodeBuffer(ranString.getBytes()); + + return enCode; + } + + /*** + * 瀵圭敤com.bang.units.SimpleEncrypt.simpleEnCode鍔犲瘑杩囩殑瀛楃涓茶繘琛岃В瀵� + * + * 璇ュ姞瀵嗛噰鐢�"鍓嶉潰13浣嶉殢鏈虹爜"+dataString+"鍚�9浣嶉殢鏈虹爜"锛岀粍鎷兼垚涓�涓瓧绗︿覆锛岃繘琛孊ASE64鍔犲瘑寰楀嚭鐨勫姞瀵嗗�� + * + * @param dataString + * 瑕佽繘琛岃В瀵嗙殑鏁版嵁婧� + * @return + */ + public static String simpleDeCode(String dataString) throws Exception { + // 杩涜瑙e瘑sun.misc.BASE64Decoder.BASE64Decoder() + byte[] enCode = new BASE64Decoder().decodeBuffer(dataString); + // 瑙e緱闅忔満鍊� + String ranString = new String(enCode); + + // System.out.println("simpleDeCode:" + ranString); + // 鎴彇鍑烘湁鏁堜綅缃弬鏁� + String daString = ranString.substring(13, ranString.length() - 9); + + return daString; + } + + public static void main(String[] args) throws Exception { + String chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ?~!@#$%^&*()_+{}:>?<|/.,';][=-`"; + String[] charsx = chars.split(""); + List<String> list = Arrays.asList(charsx); + Collections.shuffle(list); + // for (String string : list) { + // System.out.println(string); + // } + + String str = "15648sadf"; + String eStr = simpleEnCode(str); + System.out.println(eStr); + String dStr = simpleDeCode(eStr); + System.out.println(dStr); + + } + +} diff --git a/src/main/java/com/hx/util/SimpleTool.java b/src/main/java/com/hx/util/SimpleTool.java new file mode 100644 index 0000000..2428dab --- /dev/null +++ b/src/main/java/com/hx/util/SimpleTool.java @@ -0,0 +1,1053 @@ +package com.hx.util; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.FileNameMap; +import java.net.HttpURLConnection; +import java.net.InetAddress; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLDecoder; +import java.net.UnknownHostException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFDataFormatter; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; + +public class SimpleTool { + + public static SimpleDateFormat myformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static DecimalFormat fmt = new DecimalFormat("0.00"); + public static Byte[] lock = new Byte[] {0}; + + /** + * 鍚庡彴鏍煎紡鏋勫缓杩斿洖鍊兼牸寮忓垪琛�-鍚庡彴鑾峰彇鍒楄〃 + * @param count 杩斿洖鎬绘潯鏁� + * @return JSONObject 鐗瑰畾鏍煎紡鐨凧SONObject + */ + public static JSONObject resAdminLsit(Integer status,String errMsg,JSONArray arr,Integer count){ + + JSONObject fObj = new JSONObject(); + try{ + fObj.put("code", status); + fObj.put("count", count); + fObj.put("msg", errMsg); + fObj.put("data", arr); + }catch (Exception e) { + e.printStackTrace(); + } + return fObj; + } + + /** + * 鑾峰彇鎸囧畾鏍煎紡鐨凞ouble 绫诲瀷鏁版嵁 + * + * @param type + * 杞崲鏍煎紡鐨勭被鍨� 榛樿涓� "#.#" + * @param e + * 瑕佽浆鎹㈢殑鏁版嵁婧� + **/ + public static Double getTypeDouble(String type, Double e) { + if (!checkNotNull(type)) + type = "0.00"; + fmt = new DecimalFormat(type); + fmt.setRoundingMode(RoundingMode.HALF_UP); // 淇濈暀灏忔暟鐐瑰悗涓や綅骞跺洓鑸嶄簲鍏ワ紝纭繚浠烽挶鍑嗙‘ + Double d = Double.valueOf(fmt.format(e)); + return d; + } + + /** + * 棣栧瓧姣嶅ぇ鍐� + * + * @param str + */ + public static String capitalized(String str) { + if ("".equals(str.trim()) || str == null) { + return ""; + } + String key = str.substring(0, 1).toUpperCase(); + String keys = key + str.substring(1, str.length()); + return keys; + } + + /** 鍒ゆ柇鍙傛暟鏄惁涓簄ull锛屽鏋渘ull鎶涘嚭瀵瑰簲寮傚父 */ + public static void checkErrMsg(Object obj, String errMsg) { + if (!checkNotNull(obj)) + throw new RuntimeException(errMsg); + } + + /*** 鍒涘缓鏂囦欢锛堣嚜鍔ㄧ敓鎴愭枃浠跺す銆傦級(闇�瑕佺湡瀹炶矾寰�) **/ + public static File createFile(String mkdirPath, String fileName) throws IOException { + System.out.println(mkdirPath + fileName); + // mkdirPath = + // "E:\\work\\soft\\MyEclipse\\apache-tomcat-7.0.61\\webapps\\ROOT\\"; + + File f = new File(mkdirPath); + if (!f.exists()) { + f.mkdirs(); + } + File file = new File(f, fileName); + if (!file.exists()) { + file.createNewFile(); + } + + // System.out.println(file.getAbsolutePath()); + return file; + } + + /** + * 鏋勫缓杩斿洖鍊兼牸寮� + * + * @param status + * 杩斿洖鐘舵�� + * @param errMsg + * 杩斿洖闄勫甫淇℃伅 + * @param inf + * 杩斿洖瀹炰綋鍊� + * @return JSONObject 鐗瑰畾鏍煎紡鐨凧SONObject + */ + public static JSONObject res(Integer status, String errMsg, JSONObject inf) { + JSONObject res = new JSONObject(); + JSONObject fObj = new JSONObject(); + try { + res.put("status", status); + res.put("errMsg", errMsg); + + fObj.put("res", res); + fObj.put("inf", inf); + } catch (Exception e) { + e.printStackTrace(); + } + return fObj; + } + + /** + * Date绫诲瀷杞崲涓�10浣嶆椂闂存埑 + * + * @param time + * @return + */ + public static Integer DateToTimestamp(Date time) { + Timestamp ts = new Timestamp(time.getTime()); + return (int) ((ts.getTime()) / 1000); + } + + /** 鍒ゆ柇褰撳墠鏃堕棿鏄粈涔堟椂鍊� **/ + public static Boolean IsTime(Date date, Integer year, Integer month, Integer day, Integer hour, Integer minute) { + Calendar cal = new GregorianCalendar(); + cal.setTime(date); + if (year != null) { + int iyear = cal.get(Calendar.YEAR); + if (iyear != year) + return false; + } + + if (month != null) { + int imonth = cal.get(Calendar.MONTH);// 鑾峰彇鏈堜唤(鏈堜唤浠�0寮�濮嬭绠楃殑) + imonth = imonth + 1; + if (imonth != month) + return false; + } + + if (day != null) { + int iday = cal.get(Calendar.DATE);// 鑾峰彇鏃� + if (iday != day) + return false; + } + + if (hour != null) { + int ihour = cal.get(Calendar.HOUR_OF_DAY);// 24灏忔椂 0- 23 + if (ihour != hour) + return false; + } + + if (minute != null) { + int iminute = cal.get(Calendar.MINUTE); + if (iminute != minute) + return false; + } + // Boolean b = yearTag && monthTag && dayTag && hourTag && minuteTag; + return true; + } + + /** + * 鏍规嵁鍏蜂綋鏃堕棿灞炴�у垽鏂槸鍚︾浉鍚� + * + */ + public static Boolean DateEquals(Date date1, Date date2, Boolean year, Boolean month, Boolean day, Boolean hour, + Boolean minute) { + + Calendar calendar1 = new GregorianCalendar(); + Calendar calendar2 = new GregorianCalendar(); + calendar1.setTime(date1); + calendar2.setTime(date2); + + if (year) { + if (calendar1.get(Calendar.YEAR) != calendar2.get(Calendar.YEAR)) { + return false; + } + } + if (month) { + if (calendar1.get(Calendar.MONTH) != calendar2.get(Calendar.MONTH)) { + return false; + } + } + if (day) { + if (calendar1.get(Calendar.DATE) != calendar2.get(Calendar.DATE)) { + return false; + } + } + if (year) { + if (calendar1.get(Calendar.HOUR_OF_DAY) != calendar2.get(Calendar.HOUR_OF_DAY)) { + return false; + } + } + if (year) { + if (calendar1.get(Calendar.MINUTE) != calendar2.get(Calendar.MINUTE)) { + return false; + } + } + + // Boolean b = yearTag && monthTag && dayTag && hourTag && minuteTag; + + return true; + } + + /** 鑾峰彇10浣嶆暟鏃堕棿鎴� */ + public static Integer getTenTime(Date date) { + Timestamp ts = new Timestamp(date.getTime()); + return (int) ((ts.getTime()) / 1000); + } + + /** + * 鑾峰彇鎸囧畾鏃ユ湡鐨勬槑澶� difDay 鎶婃棩鏈熷線鍚庡鍔犱竴澶�.鏁存暟寰�鍚庢帹,璐熸暟寰�鍓嶇Щ鍔� + * + * @return date + */ + @SuppressWarnings("static-access") + public static Date getDetailDay(Date today, int difDay) { + Calendar calendar = new GregorianCalendar(); + calendar.setTime(today); + calendar.add(calendar.DATE, difDay);// 鎶婃棩鏈熷線鍚庡鍔犱竴澶�.鏁存暟寰�鍚庢帹,璐熸暟寰�鍓嶇Щ鍔� + Date d = calendar.getTime(); + return d; + } + + /** + * 鑾峰彇鎯宠鐨勬牸寮忕殑鏃堕棿 + * + * @return String + */ + public static String getTypeDate(String type, Date date) { + if (date == null) + return null; + + if (SimpleTool.checkNotNull(type)) { + myformat = new SimpleDateFormat(type); + String returnDate = myformat.format(date); + myformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return returnDate; + } else { + String returnDate = myformat.format(date); + return returnDate; + } + + } + + /** + * 姣旇緝涓や釜鏃堕棿澶╂暟宸� startTime - endTime + * + * @param type + * (鏃犳晥) + * @return String + * @throws ParseException + */ + public static int getDiffDate(String type, Date startTime, Date endTime) throws ParseException { + type = "yyyyMMdd"; + SimpleDateFormat myformat = new SimpleDateFormat(type); + int i = 0; + i = (int) ((myformat.parse(myformat.format(startTime)).getTime() + - myformat.parse(myformat.format(endTime)).getTime()) / (1000 * 60 * 60 * 24)); + // return + // myformat.parse(myformat.format(date1)).compareTo(myformat.parse(myformat.format(date2))); + return i; + } + + /** + * 寰楀埌涓や釜鏃堕棿鐨勫垎閽熷樊 date1 - date2 杩欎釜鏄釜濂囪懇銆備絾鏄暣鍨嬩簡銆� + * + * @return int + * @throws ParseException + */ + public static int getLeftDateForMinue(Date date1, Date date2) throws ParseException { + long times = date1.getTime() - date2.getTime(); + times = times / (1000 * 60); + return (int) times; + } + + /**鎶婂瓧绗︿覆杞负鐗瑰畾鏃堕棿鏍煎紡 + * + * @param type 鏃堕棿鏍煎紡 + * @param sDate 瀛楃涓叉椂闂达紙鍙互涓虹┖锛� + * @return date + * @throws ParseException + */ + public static Date parseStringForDate(String type, String sDate){ + Date date = null; + try { + if(SimpleTool.checkNotNull(sDate)) { + SimpleDateFormat myformat = new SimpleDateFormat(type); + date = myformat.parse(sDate); + } + } catch (Exception e) { + e.printStackTrace(); + } + return date; + } + + /** + * 鍒ゆ柇鏄惁涓虹┖ + */ + public static boolean checkNotNull(Object o) { + boolean b = false; + if (o != null && !"".equals(o)&&!"undefined".equals(o)&&!" ".equals(o)) { + b = true; + } + return b; + } + + /** + * 鍒ゆ柇鏄惁涓虹┖ (澶氫釜) + */ + public static boolean checkNotNullM(Object[] os) { + boolean b = true; + for (Object o : os) { + if (o == null || "".equals(o)) + return false; + } + return b; + } + + /** + * 鑾峰彇鏈嶅姟鍣ㄧ鐨剋ebapps璺緞 + * + * @return + */ + public String findServerPath() { + String classPath = this.getClass().getClassLoader().getResource("/").getPath(); + try { + classPath = URLDecoder.decode(classPath, "gb2312"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + String[] strPath = classPath.split("/"); + String path = ""; + for (int i = 0; i < strPath.length; i++) { + if (i > 0 && i <= 3) { + path = path + strPath[i] + "/"; + } + } + return path; + } + + /** + * 鍒犻櫎鏂囦欢 杈撳叆鐪熸槸璺緞 + */ + public static void deleteFile(String sPath) { + File file = new File(sPath); + // 鍒ゆ柇鐩綍鎴栨枃浠舵槸鍚﹀瓨鍦� + if (file.exists()) { + // 鍒ゆ柇鏄惁涓烘枃浠� + if (file.isFile()) { // 涓烘枃浠舵椂璋冪敤鍒犻櫎鏂囦欢鏂规硶 + deleteFileForOne(sPath); + } else { // 涓虹洰褰曟椂璋冪敤鍒犻櫎鐩綍鏂规硶 + throw new RuntimeException("dir is no del"); + // deleteDirectory(sPath); + } + } + } + + /** + * 鍒犻櫎鐩綍锛堟枃浠跺す锛変互鍙婄洰褰曚笅鐨勬枃浠� + * + * @param sPath + * 琚垹闄ょ洰褰曠殑鏂囦欢璺緞 + * @return 鐩綍鍒犻櫎鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse + */ + public static boolean deleteDirectory(String sPath) { + // 濡傛灉sPath涓嶄互鏂囦欢鍒嗛殧绗︾粨灏撅紝鑷姩娣诲姞鏂囦欢鍒嗛殧绗� + if (!sPath.endsWith(File.separator)) { + sPath = sPath + File.separator; + } + File dirFile = new File(sPath); + // 濡傛灉dir瀵瑰簲鐨勬枃浠朵笉瀛樺湪锛屾垨鑰呬笉鏄竴涓洰褰曪紝鍒欓��鍑� + if (!dirFile.exists() || !dirFile.isDirectory()) { + return false; + } + Boolean flag = true; + // 鍒犻櫎鏂囦欢澶逛笅鐨勬墍鏈夋枃浠�(鍖呮嫭瀛愮洰褰�) + File[] files = dirFile.listFiles(); + for (int i = 0; i < files.length; i++) { + // 鍒犻櫎瀛愭枃浠� + if (files[i].isFile()) { + flag = deleteFileForOne(files[i].getAbsolutePath()); + if (!flag) + break; + } // 鍒犻櫎瀛愮洰褰� + else { + flag = deleteDirectory(files[i].getAbsolutePath()); + if (!flag) + break; + } + } + if (!flag) + return false; + // 鍒犻櫎褰撳墠鐩綍 + if (dirFile.delete()) { + return true; + } else { + return false; + } + } + + /** + * 鍒犻櫎鍗曚釜鏂囦欢 + * + * @param sPath + * 琚垹闄ゆ枃浠剁殑鏂囦欢鍚� + * @return 鍗曚釜鏂囦欢鍒犻櫎鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse + */ + public static boolean deleteFileForOne(String sPath) { + Boolean flag = false; + File file = new File(sPath); + // 璺緞涓烘枃浠朵笖涓嶄负绌哄垯杩涜鍒犻櫎 + if (file.isFile() && file.exists()) { + file.delete(); + flag = true; + } + return flag; + } + + + /** + * 鑾峰彇uuid + */ + public static String getUUIDName() { + return UUID.randomUUID().toString(); + } + + + /** 鑾峰彇寮傚父淇℃伅 **/ + public static String getExceptionMsg(Exception e) { + StringBuffer emsg = new StringBuffer(); + if (e != null) { + StackTraceElement[] st = e.getStackTrace(); + for (StackTraceElement stackTraceElement : st) { + String exclass = stackTraceElement.getClassName(); + String method = stackTraceElement.getMethodName(); + emsg.append("[绫�:" + exclass + "]璋冪敤---" + method + "----鏃跺湪绗�" + stackTraceElement.getLineNumber() + + "琛屼唬鐮佸鍙戠敓寮傚父!寮傚父绫诲瀷:" + e.toString() + "(" + e.getMessage() + ")\r\n"); + } + } + return emsg.toString(); + } + + /** + * 鑾峰彇鎸囧畾鏍煎紡鐨凞ouble 绫诲瀷鏁版嵁 + * + * 杞崲鏍煎紡鐨勭被鍨� 榛樿涓� "#.##" + * @param e + * 瑕佽浆鎹㈢殑鏁版嵁婧� + **/ + public static Double getTypeDouble(Double e) { + fmt.setRoundingMode(RoundingMode.HALF_UP); // 淇濈暀灏忔暟鐐瑰悗涓や綅骞跺洓鑸嶄簲鍏ワ紝纭繚浠烽挶鍑嗙‘ + Double d = Double.valueOf(fmt.format(e)); + return d; + } + + + /** + * SHA1 鍔犲瘑 + * + * @param decript + * @return + */ + public static String SHA1(String decript) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-1"); + digest.update(decript.getBytes()); + byte messageDigest[] = digest.digest(); + // Create Hex String + StringBuffer hexString = new StringBuffer(); + // 瀛楄妭鏁扮粍杞崲涓� 鍗佸叚杩涘埗 鏁� + for (int i = 0; i < messageDigest.length; i++) { + String shaHex = Integer.toHexString(messageDigest[i] & 0xFF); + if (shaHex.length() < 2) { + hexString.append(0); + } + hexString.append(shaHex); + } + return hexString.toString(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return ""; + } + + + public static String getLocalIP() { + InetAddress addr = null; + try { + addr = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + + byte[] ipAddr = addr.getAddress(); + String ipAddrStr = ""; + for (int i = 0; i < ipAddr.length; i++) { + if (i > 0) { + ipAddrStr += "."; + } + ipAddrStr += ipAddr[i] & 0xFF; + } + // System.out.println("i am ip:......"+ipAddrStr); + return ipAddrStr; + } + + /**闅忔満鐢熸垚瀛楃涓诧紙0-9锛� + * + * @param lengthCount 闀垮害 + * @return + */ + public static String generateCardNo(Integer lengthCount) { + if(!SimpleTool.checkNotNull(lengthCount)) { + lengthCount = 6; + } + java.util.Random r=new java.util.Random(); + StringBuilder str = new StringBuilder();//瀹氫箟鍙橀暱瀛楃涓� + for(int i=0;i<lengthCount;i++){ + str.append(r.nextInt(10)); + } + return str.toString(); + } + + /**鍒ゆ柇鏄笉鏄棰戞枃浠� + * @param fileName 鏂囦欢鍚嶇О + * @return boolean true鏄棰戞枃浠� + */ + public static boolean getMimeType(String fileName) { + boolean b = false; + FileNameMap fileNameMap = URLConnection.getFileNameMap(); + String type = fileNameMap.getContentTypeFor(fileName); + //鏄棰憈ype鏄负绌虹殑 + if(!checkNotNull(type)) { + b = true; + } + return b; + } + + /** + * 鍒ゆ柇鏄惁涓鸿棰� + * @param fileName + * @return + */ + public static String isVideo(String fileName) { + FileNameMap fileNameMap = URLConnection.getFileNameMap(); + String type = fileNameMap.getContentTypeFor(fileName); + return type; + } + + /**鍒ゆ柇鏄惁鏄腑鏂�*/ + public static boolean isChineseChar(String str){ + boolean temp = false; + Pattern p=Pattern.compile("[\u4e00-\u9fa5]"); + Matcher m=p.matcher(str); + if(m.find()){ + temp = true; + } + return temp; + } + + /**鍘婚櫎瀛楃涓蹭腑涓嶆槸涓枃鐨勫瓧绗� + * + */ + public static String deleteNoChinese(String str){ + String name=""; + if(checkNotNull(str)){ + for(int i=0;i<str.length();i++){ + String s = str.substring(i, i+1); + if(isChineseChar(s)){ + name = name +s; + } + } + } + return name; + } + + /**鐢熸垚瀛楁瘝锛堝叏閮ㄦ槸涓枃鐨勶級*/ + public static String convertHanzi3Pinyin(String hanzi,boolean full){ + hanzi = deleteNoChinese(hanzi); + hanzi = convertHanzi2Pinyin(hanzi,false); + return hanzi; + } + + /***鑾峰彇瀛楃涓叉嫾闊崇殑绗竴涓瓧姣嶏紙澶у啓锛�**/ + public static String convertStringPinyinOne(String hanzi) { + if(SimpleTool.checkNotNull(hanzi)) { + //杞寲涓轰究瀹� + hanzi = convertHanzi2Pinyin(hanzi,false); + //杞寲澶у啓 + hanzi = hanzi.toUpperCase(); + /*//鑾峰彇绗竴涓� + byte[] datas = hanzi.getBytes(); + if(datas.length>0) { + byte[] datas2 = new byte[] {datas[0]}; + hanzi = new String(datas2); + }else { + hanzi = ""; + }*/ + } + return hanzi; + } + + + /***灏嗘眽瀛楄浆鎴愭嫾闊�(鍙栭瀛楁瘝鎴栧叏鎷�) + * @param hanzi + * @param full 鏄惁鍏ㄦ嫾 + * @return + */ + public static String convertHanzi2Pinyin(String hanzi,boolean full){ + //鑾峰彇绗竴涓瓧 + /* if(checkNotNull(hanzi)){ + boolean isHave = true; + Integer l = hanzi.length(); + Integer index = 0; + while (isHave) { + String hanzi2 = hanzi.substring(index,index+1); + if(isChineseChar(hanzi2)){ + isHave = false; + hanzi = hanzi2; + }else{ + if(index<l-1){ + index++; + }else{ + isHave = false; + } + } + } + } + */ + //鍘婚櫎鎵�鏈夌殑绌烘牸 + if(checkNotNull(hanzi)){ + hanzi = hanzi.replaceAll(" ", ""); + } + + /*** + * ^[\u2E80-\u9FFF]+$ 鍖归厤鎵�鏈変笢浜氬尯鐨勮瑷� + * ^[\u4E00-\u9FFF]+$ 鍖归厤绠�浣撳拰绻佷綋 + * ^[\u4E00-\u9FA5]+$ 鍖归厤绠�浣� + */ + String regExp="^[\u4E00-\u9FFF]+$"; + StringBuffer sb=new StringBuffer(); + if(hanzi==null||"".equals(hanzi.trim())){ + return ""; + } + String pinyin=""; + for(int i=0;i<hanzi.length();i++){ + char unit=hanzi.charAt(i); + if(match(String.valueOf(unit),regExp)){//鏄眽瀛楋紝鍒欒浆鎷奸煶 + pinyin=convertSingleHanzi2Pinyin(unit); + if(full){ + sb.append(pinyin); + }else{ + sb.append(pinyin.charAt(0)); + } + }else{ + sb.append(unit); + } + } + return sb.toString(); + } + + /***灏嗗崟涓眽瀛楄浆鎴愭嫾闊� + * @param hanzi + * @return + */ + private static String convertSingleHanzi2Pinyin(char hanzi){ + HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat(); + outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + String[] res; + StringBuffer sb=new StringBuffer(); + try { + res = PinyinHelper.toHanyuPinyinStringArray(hanzi,outputFormat); + sb.append(res[0]);//瀵逛簬澶氶煶瀛楋紝鍙敤绗竴涓嫾闊� + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + return sb.toString(); + } + + /***@param str 婧愬瓧绗︿覆 + * @param regex 姝e垯琛ㄨ揪寮� + * @return 鏄惁鍖归厤 + */ + public static boolean match(String str,String regex){ + Pattern pattern=Pattern.compile(regex); + Matcher matcher=pattern.matcher(str); + return matcher.find(); + } + + /** 璇诲彇 Excel鏂囦欢鍐呭(3.24 quan) + * + * @param excel_name File + * @return + * @throws Exception + */ + public static List<String[]> readExcelByeFile2(File excel_name) throws Exception { + // 缁撴灉闆� + List<String[]> list = new ArrayList<String[]>(); + HSSFWorkbook hssfworkbook = new HSSFWorkbook(new FileInputStream(excel_name)); + + // 閬嶅巻璇ヨ〃鏍间腑鎵�鏈夌殑宸ヤ綔琛紝i琛ㄧず宸ヤ綔琛ㄧ殑鏁伴噺 getNumberOfSheets琛ㄧず宸ヤ綔琛ㄧ殑鎬绘暟 + HSSFSheet hssfsheet = hssfworkbook.getSheetAt(0); + + // 閬嶅巻璇ヨ鎵�鏈夌殑琛�,j琛ㄧず琛屾暟 getPhysicalNumberOfRows琛岀殑鎬绘暟 + for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) { + HSSFRow hssfrow = hssfsheet.getRow(j); + if(hssfrow!=null){ + int col = hssfrow.getPhysicalNumberOfCells(); + // 鍗曡鏁版嵁 + String[] arrayString = new String[col]; + for (int i = 0; i < col; i++) { + HSSFCell cell = hssfrow.getCell(i); + if (cell == null) { + arrayString[i] = ""; + } else if (cell.getCellType() == 0) { + // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); + short format = cell.getCellStyle().getDataFormat(); + SimpleDateFormat sdf = null; + if(format == 14 || format == 31 || format == 57 || format == 58){ + //鏃ユ湡 + sdf = new SimpleDateFormat("yyyy-MM-dd"); + }else if (format == 20 || format == 32) { + //鏃堕棿 + sdf = new SimpleDateFormat("HH:mm"); + }else if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { + if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy骞�"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString[i] = formater.format(d); + } else { + arrayString[i] = new BigDecimal(cell.getNumericCellValue()).toString(); + } + } + } else {// 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� + arrayString[i] = cell.getStringCellValue().trim(); + } + } + list.add(arrayString); + } + } + return list; + } + + /** + * 璇诲彇 Excel鏂囦欢鍐呭 + * + * @param excel_name + * @param header 鏄惁鍖呮嫭琛ㄥご + * @return + * @throws Exception + */ + public static List<String[]> readExcelByeFileData(File excel_name,boolean header) throws Exception { + // 缁撴灉闆� + List<String[]> list = new ArrayList<String[]>(); + + HSSFWorkbook hssfworkbook = new HSSFWorkbook(new FileInputStream( + excel_name)); + + // 閬嶅巻璇ヨ〃鏍间腑鎵�鏈夌殑宸ヤ綔琛紝i琛ㄧず宸ヤ綔琛ㄧ殑鏁伴噺 getNumberOfSheets琛ㄧず宸ヤ綔琛ㄧ殑鎬绘暟 + for(int s=0;s<hssfworkbook.getNumberOfSheets();s++) { + HSSFSheet hssfsheet = hssfworkbook.getSheetAt(s); + int col = 0; + // 閬嶅巻璇ヨ鎵�鏈夌殑琛�,j琛ㄧず琛屾暟 getPhysicalNumberOfRows琛岀殑鎬绘暟 鍘婚櫎鏍囬 + for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) { + HSSFRow hssfrow = hssfsheet.getRow(j); + if(hssfrow!=null){ + if(j == 0) { + col = hssfrow.getPhysicalNumberOfCells(); + if(!header) { + //涓嶅寘鎷〃澶� + continue; + } + } + // 鍗曡鏁版嵁 + String[] arrayString = new String[col]; + for (int i = 0; i < col; i++) { + HSSFCell cell = hssfrow.getCell(i); + if (cell == null) { + arrayString[i] = ""; + } else if (cell.getCellType() == 0) { + // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); + if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { + short format = cell.getCellStyle().getDataFormat(); + if(format == 14 || format == 31 || format == 57 || format == 58){ + //鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛� + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy骞�"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString[i] = formater.format(d); + }else if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy骞�"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString[i] = formater.format(d); + } else { + if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){ + arrayString[i] =cell.getStringCellValue(); + }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){ + arrayString[i] =cell.getCellFormula(); + }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){ + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); + arrayString[i] =dataFormatter.formatCellValue(cell); + } + } + } + } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){ + arrayString[i] = ""; + } else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� + arrayString[i] = cell.getStringCellValue().trim(); + } + } + list.add(arrayString); + } + } + } + return list; + } + + /** + * 璇诲彇 Excel鏂囦欢鍐呭锛堝鏍′俊鎭笓鐢級 + * + * @param excel_name + * @return + * @throws Exception + */ + public static List<String[]> readExcelByeFile(File excel_name) throws Exception { + // 缁撴灉闆� + List<String[]> list = new ArrayList<String[]>(); + + HSSFWorkbook hssfworkbook = new HSSFWorkbook(new FileInputStream( + excel_name)); + + // 閬嶅巻璇ヨ〃鏍间腑鎵�鏈夌殑宸ヤ綔琛紝i琛ㄧず宸ヤ綔琛ㄧ殑鏁伴噺 getNumberOfSheets琛ㄧず宸ヤ綔琛ㄧ殑鎬绘暟 + for(int s=0;s<hssfworkbook.getNumberOfSheets();s++) { + HSSFSheet hssfsheet = hssfworkbook.getSheetAt(s); + int col = 0; + // 閬嶅巻璇ヨ鎵�鏈夌殑琛�,j琛ㄧず琛屾暟 getPhysicalNumberOfRows琛岀殑鎬绘暟 鍘婚櫎鏍囬 + for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) { + HSSFRow hssfrow = hssfsheet.getRow(j); + if(hssfrow!=null){ + if(j == 0) { + col = hssfrow.getPhysicalNumberOfCells(); + }else { + // int col = hssfrow.getPhysicalNumberOfCells(); + // 鍗曡鏁版嵁 + String[] arrayString = new String[col]; + for (int i = 0; i < col; i++) { + HSSFCell cell = hssfrow.getCell(i); + if (cell == null) { + arrayString[i] = ""; + } else if (cell.getCellType() == 0) { + // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); + if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { + short format = cell.getCellStyle().getDataFormat(); + if(format == 14 || format == 31 || format == 57 || format == 58){ + //鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛� + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy骞�"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString[i] = formater.format(d); + }else if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date d = cell.getDateCellValue(); + DateFormat formater = new SimpleDateFormat("yyyy骞�"); + // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + arrayString[i] = formater.format(d); + } else { + if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){ + arrayString[i] =cell.getStringCellValue(); + }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){ + arrayString[i] =cell.getCellFormula(); + }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){ + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); + arrayString[i] =dataFormatter.formatCellValue(cell); + } + } + } + } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){ + arrayString[i] = ""; + } else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� + cell.setCellType(Cell.CELL_TYPE_STRING); + String name = cell.getStringCellValue().trim(); + if(name.equals("-")) { + arrayString[i] = ""; + }else { + arrayString[i] = name; + } + } + } + list.add(arrayString); + } + } + } + } + return list; + } + + /**鑾峰彇瀛楃涓查噷闈㈢殑鏁板瓧锛屾寜椤哄簭鎺掑簭*/ + public static String stringNumber(String data) { + String da = null; + String regEc = "[^0-9]"; + Pattern pattern = Pattern.compile(regEc); + Matcher m = pattern.matcher(data); + da = m.replaceAll("").trim(); + return da; + } + + /** + * @param url:璇锋眰url + * @param content: 璇锋眰浣�(鍙傛暟) + * @return errorStr:閿欒淇℃伅;status:鐘舵�佺爜锛宺esponse锛氳繑鍥炴暟鎹� + * @throws JSONException + */ + public static JSONObject requestData(String url, String content) throws JSONException { + JSONObject obj = new JSONObject(); + String errMsg_r = ""; + String status_r = "0"; + String response = ""; + //PrintWriter out = null; + DataOutputStream out = null; + BufferedReader in = null; + try { + URL realUrl = new URL(url); + // 鎵撳紑鍜孶RL涔嬮棿鐨勮繛鎺� + URLConnection conn = realUrl.openConnection(); + HttpURLConnection httpUrlConnection = (HttpURLConnection) conn; + // 璁剧疆璇锋眰灞炴�� + httpUrlConnection.setRequestProperty("Content-type", "application/json;charset=UTF-8"); + //httpUrlConnection.setRequestProperty("Content-Type", "application/json"); + //httpUrlConnection.setRequestProperty("Charset", "UTF-8"); + httpUrlConnection.setRequestProperty("x-adviewrtb-version", "2.1"); + // 鍙戦�丳OST璇锋眰蹇呴』璁剧疆濡備笅涓よ + httpUrlConnection.setDoOutput(true); + httpUrlConnection.setDoInput(true); + // 鑾峰彇URLConnection瀵硅薄瀵瑰簲鐨勮緭鍑烘祦 + out = new DataOutputStream(httpUrlConnection.getOutputStream()); + //out = new PrintWriter(httpUrlConnection.getOutputStream()); + // 鍙戦�佽姹傚弬鏁� + //out.write(content); + out.write(content.getBytes("UTF-8")); + // flush杈撳嚭娴佺殑缂撳啿 + out.flush(); + httpUrlConnection.connect(); + // 瀹氫箟BufferedReader杈撳叆娴佹潵璇诲彇URL鐨勫搷搴� + // in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream())); + String wxMsgXml = IOUtils.toString(httpUrlConnection.getInputStream(), "utf-8"); + System.out.println("wxMsgXml:"+wxMsgXml); + if(SimpleTool.checkNotNull(wxMsgXml)) { + obj = JSONObject.fromObject(wxMsgXml); + } + /* String line; + while ((line = in.readLine()) != null) { + response += line; + } */ + status_r = new Integer(httpUrlConnection.getResponseCode()).toString(); + } catch (Exception e) { + System.out.println("鍙戦�� POST 璇锋眰鍑虹幇寮傚父锛�" + e); + errMsg_r = e.getMessage(); + e.printStackTrace(); + } + // 浣跨敤finally鍧楁潵鍏抽棴杈撳嚭娴併�佽緭鍏ユ祦 + finally { + try { + if (out != null) { out.close();} + if (in != null) {in.close();} + } catch (Exception ex) { + ex.printStackTrace(); + } + } + obj.put("errMsg_r", errMsg_r); + obj.put("status_r", status_r); + return obj; + } + + /**闅忔満鐢熸垚瀛楁暟锛堟暣鏁帮級锛堝寘鎷� 0锛� + * @param maxNumber 鏈�澶у�� + * @return + */ + public static Integer randomData(Integer maxNumber) { + java.util.Random r=new java.util.Random(); + return r.nextInt(maxNumber); + } + + private static final String[] HEADERS_TO_TRY = {"X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP", + "HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED", "HTTP_X_CLUSTER_CLIENT_IP", "HTTP_CLIENT_IP", + "HTTP_FORWARDED_FOR", "HTTP_FORWARDED", "HTTP_VIA", "REMOTE_ADDR", "X-Real-IP"}; + + /** + * getClientIpAddress:(鑾峰彇鐢ㄦ埛ip锛屽彲绌块�忎唬鐞�). <br/> + * @param request + * @return + * @author chenjiahe + * @Date 2018骞�3鏈�2鏃ヤ笅鍗�4:41:47 + * @since JDK 1.7 + */ + public static String getClientIpAddress(HttpServletRequest request) { + for (String header : HEADERS_TO_TRY) { + String ip = request.getHeader(header); + if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { + return ip; + } + } + return request.getRemoteAddr(); + } + +} diff --git a/src/main/java/com/hx/util/StreamUtils.java b/src/main/java/com/hx/util/StreamUtils.java new file mode 100644 index 0000000..755eb93 --- /dev/null +++ b/src/main/java/com/hx/util/StreamUtils.java @@ -0,0 +1,266 @@ +package com.hx.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; + +public class StreamUtils { + + final static int BUFFER_SIZE = 4096; + /** + * 锟斤拷InputStream转锟斤拷锟斤拷String + * + * @param in + * InputStream + * @return String + * @throws Exception + * + */ + public static String InputStreamTOString(InputStream in) { + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] data = new byte[BUFFER_SIZE]; + String string = null; + int count = 0; + try { + while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) + outStream.write(data, 0, count); + } catch (IOException e) { + e.printStackTrace(); + } + + data = null; + try { + string = new String(outStream.toByteArray(), "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return string; + } + + /** + * 锟斤拷InputStream转锟斤拷锟斤拷某锟斤拷锟街凤拷锟斤拷锟斤拷String + * + * @param in + * @param encoding + * @return + * @throws Exception + */ + public static String InputStreamTOString(InputStream in, String encoding) { + String string = null; + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] data = new byte[BUFFER_SIZE]; + int count = -1; + try { + while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) + outStream.write(data, 0, count); + } catch (IOException e) { + e.printStackTrace(); + } + + data = null; + try { + string = new String(outStream.toByteArray(), encoding); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return string; + } + + /** + * 锟斤拷String转锟斤拷锟斤拷InputStream + * + * @param in + * @return + * @throws Exception + */ + public static InputStream StringTOInputStream(String in) throws Exception { + + ByteArrayInputStream is = new ByteArrayInputStream(in.getBytes("UTF-8")); + return is; + } + + /** + * 锟斤拷String转锟斤拷锟斤拷InputStream + * + * @param in + * @return + * @throws Exception + */ + public static byte[] StringTObyte(String in) { + byte[] bytes = null; + try { + bytes = InputStreamTOByte(StringTOInputStream(in)); + } catch (IOException e) { + } catch (Exception e) { + e.printStackTrace(); + } + return bytes; + } + + /** + * 锟斤拷InputStream转锟斤拷锟斤拷byte锟斤拷锟斤拷 + * + * @param in + * InputStream + * @return byte[] + * @throws IOException + */ + public static byte[] InputStreamTOByte(InputStream in) throws IOException { + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + byte[] data = new byte[BUFFER_SIZE]; + int count = -1; + while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) + outStream.write(data, 0, count); + + data = null; + return outStream.toByteArray(); + } + + + /** + * 锟斤拷byte锟斤拷锟斤拷转锟斤拷锟斤拷InputStream + * + * @param in + * @return + * @throws Exception + */ + public static InputStream byteTOInputStream(byte[] in) throws Exception { + + ByteArrayInputStream is = new ByteArrayInputStream(in); + return is; + } + + /** + * 锟斤拷byte锟斤拷锟斤拷转锟斤拷锟斤拷String + * + * @param in + * @return + * @throws Exception + */ + public static String byteTOString(byte[] in) { + + InputStream is = null; + try { + is = byteTOInputStream(in); + } catch (Exception e) { + e.printStackTrace(); + } + return InputStreamTOString(is, "UTF-8"); + } + /** + * 锟斤拷byte锟斤拷锟斤拷转锟斤拷锟斤拷String + * + * @param in + * @return + * @throws Exception + */ + public static String getString(String in) { + + String is = null; + try { + is = byteTOString(StringTObyte(in)); + } catch (Exception e) { + e.printStackTrace(); + } + return is; + } + + // InputStream 转锟斤拷锟斤拷byte[] + public byte[] getBytes(InputStream is) throws IOException { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] b = new byte[BUFFER_SIZE]; + int len = 0; + + while ((len = is.read(b, 0, BUFFER_SIZE)) != -1) { + baos.write(b, 0, len); + } + + baos.flush(); + + byte[] bytes = baos.toByteArray(); + + System.out.println(new String(bytes)); + + return bytes; + } + /** + * 锟斤拷锟斤拷募锟铰凤拷锟斤拷锟斤拷锟斤拷募锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� + * 锟斤拷锟街斤拷为锟斤拷位锟斤拷锟斤拷 unicode 锟斤拷 + * @return + */ + public static FileInputStream getFileInputStream(String filepath) { + FileInputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(filepath); + } catch (FileNotFoundException e) { + System.out.print("锟斤拷锟斤拷锟斤拷息:锟侥硷拷锟斤拷锟斤拷锟斤拷"); + e.printStackTrace(); + } + return fileInputStream; + } + /** + * 锟斤拷锟斤拷募锟斤拷锟斤拷蟠唇锟斤拷募锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� + * 锟斤拷锟街斤拷为锟斤拷位锟斤拷锟斤拷 unicode 锟斤拷 + * @return + */ + public static FileInputStream getFileInputStream(File file) { + FileInputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(file); + } catch (FileNotFoundException e) { + System.out.print("锟斤拷锟斤拷锟斤拷息:锟侥硷拷锟斤拷锟斤拷锟斤拷"); + e.printStackTrace(); + } + return fileInputStream; + } + /** + * 锟斤拷锟斤拷募锟斤拷锟斤拷蟠唇锟斤拷募锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 + * 锟斤拷锟街斤拷为锟斤拷位锟斤拷锟斤拷 unicode 锟斤拷 + * @param file + * @param append true:锟侥硷拷锟斤拷追锟接凤拷式锟斤拷,false:锟津覆革拷原锟侥硷拷锟斤拷锟斤拷锟斤拷 + * @return + */ + public static FileOutputStream getFileOutputStream(File file,boolean append) { + FileOutputStream fileOutputStream = null; + try { + fileOutputStream = new FileOutputStream(file,append); + } catch (FileNotFoundException e) { + System.out.print("锟斤拷锟斤拷锟斤拷息:锟侥硷拷锟斤拷锟斤拷锟斤拷"); + e.printStackTrace(); + } + return fileOutputStream; + } + /** + * 锟斤拷锟斤拷募锟铰凤拷锟斤拷锟斤拷锟斤拷募锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 + * 锟斤拷锟街斤拷为锟斤拷位锟斤拷锟斤拷 unicode 锟斤拷 + * @param append true:锟侥硷拷锟斤拷追锟接凤拷式锟斤拷,false:锟津覆革拷原锟侥硷拷锟斤拷锟斤拷锟斤拷 + * @return + */ + public static FileOutputStream getFileOutputStream(String filepath,boolean append) { + FileOutputStream fileOutputStream = null; + try { + fileOutputStream = new FileOutputStream(filepath,append); + } catch (FileNotFoundException e) { + System.out.print("锟斤拷锟斤拷锟斤拷息:锟侥硷拷锟斤拷锟斤拷锟斤拷"); + e.printStackTrace(); + } + return fileOutputStream; + } + + public static File getFile(String filepath) { + return new File(filepath); + } + public static ByteArrayOutputStream getByteArrayOutputStream() { + return new ByteArrayOutputStream(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/hx/util/StringUtils.java b/src/main/java/com/hx/util/StringUtils.java new file mode 100644 index 0000000..6710290 --- /dev/null +++ b/src/main/java/com/hx/util/StringUtils.java @@ -0,0 +1,306 @@ +package com.hx.util; + +import java.io.UnsupportedEncodingException; +import java.text.MessageFormat; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 瀛楃涓插伐鍏风被 + * + * @author ThinkGem + * @version 2013-05-22 + */ +public class StringUtils { + + private static final char SEPARATOR = '_'; + private static final String CHARSET_NAME = "UTF-8"; + + /** + * 鏍煎紡鍖栧瓧绗︿覆锛屾浛鎹㈠師瀛楃涓蹭腑鐨剓0}, {1}锛屾寜椤哄簭鏇挎崲 + * + * @param oriStr + * @param args + * @return + */ + public static String format(String oriStr, Object... args) { + return MessageFormat.format(oriStr, args); + } + + /** + * 杞崲涓哄瓧鑺傛暟锟�? + * + * @param str + * @return + */ + public static byte[] getBytes(String str) { + if (str != null) { + try { + return str.getBytes(CHARSET_NAME); + } catch (UnsupportedEncodingException e) { + return null; + } + } else { + return null; + } + } + + /** + * 鍙彇鍚庝袱锟�? + * + * @param str + * @return + */ + public static String getLastTwoChars(String str) { + if (null != str && str.trim().length() > 0) { + str = str.trim(); + int len = str.length(); + if (len == 2) { + return str; + } else if (len > 2) { + return str.substring(len - 2); + } + } + return ""; + } + + /** + * 鍙彇鍚庝笁锟�? + * + * @param str + * @return + */ + public static String getLastThreeChars(String str) { + if (null != str && str.trim().length() > 0) { + str = str.trim(); + int len = str.length(); + if (len == 3) { + return str; + } else if (len > 3) { + return str.substring(len - 3); + } + } + return ""; + } + + /** + * 鏇挎崲涓烘墜鏈鸿瘑鍒殑HTML锛屽幓鎺夋牱寮忓強灞烇拷?锟斤紝淇濈暀鍥炶溅锟�? + * + * @param html + * @return + */ + public static String replaceMobileHtml(String html) { + if (html == null) { + return ""; + } + return html.replaceAll("<([a-z]+?)\\s+?.*?>", "<$1>"); + } + + /** + * 椹煎嘲鍛藉悕娉曞伐锟�? + * + * @return toCamelCase("hello_world") == "helloWorld" + * toCapitalizeCamelCase("hello_world") == "HelloWorld" + * toUnderScoreCase("helloWorld") = "hello_world" + */ + public static String toCamelCase(String s) { + if (s == null) { + return null; + } + + s = s.toLowerCase(); + + StringBuilder sb = new StringBuilder(s.length()); + boolean upperCase = false; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == SEPARATOR) { + upperCase = true; + } else if (upperCase) { + sb.append(Character.toUpperCase(c)); + upperCase = false; + } else { + sb.append(c); + } + } + + return sb.toString(); + } + + /** + * 椹煎嘲鍛藉悕娉曞伐锟�? + * + * @return toCamelCase("hello_world") == "helloWorld" + * toCapitalizeCamelCase("hello_world") == "HelloWorld" + * toUnderScoreCase("helloWorld") = "hello_world" + */ + public static String toCapitalizeCamelCase(String s) { + if (s == null) { + return null; + } + s = toCamelCase(s); + return s.substring(0, 1).toUpperCase() + s.substring(1); + } + + /** + * 椹煎嘲鍛藉悕娉曞伐锟�? + * + * @return toCamelCase("hello_world") == "helloWorld" + * toCapitalizeCamelCase("hello_world") == "HelloWorld" + * toUnderScoreCase("helloWorld") = "hello_world" + */ + public static String toUnderScoreCase(String s) { + if (s == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + boolean upperCase = false; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + boolean nextUpperCase = true; + + if (i < (s.length() - 1)) { + nextUpperCase = Character.isUpperCase(s.charAt(i + 1)); + } + + if ((i > 0) && Character.isUpperCase(c)) { + if (!upperCase || !nextUpperCase) { + sb.append(SEPARATOR); + } + upperCase = true; + } else { + upperCase = false; + } + + sb.append(Character.toLowerCase(c)); + } + + return sb.toString(); + } + + /** + * 鏍规嵁瑙勫垯regExpr,鍒ゆ柇瀛楃鍐呭鏄惁鍖归厤 + * <p> + * 鍒╃敤姝e垯琛ㄨ揪寮忚鍒欏垽鏂紝寰呴獙璇佺殑瀛楃鍐呭鏄惁绗﹀悎瑕佹眰锟�? <br> + * 姣斿'[0-9]*'鍗冲垽鏂槸鍚︿负鏁板瓧鐨勮锟�?, '^[a-z0-9_-]{3,15}$'鍗冲垽鏂槸鍚︿负鐢ㄦ埛鍚嶇殑瑙勫垯,<br> + * '((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})'鍗冲垽鏂槸鍚︿负瀵嗙爜鐨勮锟�?,<br> + * '^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$'鍗砮mail瑙勫垯,<br> + * '([^\s]+(\.(?i)(jpg|png|gif|bmp))$)'鍗冲垽鏂煇鍥剧墖鏂囦欢鏍煎紡,<br> + * '^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'鍗矷P瑙勫垯. + * + * + * @param regExpr + * 姝e垯琛ㄨ揪锟�? + * @param content + * 寰呴獙璇佺殑瀛楃鍐呭 + * @return boolean + */ + public static boolean isMatch(String regExpr, String content) { + if (StringUtils.isEmpty(regExpr, content)) + return false; + + Pattern pattern = Pattern.compile(regExpr); + Matcher matcher = pattern.matcher(content); + + return matcher.matches(); + } + + /** + * 姝e垯鍒ゆ柇绾暟锟�? + * + * @param str + * @return + */ + public static boolean isNumeric(String str) { + Pattern pattern = Pattern.compile("[0-9]*"); + Matcher isNum = pattern.matcher(str); + if (!isNum.matches()) { + return false; + } + return true; + } + + public static boolean isEmpty(String str) { + return null == str || str.trim().length() == 0 || "undefined".equals(str); + } + + /** + * 鍒ゆ柇瀛楃鍐呭涓槸鍚﹀瓨鍦ㄤ竴涓负绌虹殑瀛楃锟�? + * <p> + * 濡傛灉鍦ㄦ墍鏈夌殑瀛楃涓插唴瀹逛腑锛屽彧瑕佸瓨鍦ㄦ煇锟�?涓瓧绗︿覆涓虹┖锛屽垯杩斿洖涓簍rue, 濡傛灉锟�?鏈夌殑瀛楃涓插唴瀹逛腑锛屼笉瀛樺湪锟�?涓┖瀛楃涓诧紝鍒欒繑鍥炰负false. + * + * @param strings + * @return boolean + */ + public static boolean isEmpty(String... strings) { + if (strings == null) + return true; + + for (String str : strings) { + if (StringUtils.isEmpty(str)) + return true; + } + + return false; + } + + public static boolean isAllEmpty(String... strings) { + if (strings == null) + return true; + + for (String str : strings) { + if (!StringUtils.isEmpty(str)) + return false; + } + + return true; + } + + /** + * @param strings + * 璇ユ暟缁勬槸鍚︽湁锟�? + * @return + */ + public static boolean hasContent(String[] strings) { + if (strings != null && strings.length > 0) + return true; + + return false; + } + + /** + * @param params + * 璇ap鏄惁鏈夛拷?? + * @return + */ + public static boolean hasContent(Map<?, ?> params) { + if (params != null && params.size() > 0) + return true; + + return false; + } + + public static boolean isNumeric2(String str) { + if (null == str || isEmpty(str)) { + return false; + } + char[] chars = str.toCharArray(); + for (char c : chars) { + if (!Character.isDigit(c)) + return false; + } + return true; + } + + public static int parseInt(String string) { + if (null != string && isNumeric2(string)) { + return Integer.parseInt(string); + } + return 0; + } + +} diff --git a/src/main/java/com/hx/util/TempltUtil.java b/src/main/java/com/hx/util/TempltUtil.java new file mode 100644 index 0000000..01e917b --- /dev/null +++ b/src/main/java/com/hx/util/TempltUtil.java @@ -0,0 +1,150 @@ +package com.hx.util; + +import freemarker.template.Configuration; +import freemarker.template.DefaultObjectWrapper; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import org.springframework.core.io.ClassPathResource; + +import java.io.*; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class TempltUtil { + + public static final String PREVIEW_DOC = "/temp.docx"; + public static final String TEMP_URL = "temp"; + public static final String TEMP_NAME = "contract.tpl"; + + /** + * + * @param tempUrl 妯℃澘鎵�鍦ㄦ枃浠跺す + * @param tempName 妯℃澘鍚嶇О + * @return + * @throws IOException + */ + public static Template configTemplate(String tempUrl,String tempName) throws IOException { + Configuration config = new Configuration(); + ClassPathResource classPathResource = new ClassPathResource(tempUrl); + config.setDirectoryForTemplateLoading(classPathResource.getFile()); + config.setObjectWrapper(new DefaultObjectWrapper()); + Template template = config.getTemplate(tempName, "UTF-8"); + return template; + } + + /** + * + * @param tempUrl 妯℃澘鎵�鍦ㄦ枃浠跺す + * @param temp 妯℃澘鍚嶇О + * @param copyUrl 澶嶅埗鏂囦欢璺緞 + * @param data 妯℃澘鏁版嵁map + * return 鐢熸垚璺緞 + */ + public static String toPreview(String tempUrl,String temp,String copyUrl, Map<?, ?> data){ + try { + Template template = configTemplate(tempUrl,temp); + ClassPathResource classPathResource = new ClassPathResource(tempUrl+"/"+PREVIEW_DOC); + //鐢熸垚鏂扮殑妯℃澘 + File tempFile = classPathResource.getFile(); + copyUrl = copyUrl+"/"+DateUtil.dateFormat(new Date(),"yyyyMMddHHmmss")+tempFile.getName(); + File file = new File(copyUrl); + FileUtils.copyFile(tempFile,file); + + File file2 = new File(copyUrl); + + FileOutputStream fos = new FileOutputStream(file2); + Writer out = new OutputStreamWriter(fos, "UTF-8"); + template.process(data, out); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return copyUrl; + } + + /** + * + * @param templateUrl 妯℃澘璺緞鐩綍锛屼笉鍖呮嫭妯℃澘鍚嶇О,濡� ./src/main/resources/jsonFile + * @param templateName 妯℃澘鍚嶇О锛屽锛歞ata.tpl + * @param savaPath 鐢熸垚鏂囦欢瀛樻斁鐩綍锛屽 ./src/main/resources/jsonFile + * @param name 鐢熸垚鐨勬枃浠跺悕绉帮紝鍖呮嫭鍚庣紑鍚嶇О + * @param data 妯℃澘閲岄潰鍐呭 + * @throws Exception + */ + public static String createDataFile(String templateUrl,String templateName, + String savaPath, String name,Map<String, Object> data) throws IOException { + String targetFile = null; + Writer out = null; + if(!SimpleTool.checkNotNull(templateUrl)) { + throw new RuntimeException("templateUrl 涓虹┖"); + } + if(!SimpleTool.checkNotNull(templateName)) { + throw new RuntimeException("templateName 涓虹┖"); + } + if(!SimpleTool.checkNotNull(savaPath)) { + throw new RuntimeException("savaPath 涓虹┖"); + } + try { + if(!savaPath.endsWith("/")){ + savaPath = savaPath+"/"; + } + if(!templateUrl.endsWith("/")){ + templateUrl = templateUrl +"/"; + } + + //涓轰簡瑙e喅spingBoot鎵撳寘鎴恓ar鑾峰彇涓嶄簡鏂囦欢锛屾妸鏂囦欢淇濆瓨鍒版湰鍦� + //鎷垮埌jar閲岄潰鐨勬枃浠舵祦 + ClassPathResource classPathResource = new ClassPathResource(templateUrl+templateName); + //淇濆瓨妯℃澘鍥剧墖璺緞 + String saveTempUrl = savaPath+"temp/"; + //鍒ゆ柇鏄惁瀛樺湪浜� + File temFile = new File(saveTempUrl+templateName); + if(temFile.exists()){ + temFile = temFile.getParentFile(); + }else{ + //涓嶅瓨鍦ㄥ氨鍒涘缓涓�涓� + temFile = FileUtils.inputStreamToFile(classPathResource.getInputStream(),saveTempUrl,templateName); + temFile = temFile.getParentFile(); + } + + // 鍙嶅皠end + Configuration cfg = new Configuration(); + // 鎸囧畾妯℃澘鏂囦欢浠庝綍澶勫姞杞界殑鏁版嵁婧愶紝杩欓噷璁剧疆鎴愪竴涓枃浠剁洰褰� + cfg.setDirectoryForTemplateLoading(temFile); + cfg.setObjectWrapper(new DefaultObjectWrapper()); + cfg.setDefaultEncoding("UTF-8"); + // 鑾峰彇鎴栧垱寤烘ā鏉� + Template template = cfg.getTemplate(templateName); + template.setEncoding("UTF-8"); + + // String targetFile = "./src/template/test.html"; + //鐢熸垚璺緞 + targetFile = savaPath; + File file = new File(targetFile); + //娌℃湁鎵惧埌灏辨柊寤轰竴涓� + if (!file.isDirectory() && !file.exists()) { + file.mkdirs(); + } + targetFile += name; + System.out.println("targetFile:"+targetFile); + // 灏嗘ā鏉垮拰鏁版嵁妯″瀷鍚堝苟 杈撳嚭鍒癈onsole + out = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(targetFile), "UTF-8")); + template.process(data, out); + } catch (IOException e) { + e.printStackTrace(); + } catch (TemplateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + if(SimpleTool.checkNotNull(out)){ + out.flush(); + out.close(); + } + } + return targetFile; + } + +} \ No newline at end of file diff --git a/src/main/java/com/hx/util/TengXunMapUtil.java b/src/main/java/com/hx/util/TengXunMapUtil.java new file mode 100644 index 0000000..6aaef1c --- /dev/null +++ b/src/main/java/com/hx/util/TengXunMapUtil.java @@ -0,0 +1,191 @@ +package com.hx.util; + +import net.sf.json.JSONObject; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; + +/** + * 鑵捐鍦板浘宸ュ叿 + * @author mgchen + * + */ +public class TengXunMapUtil { + + /**key*/ + public static final String KEY_SHOP = "NDTBZ-XH6WX-TOB4C-TZFHG-2ORS3-UCBFA"; + /**绛惧悕鏍¢獙*/ + public static final String SIGN = "qI6ZmfLk0IYt7PPWThwqXMjnNjjPzSaW"; + + public static final String URL_LOCATION = "http://apis.map.qq.com/ws/geocoder/v1/?address={1}&key={2}"; + public static final String URL_CITY = "http://apis.map.qq.com/ws/geocoder/v1/?location={1}&key={2}"; + + /**鍦板潃杞崲涓虹粡绾害*/ + public static String[] getLocation(String address, String key) + { + try{ + String str = sendGet("https://apis.map.qq.com/ws/geocoder/v1/", "address=" + URLEncoder.encode(address, "utf-8") + "&key=" + key); + JSONObject obj = JSONObject.fromObject(str); + int status = obj.optInt("status", -1); + if(status == 0) + { + JSONObject rObj = obj.optJSONObject("result"); + if(rObj != null) + { + JSONObject lObj = rObj.optJSONObject("location"); + if(lObj != null) + { + Double lng = lObj.optDouble("lng", 0.0); + Double lat = lObj.optDouble("lat", 0.0); + if(lng != 0.0 && lat != 0.0) + { + return new String[]{lng.toString(), lat.toString()}; + } + + } + } + } + }catch(Exception e) + { + e.printStackTrace(); + } + + return null; + } + + /**鍦板潃杞崲涓虹粡绾害锛堢鍚嶆牎楠岋級*/ + public static String[] getLocation(String address, String key,String sign) { + try{ + sign = MD5Util.MD5Encode("/ws/geocoder/v1?address=" + address + "&key=" + key+sign,null); + String str = sendGet("https://apis.map.qq.com/ws/geocoder/v1", "address=" + address + "&key=" + key+"&sig="+sign); + JSONObject obj = JSONObject.fromObject(str); + int status = obj.optInt("status", -1); + if(status == 0) + { + JSONObject rObj = obj.optJSONObject("result"); + if(rObj != null) + { + JSONObject lObj = rObj.optJSONObject("location"); + if(lObj != null) + { + Double lng = lObj.optDouble("lng", 0.0); + Double lat = lObj.optDouble("lat", 0.0); + if(lng != 0.0 && lat != 0.0) + { + return new String[]{lng.toString(), lat.toString()}; + } + + } + } + } + }catch(Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * 鍚戞寚瀹歎RL鍙戦�丟ET鏂规硶鐨勮姹� + * + * @param url + * 鍙戦�佽姹傜殑URL + * @param param + * 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋�� + * @return URL 鎵�浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋� + */ + public static String sendGet(String url, String param) { + String result = ""; + BufferedReader in = null; + try { + String urlNameString = url + "?" + param; + System.out.println("urlNameString:"+urlNameString); + URL realUrl = new URL(urlNameString); + // 鎵撳紑鍜孶RL涔嬮棿鐨勮繛鎺� + URLConnection connection = realUrl.openConnection(); + // 璁剧疆閫氱敤鐨勮姹傚睘鎬� + connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"); + connection.setRequestProperty("connection", "Keep-Alive"); + connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"); + // 寤虹珛瀹為檯鐨勮繛鎺� + connection.connect(); + +// // 鑾峰彇鎵�鏈夊搷搴斿ご瀛楁 +// Map<String, List<String>> map = connection.getHeaderFields(); +// // 閬嶅巻鎵�鏈夌殑鍝嶅簲澶村瓧娈� +// for (String key : map.keySet()) { +// System.out.println(key + "--->" + map.get(key));/ +// } + + // 瀹氫箟 BufferedReader杈撳叆娴佹潵璇诲彇URL鐨勫搷搴� + in = new BufferedReader(new InputStreamReader( + connection.getInputStream())); + String line; + while ((line = in.readLine()) != null) { + result += line; + } + } catch (Exception e) { + System.out.println("鍙戦�丟ET璇锋眰鍑虹幇寮傚父锛�" + e); + e.printStackTrace(); + } + // 浣跨敤finally鍧楁潵鍏抽棴杈撳叆娴� + finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception e2) { + e2.printStackTrace(); + } + } + return result; + } + + public static void main(String[] args) + { + System.out.println(sendGet("http://apis.map.qq.com/ws/geocoder/v1/", "address=" +"鍖椾含甯傛捣娣�鍖哄僵鍜屽潑璺捣娣�瑗垮ぇ琛�74鍙�" + "&key=" + "11")); + } + + /**鑾峰彇鐪�/甯�*/ + public static String[] getAddress(String lat, String lng, String key) + { + try{ + String str = sendGet("http://apis.map.qq.com/ws/geocoder/v1/", "location=" + lat + "," + lng + "&key=" + key); + JSONObject obj = JSONObject.fromObject(str); + if(obj != null && obj.optInt("status", -1) == 0) + { + obj = obj.optJSONObject("result"); + if(obj != null) + { + obj = obj.optJSONObject("address_component"); + if(obj != null) + { + String nation = obj.optString("nation"); + String province = obj.optString("province"); + String city = obj.optString("city"); + String area = obj.optString("district"); + String detail = obj.optString("street") + obj.optString("street_number"); + String[] addr = new String[]{ + new String(nation.getBytes(), "utf-8"), + new String(province.getBytes(), "utf-8"), + new String(city.getBytes(), "utf-8"), + new String(area.getBytes(), "utf-8"), + new String(detail.getBytes(), "utf-8") + }; + + return addr; + } + + return null; + } + } + }catch(Exception e) + { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/hx/util/ThreadPoolUtils.java b/src/main/java/com/hx/util/ThreadPoolUtils.java new file mode 100644 index 0000000..a30af25 --- /dev/null +++ b/src/main/java/com/hx/util/ThreadPoolUtils.java @@ -0,0 +1,42 @@ +package com.hx.util; + +import org.springframework.stereotype.Component; + +import java.util.concurrent.*; + +/** + * @PackageName com.hx.util + * @ProjectName hx-parent + * @Author: ChenJiaHe + * @Date: Create in 17:12 2019/8/6 + * @Description: + * @Copyright Copyright (c) 2019, hx01@163.com All Rights Reserved. + */ +@Component +public class ThreadPoolUtils { + + public static BlockingQueue<Runnable> queueToUse = new LinkedBlockingQueue<>(120); + + /** + * @param poolSize + * @param method + * @MethodName creatExeutorService + * @Description 鍒涘缓绾跨▼姹犳柟娉� + * @Auther ChenJiaHe + * @Date 2019/8/6 17:19 + * @Since JDK 1.8 + */ + public ExecutorService creatExeutorService(int poolSize, String method, BlockingQueue<Runnable> queueToUse) { + int coreSize = Runtime.getRuntime().availableProcessors(); + if (poolSize < coreSize) { + coreSize = poolSize; + } + ThreadFactory threadFactory = r -> { + Thread t = new Thread(r, "thread created mewthod{" + method + "}"); + t.setDaemon(true); + return t; + }; + final ThreadPoolExecutor executor = new ThreadPoolExecutor(coreSize, poolSize, 60, TimeUnit.SECONDS, queueToUse, threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } +} diff --git a/src/main/java/com/hx/util/WebUtil.java b/src/main/java/com/hx/util/WebUtil.java new file mode 100644 index 0000000..db82e3c --- /dev/null +++ b/src/main/java/com/hx/util/WebUtil.java @@ -0,0 +1,53 @@ +package com.hx.util; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import com.alibaba.fastjson.JSONObject; + +/** + * + * @author lijietian + * + */ +public class WebUtil { + /** + * 杩斿洖鏁版嵁缁欏墠绔殑鏂规硶 + * + * @param msg 杩斿洖鏁版嵁 + * + */ + public static void AJAXdata(String msg) { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletResponse response = attributes.getResponse(); + + response.setContentType("text/plain");// 鏂囨湰 + response.setHeader("Cache-Control", "no-store"); + response.setCharacterEncoding("utf-8"); + try { + PrintWriter pw = response.getWriter(); + pw.write(msg); + pw.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 缁勬垚缁熶竴鐨勬牸寮� + * + */ + public static String AJAXMsg(Integer status,String errorMsg,JSONObject obj) { + JSONObject info = new JSONObject(); + info.put("status", status); + info.put("errorMsg", errorMsg); + info.put("datas", obj); + return info.toJSONString(); + } + +} diff --git a/src/main/java/com/qq/weixin/mp/aes/AesException.java b/src/main/java/com/qq/weixin/mp/aes/AesException.java new file mode 100644 index 0000000..63b2ed7 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/AesException.java @@ -0,0 +1,59 @@ +package com.qq.weixin.mp.aes; + +@SuppressWarnings("serial") +public class AesException extends Exception { + + public final static int OK = 0; + public final static int ValidateSignatureError = -40001; + public final static int ParseXmlError = -40002; + public final static int ComputeSignatureError = -40003; + public final static int IllegalAesKey = -40004; + public final static int ValidateCorpidError = -40005; + public final static int EncryptAESError = -40006; + public final static int DecryptAESError = -40007; + public final static int IllegalBuffer = -40008; + //public final static int EncodeBase64Error = -40009; + //public final static int DecodeBase64Error = -40010; + //public final static int GenReturnXmlError = -40011; + + private int code; + + private static String getMessage(int code) { + switch (code) { + case ValidateSignatureError: + return "绛惧悕楠岃瘉閿欒"; + case ParseXmlError: + return "xml瑙f瀽澶辫触"; + case ComputeSignatureError: + return "sha鍔犲瘑鐢熸垚绛惧悕澶辫触"; + case IllegalAesKey: + return "SymmetricKey闈炴硶"; + case ValidateCorpidError: + return "corpid鏍¢獙澶辫触"; + case EncryptAESError: + return "aes鍔犲瘑澶辫触"; + case DecryptAESError: + return "aes瑙e瘑澶辫触"; + case IllegalBuffer: + return "瑙e瘑鍚庡緱鍒扮殑buffer闈炴硶"; +// case EncodeBase64Error: +// return "base64鍔犲瘑閿欒"; +// case DecodeBase64Error: +// return "base64瑙e瘑閿欒"; +// case GenReturnXmlError: +// return "xml鐢熸垚澶辫触"; + default: + return null; // cannot be + } + } + + public int getCode() { + return code; + } + + AesException(int code) { + super(getMessage(code)); + this.code = code; + } + +} diff --git a/src/main/java/com/qq/weixin/mp/aes/ByteGroup.java b/src/main/java/com/qq/weixin/mp/aes/ByteGroup.java new file mode 100644 index 0000000..6ba4330 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/ByteGroup.java @@ -0,0 +1,26 @@ +package com.qq.weixin.mp.aes; + +import java.util.ArrayList; + +class ByteGroup { + ArrayList<Byte> byteContainer = new ArrayList<Byte>(); + + public byte[] toBytes() { + byte[] bytes = new byte[byteContainer.size()]; + for (int i = 0; i < byteContainer.size(); i++) { + bytes[i] = byteContainer.get(i); + } + return bytes; + } + + public ByteGroup addBytes(byte[] bytes) { + for (byte b : bytes) { + byteContainer.add(b); + } + return this; + } + + public int size() { + return byteContainer.size(); + } +} diff --git a/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java b/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java new file mode 100644 index 0000000..f1dd021 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/PKCS7Encoder.java @@ -0,0 +1,67 @@ +/** + * 瀵逛紒涓氬井淇″彂閫佺粰浼佷笟鍚庡彴鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package com.qq.weixin.mp.aes; + +import java.nio.charset.Charset; +import java.util.Arrays; + +/** + * 鎻愪緵鍩轰簬PKCS7绠楁硶鐨勫姞瑙e瘑鎺ュ彛. + */ +class PKCS7Encoder { + static Charset CHARSET = Charset.forName("utf-8"); + static int BLOCK_SIZE = 32; + + /** + * 鑾峰緱瀵规槑鏂囪繘琛岃ˉ浣嶅~鍏呯殑瀛楄妭. + * + * @param count 闇�瑕佽繘琛屽~鍏呰ˉ浣嶆搷浣滅殑鏄庢枃瀛楄妭涓暟 + * @return 琛ラ綈鐢ㄧ殑瀛楄妭鏁扮粍 + */ + static byte[] encode(int count) { + // 璁$畻闇�瑕佸~鍏呯殑浣嶆暟 + int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); + if (amountToPad == 0) { + amountToPad = BLOCK_SIZE; + } + // 鑾峰緱琛ヤ綅鎵�鐢ㄧ殑瀛楃 + char padChr = chr(amountToPad); + String tmp = new String(); + for (int index = 0; index < amountToPad; index++) { + tmp += padChr; + } + return tmp.getBytes(CHARSET); + } + + /** + * 鍒犻櫎瑙e瘑鍚庢槑鏂囩殑琛ヤ綅瀛楃 + * + * @param decrypted 瑙e瘑鍚庣殑鏄庢枃 + * @return 鍒犻櫎琛ヤ綅瀛楃鍚庣殑鏄庢枃 + */ + static byte[] decode(byte[] decrypted) { + int pad = (int) decrypted[decrypted.length - 1]; + if (pad < 1 || pad > 32) { + pad = 0; + } + return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); + } + + /** + * 灏嗘暟瀛楄浆鍖栨垚ASCII鐮佸搴旂殑瀛楃锛岀敤浜庡鏄庢枃杩涜琛ョ爜 + * + * @param a 闇�瑕佽浆鍖栫殑鏁板瓧 + * @return 杞寲寰楀埌鐨勫瓧绗� + */ + static char chr(int a) { + byte target = (byte) (a & 0xFF); + return (char) target; + } + +} diff --git a/src/main/java/com/qq/weixin/mp/aes/SHA1.java b/src/main/java/com/qq/weixin/mp/aes/SHA1.java new file mode 100644 index 0000000..e460191 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/SHA1.java @@ -0,0 +1,61 @@ +/** + * 瀵逛紒涓氬井淇″彂閫佺粰浼佷笟鍚庡彴鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package com.qq.weixin.mp.aes; + +import java.security.MessageDigest; +import java.util.Arrays; + +/** + * SHA1 class + * + * 璁$畻娑堟伅绛惧悕鎺ュ彛. + */ +class SHA1 { + + /** + * 鐢⊿HA1绠楁硶鐢熸垚瀹夊叏绛惧悕 + * @param token 绁ㄦ嵁 + * @param timestamp 鏃堕棿鎴� + * @param nonce 闅忔満瀛楃涓� + * @param encrypt 瀵嗘枃 + * @return 瀹夊叏绛惧悕 + * @throws AesException + */ + public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException + { + try { + String[] array = new String[] { token, timestamp, nonce, encrypt }; + StringBuffer sb = new StringBuffer(); + // 瀛楃涓叉帓搴� + Arrays.sort(array); + for (int i = 0; i < 4; i++) { + sb.append(array[i]); + } + String str = sb.toString(); + // SHA1绛惧悕鐢熸垚 + MessageDigest md = MessageDigest.getInstance("SHA-1"); + md.update(str.getBytes()); + byte[] digest = md.digest(); + + StringBuffer hexstr = new StringBuffer(); + String shaHex = ""; + for (int i = 0; i < digest.length; i++) { + shaHex = Integer.toHexString(digest[i] & 0xFF); + if (shaHex.length() < 2) { + hexstr.append(0); + } + hexstr.append(shaHex); + } + return hexstr.toString(); + } catch (Exception e) { + e.printStackTrace(); + throw new AesException(AesException.ComputeSignatureError); + } + } +} diff --git a/src/main/java/com/qq/weixin/mp/aes/WXBizMsgCrypt.java b/src/main/java/com/qq/weixin/mp/aes/WXBizMsgCrypt.java new file mode 100644 index 0000000..308b1a0 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/WXBizMsgCrypt.java @@ -0,0 +1,296 @@ +/** + * 瀵逛紒涓氬井淇″彂閫佺粰浼佷笟鍚庡彴鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +/** + * 閽堝org.apache.commons.codec.binary.Base64锛� + * 闇�瑕佸鍏ユ灦鍖卌ommons-codec-1.9锛堟垨commons-codec-1.8绛夊叾浠栫増鏈級 + * 瀹樻柟涓嬭浇鍦板潃锛歨ttp://commons.apache.org/proper/commons-codec/download_codec.cgi + */ +package com.qq.weixin.mp.aes; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.Random; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 鎻愪緵鎺ユ敹鍜屾帹閫佺粰浼佷笟寰俊娑堟伅鐨勫姞瑙e瘑鎺ュ彛(UTF8缂栫爜鐨勫瓧绗︿覆). + * <ol> + * <li>绗笁鏂瑰洖澶嶅姞瀵嗘秷鎭粰浼佷笟寰俊</li> + * <li>绗笁鏂规敹鍒颁紒涓氬井淇″彂閫佺殑娑堟伅锛岄獙璇佹秷鎭殑瀹夊叏鎬э紝骞跺娑堟伅杩涜瑙e瘑銆�</li> + * </ol> + * 璇存槑锛氬紓甯竕ava.security.InvalidKeyException:illegal Key Size鐨勮В鍐虫柟妗� + * <ol> + * <li>鍦ㄥ畼鏂圭綉绔欎笅杞絁CE鏃犻檺鍒舵潈闄愮瓥鐣ユ枃浠讹紙JDK7鐨勪笅杞藉湴鍧�锛� + * http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html</li> + * <li>涓嬭浇鍚庤В鍘嬶紝鍙互鐪嬪埌local_policy.jar鍜孶S_export_policy.jar浠ュ強readme.txt</li> + * <li>濡傛灉瀹夎浜咼RE锛屽皢涓や釜jar鏂囦欢鏀惧埌%JRE_HOME%\lib\security鐩綍涓嬭鐩栧師鏉ョ殑鏂囦欢</li> + * <li>濡傛灉瀹夎浜咼DK锛屽皢涓や釜jar鏂囦欢鏀惧埌%JDK_HOME%\jre\lib\security鐩綍涓嬭鐩栧師鏉ユ枃浠�</li> + * </ol> + */ +public class WXBizMsgCrypt { + + //log4j鏃ュ織 + private static Logger logger = LoggerFactory.getLogger(WXBizMsgCrypt.class.getName()); + + static Charset CHARSET = Charset.forName("utf-8"); + Base64 base64 = new Base64(); + byte[] aesKey; + String token; + String receiveid; + + /** + * 鏋勯�犲嚱鏁� + * @param token 浼佷笟寰俊鍚庡彴锛屽紑鍙戣�呰缃殑token + * @param encodingAesKey 浼佷笟寰俊鍚庡彴锛屽紑鍙戣�呰缃殑EncodingAESKey + * @param receiveid, 涓嶅悓鍦烘櫙鍚箟涓嶅悓锛岃瑙佹枃妗� + * + * @throws AesException 鎵ц澶辫触锛岃鏌ョ湅璇ュ紓甯哥殑閿欒鐮佸拰鍏蜂綋鐨勯敊璇俊鎭� + */ + public WXBizMsgCrypt(String token, String encodingAesKey, String receiveid) throws AesException { + if (encodingAesKey.length() != 43) { + throw new AesException(AesException.IllegalAesKey); + } + + this.token = token; + this.receiveid = receiveid; + aesKey = Base64.decodeBase64(encodingAesKey + "="); + } + + // 鐢熸垚4涓瓧鑺傜殑缃戠粶瀛楄妭搴� + byte[] getNetworkBytesOrder(int sourceNumber) { + byte[] orderBytes = new byte[4]; + orderBytes[3] = (byte) (sourceNumber & 0xFF); + orderBytes[2] = (byte) (sourceNumber >> 8 & 0xFF); + orderBytes[1] = (byte) (sourceNumber >> 16 & 0xFF); + orderBytes[0] = (byte) (sourceNumber >> 24 & 0xFF); + return orderBytes; + } + + // 杩樺師4涓瓧鑺傜殑缃戠粶瀛楄妭搴� + int recoverNetworkBytesOrder(byte[] orderBytes) { + int sourceNumber = 0; + for (int i = 0; i < 4; i++) { + sourceNumber <<= 8; + sourceNumber |= orderBytes[i] & 0xff; + } + return sourceNumber; + } + + // 闅忔満鐢熸垚16浣嶅瓧绗︿覆 + String getRandomStr() { + String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < 16; i++) { + int number = random.nextInt(base.length()); + sb.append(base.charAt(number)); + } + return sb.toString(); + } + + /** + * 瀵规槑鏂囪繘琛屽姞瀵�. + * + * @param text 闇�瑕佸姞瀵嗙殑鏄庢枃 + * @return 鍔犲瘑鍚巄ase64缂栫爜鐨勫瓧绗︿覆 + * @throws AesException aes鍔犲瘑澶辫触 + */ + String encrypt(String randomStr, String text) throws AesException { + ByteGroup byteCollector = new ByteGroup(); + byte[] randomStrBytes = randomStr.getBytes(CHARSET); + byte[] textBytes = text.getBytes(CHARSET); + byte[] networkBytesOrder = getNetworkBytesOrder(textBytes.length); + byte[] receiveidBytes = receiveid.getBytes(CHARSET); + + // randomStr + networkBytesOrder + text + receiveid + byteCollector.addBytes(randomStrBytes); + byteCollector.addBytes(networkBytesOrder); + byteCollector.addBytes(textBytes); + byteCollector.addBytes(receiveidBytes); + + // ... + pad: 浣跨敤鑷畾涔夌殑濉厖鏂瑰紡瀵规槑鏂囪繘琛岃ˉ浣嶅~鍏� + byte[] padBytes = PKCS7Encoder.encode(byteCollector.size()); + byteCollector.addBytes(padBytes); + + // 鑾峰緱鏈�缁堢殑瀛楄妭娴�, 鏈姞瀵� + byte[] unencrypted = byteCollector.toBytes(); + + try { + // 璁剧疆鍔犲瘑妯″紡涓篈ES鐨凜BC妯″紡 + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES"); + IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16); + cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); + + // 鍔犲瘑 + byte[] encrypted = cipher.doFinal(unencrypted); + + // 浣跨敤BASE64瀵瑰姞瀵嗗悗鐨勫瓧绗︿覆杩涜缂栫爜 + String base64Encrypted = base64.encodeToString(encrypted); + + return base64Encrypted; + } catch (Exception e) { + e.printStackTrace(); + throw new AesException(AesException.EncryptAESError); + } + } + + /** + * 瀵瑰瘑鏂囪繘琛岃В瀵�. + * + * @param text 闇�瑕佽В瀵嗙殑瀵嗘枃 + * @return 瑙e瘑寰楀埌鐨勬槑鏂� + * @throws AesException aes瑙e瘑澶辫触 + */ + String decrypt(String text) throws AesException { + byte[] original; + try { + // 璁剧疆瑙e瘑妯″紡涓篈ES鐨凜BC妯″紡 + Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); + SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); + IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); + cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); + + // 浣跨敤BASE64瀵瑰瘑鏂囪繘琛岃В鐮� + byte[] encrypted = Base64.decodeBase64(text); + + // 瑙e瘑 + original = cipher.doFinal(encrypted); + } catch (Exception e) { + logger.info("aes瑙e瘑鎶ラ敊锛�",e); + e.printStackTrace(); + throw new AesException(AesException.DecryptAESError); + } + + String xmlContent, from_receiveid; + try { + // 鍘婚櫎琛ヤ綅瀛楃 + byte[] bytes = PKCS7Encoder.decode(original); + + // 鍒嗙16浣嶉殢鏈哄瓧绗︿覆,缃戠粶瀛楄妭搴忓拰receiveid + byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20); + + int xmlLength = recoverNetworkBytesOrder(networkOrder); + + xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); + from_receiveid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), + CHARSET); + } catch (Exception e) { + e.printStackTrace(); + throw new AesException(AesException.IllegalBuffer); + } + + // receiveid涓嶇浉鍚岀殑鎯呭喌 + if (!from_receiveid.equals(receiveid)) { + throw new AesException(AesException.ValidateCorpidError); + } + return xmlContent; + + } + + /** + * 灏嗕紒涓氬井淇″洖澶嶇敤鎴风殑娑堟伅鍔犲瘑鎵撳寘. + * <ol> + * <li>瀵硅鍙戦�佺殑娑堟伅杩涜AES-CBC鍔犲瘑</li> + * <li>鐢熸垚瀹夊叏绛惧悕</li> + * <li>灏嗘秷鎭瘑鏂囧拰瀹夊叏绛惧悕鎵撳寘鎴恱ml鏍煎紡</li> + * </ol> + * + * @param replyMsg 浼佷笟寰俊寰呭洖澶嶇敤鎴风殑娑堟伅锛寈ml鏍煎紡鐨勫瓧绗︿覆 + * @param timeStamp 鏃堕棿鎴筹紝鍙互鑷繁鐢熸垚锛屼篃鍙互鐢║RL鍙傛暟鐨則imestamp + * @param nonce 闅忔満涓诧紝鍙互鑷繁鐢熸垚锛屼篃鍙互鐢║RL鍙傛暟鐨刵once + * + * @return 鍔犲瘑鍚庣殑鍙互鐩存帴鍥炲鐢ㄦ埛鐨勫瘑鏂囷紝鍖呮嫭msg_signature, timestamp, nonce, encrypt鐨剎ml鏍煎紡鐨勫瓧绗︿覆 + * @throws AesException 鎵ц澶辫触锛岃鏌ョ湅璇ュ紓甯哥殑閿欒鐮佸拰鍏蜂綋鐨勯敊璇俊鎭� + */ + public String EncryptMsg(String replyMsg, String timeStamp, String nonce) throws AesException { + // 鍔犲瘑 + String encrypt = encrypt(getRandomStr(), replyMsg); + + // 鐢熸垚瀹夊叏绛惧悕 + if (timeStamp == "") { + timeStamp = Long.toString(System.currentTimeMillis()); + } + + String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt); + + // System.out.println("鍙戦�佺粰骞冲彴鐨勭鍚嶆槸: " + signature[1].toString()); + // 鐢熸垚鍙戦�佺殑xml + String result = XMLParse.generate(encrypt, signature, timeStamp, nonce); + return result; + } + + /** + * 妫�楠屾秷鎭殑鐪熷疄鎬э紝骞朵笖鑾峰彇瑙e瘑鍚庣殑鏄庢枃. + * <ol> + * <li>鍒╃敤鏀跺埌鐨勫瘑鏂囩敓鎴愬畨鍏ㄧ鍚嶏紝杩涜绛惧悕楠岃瘉</li> + * <li>鑻ラ獙璇侀�氳繃锛屽垯鎻愬彇xml涓殑鍔犲瘑娑堟伅</li> + * <li>瀵规秷鎭繘琛岃В瀵�</li> + * </ol> + * + * @param msgSignature 绛惧悕涓诧紝瀵瑰簲URL鍙傛暟鐨刴sg_signature + * @param timeStamp 鏃堕棿鎴筹紝瀵瑰簲URL鍙傛暟鐨則imestamp + * @param nonce 闅忔満涓诧紝瀵瑰簲URL鍙傛暟鐨刵once + * @param postData 瀵嗘枃锛屽搴擯OST璇锋眰鐨勬暟鎹� + * + * @return 瑙e瘑鍚庣殑鍘熸枃 + * @throws AesException 鎵ц澶辫触锛岃鏌ョ湅璇ュ紓甯哥殑閿欒鐮佸拰鍏蜂綋鐨勯敊璇俊鎭� + */ + public String DecryptMsg(String msgSignature, String timeStamp, String nonce, String postData) + throws AesException { + + // 瀵嗛挜锛屽叕浼楄处鍙风殑app secret + // 鎻愬彇瀵嗘枃 + Object[] encrypt = XMLParse.extract(postData); + + // 楠岃瘉瀹夊叏绛惧悕 + String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt[1].toString()); + + // 鍜孶RL涓殑绛惧悕姣旇緝鏄惁鐩哥瓑 + // System.out.println("绗笁鏂规敹鍒癠RL涓殑绛惧悕锛�" + msg_sign); + // System.out.println("绗笁鏂规牎楠岀鍚嶏細" + signature); + if (!signature.equals(msgSignature)) { + throw new AesException(AesException.ValidateSignatureError); + } + + // 瑙e瘑 + String result = decrypt(encrypt[1].toString()); + return result; + } + + /** + * 楠岃瘉URL + * @param msgSignature 绛惧悕涓诧紝瀵瑰簲URL鍙傛暟鐨刴sg_signature + * @param timeStamp 鏃堕棿鎴筹紝瀵瑰簲URL鍙傛暟鐨則imestamp + * @param nonce 闅忔満涓诧紝瀵瑰簲URL鍙傛暟鐨刵once + * @param echoStr 闅忔満涓诧紝瀵瑰簲URL鍙傛暟鐨別chostr + * + * @return 瑙e瘑涔嬪悗鐨別chostr + * @throws AesException 鎵ц澶辫触锛岃鏌ョ湅璇ュ紓甯哥殑閿欒鐮佸拰鍏蜂綋鐨勯敊璇俊鎭� + */ + public String VerifyURL(String msgSignature, String timeStamp, String nonce, String echoStr) + throws AesException { + String signature = SHA1.getSHA1(token, timeStamp, nonce, echoStr); + + if (!signature.equals(msgSignature)) { + throw new AesException(AesException.ValidateSignatureError); + } + + String result = decrypt(echoStr); + return result; + } + +} \ No newline at end of file diff --git a/src/main/java/com/qq/weixin/mp/aes/XMLParse.java b/src/main/java/com/qq/weixin/mp/aes/XMLParse.java new file mode 100644 index 0000000..4e5b652 --- /dev/null +++ b/src/main/java/com/qq/weixin/mp/aes/XMLParse.java @@ -0,0 +1,106 @@ +/** + * 瀵逛紒涓氬井淇″彂閫佺粰浼佷笟鍚庡彴鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package com.qq.weixin.mp.aes; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * XMLParse class + * + * 鎻愪緵鎻愬彇娑堟伅鏍煎紡涓殑瀵嗘枃鍙婄敓鎴愬洖澶嶆秷鎭牸寮忕殑鎺ュ彛. + */ +class XMLParse { + + /** + * 鎻愬彇鍑簒ml鏁版嵁鍖呬腑鐨勫姞瀵嗘秷鎭� + * @param xmltext 寰呮彁鍙栫殑xml瀛楃涓� + * @return 鎻愬彇鍑虹殑鍔犲瘑娑堟伅瀛楃涓� + * @throws AesException + */ + public static Object[] extract(String xmltext) throws AesException { + Object[] result = new Object[3]; + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + String FEATURE = null; + // This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented + // Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl + FEATURE = "http://apache.org/xml/features/disallow-doctype-decl"; + dbf.setFeature(FEATURE, true); + + // If you can't completely disable DTDs, then at least do the following: + // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities + // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities + // JDK7+ - http://xml.org/sax/features/external-general-entities + FEATURE = "http://xml.org/sax/features/external-general-entities"; + dbf.setFeature(FEATURE, false); + + // Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-parameter-entities + // Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities + // JDK7+ - http://xml.org/sax/features/external-parameter-entities + FEATURE = "http://xml.org/sax/features/external-parameter-entities"; + dbf.setFeature(FEATURE, false); + + // Disable external DTDs as well + FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd"; + dbf.setFeature(FEATURE, false); + + // and these as well, per Timothy Morgan's 2014 paper: "XML Schema, DTD, and Entity Attacks" + dbf.setXIncludeAware(false); + dbf.setExpandEntityReferences(false); + + // And, per Timothy Morgan: "If for some reason support for inline DOCTYPEs are a requirement, then + // ensure the entity settings are disabled (as shown above) and beware that SSRF attacks + // (http://cwe.mitre.org/data/definitions/918.html) and denial + // of service attacks (such as billion laughs or decompression bombs via "jar:") are a risk." + + // remaining parser logic + DocumentBuilder db = dbf.newDocumentBuilder(); + StringReader sr = new StringReader(xmltext); + InputSource is = new InputSource(sr); + Document document = db.parse(is); + + Element root = document.getDocumentElement(); + NodeList nodelist1 = root.getElementsByTagName("Encrypt"); + NodeList nodelist2 = root.getElementsByTagName("ToUserName"); + result[0] = 0; + result[1] = nodelist1.item(0).getTextContent(); + result[2] = nodelist2.item(0).getTextContent(); + return result; + } catch (Exception e) { + e.printStackTrace(); + throw new AesException(AesException.ParseXmlError); + } + } + + /** + * 鐢熸垚xml娑堟伅 + * @param encrypt 鍔犲瘑鍚庣殑娑堟伅瀵嗘枃 + * @param signature 瀹夊叏绛惧悕 + * @param timestamp 鏃堕棿鎴� + * @param nonce 闅忔満瀛楃涓� + * @return 鐢熸垚鐨剎ml瀛楃涓� + */ + public static String generate(String encrypt, String signature, String timestamp, String nonce) { + + String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n" + + "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n" + + "<TimeStamp>%3$s</TimeStamp>\n" + "<Nonce><![CDATA[%4$s]]></Nonce>\n" + "</xml>"; + return String.format(format, encrypt, signature, timestamp, nonce); + + } +} diff --git a/src/main/main.iml b/src/main/main.iml new file mode 100644 index 0000000..be3c92e --- /dev/null +++ b/src/main/main.iml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" /> + </component> +</module> \ No newline at end of file -- Gitblit v1.8.0