|
@@ -3,15 +3,19 @@ package com.management.platform.controller;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.management.platform.entity.WeiXinTicketEntity;
|
|
|
+import com.management.platform.service.WechatAccountService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.HttpUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -23,6 +27,8 @@ import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("weixinTicket")
|
|
|
+
|
|
|
+@Slf4j
|
|
|
public class WeiXinTicketController {
|
|
|
|
|
|
@Value("${weixin.ticket.action_name.QR_SCENE}")
|
|
@@ -34,14 +40,21 @@ public class WeiXinTicketController {
|
|
|
private static final String APP_SECRET = "17ad07f90ee845f99f4c1605647ef755";
|
|
|
private static final String GRANT_TYPE = "client_credential";
|
|
|
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WechatAccountService wechatAccountService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@RequestMapping(value = "sendInterviewInvitation",method=RequestMethod.POST)
|
|
|
public HttpRespMsg sendInterviewInvitation(@RequestBody WeiXinTicketEntity reqDto) throws Exception{
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
try {
|
|
|
- String accessToken = getWeiXinAccessToken();
|
|
|
+ String accessToken = wechatAccountService.getAccessToken(6374,"");
|
|
|
String sceneStr = reqDto.getSceneStr();
|
|
|
- String result = new WeiXinTicketController().createForeverStrTicket(accessToken, sceneStr);
|
|
|
+ String result =this.createForeverStrTicket(accessToken, sceneStr);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
String ticket = null ;
|
|
|
if(null!=jsonObject){
|
|
@@ -94,7 +107,7 @@ public class WeiXinTicketController {
|
|
|
Map<String, Map<String, Integer>> mapMap = new HashMap<>();
|
|
|
mapMap.put("scene", intMap);
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
- paramsMap.put("action_name", QR_STR_SCENE);
|
|
|
+ paramsMap.put("action_name", "QR_LIMIT_STR_SCENE");
|
|
|
paramsMap.put("action_info", mapMap);
|
|
|
String jsonObject = JSONObject.toJSONString(paramsMap);
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=";
|
|
@@ -110,18 +123,35 @@ public class WeiXinTicketController {
|
|
|
* 场景str
|
|
|
* @return
|
|
|
*/
|
|
|
- public String createForeverStrTicket(String accessToken, String sceneStr) throws Exception {
|
|
|
+ public String createForeverStrTicket(String accessToken, String sceneStr){
|
|
|
Map<String, String> intMap = new HashMap<>();
|
|
|
intMap.put("scene_str", sceneStr);
|
|
|
Map<String, Map<String, String>> mapMap = new HashMap<>();
|
|
|
mapMap.put("scene", intMap);
|
|
|
Map<String, Object> paramsMap = new HashMap<>();
|
|
|
- paramsMap.put("action_name", QR_STR_SCENE);
|
|
|
+ paramsMap.put("action_name", "QR_LIMIT_STR_SCENE");
|
|
|
paramsMap.put("action_info", mapMap);
|
|
|
String jsonObject = JSONObject.toJSONString(paramsMap);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+accessToken;
|
|
|
- String result = HttpUtil.post(requestUrl,accessToken, jsonObject);
|
|
|
- return result;
|
|
|
+
|
|
|
+
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<String>(jsonObject, headers);
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(requestUrl,
|
|
|
+ HttpMethod.POST, requestEntity, String.class);
|
|
|
+
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ JSONObject json = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ log.info("返回:" + json.toJSONString());
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ log.info("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|