Commit 17cf8fee authored by Shen's avatar Shen

1. 新增浙里办微信对接模块

2. 更新服务器数据库地址
parent 7e286ec6
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
<version>1.2.60</version> <version>1.2.60</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>net.sf.json-lib</groupId> <!-- <groupId>net.sf.json-lib</groupId>-->
<artifactId>json-lib</artifactId> <!-- <artifactId>json-lib</artifactId>-->
<version>2.4</version> <!-- <version>2.4</version>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>net.sf.json-lib</groupId> <groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId> <artifactId>json-lib</artifactId>
......
package io.hmit.controller; package io.hmit.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.api.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.hmit.annotation.Login; import io.hmit.annotation.Login;
import io.hmit.common.constant.Constant; import io.hmit.common.constant.Constant;
import io.hmit.common.utils.MD5;
import io.hmit.common.utils.Result; import io.hmit.common.utils.Result;
import io.hmit.common.validator.ValidatorUtils; import io.hmit.common.validator.ValidatorUtils;
import io.hmit.config.ZhelibanUtils; import io.hmit.config.ZhelibanUtils;
import io.hmit.dto.LoginDTO; import io.hmit.dto.LoginDTO;
import io.hmit.entity.TokenEntity; import io.hmit.entity.TokenEntity;
import io.hmit.entity.UserEntity; import io.hmit.entity.UserEntity;
import io.hmit.modules.zlb.service.AuthService;
import io.hmit.service.TokenService; import io.hmit.service.TokenService;
import io.hmit.service.UserService; import io.hmit.service.UserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -35,6 +40,7 @@ import java.util.UUID; ...@@ -35,6 +40,7 @@ import java.util.UUID;
* *
* @author zsh 408538940@qq.com * @author zsh 408538940@qq.com
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
@Api(tags = "登录接口") @Api(tags = "登录接口")
...@@ -45,6 +51,9 @@ public class ApiLoginController { ...@@ -45,6 +51,9 @@ public class ApiLoginController {
@Autowired @Autowired
private TokenService tokenService; private TokenService tokenService;
@Autowired
private AuthService authService;
@PostMapping("login") @PostMapping("login")
@ApiOperation("登录") @ApiOperation("登录")
...@@ -124,4 +133,57 @@ public class ApiLoginController { ...@@ -124,4 +133,57 @@ public class ApiLoginController {
} }
} }
//个人登录 - 单点登陆
@RequestMapping(value="/check_user_ticket_id")
@ApiOperation("单点登录")
@ApiImplicitParams({
@ApiImplicitParam(name = "ticketId", value = "票据", paramType = "query", required = true, dataType="String") ,
})
public Result checkUserTicketId(@ApiIgnore @RequestParam Map<String,Object> map , HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
// 获取到票据信息ticket
log.info("开始进入这个check_user_ticket_id了————————————————————");
System.out.println(map);
Long userId;
Map<String, Object> userMap = new HashMap<>();
if(map.get("ticketId") != null){
String accessToken = authService.getTokenByTicketId((String) map.get("ticketId"));
JSONObject userInfoByToken = authService.getUserInfoByToken(accessToken);
Map<String,Object> user_map = (Map<String, Object>) userInfoByToken.get("personInfo");
if (user_map.get("idNo") !=null){
//判断是否已经存在了这条信息
UserEntity oldUser=userService.queryByIdnum(URLEncoder.encode(user_map.get("idNo").toString(), "UTF8"));
if(oldUser==null){
//将获得的信息保存到个人登陆表
String idNo = user_map.get("idNo").toString();
UserEntity user=new UserEntity();
user.setUsername(user_map.get("userName").toString());
user.setMobile(URLEncoder.encode(user_map.get("phone").toString(), "UTF8"));
user.setPassword(URLEncoder.encode(DigestUtils.sha256Hex(idNo), "UTF8"));
user.setIdCardNo(URLEncoder.encode(idNo, "UTF8"));
userService.insert(user);
userId = user.getId();
userMap.put("username", user.getUsername());
userMap.put("mobile", user.getMobile());
userMap.put("idnum",user.getIdCardNo());
}else{
userId = oldUser.getId();
userMap.put("username", oldUser.getUsername());
userMap.put("mobile", oldUser.getMobile());
userMap.put("idnum",oldUser.getIdCardNo());
}
TokenEntity tokenEntity = tokenService.createToken(userId);
userMap.put("token", tokenEntity.getToken());
userMap.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis());
}
return new Result().ok(userMap);
}else{
return new Result().error("票据信息为空");
}
}
} }
package io.hmit.modules.zlb.constants;
/**
* @author jie.chen
* @date 2022-03-30 15:24
*/
public interface Constants {
/**
* 单点登录 ticketId换token的地址
*/
String ACCESS_TOKEN_URL = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000007/uc/sso/access_token";
/**
* 单点登录 token获取用户信息地址
*/
String GET_USER_INFO_URL = "https://ibcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000008/uc/sso/getUserInfo";
/**
* IRS请求携带的请求头
*/
String X_BG_HMAC_ACCESS_KEY = "X-BG-HMAC-ACCESS-KEY";
String X_BG_HMAC_SIGNATURE = "X-BG-HMAC-SIGNATURE";
String X_BG_HMAC_ALGORITHM = "X-BG-HMAC-ALGORITHM";
String X_BG_DATE_TIME = "X-BG-DATE-TIME";
/**
* IRS签名算法
*/
String DEFAULT_HMAC_SIGNATURE = "hmac-sha256";
/**
* 应用ID
*/
String APP_ID = "2001401510";
/**
* 微信端固定值为weixin
*/
String WEIXIN_ENDPOINT_TYPE = "weixin";
/**
* IRS 申请组件生成的AK
*/
String IRS_AK = "BCDSGA_23cb33012037fc566a93a50762206b3e";
/**
* IRS 申请组件生成的SK
*/
String IRS_SK = "BCDSGS_5c410b84ac10211dfdb3b0c546c4e6ce";
}
/**
* TODO
*
* @author Shen && syf0412@vip.qq.com
* @since 2022/9/22 13:43
*/
package io.hmit.modules.zlb;
\ No newline at end of file
package io.hmit.modules.zlb.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.hmit.modules.zlb.constants.Constants;
import io.hmit.modules.zlb.utils.IrsSignRes;
import io.hmit.modules.zlb.utils.IrsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.util.Map;
/**
* @author jie.chen
* @date 2022-03-30 15:49
*/
@Component
public class AuthService {
@Autowired
private RestTemplateBuilder restTemplateBuilder;
private RestTemplate restTemplate;
@PostConstruct
void init() {
restTemplate = restTemplateBuilder.build();
}
public String getTokenByTicketId(String ticketId) {
HttpHeaders headers = getHttpHeaders(Constants.ACCESS_TOKEN_URL);
JSONObject body = new JSONObject();
body.put("appId", Constants.APP_ID);
body.put("ticketId", ticketId);
HttpEntity<Map<String, Object>> request = new HttpEntity<>(body, headers);
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(Constants.ACCESS_TOKEN_URL, request, String.class);
return checkResponse(stringResponseEntity).getJSONObject("data").getString("accessToken");
}
public JSONObject getUserInfoByToken(String accessToken) {
HttpHeaders headers = getHttpHeaders(Constants.GET_USER_INFO_URL);
JSONObject body = new JSONObject();
body.put("token", accessToken);
HttpEntity<Map<String, Object>> request = new HttpEntity<>(body, headers);
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(Constants.GET_USER_INFO_URL, request, String.class);
return checkResponse(stringResponseEntity).getJSONObject("data");
}
private JSONObject checkResponse(ResponseEntity<String> stringResponseEntity) {
if (!stringResponseEntity.getStatusCode().is2xxSuccessful()) {
//请求失败
throw new RuntimeException("status:" + stringResponseEntity.getStatusCodeValue() + " " + stringResponseEntity.getBody());
}
JSONObject result = JSON.parseObject(stringResponseEntity.getBody());
if (result.containsKey("errorCode") && result.getString("errorCode") != null && !result.getBooleanValue("success")) {
//业务错误
throw new RuntimeException(result.toString());
}
return result;
}
private HttpHeaders getHttpHeaders(String url) {
IrsSignRes res = IrsUtils.sign(url, "POST");
HttpHeaders headers = new HttpHeaders();
headers.add(Constants.X_BG_HMAC_ACCESS_KEY, res.getAccessKey());
headers.add(Constants.X_BG_HMAC_ALGORITHM, res.getAlgorithm());
headers.add(Constants.X_BG_HMAC_SIGNATURE, res.getSignature());
headers.add(Constants.X_BG_DATE_TIME, res.getDateTime());
return headers;
}
}
package io.hmit.modules.zlb.utils;
import lombok.Data;
/**
* @author jie.chen
* @date 2022-03-30 15:28
*/
@Data
public class IrsSignRes {
private String accessKey;
private String signature;
private String algorithm;
private String dateTime;
}
package io.hmit.modules.zlb.utils;
import io.hmit.modules.zlb.constants.Constants;
import lombok.SneakyThrows;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author jie.chen
* @date 2022-03-30 15:28
*/
public class IrsUtils {
@SneakyThrows
public static IrsSignRes sign(String url, String method) {
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(url).build();
uriComponents = uriComponents.encode();
List<String> queryArr = new ArrayList<>();
MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
for (Map.Entry<String, List<String>> next : queryParams.entrySet()) {
for (String va : next.getValue()) {
if (va == null) {
queryArr.add(next.getKey() + "=");
} else {
queryArr.add(next.getKey() + "=" + va);
}
}
}
//按照字典排序
Collections.sort(queryArr);
///Tue, 09 Nov 2021 08:49:20 GMT
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String dateTime = dateFormat.format(new Date());
String signStr = method.toUpperCase() + "\n" +
//拼接url path
uriComponents.getPath() + "\n" +
//拼接url query
String.join("&", queryArr) + "\n" +
Constants.IRS_AK + "\n" +
dateTime + "\n";
String sign = hmacSha256Base64(signStr, Constants.IRS_SK);
IrsSignRes res = new IrsSignRes();
res.setSignature(sign);
res.setAccessKey(Constants.IRS_AK);
res.setDateTime(dateTime);
res.setAlgorithm(Constants.DEFAULT_HMAC_SIGNATURE);
return res;
}
@SneakyThrows
private static String hmacSha256Base64(String content, String key) {
Mac hmacSHA256 = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
hmacSHA256.init(secretKey);
byte[] bytes = hmacSHA256.doFinal(content.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(bytes);
}
public static void main(String[] args) {
System.out.println(sign("https://bcdsg.zj.gov.cn:8443/restapi/prod/IC33000020220329000007/uc/sso/getUserInfo", "POST"));
}
}
...@@ -4,9 +4,9 @@ spring: ...@@ -4,9 +4,9 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://112.51.130.215:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # url: jdbc:mysql://112.51.130.215:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
url: jdbc:mysql://sh-cdb-jsrwe2i2.sql.tencentcdb.com:60548/bl_appointment?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useSSL=false url: jdbc:mysql://119.3.143.77:3306/bl_appointment?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: hmit_user
password: Hmit@2020 password: HmitUser@1234
initial-size: 10 initial-size: 10
max-active: 100 max-active: 100
min-idle: 10 min-idle: 10
......
...@@ -4,9 +4,9 @@ spring: ...@@ -4,9 +4,9 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://localhost:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # url: jdbc:mysql://localhost:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
url: jdbc:mysql://sh-cdb-jsrwe2i2.sql.tencentcdb.com:60548/bl_appointment?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false url: jdbc:mysql://119.3.143.77:3306/bl_appointment?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: hmit_user
password: Hmit@2020 password: HmitUser@1234
initial-size: 10 initial-size: 10
max-active: 100 max-active: 100
min-idle: 10 min-idle: 10
......
...@@ -4,9 +4,9 @@ spring: ...@@ -4,9 +4,9 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://localhost:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # url: jdbc:mysql://localhost:3306/security_enterprise?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
url: jdbc:mysql://sh-cdb-jsrwe2i2.sql.tencentcdb.com:60548/bl_appointment?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false url: jdbc:mysql://119.3.143.77:3306/bl_appointment?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: hmit_user
password: Hmit@2020 password: HmitUser@1234
initial-size: 10 initial-size: 10
max-active: 100 max-active: 100
min-idle: 10 min-idle: 10
......
...@@ -4,8 +4,10 @@ package io.hmit.common.utils; ...@@ -4,8 +4,10 @@ package io.hmit.common.utils;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64;
/** /**
* 说明:MD5处理 * 说明:MD5处理
...@@ -48,9 +50,11 @@ public class MD5 { ...@@ -48,9 +50,11 @@ public class MD5 {
public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException { public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
//确定计算方法 //确定计算方法
MessageDigest md5= MessageDigest.getInstance("MD5"); MessageDigest md5= MessageDigest.getInstance("MD5");
BASE64Encoder base64en = new BASE64Encoder(); // BASE64Encoder base64en = new BASE64Encoder();
Base64.Encoder encoder = Base64.getEncoder();
//加密后的字符串 //加密后的字符串
String newstr=base64en.encode(md5.digest(str.getBytes("utf-8"))); // String newstr=base64en.encode(md5.digest(str.getBytes("utf-8")));
String newstr = encoder.encodeToString(md5.digest(str.getBytes(StandardCharsets.UTF_8)));
return newstr; return newstr;
} }
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException { public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
......
...@@ -212,7 +212,7 @@ ...@@ -212,7 +212,7 @@
<pluginRepository> <pluginRepository>
<id>public</id> <id>public</id>
<name>aliyun nexus</name> <name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
<releases> <releases>
<enabled>true</enabled> <enabled>true</enabled>
</releases> </releases>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment