WxController.java
3.12 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
package com.example.controller;
import com.example.models.ImgInfo;
import com.example.service.ImgInfoService;
import com.example.service.http.ClientConfigService;
import com.example.service.http.ClientConfigServiceImpl;
import com.example.service.http.HttpPostService;
import com.example.support.model.MessageEntity;
import com.example.utils.file.DefaultFileUpload;
import com.example.utils.file.FileUploadInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;
/**
* Created by JA on 17/7/3.
*/
@RequestMapping("/kmr/wx")
@RestController
public class WxController {
// String jssdkurl = "http://gfwp.gac-toyota.com.cn/GTMCfamily/index.php/campaign/api2/getjssdk";
//
// String getopenidurl = "http://gfwp.gac-toyota.com.cn/GTMCfamily/index.php/campaign/api2/getjssdk";
//
// @Autowired
// private HttpPostService httpPostService;
//
//
// @RequestMapping("/getjssdk")
// public MessageEntity getjssdk(HttpServletRequest request, @RequestParam String url) {
// MessageEntity.Builder builder = new MessageEntity.Builder(request);
// String newUrl = jssdkurl + "?url="+ url;
// Map<String, Object> map = null;
// try {
// map = httpPostService.httpPost(newUrl, null);
// } catch (IOException e) {
// e.printStackTrace();
// }
// return builder.success(true).code("2000").content(map).create();
// }
@RequestMapping("/getUser")
public MessageEntity oauth(HttpServletRequest request, @RequestParam String accessToken, String openid) {
MessageEntity.Builder builder = new MessageEntity.Builder(request);
ClientConfigService configService = new ClientConfigServiceImpl();
RestClient restClient = new RestClient(configService.getClientConfig());
Resource resource = restClient.resource("https://api.weixin.qq.com/sns/userinfo");
resource.queryParam("access_token", accessToken);
resource.queryParam("openid", openid);
resource.queryParam("lang", "zh_CN");
ClientResponse response = resource.get();
String responseEntity = response.getEntity(String.class);
Map readValue = null;
// System.out.println("responseEntity:::"+responseEntity);
ObjectMapper mapper = new ObjectMapper();
try {
readValue = mapper.readValue(responseEntity, Map.class);
if (null != readValue.get("errcode")) {
return null;
}
} catch (IOException e) {
e.printStackTrace();;
}
return builder.success(true).code("2000").content(readValue).create();
}
}