FaceCollectServ.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. package biz.xy;
  2. import base.WechatC;
  3. import com.google.gson.JsonElement;
  4. import com.google.gson.JsonObject;
  5. import com.google.gson.JsonParser;
  6. import jakarta.servlet.http.HttpServletRequest;
  7. import okhttp3.Response;
  8. import org.apache.commons.io.FileUtils;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.apache.logging.log4j.LogManager;
  11. import org.apache.logging.log4j.Logger;
  12. import ss.AppB;
  13. import ss.cmn.idcard.IdcardU;
  14. import ss.cmn.str.StrDate;
  15. import ss.cmn.str.StrUuid;
  16. import ss.db.Db;
  17. import ss.db.FaceCollectDb;
  18. import ss.db.SqlCmd;
  19. import ss.http.HttpU;
  20. import ss.serv.Serv;
  21. import ss.serv.ServC;
  22. import java.io.File;
  23. import java.sql.SQLException;
  24. import java.sql.Timestamp;
  25. import java.net.URLEncoder;
  26. import java.nio.charset.StandardCharsets;
  27. import java.text.SimpleDateFormat;
  28. import java.util.LinkedHashMap;
  29. import java.util.Map;
  30. import java.util.concurrent.ConcurrentHashMap;
  31. /**
  32. * 2026-07-25:匿名人脸采集服务。
  33. * 使用 FACE_COLLECT 独立数据源,提供扫码令牌校验、身份证号验重、提交覆盖和结果查询。
  34. */
  35. public class FaceCollectServ extends Serv {
  36. private static final Logger log4j = LogManager.getLogger(FaceCollectServ.class);
  37. private static final String TAB_FACE_COLLECT = "XY_FACE_COLLECT";
  38. private static final String TAB_FACE_COLLECT_LOG = "XY_FACE_COLLECT_LOG";
  39. private static final String TAB_FACE_COLLECT_TOKEN = "XY_FACE_COLLECT_TOKEN";
  40. private static final String SEQ_FACE_COLLECT = "SEQ_XY_FACE_COLLECT";
  41. private static final String SEQ_FACE_COLLECT_LOG = "SEQ_XY_FACE_COLLECT_LOG";
  42. private static final String SEQ_FACE_COLLECT_TOKEN = "SEQ_XY_FACE_COLLECT_TOKEN";
  43. private static final String DEF_SCENE = "faceCollect";
  44. private static final String DEF_CHANNEL = "miniProgram";
  45. private static final String DEF_PLATFORM = "mp-weixin";
  46. private static final String DEF_QRCODE_PAGE = "pages/public/faceCollect/index";
  47. private static final String DEF_QRCODE_DIR = "faceCollect/qrcode";
  48. private static final String DEF_QRCODE_ENV = "release";
  49. private static final int DEF_QRCODE_EXPIRE_DAYS = 30;
  50. private static final String URL_WECHAT_QRCODE =
  51. "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s";
  52. private static final int HK_SYNC_STATUS_UNSYNC = 0;
  53. private static final int JLZT_EDITING = 1;
  54. private static final long DUP_REQ_GAP_MS = 1200L;
  55. private static final long SUBMIT_REQ_GAP_MS = 3000L;
  56. private static final int RATE_LIMIT_MAP_MAX = 4096;
  57. private static final long RATE_LIMIT_CLEANUP_MS = 10 * 60 * 1000L;
  58. private static final ConcurrentHashMap<String, Long> RATE_LIMIT_TS_MAP = new ConcurrentHashMap<>();
  59. @SuppressWarnings("unused")
  60. public String chkSceneToken() {
  61. super.wrJsonByResp(chkSceneTokenResult());
  62. return ServC.SERV_notByA;
  63. }
  64. @SuppressWarnings("unused")
  65. public String chkDupBySfzh() {
  66. super.wrJsonByResp(chkDupBySfzhResult());
  67. return ServC.SERV_notByA;
  68. }
  69. @SuppressWarnings("unused")
  70. public String submit() {
  71. super.wrJsonByResp(submitResult());
  72. return ServC.SERV_notByA;
  73. }
  74. @SuppressWarnings("unused")
  75. public String uploadTrace() {
  76. super.wrJsonByResp(uploadTraceResult());
  77. return ServC.SERV_notByA;
  78. }
  79. @SuppressWarnings("unused")
  80. public String queryResult() {
  81. super.wrJsonByResp(queryResultData());
  82. return ServC.SERV_notByA;
  83. }
  84. @SuppressWarnings("unused")
  85. public String genQrcode() {
  86. super.wrJsonByResp(genQrcodeResult());
  87. return ServC.SERV_notByA;
  88. }
  89. private Map<String, Object> genQrcodeResult() {
  90. String batchId = StringUtils.defaultIfBlank(rdReqTrim("batchId"), buildBatchId());
  91. String remark = StringUtils.left(StringUtils.defaultIfBlank(rdReqTrim("remark"), "匿名人脸采集二维码"), 500);
  92. String envVersion = normalizeEnvVersion(rdReqTrim("envVersion"));
  93. boolean checkPath = rdReqBool("checkPath", false);
  94. Integer maxSubmitNum = rdReqNullableInt("maxSubmitNum");
  95. Timestamp expireTime;
  96. try {
  97. expireTime = resolveReqExpireTime();
  98. } catch (Exception e) {
  99. return mkFail("FACE_COLLECT_PARAM_INVALID", rdErrMsg(e, "二维码有效期参数不正确。"));
  100. }
  101. if (StringUtils.isBlank(batchId))
  102. return mkFail("FACE_COLLECT_PARAM_INVALID", "二维码批次不能为空。");
  103. if (!"release".equals(envVersion) && !"trial".equals(envVersion) && !"develop".equals(envVersion))
  104. return mkFail("FACE_COLLECT_PARAM_INVALID", "envVersion 仅支持 release、trial、develop。");
  105. if (expireTime == null || !expireTime.after(new Timestamp(System.currentTimeMillis())))
  106. return mkFail("FACE_COLLECT_PARAM_INVALID", "二维码过期时间必须大于当前时间。");
  107. if (maxSubmitNum != null && maxSubmitNum <= 0)
  108. return mkFail("FACE_COLLECT_PARAM_INVALID", "maxSubmitNum 必须大于 0。");
  109. if (StringUtils.isBlank(AppB.imgBaseDir))
  110. return mkFail("FACE_COLLECT_CFG_ERROR", "系统未配置图片根目录,无法保存二维码。");
  111. String token = StrUuid.makeUuid();
  112. String sceneValue = token;
  113. String qrPath = buildQrcodeRelPath(token);
  114. File qrFile = null;
  115. try (Db gdba = FaceCollectDb.makeConn()) {
  116. if (gdba == null)
  117. return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
  118. byte[] qrBytes = rdWechatMiniProgramQrcode(sceneValue, envVersion, checkPath);
  119. qrFile = new File(AppB.imgBaseDir, qrPath.replace("/", File.separator));
  120. File parent = qrFile.getParentFile();
  121. if (parent != null && !parent.exists() && !parent.mkdirs())
  122. throw new RuntimeException("二维码目录创建失败:" + parent.getAbsolutePath());
  123. FileUtils.writeByteArrayToFile(qrFile, qrBytes);
  124. long tokenId = gdba.rdNextSeqVal(SEQ_FACE_COLLECT_TOKEN);
  125. Timestamp now = new Timestamp(System.currentTimeMillis());
  126. SqlCmd insSql = new SqlCmd("insert into " + TAB_FACE_COLLECT_TOKEN +
  127. " (TOKEN_ID,TOKEN,SCENE,BATCH_ID,STATUS,EXPIRE_TIME,MAX_SUBMIT_NUM,CUR_SUBMIT_NUM,REMARK,CJSJ)" +
  128. " values (:tokenId,:token,:scene,:batchId,1,:expireTime,:maxSubmitNum,0,:remark,:cjsj)");
  129. insSql.wrLongParm("tokenId", tokenId);
  130. insSql.wrStrParm("token", token);
  131. insSql.wrStrParm("scene", DEF_SCENE);
  132. insSql.wrStrParm("batchId", StringUtils.left(batchId, 100));
  133. insSql.wrTimeParm("expireTime", expireTime);
  134. insSql.wrIntParm("maxSubmitNum", maxSubmitNum);
  135. insSql.wrStrParm("remark", remark);
  136. insSql.wrTimeParm("cjsj", now);
  137. gdba.doModByC(insSql);
  138. logOper(gdba, 0L, "", token, "genQrcode", true,
  139. "二维码生成成功,envVersion=" + envVersion + ",batchId=" + batchId + "。");
  140. gdba.commit();
  141. Map<String, Object> result = mkOk("二维码生成成功");
  142. Map<String, Object> data = castData(result);
  143. data.put("token", token);
  144. data.put("scene", DEF_SCENE);
  145. data.put("sceneValue", sceneValue);
  146. data.put("page", DEF_QRCODE_PAGE);
  147. data.put("batchId", batchId);
  148. data.put("expireTime", fmtTime(expireTime));
  149. data.put("maxSubmitNum", maxSubmitNum);
  150. data.put("envVersion", envVersion);
  151. data.put("checkPath", checkPath);
  152. data.put("qrPath", qrPath);
  153. data.put("qrPreviewUrl", buildQrcodePreviewUrl(qrPath));
  154. data.put("miniProgramAppId", WechatC.WECHATP_appId);
  155. return result;
  156. } catch (Exception e) {
  157. if (qrFile != null && qrFile.exists())
  158. FileUtils.deleteQuietly(qrFile);
  159. log4j.error("FaceCollectServ.genQrcodeResult() 异常", e);
  160. return mkFail("FACE_COLLECT_QRCODE_FAIL", rdErrMsg(e, "生成小程序二维码失败。"));
  161. }
  162. }
  163. private Map<String, Object> chkSceneTokenResult() {
  164. String token = rdReqTrim("token");
  165. String scene = rdReqTrim("scene");
  166. String batchId = rdReqTrim("batchId");
  167. try (Db gdba = FaceCollectDb.makeConn()) {
  168. if (gdba == null)
  169. return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
  170. TokenChkResult tokenChk = chkToken(gdba, token, scene, batchId, false, false);
  171. Map<String, Object> result = tokenChk.result;
  172. logOper(gdba, 0L, "", token, "chkSceneToken", rdBool(result.get("ok")), rdStr(result.get("msg")));
  173. if (rdBool(result.get("ok")) && tokenChk.tokenRow != null) {
  174. Map<String, Object> data = castData(result);
  175. data.put("needMatchStudent", false);
  176. }
  177. gdba.commit();
  178. return result;
  179. } catch (Exception e) {
  180. log4j.error("FaceCollectServ.chkSceneTokenResult() 异常", e);
  181. return mkFail("FACE_COLLECT_TOKEN_INVALID", rdErrMsg(e, "二维码已失效或不存在。"));
  182. }
  183. }
  184. private Map<String, Object> chkDupBySfzhResult() {
  185. String sfzh = normalizeSfzh(rdReqTrim("sfzh"));
  186. String token = rdReqTrim("token");
  187. String scene = rdReqTrim("scene");
  188. String batchId = rdReqTrim("batchId");
  189. if (StringUtils.isBlank(sfzh))
  190. return mkFail("FACE_COLLECT_PARAM_INVALID", "身份证号不能为空。");
  191. if (!IdcardU.chk(sfzh))
  192. return mkFail("FACE_COLLECT_PARAM_INVALID", "身份证号格式不正确。");
  193. if (hitRateLimit("dup:" + sfzh, DUP_REQ_GAP_MS))
  194. return mkFail("FACE_COLLECT_RATE_LIMIT", "请求过于频繁,请稍后再试。");
  195. try (Db gdba = FaceCollectDb.makeConn()) {
  196. if (gdba == null)
  197. return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
  198. if (StringUtils.isNotBlank(token)) {
  199. TokenChkResult tokenChk = chkToken(gdba, token, scene, batchId, false, false);
  200. if (!rdBool(tokenChk.result.get("ok"))) {
  201. logOper(gdba, 0L, sfzh, token, "chkDupBySfzh", false, rdStr(tokenChk.result.get("msg")));
  202. gdba.commit();
  203. return tokenChk.result;
  204. }
  205. }
  206. Map<String, Object> currentRow = selCurrentFaceCollectRow(gdba, sfzh);
  207. Map<String, Object> result = mkOk("查询成功");
  208. Map<String, Object> data = castData(result);
  209. boolean exists = currentRow != null && !currentRow.isEmpty();
  210. data.put("exists", exists);
  211. data.put("needConfirmOnSubmit", exists);
  212. if (exists) {
  213. data.put("lastSubmitTime", fmtTime(currentRow.get("cjsj")));
  214. data.put("lastStudentName", rdStr(currentRow.get("xm")));
  215. data.put("tipMsg", "该身份证号已提交过人脸图片,再次提交将覆盖当前有效人脸图片。");
  216. } else {
  217. data.put("tipMsg", "");
  218. }
  219. logOper(gdba, 0L, sfzh, token, "chkDupBySfzh", true, exists ? "已存在当前有效记录。" : "未命中当前有效记录。");
  220. gdba.commit();
  221. return result;
  222. } catch (Exception e) {
  223. log4j.error("FaceCollectServ.chkDupBySfzhResult() 异常", e);
  224. return mkFail("FACE_COLLECT_QUERY_FAIL", rdErrMsg(e, "身份证号验重失败。"));
  225. }
  226. }
  227. private Map<String, Object> submitResult() {
  228. HttpServletRequest request = super.req;
  229. String xm = StringUtils.trimToEmpty(rdReqTrim("xm"));
  230. String sfzh = normalizeSfzh(rdReqTrim("sfzh"));
  231. String imgPath = rdReqTrim("imgPath");
  232. String rawImgPath = StringUtils.defaultIfBlank(rdReqTrim("rawImgPath"), imgPath);
  233. String token = rdReqTrim("token");
  234. String scene = rdReqTrim("scene");
  235. String batchId = rdReqTrim("batchId");
  236. boolean confirmCover = rdBoolStr(rdReqTrim("confirmCover"));
  237. String clientDeviceId = StringUtils.defaultIfBlank(rdReqTrim("clientDeviceId"), rdReqTrim("devId"));
  238. String clientModel = StringUtils.defaultIfBlank(rdReqTrim("clientModel"), rdReqTrim("sbmc"));
  239. String clientPlatform = StringUtils.defaultIfBlank(rdReqTrim("clientPlatform"), DEF_PLATFORM);
  240. String clientIp = rdClientIp(request);
  241. if (StringUtils.isBlank(xm))
  242. return mkFail("FACE_COLLECT_PARAM_INVALID", "学生姓名不能为空。");
  243. if (StringUtils.isBlank(sfzh))
  244. return mkFail("FACE_COLLECT_PARAM_INVALID", "身份证号不能为空。");
  245. if (!IdcardU.chk(sfzh))
  246. return mkFail("FACE_COLLECT_PARAM_INVALID", "身份证号格式不正确。");
  247. if (StringUtils.isBlank(imgPath))
  248. return mkFail("FACE_COLLECT_IMG_REQUIRED", "人脸图片不能为空。");
  249. if (!ifValidUploadPath(imgPath) || !ifValidUploadPath(rawImgPath))
  250. return mkFail("FACE_COLLECT_PARAM_INVALID", "图片路径不合法,请重新拍照上传。");
  251. if (StringUtils.isBlank(token))
  252. return mkFail("FACE_COLLECT_TOKEN_INVALID", "缺少有效的二维码令牌。");
  253. if (hitRateLimit("submit:" + sfzh, SUBMIT_REQ_GAP_MS))
  254. return mkFail("FACE_COLLECT_RATE_LIMIT", "提交过于频繁,请稍后再试。");
  255. try (Db gdba = FaceCollectDb.makeConn()) {
  256. if (gdba == null)
  257. return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
  258. TokenChkResult tokenChk = chkToken(gdba, token, scene, batchId, true, true);
  259. if (!rdBool(tokenChk.result.get("ok"))) {
  260. logOper(gdba, 0L, sfzh, token, "submit", false, rdStr(tokenChk.result.get("msg")));
  261. gdba.commit();
  262. return tokenChk.result;
  263. }
  264. Map<String, Object> currentRow = selCurrentFaceCollectRow(gdba, sfzh);
  265. boolean isCover = currentRow != null && !currentRow.isEmpty();
  266. if (isCover && !confirmCover) {
  267. Map<String, Object> result = mkFail("FACE_COLLECT_NEED_CONFIRM_COVER",
  268. "该身份证号已提交过人脸图片,本次提交会覆盖上一次当前有效人脸图片,请确认后再提交。");
  269. Map<String, Object> data = castData(result);
  270. data.put("needConfirmCover", true);
  271. data.put("lastSubmitTime", fmtTime(currentRow.get("cjsj")));
  272. data.put("lastStudentName", rdStr(currentRow.get("xm")));
  273. logOper(gdba, 0L, sfzh, token, "submit", false, rdStr(result.get("msg")));
  274. gdba.commit();
  275. return result;
  276. }
  277. int versionNo = rdInt(currentRow == null ? null : currentRow.get("version_no"), 0) + 1;
  278. long faceCollectId = gdba.rdNextSeqVal(SEQ_FACE_COLLECT);
  279. Timestamp now = new Timestamp(System.currentTimeMillis());
  280. long coveredFaceCollectId = rdLong(currentRow == null ? null : currentRow.get("face_collect_id"));
  281. if (isCover) {
  282. SqlCmd resetSql = new SqlCmd("update " + TAB_FACE_COLLECT +
  283. " set IS_CURRENT=0,XGSJ=:xgsj where SFZH=:sfzh and IS_CURRENT=1");
  284. resetSql.wrTimeParm("xgsj", now);
  285. resetSql.wrStrParm("sfzh", sfzh);
  286. gdba.doModByC(resetSql);
  287. }
  288. SqlCmd insSql = new SqlCmd("insert into " + TAB_FACE_COLLECT +
  289. " (FACE_COLLECT_ID,XM,SFZH,IMG_PATH,RAW_IMG_PATH,VERSION_NO,IS_CURRENT,SRC_CHANNEL,QR_TOKEN,BATCH_ID," +
  290. " CLIENT_DEVICE_ID,CLIENT_MODEL,CLIENT_PLATFORM,CLIENT_IP,SYNC_HK_STATUS,CJSJ,JLZTM)" +
  291. " values (:faceCollectId,:xm,:sfzh,:imgPath,:rawImgPath,:versionNo,1,:srcChannel,:qrToken,:batchId," +
  292. " :clientDeviceId,:clientModel,:clientPlatform,:clientIp,:syncHkStatus,:cjsj,:jlztm)");
  293. insSql.wrLongParm("faceCollectId", faceCollectId);
  294. insSql.wrStrParm("xm", xm);
  295. insSql.wrStrParm("sfzh", sfzh);
  296. insSql.wrStrParm("imgPath", imgPath);
  297. insSql.wrStrParm("rawImgPath", rawImgPath);
  298. insSql.wrIntParm("versionNo", versionNo);
  299. insSql.wrStrParm("srcChannel", DEF_CHANNEL);
  300. insSql.wrStrParm("qrToken", token);
  301. insSql.wrStrParm("batchId", rdStr(tokenChk.tokenRow.get("batch_id")));
  302. insSql.wrStrParm("clientDeviceId", clientDeviceId);
  303. insSql.wrStrParm("clientModel", clientModel);
  304. insSql.wrStrParm("clientPlatform", clientPlatform);
  305. insSql.wrStrParm("clientIp", clientIp);
  306. insSql.wrIntParm("syncHkStatus", HK_SYNC_STATUS_UNSYNC);
  307. insSql.wrTimeParm("cjsj", now);
  308. insSql.wrIntParm("jlztm", JLZT_EDITING);
  309. gdba.doModByC(insSql);
  310. SqlCmd updTokenSql = new SqlCmd("update " + TAB_FACE_COLLECT_TOKEN +
  311. " set CUR_SUBMIT_NUM=nvl(CUR_SUBMIT_NUM,0)+1 where TOKEN_ID=:tokenId");
  312. updTokenSql.wrLongParm("tokenId", rdLong(tokenChk.tokenRow.get("token_id")));
  313. gdba.doModByC(updTokenSql);
  314. String logMsg = isCover
  315. ? "覆盖提交成功,已将上一次当前有效记录转为历史版本。"
  316. : "首次提交成功。";
  317. logOper(gdba, faceCollectId, sfzh, token, "submit", true, logMsg);
  318. gdba.commit();
  319. Map<String, Object> result = mkOk(isCover
  320. ? "提交成功,本次已覆盖上一次当前有效人脸图片"
  321. : "提交成功");
  322. Map<String, Object> data = castData(result);
  323. data.put("faceCollectId", faceCollectId);
  324. data.put("isCover", isCover);
  325. data.put("coveredFaceCollectId", isCover ? coveredFaceCollectId : 0L);
  326. data.put("versionNo", versionNo);
  327. data.put("submitTime", fmtTime(now));
  328. data.put("imgPath", imgPath);
  329. data.put("currentTokenSubmitNum", rdInt(tokenChk.tokenRow.get("cur_submit_num"), 0) + 1);
  330. return result;
  331. } catch (Exception e) {
  332. log4j.error("FaceCollectServ.submitResult() 异常", e);
  333. return mkFail("FACE_COLLECT_SAVE_FAIL", rdErrMsg(e, "提交失败,请稍后重试。"));
  334. }
  335. }
  336. private Map<String, Object> queryResultData() {
  337. long faceCollectId = rdReqLong("faceCollectId");
  338. String sfzh = normalizeSfzh(rdReqTrim("sfzh"));
  339. if (faceCollectId <= 0 && StringUtils.isBlank(sfzh))
  340. return mkFail("FACE_COLLECT_PARAM_INVALID", "缺少查询参数。");
  341. try (Db gdba = FaceCollectDb.makeConn()) {
  342. if (gdba == null)
  343. return mkFail("FACE_COLLECT_DB_ERROR", "人脸采集数据源不可用。");
  344. Map<String, Object> row = faceCollectId > 0
  345. ? selFaceCollectRowById(gdba, faceCollectId)
  346. : selCurrentFaceCollectRow(gdba, sfzh);
  347. if (row == null || row.isEmpty()) {
  348. logOper(gdba, faceCollectId, sfzh, rdReqTrim("token"), "queryResult", false, "未查询到人脸采集记录。");
  349. gdba.commit();
  350. return mkFail("FACE_COLLECT_NOT_FOUND", "未查询到人脸采集记录。");
  351. }
  352. Map<String, Object> result = mkOk("查询成功");
  353. Map<String, Object> data = castData(result);
  354. data.put("faceCollectId", rdLong(row.get("face_collect_id")));
  355. data.put("xm", rdStr(row.get("xm")));
  356. data.put("sfzhMask", maskSfzh(rdStr(row.get("sfzh"))));
  357. data.put("imgPath", rdStr(row.get("img_path")));
  358. data.put("rawImgPath", rdStr(row.get("raw_img_path")));
  359. data.put("isCurrent", rdInt(row.get("is_current"), 0) == 1);
  360. data.put("versionNo", rdInt(row.get("version_no"), 0));
  361. data.put("submitTime", fmtTime(row.get("cjsj")));
  362. data.put("syncHkStatus", rdInt(row.get("sync_hk_status"), 0));
  363. data.put("syncHkMsg", rdStr(row.get("sync_hk_msg")));
  364. data.put("batchId", rdStr(row.get("batch_id")));
  365. logOper(gdba, rdLong(row.get("face_collect_id")), rdStr(row.get("sfzh")),
  366. rdReqTrim("token"), "queryResult", true, "查询成功。");
  367. gdba.commit();
  368. return result;
  369. } catch (Exception e) {
  370. log4j.error("FaceCollectServ.queryResultData() 异常", e);
  371. return mkFail("FACE_COLLECT_QUERY_FAIL", rdErrMsg(e, "查询失败,请稍后再试。"));
  372. }
  373. }
  374. private Map<String, Object> uploadTraceResult() {
  375. String token = rdReqTrim("token");
  376. String scene = StringUtils.defaultIfBlank(rdReqTrim("scene"), DEF_SCENE);
  377. String batchId = rdReqTrim("batchId");
  378. String uploadReason = StringUtils.left(rdReqTrim("uploadReason"), 100);
  379. String latestEvent = StringUtils.left(rdReqTrim("latestEvent"), 100);
  380. String clientPage = StringUtils.left(rdReqTrim("clientPage"), 200);
  381. String traceSize = rdReqTrim("traceSize");
  382. String traceJson = rdReqTrim("traceJson");
  383. String summary = buildTraceUploadSummary(uploadReason, latestEvent, traceSize, clientPage, traceJson);
  384. String clientIp = rdClientIp(super.req);
  385. String contentType = rdReqContentType();
  386. String paramKeys = rdReqParamKeys();
  387. if (StringUtils.isBlank(token))
  388. return mkTraceUploadFail("FACE_COLLECT_PARAM_INVALID", "缺少二维码令牌。",
  389. "missing_token", token, scene, batchId, clientIp, contentType, paramKeys, summary, null);
  390. if (StringUtils.isBlank(traceJson))
  391. return mkTraceUploadFail("FACE_COLLECT_PARAM_INVALID", "缺少调试日志内容。",
  392. "missing_trace_json", token, scene, batchId, clientIp, contentType, paramKeys, summary, null);
  393. try (Db gdba = FaceCollectDb.makeConn()) {
  394. if (gdba == null) {
  395. return mkTraceUploadFail("FACE_COLLECT_TRACE_UPLOAD_FAIL", "调试日志上报失败。",
  396. "db_unavailable", token, scene, batchId, clientIp, contentType, paramKeys, summary, null);
  397. }
  398. JsonElement traceElement = JsonParser.parseString(traceJson);
  399. String traceCompact = StringUtils.left(traceElement.toString(), 8000);
  400. log4j.warn("FaceCollectServ.uploadTraceResult() token={}, scene={}, batchId={}, clientIp={}, contentType={}, paramKeys={}, summary={}, trace={}",
  401. maskToken(token), scene, batchId, clientIp, contentType, paramKeys, summary, traceCompact);
  402. logOper(gdba, 0L, "", token, "uploadTrace", true, StringUtils.left(summary, 1000));
  403. gdba.commit();
  404. Map<String, Object> result = mkOk("调试日志上报成功");
  405. Map<String, Object> data = castData(result);
  406. data.put("scene", scene);
  407. data.put("batchId", batchId);
  408. data.put("uploadReason", uploadReason);
  409. data.put("latestEvent", latestEvent);
  410. data.put("traceSize", traceSize);
  411. data.put("recvTime", fmtTime(new Timestamp(System.currentTimeMillis())));
  412. return result;
  413. } catch (Exception e) {
  414. return mkTraceUploadFail("FACE_COLLECT_TRACE_UPLOAD_FAIL", rdErrMsg(e, "调试日志上报失败。"),
  415. "exception", token, scene, batchId, clientIp, contentType, paramKeys, summary, e);
  416. }
  417. }
  418. private String buildTraceUploadSummary(String uploadReason, String latestEvent, String traceSize,
  419. String clientPage, String traceJson) {
  420. return "reason=" + StringUtils.defaultIfBlank(uploadReason, "-")
  421. + ",event=" + StringUtils.defaultIfBlank(latestEvent, "-")
  422. + ",traceSize=" + StringUtils.defaultIfBlank(traceSize, "-")
  423. + ",traceJsonLen=" + StringUtils.length(traceJson)
  424. + ",page=" + StringUtils.defaultIfBlank(clientPage, "-");
  425. }
  426. private Map<String, Object> mkTraceUploadFail(String code, String msg, String failReason,
  427. String token, String scene, String batchId,
  428. String clientIp, String contentType, String paramKeys,
  429. String summary, Exception e) {
  430. if (e == null) {
  431. log4j.warn("FaceCollectServ.uploadTraceResult() 业务失败: reason={}, token={}, scene={}, batchId={}, clientIp={}, contentType={}, paramKeys={}, summary={}",
  432. failReason, maskToken(token), scene, batchId, clientIp, contentType, paramKeys, summary);
  433. } else {
  434. log4j.error("FaceCollectServ.uploadTraceResult() 异常: reason={}, token={}, scene={}, batchId={}, clientIp={}, contentType={}, paramKeys={}, summary={}",
  435. failReason, maskToken(token), scene, batchId, clientIp, contentType, paramKeys, summary, e);
  436. }
  437. return mkFail(code, msg);
  438. }
  439. private TokenChkResult chkToken(Db gdba, String token, String reqScene, String reqBatchId,
  440. boolean needQuota, boolean forUpdate) throws SQLException {
  441. if (StringUtils.isBlank(token))
  442. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_INVALID", "二维码已失效或不存在。"), null);
  443. StringBuilder sql = new StringBuilder("select TOKEN_ID,TOKEN,SCENE,BATCH_ID,STATUS,EXPIRE_TIME,MAX_SUBMIT_NUM,CUR_SUBMIT_NUM" +
  444. " from " + TAB_FACE_COLLECT_TOKEN + " where TOKEN=:token");
  445. if (forUpdate)
  446. sql.append(" for update");
  447. SqlCmd sqlCmd = new SqlCmd(sql.toString());
  448. sqlCmd.wrStrParm("token", token);
  449. Map<String, Object> tokenRow = gdba.doSelMapByC(sqlCmd);
  450. if (tokenRow == null || tokenRow.isEmpty())
  451. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_INVALID", "二维码已失效或不存在。"), null);
  452. int status = rdInt(tokenRow.get("status"), 0);
  453. Timestamp expireTime = rdTime(tokenRow.get("expire_time"));
  454. Timestamp now = new Timestamp(System.currentTimeMillis());
  455. if (status == 0)
  456. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_INVALID", "二维码已停用。"), tokenRow);
  457. if (status == 9 || (expireTime != null && expireTime.before(now)))
  458. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_EXPIRED", "二维码已过期。"), tokenRow);
  459. String dbScene = StringUtils.defaultIfBlank(rdStr(tokenRow.get("scene")), DEF_SCENE);
  460. String dbBatchId = rdStr(tokenRow.get("batch_id"));
  461. if (StringUtils.isNotBlank(reqScene) && !StringUtils.equalsIgnoreCase(reqScene, dbScene))
  462. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_INVALID", "二维码场景不匹配。"), tokenRow);
  463. if (StringUtils.isNotBlank(reqBatchId) && StringUtils.isNotBlank(dbBatchId)
  464. && !StringUtils.equals(reqBatchId, dbBatchId))
  465. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_INVALID", "二维码批次不匹配。"), tokenRow);
  466. if (needQuota) {
  467. Integer maxSubmitNum = rdNullableInt(tokenRow.get("max_submit_num"));
  468. int curSubmitNum = rdInt(tokenRow.get("cur_submit_num"), 0);
  469. if (maxSubmitNum != null && maxSubmitNum > 0 && curSubmitNum >= maxSubmitNum)
  470. return new TokenChkResult(mkFail("FACE_COLLECT_TOKEN_EXHAUSTED", "当前二维码提交次数已达上限。"), tokenRow);
  471. }
  472. Map<String, Object> result = mkOk("校验通过");
  473. Map<String, Object> data = castData(result);
  474. data.put("valid", true);
  475. data.put("scene", dbScene);
  476. data.put("batchId", dbBatchId);
  477. data.put("expireTime", fmtTime(expireTime));
  478. data.put("needMatchStudent", false);
  479. data.put("curSubmitNum", rdInt(tokenRow.get("cur_submit_num"), 0));
  480. data.put("maxSubmitNum", rdNullableInt(tokenRow.get("max_submit_num")));
  481. return new TokenChkResult(result, tokenRow);
  482. }
  483. private Map<String, Object> selCurrentFaceCollectRow(Db gdba, String sfzh) throws SQLException {
  484. SqlCmd sqlCmd = new SqlCmd("select * from (" +
  485. " select FACE_COLLECT_ID,XM,SFZH,IMG_PATH,RAW_IMG_PATH,VERSION_NO,IS_CURRENT,BATCH_ID,SYNC_HK_STATUS,SYNC_HK_MSG,CJSJ" +
  486. " from " + TAB_FACE_COLLECT +
  487. " where SFZH=:sfzh and IS_CURRENT=1 order by VERSION_NO desc, FACE_COLLECT_ID desc" +
  488. " ) where rownum=1");
  489. sqlCmd.wrStrParm("sfzh", sfzh);
  490. Map<String, Object> row = gdba.doSelMapByC(sqlCmd);
  491. return row == null || row.isEmpty() ? null : row;
  492. }
  493. private Map<String, Object> selFaceCollectRowById(Db gdba, long faceCollectId) throws SQLException {
  494. SqlCmd sqlCmd = new SqlCmd("select FACE_COLLECT_ID,XM,SFZH,IMG_PATH,RAW_IMG_PATH,VERSION_NO,IS_CURRENT,BATCH_ID,SYNC_HK_STATUS,SYNC_HK_MSG,CJSJ" +
  495. " from " + TAB_FACE_COLLECT + " where FACE_COLLECT_ID=:faceCollectId");
  496. sqlCmd.wrLongParm("faceCollectId", faceCollectId);
  497. Map<String, Object> row = gdba.doSelMapByC(sqlCmd);
  498. return row == null || row.isEmpty() ? null : row;
  499. }
  500. private void logOper(Db gdba, long faceCollectId, String sfzh, String token,
  501. String operType, boolean ok, String operMsg) {
  502. try {
  503. long logId = gdba.rdNextSeqVal(SEQ_FACE_COLLECT_LOG);
  504. SqlCmd sqlCmd = new SqlCmd("insert into " + TAB_FACE_COLLECT_LOG +
  505. " (LOG_ID,FACE_COLLECT_ID,SFZH,OPER_TYPE,OPER_DESC,CLIENT_IP,CLIENT_DEVICE_ID,CLIENT_MODEL,QR_TOKEN,OPER_RESULT,OPER_MSG,CJSJ)" +
  506. " values (:logId,:faceCollectId,:sfzh,:operType,:operDesc,:clientIp,:clientDeviceId,:clientModel,:qrToken,:operResult,:operMsg,:cjsj)");
  507. sqlCmd.wrLongParm("logId", logId);
  508. sqlCmd.wrLongParm("faceCollectId", faceCollectId > 0 ? faceCollectId : null);
  509. sqlCmd.wrStrParm("sfzh", sfzh);
  510. sqlCmd.wrStrParm("operType", operType);
  511. sqlCmd.wrStrParm("operDesc", operType);
  512. sqlCmd.wrStrParm("clientIp", rdClientIp(super.req));
  513. sqlCmd.wrStrParm("clientDeviceId", StringUtils.defaultIfBlank(rdReqTrim("clientDeviceId"), rdReqTrim("devId")));
  514. sqlCmd.wrStrParm("clientModel", StringUtils.defaultIfBlank(rdReqTrim("clientModel"), rdReqTrim("sbmc")));
  515. sqlCmd.wrStrParm("qrToken", token);
  516. sqlCmd.wrIntParm("operResult", ok ? 1 : 0);
  517. sqlCmd.wrStrParm("operMsg", StringUtils.left(StringUtils.defaultString(operMsg), 1000));
  518. sqlCmd.wrTimeParm("cjsj", new Timestamp(System.currentTimeMillis()));
  519. gdba.doModByC(sqlCmd);
  520. } catch (Exception e) {
  521. log4j.warn("FaceCollectServ.logOper() 写操作日志失败,operType={}", operType, e);
  522. }
  523. }
  524. private Map<String, Object> mkOk(String msg) {
  525. Map<String, Object> result = new LinkedHashMap<>();
  526. result.put("ok", true);
  527. result.put("code", "0");
  528. result.put("msg", msg);
  529. result.put("data", new LinkedHashMap<String, Object>());
  530. return result;
  531. }
  532. private Map<String, Object> mkFail(String code, String msg) {
  533. Map<String, Object> result = new LinkedHashMap<>();
  534. result.put("ok", false);
  535. result.put("code", code);
  536. result.put("msg", msg);
  537. result.put("data", new LinkedHashMap<String, Object>());
  538. return result;
  539. }
  540. @SuppressWarnings("unchecked")
  541. private Map<String, Object> castData(Map<String, Object> result) {
  542. Object data = result.get("data");
  543. if (data instanceof Map)
  544. return (Map<String, Object>) data;
  545. Map<String, Object> map = new LinkedHashMap<>();
  546. result.put("data", map);
  547. return map;
  548. }
  549. private String rdReqTrim(String parmName) {
  550. return StringUtils.trimToEmpty(super.req == null ? null : super.req.getParameter(parmName));
  551. }
  552. private String rdReqContentType() {
  553. if (super.req == null)
  554. return "";
  555. return StringUtils.defaultString(super.req.getContentType());
  556. }
  557. private String rdReqParamKeys() {
  558. if (super.req == null || super.req.getParameterMap() == null || super.req.getParameterMap().isEmpty())
  559. return "";
  560. return StringUtils.left(String.join(",", super.req.getParameterMap().keySet()), 500);
  561. }
  562. private boolean rdReqBool(String parmName, boolean defVal) {
  563. String valStr = rdReqTrim(parmName);
  564. if (StringUtils.isBlank(valStr))
  565. return defVal;
  566. return rdBoolStr(valStr);
  567. }
  568. private Integer rdReqNullableInt(String parmName) {
  569. String valStr = rdReqTrim(parmName);
  570. if (StringUtils.isBlank(valStr))
  571. return null;
  572. try {
  573. return Integer.parseInt(valStr);
  574. } catch (Exception e) {
  575. return null;
  576. }
  577. }
  578. private long rdReqLong(String parmName) {
  579. String valStr = rdReqTrim(parmName);
  580. if (StringUtils.isBlank(valStr))
  581. return 0L;
  582. try {
  583. return Long.parseLong(valStr);
  584. } catch (Exception e) {
  585. return 0L;
  586. }
  587. }
  588. private boolean rdBoolStr(String valStr) {
  589. return "1".equals(valStr) || "true".equalsIgnoreCase(valStr) || "yes".equalsIgnoreCase(valStr);
  590. }
  591. private boolean rdBool(Object valObj) {
  592. if (valObj instanceof Boolean)
  593. return (Boolean) valObj;
  594. if (valObj == null)
  595. return false;
  596. return rdBoolStr(String.valueOf(valObj));
  597. }
  598. private Integer rdNullableInt(Object valObj) {
  599. if (valObj == null)
  600. return null;
  601. if (valObj instanceof Number)
  602. return ((Number) valObj).intValue();
  603. String valStr = String.valueOf(valObj).trim();
  604. if (valStr.isEmpty())
  605. return null;
  606. return Integer.parseInt(valStr);
  607. }
  608. private int rdInt(Object valObj, int defVal) {
  609. Integer val = rdNullableInt(valObj);
  610. return val == null ? defVal : val;
  611. }
  612. private long rdLong(Object valObj) {
  613. if (valObj == null)
  614. return 0L;
  615. if (valObj instanceof Number)
  616. return ((Number) valObj).longValue();
  617. try {
  618. return Long.parseLong(String.valueOf(valObj).trim());
  619. } catch (Exception e) {
  620. return 0L;
  621. }
  622. }
  623. private Timestamp rdTime(Object valObj) {
  624. if (valObj instanceof Timestamp)
  625. return (Timestamp) valObj;
  626. return null;
  627. }
  628. private String rdStr(Object valObj) {
  629. return valObj == null ? "" : String.valueOf(valObj);
  630. }
  631. private String fmtTime(Object timeObj) {
  632. Timestamp ts = rdTime(timeObj);
  633. if (ts == null)
  634. return "";
  635. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ts);
  636. }
  637. private String normalizeSfzh(String sfzh) {
  638. return StringUtils.upperCase(StringUtils.deleteWhitespace(StringUtils.defaultString(sfzh)));
  639. }
  640. private String maskSfzh(String sfzh) {
  641. String val = normalizeSfzh(sfzh);
  642. if (val.length() <= 8)
  643. return val;
  644. return val.substring(0, 4) + "**********" + val.substring(val.length() - 4);
  645. }
  646. private String maskToken(String token) {
  647. String val = StringUtils.defaultString(token).trim();
  648. if (val.length() <= 10)
  649. return val;
  650. return val.substring(0, 6) + "******" + val.substring(val.length() - 4);
  651. }
  652. private boolean ifValidUploadPath(String imgPath) {
  653. if (StringUtils.isBlank(imgPath))
  654. return false;
  655. if (imgPath.contains("..") || imgPath.contains(":") || imgPath.startsWith("/") || imgPath.startsWith("\\"))
  656. return false;
  657. return imgPath.matches("^[0-9A-Za-z/_-]+\\.[0-9A-Za-z]{2,10}$");
  658. }
  659. private String rdClientIp(HttpServletRequest request) {
  660. if (request == null)
  661. return "";
  662. String[] headerArr = {"X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP"};
  663. for (String headerName : headerArr) {
  664. String val = request.getHeader(headerName);
  665. if (StringUtils.isBlank(val) || "unknown".equalsIgnoreCase(val))
  666. continue;
  667. if (val.contains(","))
  668. return StringUtils.trim(val.split(",")[0]);
  669. return StringUtils.trim(val);
  670. }
  671. return StringUtils.defaultString(request.getRemoteAddr());
  672. }
  673. private boolean hitRateLimit(String key, long gapMs) {
  674. long now = System.currentTimeMillis();
  675. cleanupRateLimitMap(now);
  676. final boolean[] limited = {false};
  677. RATE_LIMIT_TS_MAP.compute(key, (k, oldVal) -> {
  678. if (oldVal != null && now - oldVal < gapMs) {
  679. limited[0] = true;
  680. return oldVal;
  681. }
  682. return now;
  683. });
  684. return limited[0];
  685. }
  686. private void cleanupRateLimitMap(long now) {
  687. if (RATE_LIMIT_TS_MAP.size() < RATE_LIMIT_MAP_MAX)
  688. return;
  689. for (Map.Entry<String, Long> entry : RATE_LIMIT_TS_MAP.entrySet()) {
  690. Long oldVal = entry.getValue();
  691. if (oldVal != null && now - oldVal > RATE_LIMIT_CLEANUP_MS)
  692. RATE_LIMIT_TS_MAP.remove(entry.getKey(), oldVal);
  693. }
  694. }
  695. private String rdErrMsg(Exception e, String defMsg) {
  696. String msg = e == null ? "" : e.getMessage();
  697. return StringUtils.isBlank(msg) ? defMsg : msg;
  698. }
  699. private Timestamp resolveReqExpireTime() throws Exception {
  700. String expireTimeStr = rdReqTrim("expireTime");
  701. if (StringUtils.isNotBlank(expireTimeStr)) {
  702. try {
  703. return StrDate.toTimestamp(expireTimeStr, "yyyy-MM-dd HH:mm:ss");
  704. } catch (Exception ignore) {
  705. return StrDate.toTimestamp(expireTimeStr, "yyyy-MM-dd HH:mm");
  706. }
  707. }
  708. Integer expireDays = rdReqNullableInt("expireDays");
  709. if (expireDays == null)
  710. expireDays = DEF_QRCODE_EXPIRE_DAYS;
  711. if (expireDays <= 0)
  712. throw new RuntimeException("expireDays 必须大于 0。");
  713. return new Timestamp(System.currentTimeMillis() + expireDays.longValue() * 24 * 60 * 60 * 1000L);
  714. }
  715. private String normalizeEnvVersion(String envVersion) {
  716. return StringUtils.defaultIfBlank(StringUtils.trimToNull(envVersion), DEF_QRCODE_ENV).toLowerCase();
  717. }
  718. private String buildBatchId() {
  719. return "FC" + new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
  720. }
  721. private String buildQrcodeRelPath(String token) {
  722. return DEF_QRCODE_DIR + "/" + new SimpleDateFormat("yyyy/MM/dd").format(new java.util.Date()) + "/" + token + ".jpg";
  723. }
  724. private String buildQrcodePreviewUrl(String qrPath) {
  725. return ServC.SPATH_root + "?" + ServC.URL_ssServ + "=dlByHttp&type=img&path=" +
  726. URLEncoder.encode(qrPath, StandardCharsets.UTF_8);
  727. }
  728. private byte[] rdWechatMiniProgramQrcode(String sceneValue, String envVersion, boolean checkPath) throws Exception {
  729. String accessToken = rdWechatMiniProgramAccessToken();
  730. if (StringUtils.isBlank(accessToken))
  731. throw new RuntimeException("未获取到微信 access_token。");
  732. JsonObject reqBody = new JsonObject();
  733. reqBody.addProperty("scene", sceneValue);
  734. reqBody.addProperty("page", DEF_QRCODE_PAGE);
  735. reqBody.addProperty("env_version", envVersion);
  736. reqBody.addProperty("check_path", checkPath);
  737. try (Response response = HttpU.doPostUrl(String.format(URL_WECHAT_QRCODE, accessToken), reqBody)) {
  738. if (response == null || response.body() == null)
  739. throw new RuntimeException("微信小程序码接口无响应。");
  740. byte[] bodyBytes = response.body().bytes();
  741. if (bodyBytes.length == 0)
  742. throw new RuntimeException("微信小程序码接口返回空内容。");
  743. if (ifJsonBody(bodyBytes))
  744. throw new RuntimeException(parseWechatErrMsg(bodyBytes));
  745. return bodyBytes;
  746. }
  747. }
  748. private String rdWechatMiniProgramAccessToken() {
  749. JsonObject tokenResp = HttpU.getUrl(WechatC.URL_rdWechatpToken);
  750. if (tokenResp == null)
  751. return null;
  752. JsonElement accessToken = tokenResp.get("access_token");
  753. return accessToken == null ? null : accessToken.getAsString();
  754. }
  755. private boolean ifJsonBody(byte[] bodyBytes) {
  756. for (byte bodyByte : bodyBytes) {
  757. char ch = (char) (bodyByte & 0xFF);
  758. if (Character.isWhitespace(ch))
  759. continue;
  760. return ch == '{' || ch == '[';
  761. }
  762. return false;
  763. }
  764. private String parseWechatErrMsg(byte[] bodyBytes) {
  765. try {
  766. String bodyStr = new String(bodyBytes, StandardCharsets.UTF_8);
  767. JsonObject errObj = JsonParser.parseString(bodyStr).getAsJsonObject();
  768. String errCode = errObj.has("errcode") ? errObj.get("errcode").getAsString() : "";
  769. String errMsg = errObj.has("errmsg") ? errObj.get("errmsg").getAsString() : bodyStr;
  770. return "微信小程序码生成失败:errcode=" + errCode + ",errmsg=" + errMsg;
  771. } catch (Exception e) {
  772. return "微信小程序码生成失败,且错误返回无法解析。";
  773. }
  774. }
  775. private static class TokenChkResult {
  776. private final Map<String, Object> result;
  777. private final Map<String, Object> tokenRow;
  778. private TokenChkResult(Map<String, Object> result, Map<String, Object> tokenRow) {
  779. this.result = result;
  780. this.tokenRow = tokenRow;
  781. }
  782. }
  783. }