Commit a4675492 authored by vv's avatar vv

金融风控client端

parents
Pipeline #331 failed with stages
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
.mvn/
log/
mvnw
mvnw.cmd
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/
### VS Code ###
.vscode/
# 一汽红旗轨迹演示
## 主要功能
* 行程切分
* 基于行程的绑路(轨迹纠偏)
* 取得行程当时的天气信息
\ No newline at end of file
<?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.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>aidataClient</groupId>
<artifactId>aidataClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aidataClient</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<!--<exclude>application*.yml</exclude>
<exclude>application*.properties</exclude>
<exclude>logback-spring.xml</exclude>-->
</excludes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
package com.esv.frc.client;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description:提供服务的Client端
* @version:1.0
*/
@Slf4j
public class Client {
private String charset = "utf-8";
@Value("${FOTACAPATH}")
private String FOTACAPATH;
private String accessKey;
private String secretKey;
public Client(String accessKey, String secretKey) {
this.accessKey=accessKey;
this.secretKey=secretKey;
}
public String request(String url, Map<String, String> data){
return "";
}
private void requestHttpsService(){
String httpOrgCreateTest = "http/sma/api/login";
{
Map<String,String> createMap = new HashMap<String,String>();
createMap.put("userName", "userName");
createMap.put("password", "password");
createMap.put("domain", "domain");
String httpOrgCreateTestRtn = null;
try {
httpOrgCreateTestRtn = HttpsWithCA.sendHttpsGetSessionId(FOTACAPATH,httpOrgCreateTest,createMap,"",charset);
} catch (IOException e) {
log.info("请求FOTA获取sessionId出错,异常=" + e);
}
JSONObject jsonObject = JSONObject.parseObject(httpOrgCreateTestRtn);
String sessionId = jsonObject.getString("sessionId");
}
}
}
package com.esv.frc.client;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
package com.esv.frc.client;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
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.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Slf4j
public class HttpsWithCA {
private static SSLContext sslContext = null;
public static void main(String[] args) throws Exception {
/*String url = "https://testswm.gwm.com.cn/sma/api/logout";
String body = sendHttpsPostWithCA(url, new JSONObject(), "utf-8");
System.out.println("响应结果:" + body);*/
}
/**
* 设置信任自定义证书
*
* @param caPath 证书路径
* @return
*/
public static SSLContext custom(String caPath){
SSLContext context = null;
FileInputStream instream = null;
try {
CertificateFactory cAf = CertificateFactory.getInstance("X.509");
instream = new FileInputStream(caPath);
X509Certificate ca = (X509Certificate) cAf.generateCertificate(instream);
KeyStore caKs = KeyStore.getInstance("JKS");
caKs.load(null, null);
caKs.setCertificateEntry("ca-certificate", ca);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(caKs);
// finally, create SSL socket factory
context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), new SecureRandom());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != instream) {
instream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return context;
}
/**
* 模拟请求
*
* @param url 资源地址
* @param paramJson 参数
* @param encoding 编码
* @return
* @throws IOException
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
* @throws ClientProtocolException
*/
/**
* 使用自定义证书进行https请求
* @param url
* @param paramJson
* @param encoding
* @return
* @throws ClientProtocolException
* @throws IOException
*/
public static String sendHttpsPostWithCA(String fotapath,String url, JSONObject paramJson, String encoding) throws ClientProtocolException, IOException {
String body = "";
//SSLContext sslcontext = custom("D:\\data\\gwm.com.cn.crt");
//SSLContext sslcontext = custom("/data/gwm.com.cn.crt");
SSLContext sslcontext = custom(fotapath);
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslcontext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager);
//创建自定义的httpclient对象
CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build();
// CloseableHttpClient client = HttpClients.createDefault();
//创建post方式请求对象
HttpPost httpPost = new HttpPost(url);
// 设置header信息
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
// 设置请求体
StringEntity requestEntity = new StringEntity(paramJson.toString(), Charset.forName("UTF-8"));
requestEntity.setContentEncoding("UTF-8");
httpPost.setEntity(requestEntity);
//执行请求操作,并拿到结果(同步阻塞)
CloseableHttpResponse response = client.execute(httpPost);
//获取结果实体
HttpEntity entity = response.getEntity();
if (entity != null) {
//按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity, encoding);
}
EntityUtils.consume(entity);
//释放链接
response.close();
return body;
}
public static String sendHttpsUploadFile(String fotapath,String url, MultipartFile file, String sessionId,String charset) {
String body = "";
if(sslContext == null){
sslContext = custom(fotapath);
}
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslContext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager);
//创建自定义的httpclient对象
CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build();
//创建post方式请求对象
HttpPost httpPost = new HttpPost(url);
String fileName = file.getOriginalFilename();
//HttpPost httpPost = new HttpPost(uploadUrl);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
try {
builder.addBinaryBody("file", file.getInputStream(), ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
if(sessionId!=""){
httpPost.setHeader("sessionId", sessionId);
}
//执行请求操作,并拿到结果(同步阻塞)
CloseableHttpResponse response = client.execute(httpPost);
//获取结果实体
HttpEntity entity1 = response.getEntity();
if (entity1 != null) {
//按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity1, charset);
}
EntityUtils.consume(entity1);
//释放链接
response.close();
}catch (Exception e){
log.error("请求上传车辆信息文件出错,异常 = " + e);
}
return body;
}
public static String sendHttpsGetSessionId(String fotacapath,String url, Map<String,String> map, String sessionId, String charset) throws ClientProtocolException, IOException {
String body = "";
if(sslContext == null){
sslContext = custom(fotacapath);
}
// 设置协议http和https对应的处理socket链接工厂的对象
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslContext))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
HttpClients.custom().setConnectionManager(connManager);
//创建自定义的httpclient对象
CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build();
//创建post方式请求对象
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Accept", "application/json");
Iterator iterator = map.entrySet().iterator();
List<NameValuePair> list = new ArrayList<NameValuePair>();
while(iterator.hasNext()){
Map.Entry<String,String> elem = (Map.Entry<String, String>) iterator.next();
list.add(new BasicNameValuePair(elem.getKey(),elem.getValue()));
}
if(list.size() > 0){
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset);
httpPost.setEntity(entity);
}
//执行请求操作,并拿到结果(同步阻塞)
CloseableHttpResponse response = client.execute(httpPost);
//获取结果实体
HttpEntity entity1 = response.getEntity();
if (entity1 != null) {
//按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity1, charset);
}
EntityUtils.consume(entity1);
//释放链接
response.close();
return body;
}
}
package com.esv.frc.client;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
//用于进行Https请求的HttpClient
public class SSLClient extends DefaultHttpClient{
public SSLClient() throws Exception{
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
}
\ No newline at end of file
package com.esv.frc.client;
import java.io.UnsupportedEncodingException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @description:
* @project: track_demo_yq_hq
* @name: com.esv.frc.client.test
* @author: 陈洪艳
* @email: chenhongyan@esvtek.com
* @createTime: 2020/5/29 11:06
* @version:1.0
*/
public class test {
public static void main(String[] args) throws Exception{
String access_key = "65da59b074984ba09809e6c58b0ef013";
String secret_key = "b2b32a11db044423b18de6396b7ab50e";
String api_uri = "/credit-scoring-ai/users/id-check/v1/simple-identity-check";
String sign_str = "POST" + "$" + api_uri + "$" + "application/json" + "$";
BASE64Encoder encoder = new BASE64Encoder();
BASE64Decoder decoder = new BASE64Decoder();
System.out.println("hmac_sha:"+(hmac_sha1(sign_str, secret_key)));
System.out.println("encoder:" + encoder.encode((hmac_sha1(sign_str, secret_key)).getBytes()));
System.out.println("Decoder:" + decoder.decodeBuffer(encoder.encode((hmac_sha1(sign_str, secret_key)).getBytes())));
String authorization = access_key + ":" + encoder.encode((hmac_sha1(sign_str, secret_key)).getBytes());
//System.out.println(authorization);
}
public static String hmac_sha1(String value, String key) {
try {
byte[] keyBytes = key.getBytes();
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(value.getBytes());
String hexBytes = byte2hex(rawHmac);
return hexBytes;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String byte2hex(final byte[] b){
String hs="";
String stmp="";
for (int n=0; n<b.length; n++){
stmp=(java.lang.Integer.toHexString(b[n] & 0xFF));
if (stmp.length()==1) hs=hs+"0"+stmp;
else hs=hs+stmp;
}
return hs;
}
private static String appendEqualSign(String s){
int len = s.length();
int appendNum = 8 - (int)(len/8);
for (int n=0; n<appendNum; n++){
s += "%3D";
}
return s;
}
public void test() throws Exception{
final BASE64Encoder encoder = new BASE64Encoder();
final BASE64Decoder decoder = new BASE64Decoder();
final String text = "字串文字";
final byte[] textByte = text.getBytes("UTF-8");
//编码
final String encodedText = encoder.encode(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decodeBuffer(encodedText), "UTF-8"));
final BASE64Encoder encoder1 = new BASE64Encoder();
final BASE64Decoder decoder1 = new BASE64Decoder();
final String text = "字串文字";
final byte[] textByte = text.getBytes("UTF-8");
//编码
final String encodedText = encoder1.encode(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder1.decodeBuffer(encodedText), "UTF-8"));
}
}
server:
port: 2001
\ No newline at end of file
<?xml version="1.0"?>
<configuration>
<!-- ch.qos.logback.core.ConsoleAppender 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/logFile.server.current.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>log/backup/logFile.server.%d{yyyy-MM}.%i.zip</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>6</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy/MM/dd-HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<!-- 日志级别 -->
<logger name="com.esv" level="debug"/>
<root>
<level value="info" />
<appender-ref ref="console" />
<!--<appender-ref ref="file" />-->
</root>
</configuration>
\ No newline at end of file
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