Commit 122cd1e7 authored by aiden's avatar aiden

Default Changelist

parents
Pipeline #340 failed with stages
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
This diff is collapsed.
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pvuv</groupId>
<artifactId>pvuv</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pvuv</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<selenium.version>2.42.2</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.movitech.apollo</groupId>
<artifactId>apollo-framework</artifactId>
<version>0.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.pvuv.pvuv;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PvuvApplication {
public static void main(String[] args) {
SpringApplication.run(PvuvApplication.class, args);
}
}
This diff is collapsed.
package com.pvuv.pvuv.model;
import java.math.BigDecimal;
import java.util.List;
/**
* Created by allen on 2018/4/3.
*/
public class MiniprogramUv {
private List<PUv> list;
public List<PUv> getList() {
return list;
}
public void setList(List<PUv> list) {
this.list = list;
}
public class PUv{
/**
* 日期
*/
private String ref_date;
/**
* session次数
*/
private Integer session_cnt;
/**
* pv数据
*/
private Integer visit_pv;
/**
* uv数据
*/
private Integer visit_uv;
/**
* 新uv数据
*/
private Integer visit_uv_new;
/**
* 次均停留时长
*/
private BigDecimal stay_time_uv;
/**
* stay_time_session
*/
private BigDecimal stay_time_session;
/**
* 访问深度
*/
private BigDecimal visit_depth;
/**
*
* @return
*/
public String getRef_date() {
return ref_date;
}
public void setRef_date(String ref_date) {
this.ref_date = ref_date;
}
public Integer getSession_cnt() {
return session_cnt;
}
public void setSession_cnt(Integer session_cnt) {
this.session_cnt = session_cnt;
}
public Integer getVisit_pv() {
return visit_pv;
}
public void setVisit_pv(Integer visit_pv) {
this.visit_pv = visit_pv;
}
public Integer getVisit_uv() {
return visit_uv;
}
public void setVisit_uv(Integer visit_uv) {
this.visit_uv = visit_uv;
}
public Integer getVisit_uv_new() {
return visit_uv_new;
}
public void setVisit_uv_new(Integer visit_uv_new) {
this.visit_uv_new = visit_uv_new;
}
public BigDecimal getStay_time_uv() {
return stay_time_uv;
}
public void setStay_time_uv(BigDecimal stay_time_uv) {
this.stay_time_uv = stay_time_uv;
}
public BigDecimal getStay_time_session() {
return stay_time_session;
}
public void setStay_time_session(BigDecimal stay_time_session) {
this.stay_time_session = stay_time_session;
}
public BigDecimal getVisit_depth() {
return visit_depth;
}
public void setVisit_depth(BigDecimal visit_depth) {
this.visit_depth = visit_depth;
}
}
}
This diff is collapsed.
package com.pvuv.pvuv.util;
import org.apache.http.Consts;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.charset.CodingErrorAction;
/**
* Created by villiam on 17/6/8.
*/
public class HttpClientConnectionPool {
private static final Logger LOG = LoggerFactory.getLogger(HttpClientConnectionPool.class);
static final int timeOut = 50 * 1000;
static PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
static {
connectionManager.setMaxTotal(2000);
connectionManager.setDefaultMaxPerRoute(1000);
connectionManager.setDefaultSocketConfig(getSocketConfig());
connectionManager.setDefaultConnectionConfig(getConnectionConfig());
}
public static CloseableHttpClient getClient(){
return HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(getRequestConfig())
.build();
}
private static RequestConfig getRequestConfig() {
// 配置请求的超时设置
return RequestConfig.custom()
.setConnectionRequestTimeout(timeOut)
.setConnectTimeout(timeOut).setSocketTimeout(timeOut).build();
}
private static SocketConfig getSocketConfig(){
return SocketConfig.custom()
.setTcpNoDelay(true) //是否立即发送数据,设置为true会关闭Socket缓冲,默认为false
.setSoReuseAddress(true) //是否可以在一个进程关闭Socket后,即使它还没有释放端口,其它进程还可以立即重用端口
.setSoTimeout(50000) //接收数据的等待超时时间,单位ms
.setSoLinger(6) //关闭Socket时,要么发送完所有数据,要么等待60s后,就关闭连接,此时socket.close()是阻塞的
.setSoKeepAlive(true) //开启监视TCP连接是否有效
.build();
}
private static ConnectionConfig getConnectionConfig(){
return ConnectionConfig.custom()
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.setCharset(Consts.UTF_8)
.build();
}
public static void releaseResponse(CloseableHttpResponse httpResponse){
try {
if(null != httpResponse){
httpResponse.close();
}
}catch (IOException e){
LOG.error("shut down response error happened: "+e.getMessage());
}
}
}
package com.pvuv.pvuv.util;
import com.google.gson.Gson;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by villiam on 16/7/19.
*/
public class HttpUtils {
private static final Logger LOG = LoggerFactory.getLogger(HttpUtils.class);
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
/**
* POST请求
*
* @param url
* URL
* @param parameterMap
* 请求参数
* @return 返回结果
*/
public static String post(String url, Map<String, Object> parameterMap) {
Assert.hasText(url);
String result = null;
Gson gson = new Gson();
CloseableHttpClient httpclient = HttpClientConnectionPool.getClient();
CloseableHttpResponse httpResponse = null;
try {
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (parameterMap != null) {
for (Map.Entry<String, Object> entry : parameterMap.entrySet()) {
String name = entry.getKey();
String value = ConvertUtils.convert(entry.getValue());
if (StringUtils.isNotEmpty(name)) {
nameValuePairs.add(new BasicNameValuePair(name, value));
}
}
}
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
httpResponse = httpclient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
HttpClientConnectionPool.releaseResponse(httpResponse);
}
return result;
}
/**
* GET请求
*
* @param url
* URL
* @param parameterMap
* 请求参数
* @return 返回结果
*/
public static String get(String url, Map<String, Object> parameterMap) {
Assert.hasText(url);
String result = null;
CloseableHttpClient httpClient = HttpClientConnectionPool.getClient();
CloseableHttpResponse httpResponse = null;
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (parameterMap != null) {
for (Map.Entry<String, Object> entry : parameterMap.entrySet()) {
String name = entry.getKey();
String value = ConvertUtils.convert(entry.getValue());
if (StringUtils.isNotEmpty(name)) {
nameValuePairs.add(new BasicNameValuePair(name, value));
}
}
}
HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")));
httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
HttpClientConnectionPool.releaseResponse(httpResponse);
}
return result;
}
/**
* GET请求
*
* @param url
* URL
* @param header
* Header
* @param parameterMap
* 请求参数
* @return 返回结果
*/
public static String getWithHeader(String url,String header, Map<String, Object> parameterMap) {
Assert.hasText(url);
String result = null;
CloseableHttpClient httpclient = HttpClientConnectionPool.getClient();
CloseableHttpResponse httpResponse = null;
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (parameterMap != null) {
for (Map.Entry<String, Object> entry : parameterMap.entrySet()) {
String name = entry.getKey();
String value = ConvertUtils.convert(entry.getValue());
if (StringUtils.isNotEmpty(name)) {
nameValuePairs.add(new BasicNameValuePair(name, value));
}
}
}
HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")));
httpGet.setHeader("apikey",header);
httpResponse = httpclient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
HttpClientConnectionPool.releaseResponse(httpResponse);
}
return result;
}
/**
* 得到HTTP请求body中的JSON字符串
* @param inputStream
* @return
* @throws IOException
*/
public static String getRequestBody(InputStream inputStream) throws IOException {
Gson gson = new Gson();
Reader input = new InputStreamReader(inputStream,"UTF-8");
Writer output = new StringWriter();
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int n = 0;
while(-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return gson.toJson(output.toString());
}
/**
* POST请求
*
* @param url
* URL
* @param body
* 请求参数
* @return 返回结果
*/
public static String postWithBody(String url,Map<String, String> headers, String body) {
Assert.hasText(url);
String result = null;
CloseableHttpClient httpClient = HttpClientConnectionPool.getClient();
CloseableHttpResponse httpResponse = null;
try {
HttpPost httpPost = new HttpPost(url);
// 添加http headers
if (headers != null && headers.size() > 0) {
for (String key : headers.keySet()) {
httpPost.addHeader(key, headers.get(key));
}
}
httpPost.setHeader("Content-Type","application/json");
httpPost.setEntity(new StringEntity(body,"UTF-8"));
httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (ClientProtocolException e) {
LOG.error(e.toString() + "http response result is " + result);
e.printStackTrace();
} catch (Exception e) {
LOG.error(e.toString() + "http response result is " + result);
e.printStackTrace();
} finally {
HttpClientConnectionPool.releaseResponse(httpResponse);
}
return result;
}
}
package com.pvuv.pvuv.util;
import java.util.HashMap;
import java.util.Map;
public class SystemConstant {
//登录类型
public static final int LOGIN_TYPE_WEB = 0;
public static final int LOGIN_TYPE_ANDROID = 1;
public static final String COOKIE_USER_PRE = "ubaby_user_";
public static final String COOKIE_PSW_PRE = "ubaby_psw_";
//WEB SERVICE URL映射常量地址
public static final String WS_URL_LOGIN = "/login/{accountCode}/{password}";
public static final String WS_URL_LIST_ALLBRAND = "/listAllBrand/{token}";
public static final String WS_URL_LIST_ALLCATEGORY = "/listAllCategory/{token}";
public static final String WS_URL_LIST_ALLFOLDER = "/listAllFolder/{token}";
public static final String WS_URL_LIST_BRAND_FOLDER = "/listBrandFolder/{brandId}/{token}";
//URL映射常量地址
public static final String URL_REALTIME_CONTROLLER = "/realtime";
public static final String URL_TAOBAOMESSAGE_CONTROLLER = "/externalInterface";
public static final String URL_WAREHOUSE_CONTROLLER = "/warehouse";
public static final String URL_REALTIMEINTER_CONTROLLER = "/realtimeInterface";
public static final String URL_API_CREATED = "/api/created";
public static final String URL_USER_CONTROLLER = "/userController";
public static final String URL_EMAIL_CONTROLLER = "/emailController";
public static final String URL_FTP_CONTROLLER = "/ftpController";
public static final String URL_SWITCH_CONTROLLER = "/switchController";
public static final String URL_ROLE_CONTROLLER = "/roleController";
public static final String URL_RESOURCE_CONTROLLER = "/resourceController";
public static final String URL_MENU_CONTROLLER = "/menuController";
public static final String URL_GROUP_CONTROLLER = "/groupController";
public static final String URL_JOB_CONTROLLER = "/ckcjob";
public static final String URL_JOB_SHOPEXCHANGE = "/shopExchange";
public static final String URL_SCHEDULE_CONTROLLER = "/ckSchedule";
public static final String URL_SHOP_CONTROLLER = "/shop";
public static final String URL_CUSTOMER_CONTROLLER = "/customer";
public static final String URL_COMMON = "/common";
public static final String URL_TAOBAOAG_CONTROLLER ="/taobaoAG";
public static final String URL_OA_CONTROLLER = "/oa";
public static final String URL_CUSTOMER_LOG_CONTROLLER = "/customerlog";
public static final String URL_PROMOTION_CONTROLLER= "/promotion";
public static final String URL_SHOPMANAGER_CONTROLLER = "/shopManager";
public static final String URL_JOBMANAGER_CONTROLLER = "/jobManager";
public static final String URL_PRICEMANAGER_CONTROLLER = "/priceManager";
public static final String URL_ALIPAYSTATEMENT_CONTROLLER = "/alipayStatement";
public static final String URL_GOODS_CONTROLLER = "/goods";
public static final String URL_WEEK_REPORT_CONTROLLER = "/weekReport";
public static final String URL_INVENTORY_CONTROLLER = "/inventory";
public static final String URL_MATCHPRODUCT_CONTROLLER = "/matchProduct";
public static final String URL_PRODUCT_CONTROLLER = "/product";
public static final String URL_DIVIDE_CONTROLLER = "/divide";
public static final String URL_CATEGORY_CONTROLLER = "/category";
public static final String URL_ORDER_LOG_CONTROLLER = "/orderLog";
public static final String URL_ORDER_CONTROLLER = "/order";
public static final String URL_SHIPPING_CONTROLLER = "/ship";
public static final String URL_HISTORYORDER_CONTROLLER = "/historyOrder";
public static final String URL_PM_CONTROLLER = "/pmController";
public static final String URL_RETURN_CONTROLLER = "/return";
public static final String URL_REPEAT_CONTROLLER = "/repeat";
public static final String URL_VIP_CONTROLLER = "/vip";
public static final String URL_SHORTSTOCK_CONTROLLER = "/shortStock";
public static final String URL_UPPRODUCT_CONTROLLER = "/upproduct";
public static final String URL_WECHATPAY_CONTROLLER = "/wechatPay";
public static final String URL_RESERVE_CONTROLLER = "/reserve";
public static final String URL_PRESALE_CONTROLLER = "/presale";
public static final String URL_REPORT_CONTROLLER = "/report";
public static final String URL_MERGE_ORDER_CONTROLLER = "/mergeOrder";
public static final String URL_RETURNREPORT_CONTROLLER = "/returnReport";
public static final String URL_USER_REGISTER = "/reg";
public static final String URL_USER_LOGIN = "/login";
public static final String URL_USER_LOGOUT = "/logout";
public static final String URL_COMBOGRID = "/combogrid";
public static final String URL_COMBOBOX = "/combobox";
public static final String URL_DATAGRID = "/datagrid";
public static final String URL_REMOVE = "/remove";
public static final String URL_UPDATE_STATUS= "/updateStatus";
public static final String URL_ADD = "/add";
public static final String URL_EDIT = "/edit";
public static final String URL_MODIFY_ROLE = "/modifyRole";
public static final String URL_MODIFY_GROUP = "/modifyGroup";
public static final String URL_MODIFY_PWD = "/modifyPwd";
public static final String URL_CURRENT_USER_PWD = "/modifyCurrentUserPwd";
public static final String URL_USER_INFO = "/userInfo";
public static final String URL_TREE_GRID = "/treegrid";
public static final String URL_ALLTREE_GRID = "/allTreeNode";
public static final String URL_ORDER_HANGS="/taobaoTrade";
public static final String URL_EDIT_TRADEADDRESS="/taobaoaddress";
public static final String URL_GUAVA_CATCH = "/guava";
//VIEW地址
public static final String VIEW_USER_INFO = "user/userInfo";
//常用格式
public static final String FORMAT_DATE_YMDHMS = "yyyy-MM-dd HH:mm:ss";
public static final String FORMAT_DATE_HH = "HH";
public static final String FORMAT_DATE_YMDHMS_STRING = "yyyyMMddHHmmss";
public static final String FORMAT_DATE_YMD = "yyyy-MM-dd";
public static final String FORMAT_MONTH = "yyyy-MM";
public static final String FORMAT_DATE_YYMMDD = "yyyyMMdd";
public static final String FORMAT_DATE_YYMM = "yyyyMM";
public static final String FORMAT_DATE_MDYHMS = "MM/dd/yy HH:mm";
public static final String CRON_DATE_FORMAT = "ss mm HH dd MM ? yyyy";
//消息字符串
public static final String MSG_REGISTER_SUCCESS = "注册成功!";
public static final String MSG_DELETE_SUCCESS = "删除成功!";
public static final String MSG_DELETE_FAIL = "删除失败!";
public static final String MSG_LOGIN_SUCCESS = "登录成功!";
public static final String MSG_LOGIN_FAIL = "登录失败!";
public static final String MSG_ADD_SUCCESS = "添加成功!";
public static final String MSG_ADD_FAIL = "添加失败!";
public static final String MSG_EDIT_SUCCESS = "修改成功!";
public static final String MSG_EDIT_FAIL = "修改失败!";
public static final String MSG_RECORD_ALREADY_EXIST = "记录已经存在!";
public static final String MSG_UPLOAD_SUCCESS = "上传成功!";
public static final String MSG_UPLOAD_FAIL = "上传失败!";
public static final String MSG_SUCCESS_DELIVERY = "发货成功!";
public static final String MSG_FAILED_DELIVERY = "发货失败!";
public static final String JOB_LAUNCH_FAIL ="Job启动失败!";
public static final String JOB_LAUNCH_SUCCESS="Job启动成功!";
public static final String JOB_CORRECTNESS_INFOR="请填写店铺与时间!";
public static final String JOB_ERROR_INFO = "Job错误信息:";
public static final String JOB_STOP_SUCCESS="已经停止了{0}个Job!";
public static final String JOB_STOP_FAIL="停止Job失败,错误信息如下:";
public static final String MSG_ORDEREXPORT_FAIL = "订单导出失败!";
public static final String MSG_ORDEREXPORT_SUCCESS = "订单导出成功!";
public static final String SHOP_ID_NOT_IN=" and shopid !=5 and shopid !=10 and shopid !=12 and shopid !=31";
public static final String DAILY_REPORT_SHOP_ID_NOT_IN=" and shopid !=5 and shopid !=10 and shopid !=31 and shopid !=6 and shopid !=12 and !ISNULL(shopid)";
public static final String PROMOTION="promotion_";
// 品牌名字
public static final String BRAND_CK="ck";
public static final String BRAND_PEDRO="pedro";
public static Map<String,String> kuaiDi100 = new HashMap<String, String>();
static {
kuaiDi100.put("sf","shunfeng");
kuaiDi100.put("COD","jd");
kuaiDi100.put("CSCOD","shunfeng");
kuaiDi100.put("EMS","EMS");
kuaiDi100.put("ZTO","zhongtong");
}
}
package com.pvuv.pvuv.util;
import com.movitech.apollo.foundation.util.SequenceUtils;
import com.movitech.apollo.seamwork.model.Guidable;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
/**
* General utility classes<br>
* <br>
*
* @created Jan 25, 2007 @ 12:14:05 PM
* @author dzhao
* @version 1.0
*/
public final class Utils {
// For random string/GUID generation
public static final String UPPER_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String LOWER_ALPHA = "abcdefghijklmnopqrstuvwxyz";
public static final String ALPHA = UPPER_ALPHA + LOWER_ALPHA;
public static final String ALPHANUMERIC = ALPHA + "0123456789";
public static final String GUID_ALPHA = ALPHANUMERIC + "-_";
private static final Random RANDOM = new Random();
public static String integrityFileFolderLocation(String location) {
if (!location.substring(location.length()-1).equals("/")) {
return location + "/";
}
return location;
}
public static Double getDoubleValueOf(String doubleValue) {
if (doubleValue != null) {
return Double.valueOf(doubleValue);
} else {
return 0.00;
}
}
public static Double getDoubleValueOf(Long doubleValue) {
return getDoubleValueOf(doubleValue.toString());
}
/**
* Create a random GUID of the maximum length<br>
* First and last chars have to be alphanumeric
*
* @return random guid
*/
public static final String randomProductGuid() {
return "CK-" + randomString(ALPHANUMERIC, 1) + randomString(GUID_ALPHA, 28 - 2) + randomString(ALPHANUMERIC, 1);
}
/**
* Create a random GUID of the maximum length<br>
* First and last chars have to be alphanumeric
*
* @return random guid
*/
public static final String randomGuid() {
return randomString(ALPHANUMERIC, 1) + randomString(GUID_ALPHA, Guidable.MAX_GUID_SIZE - 2) + randomString(ALPHANUMERIC, 1);
}
/**
* Create a string of random characters given an alphabet
*
* @param alpha
* @param length
* @return random string
*/
public static final String randomString(String alpha, int length) {
StringBuilder out = new StringBuilder();
for (int i = 0; i < length; i++) {
out.append(alpha.charAt(RANDOM.nextInt(alpha.length())));
}
return out.toString();
}
/**
* Generate a number of random integer
*
* @param length
* @return random string
*/
public static final Integer randomInteger(int length) {
return RANDOM.nextInt(length) + 1;
}
/**
* Generate a string of random characters
*
* @param length
* @return random string
*/
public static final String randomString(int length) {
return randomString(ALPHA, length);
}
/**
* Create a random GUID for orders
* @param shopAlias shop type like: TB,ES,MS
* @param orderAlias order type like: OD, RO, CO
* @return
*/
public static final String randomGuid(String shopAlias, String orderAlias) {
StringBuilder out = new StringBuilder();
out.append(shopAlias);
out.append(orderAlias);
String code = SequenceUtils.getSequenceCodeByDay(out.toString(), 3);
return code;
}
public static String convertDateToString(Date date, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
}
public static Date convertStringToDate(String date, String pattern) {
if(date=="")
return null;
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
try {
return sdf.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return new Date();
}
public static String formatDate(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
return sdf.format(date);
}
public static String removeSpecialCharacter(String targetString) {
if (targetString.indexOf("}") > 0 || targetString.indexOf("{") > 0) {
targetString = targetString.replaceAll("\\{", "");
targetString = targetString.replaceAll("\\}", "");
}
return targetString;
}
public static String removeSpecialCharacterJson(String targetString) {
if (targetString.indexOf("]") > 0 || targetString.indexOf("[") > 0) {
targetString = targetString.replaceAll("\\[", "");
targetString = targetString.replaceAll("\\]", "");
}
return targetString;
}
public static String replaceSpecialCharacter(String targetString) {
if (targetString != null) {
char[] invalidateChars = new char[]{'\t', '\r','\n', ',','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','[',']',':',';','\'','.','<','>','?','\\','|','\b'};
if (!StringUtils.containsNone(targetString, invalidateChars)){
for(char invalidateChar: invalidateChars) {
targetString = StringUtils.replaceChars(targetString, invalidateChar, ' ');
}
}
}
return targetString;
}
public static String convertObject2Json(Object obj) {
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(obj);
return json;
} catch (IOException e) {
e.printStackTrace();
return "{}";
}
}
private static byte[] lock = new byte[0];
// 位数,默认是9位
private final static long ramdomMath = 1000000000;
public static String createTaobaotidSplit(String seed) {
long r = 0;
synchronized (lock) {
r = (long) ((Math.random() + 1) * ramdomMath);
}
return seed+ System.currentTimeMillis() + String.valueOf(r).substring(1);
}
/**
*
* @param fileName 写入的文件名,完整地址
* @param text 写入文本内容
*/
public static void writerFile(String fileName,String text) {
File file = new File(fileName);
FileWriter fileWriter=null;
try {
if (!file.exists()){
file.createNewFile();
}
fileWriter = new FileWriter(file,true);
fileWriter.write(text);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (fileWriter !=null) {
fileWriter.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.pvuv.pvuv.util;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* Created by villiam on 18/3/20.
*/
public class WechatUtils {
private static final String access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx072302256a82deb1&secret=13b1c66b86e402562249b9478b54732d";
private static final String data_url = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=";
private static final String pedro_access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx56ccb2900f39febe&secret=1c0fdee749bbafa0e15a7cdb58d3c9d5";
private static final String pedro_data_url = "https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=";
public static String getAccessToken(){
String token = "";
String result = HttpUtils.get(access_token_url, null);
JSONObject jsonResult = JSONObject.fromObject(result);
if(StringUtils.isNotEmpty(result))
token = jsonResult.getString("access_token");
return token;
}
public static String getWeChatData(String token, String begin, String end){
if(StringUtils.isNotEmpty(token)){
Map<String, Object> parameterMap = new HashMap<String, Object>();
JSONObject jsonObject = new JSONObject();
// jsonObject.put("begin_date","20180318");
// jsonObject.put("end_date","20180318");
jsonObject.put("begin_date",begin);
jsonObject.put("end_date",end);
return HttpUtils.postWithBody(data_url + token, null, jsonObject.toString());
}
return null;
}
public static String getPedroAccessToken(){
String token = "";
String result = HttpUtils.get(pedro_access_token_url, null);
JSONObject jsonResult = JSONObject.fromObject(result);
if(StringUtils.isNotEmpty(result))
token = jsonResult.getString("access_token");
return token;
}
public static String getPedroWeChatData(String token, String begin, String end){
if(StringUtils.isNotEmpty(token)){
Map<String, Object> parameterMap = new HashMap<String, Object>();
JSONObject jsonObject = new JSONObject();
// jsonObject.put("begin_date","20180318");
// jsonObject.put("end_date","20180318");
jsonObject.put("begin_date",begin);
jsonObject.put("end_date",end);
return HttpUtils.postWithBody(pedro_data_url + token, null, jsonObject.toString());
}
return null;
}
public static void main(String args[]){
System.out.println(getWeChatData(getAccessToken(), DateUtil.format(DateUtil.getYesterday(), SystemConstant.FORMAT_DATE_YYMMDD),DateUtil.format(DateUtil.getYesterday(),SystemConstant.FORMAT_DATE_YYMMDD)));
System.out.println(getPedroWeChatData(getPedroAccessToken(), DateUtil.format(DateUtil.getYesterday(), SystemConstant.FORMAT_DATE_YYMMDD),DateUtil.format(DateUtil.getYesterday(),SystemConstant.FORMAT_DATE_YYMMDD)));
}
}
package com.pvuv.pvuv;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PvuvApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment