修改登录
This commit is contained in:
parent
54c250a7a6
commit
c41d50c54f
@ -77,6 +77,17 @@ public class PublicController {
|
|||||||
return Response.error("微信授权失败");
|
return Response.error("微信授权失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map resultMap = userService.getAppUser(phoneInfo.getPurePhoneNumber());
|
||||||
|
// 取出code
|
||||||
|
Integer code = (Integer) resultMap.get("code");
|
||||||
|
if (code != 200){
|
||||||
|
String msg = (String) resultMap.get("msg");
|
||||||
|
if (msg != null && !msg.isEmpty()){
|
||||||
|
return Response.error(code,null,msg);
|
||||||
|
}
|
||||||
|
return Response.error(code,null,"登陆失败");
|
||||||
|
}
|
||||||
|
|
||||||
// 用户登陆
|
// 用户登陆
|
||||||
LoginDto g = userService.UserLoginWithMobile(phoneInfo.getPurePhoneNumber());
|
LoginDto g = userService.UserLoginWithMobile(phoneInfo.getPurePhoneNumber());
|
||||||
return Response.success(g);
|
return Response.success(g);
|
||||||
@ -219,6 +230,17 @@ public class PublicController {
|
|||||||
return Response.error("微信授权失败");
|
return Response.error("微信授权失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map resultMap = userService.getAppUser(request.getPhone());
|
||||||
|
// 取出code
|
||||||
|
Integer code = (Integer) resultMap.get("code");
|
||||||
|
if (code != 200){
|
||||||
|
String msg = (String) resultMap.get("msg");
|
||||||
|
if (msg != null && !msg.isEmpty()){
|
||||||
|
return Response.error(code,null,msg);
|
||||||
|
}
|
||||||
|
return Response.error(code,null,"登陆失败");
|
||||||
|
}
|
||||||
|
|
||||||
// 用户登陆
|
// 用户登陆
|
||||||
LoginDto g = userService.UserLoginWithMobile(request.getPhone());
|
LoginDto g = userService.UserLoginWithMobile(request.getPhone());
|
||||||
return Response.success(g);
|
return Response.success(g);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.example.caseData.service;
|
package com.example.caseData.service;
|
||||||
|
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.example.caseData.config.EnvConfig;
|
import com.example.caseData.config.EnvConfig;
|
||||||
@ -15,11 +16,11 @@ import com.example.caseData.extend.app.UserInfo.GetUserInfoResponse;
|
|||||||
import com.example.caseData.extend.app.UserInfo.UserInfo;
|
import com.example.caseData.extend.app.UserInfo.UserInfo;
|
||||||
import com.example.caseData.extend.weChat.WxMaServiceUtils;
|
import com.example.caseData.extend.weChat.WxMaServiceUtils;
|
||||||
import com.example.caseData.model.*;
|
import com.example.caseData.model.*;
|
||||||
import com.example.caseData.request.UserRequest.ReportUserScoreRequest;
|
|
||||||
import com.example.caseData.utils.JwtUtil;
|
import com.example.caseData.utils.JwtUtil;
|
||||||
import com.example.caseData.utils.Replace;
|
import com.example.caseData.utils.Replace;
|
||||||
|
import com.example.caseData.utils.Sha256Util;
|
||||||
import com.example.caseData.utils.StringToInt;
|
import com.example.caseData.utils.StringToInt;
|
||||||
import com.example.caseData.config.EnvConfig;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -31,16 +32,9 @@ import java.net.URL;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.Year;
|
import java.time.Year;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Random;
|
import java.util.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
|
import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
|
||||||
@ -99,6 +93,8 @@ public class UserService {
|
|||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public LoginDto UserLoginWithMobile(String phone) throws BusinessException {
|
public LoginDto UserLoginWithMobile(String phone) throws BusinessException {
|
||||||
|
|
||||||
|
|
||||||
// 获取app用户数据
|
// 获取app用户数据
|
||||||
GetUserInfoResponse result = userInfo.getUserInfoByMobile(phone);
|
GetUserInfoResponse result = userInfo.getUserInfoByMobile(phone);
|
||||||
UserModel user = GetAppUserInfo(result);
|
UserModel user = GetAppUserInfo(result);
|
||||||
@ -374,6 +370,26 @@ public class UserService {
|
|||||||
return caseClinicalDoctor;
|
return caseClinicalDoctor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map getAppUser(String mobile) {
|
||||||
|
try {
|
||||||
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
|
params.put("mobile", mobile);
|
||||||
|
params.put("platform", "case");
|
||||||
|
params.put("timestamp", System.currentTimeMillis() / 1000);
|
||||||
|
String signature = Sha256Util.getSign(params, "zd8V2LYD4achjFZrbHgD2PuzKuthDCVx");
|
||||||
|
params.put("signature", signature);
|
||||||
|
String result = HttpUtil.post("https://wx.igandan.com/hcp/getInfo", params);
|
||||||
|
// 解析JSON
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Map resultMap = objectMapper.readValue(result, Map.class);
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
79
src/main/java/com/example/caseData/utils/EncryptionKit.java
Normal file
79
src/main/java/com/example/caseData/utils/EncryptionKit.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2015, James Zhan 詹波 (jfinal@126.com).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example.caseData.utils;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
public class EncryptionKit {
|
||||||
|
|
||||||
|
public static String md5Encrypt(String srcStr) {
|
||||||
|
return encrypt("MD5", srcStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha1Encrypt(String srcStr) {
|
||||||
|
return encrypt("SHA-1", srcStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha256Encrypt(String srcStr) {
|
||||||
|
return encrypt("SHA-256", srcStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha384Encrypt(String srcStr) {
|
||||||
|
return encrypt("SHA-384", srcStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sha512Encrypt(String srcStr) {
|
||||||
|
return encrypt("SHA-512", srcStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encrypt(String algorithm, String srcStr) {
|
||||||
|
try {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
MessageDigest md = MessageDigest.getInstance(algorithm);
|
||||||
|
byte[] bytes = md.digest(srcStr.getBytes("utf-8"));
|
||||||
|
for (byte b : bytes) {
|
||||||
|
String hex = Integer.toHexString(b & 0xFF);
|
||||||
|
if (hex.length() == 1)
|
||||||
|
result.append("0");
|
||||||
|
result.append(hex);
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String HMACSHA256(String data, String key) {
|
||||||
|
try {
|
||||||
|
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
|
||||||
|
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
|
||||||
|
sha256_HMAC.init(secret_key);
|
||||||
|
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte item : array) {
|
||||||
|
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
|
||||||
|
}
|
||||||
|
return sb.toString().toLowerCase();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
src/main/java/com/example/caseData/utils/Sha256Util.java
Normal file
46
src/main/java/com/example/caseData/utils/Sha256Util.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.example.caseData.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
*/
|
||||||
|
public class Sha256Util {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
* @param params
|
||||||
|
* @param accessToken
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getSign(Map<String, Object> params, String accessToken) {
|
||||||
|
List<String> keys = new ArrayList<>(params.keySet());
|
||||||
|
List<String> tmp = new ArrayList<>();
|
||||||
|
Collections.sort(keys);
|
||||||
|
for (String key : keys) {
|
||||||
|
if (!StrUtil.isEmptyIfStr(params.get(key))) {
|
||||||
|
tmp.add(key + "=" + params.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String join = String.join("&", tmp);
|
||||||
|
return EncryptionKit.HMACSHA256(join, accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSignString(Map<String, String> params, String accessToken) {
|
||||||
|
List<String> keys = new ArrayList<>(params.keySet());
|
||||||
|
List<String> tmp = new ArrayList<>();
|
||||||
|
Collections.sort(keys);
|
||||||
|
for (String key : keys) {
|
||||||
|
if (!StrUtil.isEmptyIfStr(params.get(key))) {
|
||||||
|
tmp.add(key + "=" + params.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String join = String.join("&", tmp);
|
||||||
|
return EncryptionKit.HMACSHA256(join, accessToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user