Skip to content

Commit bbf19c3

Browse files
committed
exceptionHandler
1 parent 4952ff3 commit bbf19c3

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

src/main/java/com/luna/commons/tencent/TencentAPI.java renamed to src/main/java/com/luna/commons/tencent/TencentAuthAPI.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
import org.apache.http.HttpResponse;
88
import java.util.Map;
99

10-
public class TencentAPI {
10+
public class TencentAuthAPI {
1111

1212
/**
1313
* 腾讯身份证识别
1414
*
15-
* @param base64Str 身份证照片
15+
* @param str 身份证照片可为URL
1616
* @return
1717
* @throws Exception
1818
*/
19-
public static JSONObject idOcrCheck(String id, String key, String base64Str) throws Exception {
19+
public static JSONObject idOcrCheck(String id, String key, String str) throws Exception {
2020
String body;
2121
// 判断是否为base64编码
22-
if (Base64Util.isBase64(base64Str)) {
23-
body = "{" + "\"ImageBase64\": \"" + base64Str + "\"" + "}";
22+
if (Base64Util.isBase64(str)) {
23+
body = "{" + "\"ImageBase64\": \"" + str + "\"" + "}";
2424
} else {
25-
body = "{" + "\"ImageBase64\": \"" + Base64Util.encodeBase64String(ImageUtils.getBytes(base64Str)) + "\""
25+
body = "{" + "\"ImageBase64\": \"" + Base64Util.encodeBase64String(ImageUtils.getBytes(str)) + "\""
2626
+ "}";
2727
}
2828
Map postHeader = TencentCloudAPITC3.getPostHeader(id, key, "ocr",
@@ -36,6 +36,9 @@ public static JSONObject idOcrCheck(String id, String key, String base64Str) thr
3636

3737
/**
3838
* 腾讯云手机号在网检查 不支持电信手机号
39+
* <p>
40+
* 0.4
41+
* <p/>
3942
*
4043
* @param mobile
4144
* @return
@@ -57,7 +60,11 @@ public static JSONObject mobileCheck(String id, String key, String mobile) throw
5760
}
5861

5962
/**
60-
* 腾讯云身份证两要素
63+
* 身份证两要素
64+
* <p>
65+
* 0.3
66+
* <p/>
67+
* 建议测试采用云市场Api
6168
*
6269
* @param id
6370
* @param name
@@ -80,7 +87,10 @@ public static JSONObject idNameCheck(String id, String key, String idCard, Strin
8087
}
8188

8289
/**
83-
* 腾讯云银行卡三要素 姓名 卡号 办理卡号证件
90+
* 银行卡三要素 姓名 卡号 办理卡号证件
91+
* <p>
92+
* 0.4
93+
* <p/>
8494
*
8595
* @param id
8696
* @param name
@@ -106,17 +116,16 @@ public static JSONObject bankCardIdNameCheck(String id, String key, String idCar
106116
}
107117

108118
/**
109-
* ==收费,需安全级别较高==
110-
* 腾讯人脸身份证识别
119+
* 腾讯人脸照片核身
111120
*
112121
* @param base64Str 人脸照片
113122
* @param name 姓名
114123
* @param idCard 身份证号
115124
* @return
116125
* @throws Exception
117126
*/
118-
public static JSONObject idAndFaceCheck(String id, String key, String base64Str, String name,
119-
String idCard) throws Exception {
127+
public static JSONObject idAndFaceCheck(String id, String key, String base64Str, String name, String idCard)
128+
throws Exception {
120129
String body = "{\n" +
121130
"\t\"IdCard\":\"" + idCard + "\",\n" +
122131
" \"Name\":\"" + name + "\",\n" +

src/main/java/com/luna/commons/tencent/TencentFaceApi.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
import com.luna.commons.dto.constant.ResultCode;
9+
import com.luna.commons.exception.base.BaseException;
810
import org.apache.http.HttpResponse;
911

1012
import com.alibaba.fastjson.JSON;
@@ -110,7 +112,12 @@ public static boolean modifyFaceDatabase(String id, String key, String groupId,
110112
HttpResponse httpResponse =
111113
HttpUtils.doPost("https://" + TencentConstant.FACE_CHECK, "/", postHeader, null, body);
112114
JSONObject response = HttpUtils.getResponse(httpResponse);
113-
return JSON.parseObject(response.getString("Response")).getString("Error") == null;
115+
String string = JSON.parseObject(response.getString("Response")).getString("Error");
116+
if ("".equals(string)) {
117+
return true;
118+
} else {
119+
throw new BaseException(ResultCode.ERROR_SYSTEM_EXCEPTION, string);
120+
}
114121
}
115122

116123
/**
@@ -227,7 +234,7 @@ public static boolean deleteFace(String id, String key, String personId)
227234
*
228235
* @param id
229236
* @param key
230-
* @param personId
237+
* @param personId 人员id
231238
* @return
232239
* @throws Exception
233240
*/
@@ -251,8 +258,8 @@ public static boolean getFace(String id, String key, String personId)
251258
*
252259
* @param id
253260
* @param key
254-
* @param image64
255-
* @param groupIds
261+
* @param image64 人员图片
262+
* @param groupIds 人员组 array of String
256263
* @return
257264
* @throws Exception
258265
*/
@@ -299,8 +306,8 @@ public static String searchFaceByGroup(String id, String key, String image64, St
299306
*
300307
* @param id
301308
* @param key
302-
* @param personId
303-
* @param image64
309+
* @param personId 人员id
310+
* @param image64 人员照片
304311
* @return
305312
* @throws Exception
306313
*/
@@ -375,7 +382,7 @@ public static Double faceCheck(String id, String key, String image641, String im
375382
if ("".equals(string)) {
376383
return Double.parseDouble(JSON.parseObject(response.getString("Response")).getString("Score"));
377384
} else {
378-
return null;
385+
throw new BaseException(ResultCode.ERROR_SYSTEM_EXCEPTION, string);
379386
}
380387
}
381388

src/main/resource/db/tb_template.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Navicat Premium Data Transfer
3+
4+
Source Server : luna-tencent
5+
Source Server Type : MySQL
6+
Source Server Version : 50728
7+
Source Host : 111.229.114.126:3307
8+
Source Schema : luna-message
9+
10+
Target Server Type : MySQL
11+
Target Server Version : 50728
12+
File Encoding : 65001
13+
14+
Date: 07/06/2020 16:29:54
15+
*/
16+
17+
SET NAMES utf8mb4;
18+
SET FOREIGN_KEY_CHECKS = 0;
19+
20+
-- ----------------------------
21+
-- Table structure for tb_template
22+
-- ----------------------------
23+
DROP TABLE IF EXISTS `tb_template`;
24+
CREATE TABLE `tb_template` (
25+
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
26+
`create_time` datetime(0) NOT NULL,
27+
`modified_time` datetime(0) NOT NULL,
28+
`subject` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
29+
`content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
30+
PRIMARY KEY (`id`) USING BTREE
31+
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
32+
33+
-- ----------------------------
34+
-- Records of tb_template
35+
-- ----------------------------
36+
INSERT INTO `tb_template` VALUES (13, '2020-02-05 20:41:33', '2020-02-05 20:41:31', '您已重置密码', '您已重置密码,新密码为:${newPassword},请妥善保存。');
37+
INSERT INTO `tb_template` VALUES (14, '2020-02-05 20:41:33', '2020-02-05 20:41:31', '您的验证码', '您的验证码是:${authCode},5分钟有效,打死也不要告诉别人哦。');
38+
39+
SET FOREIGN_KEY_CHECKS = 1;

0 commit comments

Comments
 (0)