接口优化

This commit is contained in:
dzl 2025-05-29 18:24:27 +08:00
parent c385341a79
commit d03e995a37

View File

@ -65,7 +65,6 @@ public class VerifyUtil {
/** /**
* 微信工具类构造函数 * 微信工具类构造函数
*
*/ */
public VerifyUtil() throws IOException { public VerifyUtil() throws IOException {
client = new OkHttpClient(); client = new OkHttpClient();
@ -77,7 +76,7 @@ public class VerifyUtil {
* @param code 微信登录返回的code * @param code 微信登录返回的code
* @return openId * @return openId
*/ */
public JSONObject wechatAuthority(String code){ public JSONObject wechatAuthority(String code) {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("appid", wechatConfig.getAppId()); params.put("appid", wechatConfig.getAppId());
params.put("secret", wechatConfig.getAppSecret()); params.put("secret", wechatConfig.getAppSecret());
@ -90,8 +89,8 @@ public class VerifyUtil {
* 解密微信用户信息 * 解密微信用户信息
* *
* @param encryptedData 加密数据 * @param encryptedData 加密数据
* @param sessionKey 会话密钥 * @param sessionKey 会话密钥
* @param iv 初始向量 * @param iv 初始向量
* @return 解密后的用户信息 * @return 解密后的用户信息
*/ */
public String decryptData(String encryptedData, String sessionKey, String iv) { public String decryptData(String encryptedData, String sessionKey, String iv) {
@ -153,23 +152,22 @@ public class VerifyUtil {
log.error("验证用户实名失败"); log.error("验证用户实名失败");
return JsonResult.failed("验证用户实名失败"); return JsonResult.failed("验证用户实名失败");
} }
if ("10000".equals(result.getString("code"))){ if ("10000".equals(result.getString("code"))) {
// 3. 解密结果 // 3. 解密结果
String data = securityContext.decrypt(result.getString("data"), realNameVerifyConfig.getClientPrivateKey()); String data = securityContext.decrypt(result.getString("data"), realNameVerifyConfig.getClientPrivateKey());
JSONObject jsonData = JSON.parseObject(data); JSONObject jsonData = JSON.parseObject(data);
if("10000".equals(jsonData.getString("code"))&&"1".equals(jsonData.getJSONObject("data").getString("state"))){ if ("10000".equals(jsonData.getString("code")) && "1".equals(jsonData.getJSONObject("data").getString("state"))) {
// 4. 更新用户实名信息 // 4. 更新用户实名信息
return JsonResult.success("验证用户实名成功"); return JsonResult.success("验证用户实名成功");
} }
}else{
log.error("验证用户实名失败,{} {}", result.getString("code"), result.getString("message"));
return JsonResult.failed(result.getString("code") +", "+ result.getString("message"));
} }
}catch (EncryptFailureException e) { log.error("验证用户实名失败,{} {}", result.getString("code"), result.getString("message"));
return JsonResult.failed(result.getString("code") + ", " + result.getString("message"));
} catch (EncryptFailureException e) {
log.error("加密失败", e); log.error("加密失败", e);
return JsonResult.failed("加密失败"); return JsonResult.failed("加密失败");
}catch (SignFailureException e) { } catch (SignFailureException e) {
log.error("签名失败", e); log.error("签名失败", e);
return JsonResult.failed("签名失败"); return JsonResult.failed("签名失败");
} catch (DecryptFailureException e) { } catch (DecryptFailureException e) {
@ -181,8 +179,8 @@ public class VerifyUtil {
/** /**
* 发送HTTP GET请求 * 发送HTTP GET请求
* *
* @param func_ 功能描述 * @param func_ 功能描述
* @param url 请求URL * @param url 请求URL
* @param params 请求参数 * @param params 请求参数
* @return 响应结果 * @return 响应结果
*/ */
@ -206,7 +204,7 @@ public class VerifyUtil {
} }
if (response.body() != null) { if (response.body() != null) {
log.error("{}, 请求{}失败, {}", func_, url, response.body().string()); log.error("{}, 请求{}失败, {}", func_, url, response.body().string());
}else { } else {
log.error("{}, 请求{}失败", func_, url); log.error("{}, 请求{}失败", func_, url);
} }
return null; return null;