ipo所有功能及配置
parent
3bce761671
commit
ceb1613f62
@ -0,0 +1,444 @@
|
||||
package com.sztzjy.fund_investment.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sztzjy.fund_investment.annotation.AnonymousAccess;
|
||||
import com.sztzjy.fund_investment.entity.User;
|
||||
import com.sztzjy.fund_investment.entity.UserExample;
|
||||
import com.sztzjy.fund_investment.mapper.UserMapper;
|
||||
import com.sztzjy.fund_investment.service.IIlabService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/stu/ilabControllerTest")
|
||||
@Api(tags = "学生端--国家虚拟仿真test接口")
|
||||
public class IlabControllerTest {
|
||||
@Autowired
|
||||
IIlabService iIlabService;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
@Value("${file.path}")
|
||||
private String filePath;
|
||||
|
||||
|
||||
String appid = "107223";
|
||||
String secret = "5F2pfvRDXq5ybF4imPA02TJZfaYA1hPXTTvPjtwk+OE=";
|
||||
|
||||
//刷数据接口
|
||||
@GetMapping("shuashuju")
|
||||
@AnonymousAccess
|
||||
@ApiOperation("数据上传")
|
||||
public String shuashuju(@RequestParam String username,
|
||||
@RequestParam String ticket){
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andNameEqualTo(username);
|
||||
List<User> users = userMapper.selectByExample(example);
|
||||
if(users.isEmpty() || users==null){
|
||||
return "用户名不存在";
|
||||
}else {
|
||||
String un = users.get(0).getUsername();
|
||||
int startIndex = ticket.indexOf("ticket=") + "ticket=".length();
|
||||
int endIndex = ticket.indexOf("&token");
|
||||
String ticket1 = ticket.substring(startIndex, endIndex);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Map<String, String> accessToken = getAccessToken2(ticket1);
|
||||
try {
|
||||
// dataUpload(accessToken.get("access_token"),"mj_5696581","db524a12cf604980977d0ea4340d8e95");
|
||||
dataUpload(accessToken.get("access_token"),un, String.valueOf(UUID.randomUUID()).replaceAll("-",""));
|
||||
} catch (IOException e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
return "成功";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//获取AccessToken
|
||||
@GetMapping("getAccessToken")
|
||||
@AnonymousAccess
|
||||
public void getAccessToken(@ApiParam("ticket") @RequestParam String ticket) {
|
||||
Map<String,String> map=iIlabService.getAccessToken(ticket);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("dataUpload")
|
||||
@AnonymousAccess
|
||||
@ApiOperation("数据上传+实验报告上传")
|
||||
public void dataUpload(@ApiParam("access_token") @RequestParam String accessToken,
|
||||
@ApiParam("un") @RequestParam String un,
|
||||
@ApiParam("userId") @RequestParam String userId) throws IOException {
|
||||
accessToken = URLEncoder.encode(accessToken, "UTF-8");
|
||||
String accessTokenRepalce = accessToken.replaceAll("\\+", "%2B");
|
||||
// long nowTime = System.currentTimeMillis();
|
||||
long endTime = System.currentTimeMillis()-1000;
|
||||
long startTime = endTime- 1000 * 600;
|
||||
//定义发送数据
|
||||
String requestBody = "{\n" +
|
||||
" \"username\": \""+un+"\",\n" +
|
||||
" \"title\": \"股权基金投资虚拟仿真实验\",\n" +
|
||||
" \"status\": 1,\n" +
|
||||
" \"score\": 90,\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"appid\": \"107223\",\n" +
|
||||
" \"originId\": \""+userId+"\",\n" +
|
||||
" \"steps\": [\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 1,\n" +
|
||||
" \"title\": \"实验步骤1\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 2,\n" +
|
||||
" \"title\": \"实验步骤2\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 3,\n" +
|
||||
" \"title\": \"实验步骤3\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 4,\n" +
|
||||
" \"title\": \"实验步骤4\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 5,\n" +
|
||||
" \"title\": \"实验步骤5\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 6,\n" +
|
||||
" \"title\": \"实验步骤6\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 7,\n" +
|
||||
" \"title\": \"实验步骤7\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 8,\n" +
|
||||
" \"title\": \"实验步骤8\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 9,\n" +
|
||||
" \"title\": \"实验步骤9\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"seq\": 10,\n" +
|
||||
" \"title\": \"实验步骤10\",\n" +
|
||||
" \"startTime\": "+startTime+",\n" +
|
||||
" \"endTime\": "+endTime+",\n" +
|
||||
" \"timeUsed\": 600,\n" +
|
||||
" \"expectTime\": 2,\n" +
|
||||
" \"maxScore\": 10,\n" +
|
||||
" \"score\": 8,\n" +
|
||||
" \"repeatCount\": 1,\n" +
|
||||
" \"evaluation\": \"优\",\n" +
|
||||
" \"scoringModel\": \"赋分模型\",\n" +
|
||||
" \"remarks\": \"备注\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}\n" +
|
||||
"\n";
|
||||
//定义接收数据
|
||||
JSONObject result = new JSONObject();
|
||||
String url = "https://www.ilab-x.com/open/api/v2/data_upload?access_token="+accessTokenRepalce;
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
//请求参数转JOSN字符串
|
||||
StringEntity entity = new StringEntity(requestBody, "UTF-8");
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
try {
|
||||
HttpResponse response = client.execute(httpPost);
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
result = JSON.parseObject(EntityUtils.toString(response.getEntity(), "UTF-8"));
|
||||
System.out.println(result.toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("error", "连接错误!");
|
||||
}
|
||||
//关闭连接
|
||||
try {
|
||||
client.close();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
attachmentUpload(accessTokenRepalce,userId);
|
||||
}
|
||||
|
||||
//实验报告上传
|
||||
@PostMapping("attachmentUpload")
|
||||
@AnonymousAccess
|
||||
public void attachmentUpload(@ApiParam("access_token") @RequestParam String accessToken,
|
||||
@ApiParam("userId")@RequestParam String userId) throws IOException {
|
||||
String appid = "107223";
|
||||
String secret = "5F2pfvRDXq5ybF4imPA02TJZfaYA1hPXTTvPjtwk+OE=";
|
||||
// String filePath = "C:\\Users\\86132\\Desktop\\fsdownload";
|
||||
// String filePath = filePath;
|
||||
// accessToken = URLEncoder.encode(accessToken, "UTF-8");
|
||||
// String accessTokenRepalce = accessToken.replaceAll("\\+", "%2B");
|
||||
String url = "https://www.ilab-x.com/open/api/v2/attachment_upload" +
|
||||
"?access_token=" + accessToken +
|
||||
"&appid=" + appid +
|
||||
"&originId=" + userId+
|
||||
"&filename=abc.pdf&title=%E6%B5%8B%E8%AF%95%E5%AE%9E%E9%AA%8C%E6%8A%A5%E5%91%8A";
|
||||
|
||||
// String pdfFilePath = filePath +"/abc.pdf";
|
||||
String pdfFilePath = "C:\\Users\\86132\\Desktop\\abc.pdf";
|
||||
|
||||
File file = new File(pdfFilePath);
|
||||
URL apiUrl = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
|
||||
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||
|
||||
try (
|
||||
DataOutputStream request = new DataOutputStream(connection.getOutputStream());
|
||||
FileInputStream fileInput = new FileInputStream(file)
|
||||
) {
|
||||
request.writeBytes("--" + boundary + "\r\n");
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n");
|
||||
request.writeBytes("Content-Type: application/pdf\r\n\r\n");
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fileInput.read(buffer)) != -1) {
|
||||
request.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
request.writeBytes("\r\n--" + boundary + "--\r\n");
|
||||
}
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
System.out.println("Response Code : " + responseCode);
|
||||
|
||||
InputStream responseStream;
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
responseStream = connection.getInputStream();
|
||||
} else {
|
||||
responseStream = connection.getErrorStream();
|
||||
}
|
||||
|
||||
if (responseStream != null) {
|
||||
try (Scanner scanner = new Scanner(responseStream)) {
|
||||
String responseBody = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
|
||||
System.out.println("Response : " + responseBody); // Entire response from the server
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Map<String, String> getAccessToken2(String ticket) {
|
||||
String appid = "107223";
|
||||
String secret = "5F2pfvRDXq5ybF4imPA02TJZfaYA1hPXTTvPjtwk+OE=";
|
||||
Map<String, String> returnMap=new HashMap<>();
|
||||
try {
|
||||
String ticketEncode = URLEncoder.encode(ticket, "UTF-8");
|
||||
String signature = ticket + appid + secret;
|
||||
String signatureMD5 = DigestUtils.md5DigestAsHex(signature.getBytes("UTF-8")).toUpperCase();
|
||||
String url = "https://www.ilab-x.com/open/api/v2/token" +
|
||||
"?ticket=" + ticketEncode +
|
||||
"&appid=" + appid +
|
||||
"&signature=" + signatureMD5;
|
||||
URL apiUrl = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
|
||||
|
||||
// 设置请求类型为GET
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
// 获取响应
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
StringBuffer response = new StringBuffer();
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
// 打印响应内容
|
||||
com.alibaba.fastjson.JSONObject jsonObject = JSONObject.parseObject(response.toString());
|
||||
System.out.println(jsonObject.getString("access_token"));
|
||||
System.out.println(jsonObject.getString("un"));
|
||||
System.out.println(jsonObject.getString("dis"));
|
||||
System.out.println(jsonObject.getInteger("code"));
|
||||
returnMap.put("access_token",jsonObject.getString("access_token"));
|
||||
returnMap.put("un",jsonObject.getString("un"));
|
||||
returnMap.put("dis",jsonObject.getString("dis"));
|
||||
returnMap.put("code",jsonObject.getString("code"));
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
//获取AccessToken
|
||||
@PostMapping("shuashuju")
|
||||
@AnonymousAccess
|
||||
public String shuashuju(@RequestBody String aaa) {
|
||||
String token=aaa;
|
||||
int startIndex = token.indexOf("ticket=") + "ticket=".length();
|
||||
int endIndex = token.indexOf("&token");
|
||||
String ticket = token.substring(startIndex, endIndex);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Map<String, String> accessToken = getAccessToken2(ticket);
|
||||
try {
|
||||
// dataUpload(accessToken.get("access_token"),"mj_5696581","db524a12cf604980977d0ea4340d8e95");
|
||||
dataUpload(accessToken.get("access_token"),"mj_5686301", String.valueOf(UUID.randomUUID()).replaceAll("-",""));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String token=
|
||||
//""
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ;
|
||||
// int startIndex = token.indexOf("ticket=") + "ticket=".length();
|
||||
// int endIndex = token.indexOf("&token");
|
||||
// String ticket = token.substring(startIndex, endIndex);
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// Map<String, String> accessToken = getAccessToken2(ticket);
|
||||
// try {
|
||||
//// dataUpload(accessToken.get("access_token"),"mj_5696581","db524a12cf604980977d0ea4340d8e95");
|
||||
// dataUpload(accessToken.get("access_token"),"mj_5686301", String.valueOf(UUID.randomUUID()).replaceAll("-",""));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
# 120服务器配置文件
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
db-type: mysql
|
||||
url: jdbc:mysql://${DB_HOST:120.78.220.29}:${DB_PORT:3306}/${DB_NAME:fund_investment}?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&allowMultiQueries=true
|
||||
# url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:fund_investment}?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
username: ${DB_USER:root}
|
||||
password: ${DB_PWD:Biemo123}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
|
||||
# 文件存储
|
||||
file:
|
||||
type: local
|
||||
path: /usr/local/tianzeProject/fundInvestment/uploadFile
|
||||
|
||||
timer:
|
||||
enable: false
|
||||
|
||||
|
||||
swagger:
|
||||
enable: true
|
||||
tokenHeader: Authorization
|
||||
title: 天择外汇模拟交易 • 接口文档
|
||||
description: 天择外汇模拟交易WebAPI接口文档
|
||||
contactName: 深圳天择教育科技有限公司
|
||||
contactAddress: www.sztzjy.com
|
||||
version: @project.version@
|
Loading…
Reference in New Issue