|
|
@@ -1,22 +1,44 @@
|
|
|
package com.chuanghai.repair.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
+import com.auth0.jwt.interfaces.DecodedJWT;
|
|
|
+import com.chuanghai.repair.auth.CrossInfoCache;
|
|
|
+import com.chuanghai.repair.auth.JSONAuthentication;
|
|
|
import com.chuanghai.repair.entity.RepairsAdmin;
|
|
|
+import com.chuanghai.repair.entity.RepairsStudent;
|
|
|
import com.chuanghai.repair.entity.RepairsWork;
|
|
|
import com.chuanghai.repair.service.RepairsAdminService;
|
|
|
+import com.chuanghai.repair.service.RepairsStudentService;
|
|
|
import com.chuanghai.repair.service.RepairsWorkService;
|
|
|
import com.chuanghai.repair.utils.CreateTokenUtil;
|
|
|
+import com.sun.deploy.net.URLEncoder;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.URI;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @Author: bingo
|
|
|
@@ -35,6 +57,9 @@ public class LoginController {
|
|
|
@Resource(name = "repairsWorkService")
|
|
|
private RepairsWorkService repairsWorkService;
|
|
|
|
|
|
+ @Resource(name = "repairsStudentService")
|
|
|
+ private RepairsStudentService repairsStudentService;
|
|
|
+
|
|
|
/**
|
|
|
* 管理员登录
|
|
|
*
|
|
|
@@ -43,22 +68,19 @@ public class LoginController {
|
|
|
*/
|
|
|
@ApiOperation("管理员登录")
|
|
|
@PostMapping(value = "/loginAdmin")
|
|
|
- public RepairsAdmin loginAdmin(@ApiParam(name = "管理员手机号码", required = true)String phone,@ApiParam(name = "管理员密码", required = true) String password) {
|
|
|
- RepairsAdmin repairsAdmin =null;
|
|
|
-
|
|
|
+ public String loginAdmin(@ApiParam(name = "管理员手机号码", required = true) String phone,
|
|
|
+ @ApiParam(name = "管理员密码", required = true) String password) {
|
|
|
+ String adminIdToken = "";
|
|
|
try {
|
|
|
- repairsAdmin =repairsAdminService.loginAdmin(phone, password);
|
|
|
- String adminToken = CreateTokenUtil.token(repairsAdmin.getAdminName(), repairsAdmin.getAdminPassword());
|
|
|
- System.out.println(adminToken);
|
|
|
- }catch (Exception e){
|
|
|
+ RepairsAdmin repairsAdmin = repairsAdminService.loginAdmin(phone, password);
|
|
|
+ adminIdToken = CreateTokenUtil.getToken(String.valueOf(repairsAdmin.getAdminId()));
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return repairsAdmin;
|
|
|
+ return adminIdToken;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 维修工登录
|
|
|
*
|
|
|
@@ -67,37 +89,128 @@ public class LoginController {
|
|
|
*/
|
|
|
@ApiOperation("维修工登录")
|
|
|
@PostMapping(value = "/loginWork")
|
|
|
- public RepairsWork loginWork(@ApiParam(name = "维修工手机号码", required = true) String phone,@ApiParam(name = "维修工登录密码", required = true) String password) {
|
|
|
- RepairsWork repairsWork =null;
|
|
|
+ public String loginWork(@ApiParam(name = "维修工手机号码", required = true) String phone,
|
|
|
+ @ApiParam(name = "维修工登录密码", required = true) String password) {
|
|
|
+ String workIdToken = "";
|
|
|
try {
|
|
|
- repairsWork = repairsWorkService.loginWork(phone, password);
|
|
|
-
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
+ RepairsWork repairsWork = repairsWorkService.loginWork(phone, password);
|
|
|
+ workIdToken = CreateTokenUtil.getToken(String.valueOf(repairsWork.getWorkId()));
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return repairsWork;
|
|
|
+ return workIdToken;
|
|
|
}
|
|
|
|
|
|
- /* @RequestMapping(value = "/loginAdmin")
|
|
|
- public Map<String,Object> loginAdmin(HttpServletRequest request, RepairsAdmin repairsAdmin){
|
|
|
- HashMap<String,Object> map =new HashMap<String,Object>();
|
|
|
+
|
|
|
+ @GetMapping("/getCardNumber")
|
|
|
+ public JSONObject getCardNumber(String wxcode, String state) {
|
|
|
+ JSONObject cardNumberJson = new JSONObject();
|
|
|
try {
|
|
|
- RepairsAdmin loginAdmin = repairsAdminService.loginAdmin(repairsAdmin);
|
|
|
- HttpSession session = request.getSession();
|
|
|
- session.setAttribute("RepairsAdmin", loginAdmin);
|
|
|
+ wxcode = "wxcode=" + wxcode + "&";
|
|
|
+ String app_key = "app_key=EE28EE2C93296F4E&";
|
|
|
+ String app_secret = "app_secret=5071958561AA629530AAA31503088330&";
|
|
|
+ String grant_type = "grant_type=authorization_code&";
|
|
|
+ String redirect_uri = "redirect_uri=http://binguo.vaiwan.com/login/getCardNumber";
|
|
|
+ String url = "https://open.wecard.qq.com/connect/oauth2/token?";
|
|
|
+ String accessTokenUrl = url + wxcode + app_key + app_secret + grant_type + redirect_uri;
|
|
|
+ // -------------------------------> 获取Rest客户端实例
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ // -------------------------------> (选择性设置)请求头信息
|
|
|
+ // HttpHeaders实现了MultiValueMap接口
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ // 设置contentType
|
|
|
+ // httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ // 给请求header中添加一些数据
|
|
|
+ // ------------------------------->将请求头、请求体数据,放入HttpEntity中
|
|
|
+ // 请求体的类型任选即可;只要保证 请求体 的类型与HttpEntity类的泛型保持一致即可
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(paramMap, httpHeaders);
|
|
|
+ StringBuffer paramsURL = new StringBuffer(accessTokenUrl);
|
|
|
+ // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
|
|
|
+ // paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
|
|
|
+ URI uri = URI.create(paramsURL.toString());
|
|
|
+ // -------------------------------> 执行请求并返回结果
|
|
|
+ // 此处的泛型 对应 响应体数据 类型;即:这里指定响应体的数据装配为String
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(uri, httpEntity, String.class);
|
|
|
+ JSONObject objParam = JSON.parseObject(response.getBody());
|
|
|
+ String access_token = "";
|
|
|
+ for (Map.Entry<String, Object> entry : objParam.entrySet()) {
|
|
|
+ Object o = entry.getValue();
|
|
|
+ if (o instanceof String) {
|
|
|
+ if (entry.getKey().equals("access_token")) {
|
|
|
+ access_token = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info?access_token=" + access_token + "&scope=snsapi_base";
|
|
|
+ StringBuffer userInfoURl = new StringBuffer(userInfoUrl);
|
|
|
+ // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
|
|
|
+ // paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
|
|
|
+ URI urm = URI.create(userInfoURl.toString());
|
|
|
+ // 此处的泛型 对应 响应体数据 类型;即:这里指定响应体的数据装配为String
|
|
|
+ ResponseEntity<String> responsem = restTemplate.postForEntity(urm, httpEntity, String.class);
|
|
|
+ JSONObject obj = JSON.parseObject(responsem.getBody());
|
|
|
+ String studentId = "";
|
|
|
+ String studentName = "";
|
|
|
+ String studentSex = "";
|
|
|
+ String studentPhone = "";
|
|
|
+ String studentOtherPhone = "";
|
|
|
+ String studentClazz = "";
|
|
|
+ String dormNumber = "";
|
|
|
+ String studentDormitory = "";
|
|
|
+ String studentStatus = "1";
|
|
|
+ String studentCampus = "";
|
|
|
+ String cardNumber = "";
|
|
|
+ for (Map.Entry<String, Object> entry : obj.entrySet()) {
|
|
|
+ Object o = entry.getValue();
|
|
|
+ if (o instanceof String) {
|
|
|
+ if (entry.getKey().equals("card_number")) {
|
|
|
+ studentId = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("gender")) {
|
|
|
+ studentSex = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("name")) {
|
|
|
+ studentName = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("telephone")) {
|
|
|
+ studentPhone = (String) entry.getValue();
|
|
|
+ studentPhone = studentPhone.substring(5);
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("class")) {
|
|
|
+ studentClazz = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("dorm_number")) {
|
|
|
+ dormNumber = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("dorm_number")) {
|
|
|
+ studentDormitory = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("campus")) {
|
|
|
+ studentCampus = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ if (entry.getKey().equals("card_number")) {
|
|
|
+ cardNumber = (String) entry.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if(loginAdmin==null) {
|
|
|
- map.put("flag", false);
|
|
|
- }else {
|
|
|
- map.put("flag", true);
|
|
|
}
|
|
|
- }catch (Exception e) {
|
|
|
+ RepairsStudent repairsStudent = new RepairsStudent(studentId, studentName, studentSex,
|
|
|
+ studentPhone, studentOtherPhone, studentClazz, dormNumber,
|
|
|
+ studentDormitory, studentStatus, studentCampus,cardNumber);
|
|
|
+ System.out.println(studentId);
|
|
|
+ RepairsStudent student = repairsStudentService.queryByStudentId(studentId);
|
|
|
+ System.out.println(student);
|
|
|
+ if(student==null){
|
|
|
+ repairsStudentService.insertStudent(repairsStudent);
|
|
|
+ }
|
|
|
+ cardNumberJson.put("card_number",cardNumber);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- map.put("flag", false);
|
|
|
}
|
|
|
- return map;}*/
|
|
|
-
|
|
|
+ return cardNumberJson;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|