ImgInfoController.java
4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.example.controller;
import com.example.models.ImgInfo;
import com.example.service.ImgInfoService;
import com.example.support.model.MessageEntity;
import com.example.utils.file.DefaultFileUpload;
import com.example.utils.file.FileUploadInfo;
import com.example.utils.md5.MD5Utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Map;
/**
* Created by JA on 17/7/3.
*/
@RequestMapping("/kmr/img")
@RestController
public class ImgInfoController {
@Autowired
private ImgInfoService imgInfoService;
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public MessageEntity upload(HttpServletRequest request,@RequestPart final MultipartFile file,@ModelAttribute ImgInfo imgInfo,
String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
String code = "9000";
String openid = imgInfo.getOpenid();
boolean flag = false;
if(StringUtils.isNotBlank(jsondata)){
jsondata = URLDecoder.decode(jsondata);
ObjectMapper objectMapper = new ObjectMapper();
Map map = null;
try {
map = objectMapper.readValue(jsondata, Map.class);
} catch (IOException e) {
e.printStackTrace();
}
// if(map != null && map.containsKey("gtmc_code") && map.get("gtmc_code").toString().equals("200")){
// String checksum1 = MD5Utils.hash(access_token + openid + state + timestamp + rands + jsondata + secret);
// if(checksum1.equals(checksum)){
imgInfo.setGtmcUid(map.get("gtmc_uid").toString());
imgInfo.setGtmcDepartment(map.get("gtmc_department").toString());
imgInfo.setGtmcName(map.get("gtmc_name").toString());
FileUploadInfo info = new DefaultFileUpload().upload("/data/home/app/4Q0i/uimg", file);
String url = info.getUrl();
imgInfo.setImgUrl(url);
boolean b = this.imgInfoService.create(imgInfo);
if(b){
code = "2000";
flag = true;
}
// }
// }
}
return builder.success(flag).content(imgInfo).code(code).create();
}
@RequestMapping(value = "/upload/base64", method = RequestMethod.POST)
public MessageEntity uploadbase64(HttpServletRequest request,@RequestBody String base64,@ModelAttribute ImgInfo imgInfo,
String access_token, String state, String timestamp, String rands, String jsondata, String checksum, String secret) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
String code = "9000";
String openid = imgInfo.getOpenid();
boolean flag = false;
if(StringUtils.isNotBlank(jsondata)){
jsondata = URLDecoder.decode(jsondata);
ObjectMapper objectMapper = new ObjectMapper();
Map map = null;
try {
map = objectMapper.readValue(jsondata, Map.class);
} catch (IOException e) {
e.printStackTrace();
}
// if(map != null && map.containsKey("gtmc_code") && map.get("gtmc_code").toString().equals("200")){
// String checksum1 = MD5Utils.hash(access_token + openid + state + timestamp + rands + jsondata + secret);
// if(checksum1.equals(checksum)){
imgInfo.setGtmcUid(map.get("gtmc_uid").toString());
imgInfo.setGtmcDepartment(map.get("gtmc_department").toString());
imgInfo.setGtmcName(map.get("gtmc_name").toString());
FileUploadInfo info = new DefaultFileUpload().uploadBase64("/data/home/app/4Q0i/uimg", base64);
String url = info.getUrl();
imgInfo.setImgUrl(url);
boolean b = this.imgInfoService.create(imgInfo);
if(b){
code = "2000";
flag = true;
}
// }
// }
}
return builder.success(flag).content(imgInfo).code(code).create();
}
@RequestMapping("/getbyopenid")
public MessageEntity getbyopenid(HttpServletRequest request, @RequestParam String openid) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
ImgInfo imgInfo = this.imgInfoService.getNewByOpenid(openid);
return builder.success(true).code("2000").content(imgInfo).create();
}
}