Commit e71b5dd4 authored by fangxinjiang's avatar fangxinjiang

手机号码校验

parent 8ac021ed
......@@ -93,6 +93,7 @@ public class TEmpFamilyController {
if (Common.isNotNull(checkRes)){
return R.failed(checkRes);
}
tEmpFamily.setDeleteFlag(CommonConstants.ZERO_STRING);
return R.ok(tEmpFamilyService.save(tEmpFamily));
}
......
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.check.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 手机号码校验
*
* @author fxj
* @date 2022-06-20 17:29:03
*/
@Data
@TableName("t_check_mobile")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "手机号码校验")
public class TCheckMobile extends BaseEntity {
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description ="id")
private String id;
/**
* 0:初始数据 1:API验证结果
*/
@Schema(description ="0:初始数据 1:API验证结果")
private String type;
/**
* 手机号码
*/
@Schema(description ="手机号码")
private String mobile;
/**
* 手机号所属区域。样例:省-市
*/
@Schema(description ="手机号所属区域。样例:省-市")
private String area;
/**
* 手机号运营商类型。样例:中国移动 GSM
*/
@Schema(description ="手机号运营商类型。样例:中国移动 GSM")
private String numbertype;
/**
* 是否收费,枚举值:1 :收费 0:不收费
*/
@Schema(description ="是否收费,枚举值:1 :收费 0:不收费")
private String chargesstatus;
/**
* 检测结果,枚举值:0:空号 1:实号 2:停机 3:库无 4:沉默号 5:风险号 10:配置异常
*/
@Schema(description ="检测结果,枚举值:0:空号 1:实号 2:停机 3:库无 4:沉默号 5:风险号 10:配置或接口异常")
private String status;
/**
* 响应code码解释
*/
@Schema(description ="响应code码解释")
private String message;
}
package com.yifu.cloud.plus.v1.check.utils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.yifu.cloud.plus.v1.check.entity.TCheckIdCard;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.beans.factory.annotation.Value;
import java.util.HashMap;
......@@ -13,7 +18,7 @@ import java.util.Map;
* @description 测试身份证
* @date 2022/5/7
*/
public class CheckIdCard {
public class ChecksUtil {
@Value("${canCheck}")
private static boolean canCheck;
......@@ -30,16 +35,63 @@ public class CheckIdCard {
if (canCheck) {
// 1.调用身份信息校验api
extracted(checkIdCard);
checkIdCardMethod(checkIdCard);
} else {
checkIdCard.setIsTrue(0);
checkIdCard.setReason("nacos中checks.yaml的配置canCheck未开启!");
}
}
public static R<Map<String,TCheckMobile>> checkMobile(String mobiles) {
Map<String,TCheckMobile> checkMobiles = new HashMap<>();
if (canCheck) {
// 1.调用身份信息校验api
return checkMobileMethod(mobiles,checkMobiles);
} else {
return R.failed("nacos中checks.yaml的配置canCheck未开启!");
}
}
private static R<Map<String,TCheckMobile>> checkMobileMethod(String mobiles, Map<String,TCheckMobile> checkMobileMap) {
final JsonObject jsonObject = ChecksUtil.invokeMobile(mobiles);
// 2.处理返回结果
if (jsonObject != null) {
//响应code码。200000:成功,其他失败
String code = jsonObject.get("code").getAsString();
if ("200000".equals(code) && jsonObject.get("data") != null) {
// 调用身份信息校验成功
// 解析结果数据,进行业务处理
// 校验状态码 200000:成功,其他失败
JsonObject resJson = jsonObject.get("data").getAsJsonObject();
String message = jsonObject.get("message").getAsString();
JsonArray mobileArray = resJson.getAsJsonArray();
if (Common.isNotNull(mobileArray) && mobileArray.size() > CommonConstants.ZERO_INT){
TCheckMobile mobile = null;
for (int i = 0;i < mobileArray.size(); i++){
mobile = new TCheckMobile();
mobile.setMobile(mobileArray.get(i).getAsJsonObject().get("mobile").getAsString());
mobile.setArea(mobileArray.get(i).getAsJsonObject().get("area").getAsString());
mobile.setNumbertype(mobileArray.get(i).getAsJsonObject().get("numberType").getAsString());
mobile.setChargesstatus(mobileArray.get(i).getAsJsonObject().get("chargesStatus").getAsString());
mobile.setStatus(mobileArray.get(i).getAsJsonObject().get("status").getAsString());
mobile.setMessage(message);
mobile.setType(CommonConstants.ONE_STRING);
checkMobileMap.put(mobile.getMobile(),mobile);
}
}
} else {
// 记录错误日志,正式项目中请换成log打印
return R.failed("手机号校验失败,code:" + code + ",msg:" + jsonObject.get("message").getAsString());
}
} else {
return R.failed("接口无返回数据");
}
return R.ok(checkMobileMap);
}
// 核心调用
private static void extracted(TCheckIdCard checkIdCard) {
final JsonObject jsonObject = CheckIdCard.invokeIdCard(checkIdCard.getName(), checkIdCard.getIdCard());
private static void checkIdCardMethod(TCheckIdCard checkIdCard) {
final JsonObject jsonObject = ChecksUtil.invokeIdCard(checkIdCard.getName(), checkIdCard.getIdCard());
// 2.处理返回结果
if (jsonObject != null) {
//响应code码。200000:成功,其他失败
......@@ -78,4 +130,20 @@ public class CheckIdCard {
// 解析json,并返回结果
return jsonParser.parse(result).getAsJsonObject();
}
/**
* @Author fxj
* @Description 手机号码状态检测
* @Date 17:50 2022/6/20
* @param mobiles 检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码
**/
private static JsonObject invokeMobile(String mobiles) {
Map<String, String> params = new HashMap<>();
params.put("appId", APP_ID_ID_CARD);
params.put("appKey", APP_KEY_ID_CARD);
params.put("mobiles", mobiles);
String result = HttpUtils.post(API_URL_ID_CARD, params);
// 解析json,并返回结果
return jsonParser.parse(result).getAsJsonObject();
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.job.config.SchedulerBeanFactoryConfig
\ No newline at end of file
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.check.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import com.yifu.cloud.plus.v1.check.service.TCheckMobileService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
* 手机号码校验
*
* @author fxj
* @date 2022-06-20 17:29:03
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/tcheckmobile" )
@Tag(name = "手机号码校验管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class TCheckMobileController {
private final TCheckMobileService tCheckMobileService;
/**
* 分页查询
* @param page 分页对象
* @param tCheckMobile 手机号码校验
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('demo_tcheckmobile_get')" )
public R getTCheckMobilePage(Page page, TCheckMobile tCheckMobile) {
return R.ok(tCheckMobileService.page(page, Wrappers.query(tCheckMobile)));
}
/**
* 通过id查询手机号码校验
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('demo_tcheckmobile_get')" )
public R getById(@PathVariable("id" ) String id) {
return R.ok(tCheckMobileService.getById(id));
}
/**
* 新增手机号码校验
* @param tCheckMobile 手机号码校验
* @return R
*/
@Operation(summary = "新增手机号码校验", description = "新增手机号码校验")
@SysLog("新增手机号码校验" )
@PostMapping
@PreAuthorize("@pms.hasPermission('demo_tcheckmobile_add')" )
public R save(@RequestBody TCheckMobile tCheckMobile) {
return R.ok(tCheckMobileService.save(tCheckMobile));
}
/**
* 修改手机号码校验
* @param tCheckMobile 手机号码校验
* @return R
*/
@Operation(summary = "修改手机号码校验", description = "修改手机号码校验")
@SysLog("修改手机号码校验" )
@PutMapping
@PreAuthorize("@pms.hasPermission('demo_tcheckmobile_edit')" )
public R updateById(@RequestBody TCheckMobile tCheckMobile) {
return R.ok(tCheckMobileService.updateById(tCheckMobile));
}
/**
* 通过id删除手机号码校验
* @param id id
* @return R
*/
@Operation(summary = "通过id删除手机号码校验", description = "通过id删除手机号码校验")
@SysLog("通过id删除手机号码校验" )
@DeleteMapping("/{id}" )
@PreAuthorize("@pms.hasPermission('demo_tcheckmobile_del')" )
public R removeById(@PathVariable String id) {
return R.ok(tCheckMobileService.removeById(id));
}
/**
* 手机号码状态校验
* @param mobiles 检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码
* @return R
*/
@Operation(description = "检测手机号,多个手机号码用英文半角逗号隔开,仅支持国内号码")
@SysLog("检测手机号状态" )
@Inner
@GetMapping("/checkMobiles" )
public R checkMobiles(String mobiles) {
return R.ok(tCheckMobileService.checkMobiles(mobiles));
}
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.check.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import org.apache.ibatis.annotations.Mapper;
/**
* 手机号码校验
*
* @author fxj
* @date 2022-06-20 17:29:03
*/
@Mapper
public interface TCheckMobileMapper extends BaseMapper<TCheckMobile> {
}
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.check.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.Map;
/**
* 手机号码校验
*
* @author fxj
* @date 2022-06-20 17:29:03
*/
public interface TCheckMobileService extends IService<TCheckMobile> {
R<Map<String,TCheckMobile>> checkMobiles(String mobiles);
}
......@@ -10,7 +10,7 @@ import com.yifu.cloud.plus.v1.check.mapper.TCheckIdCardMapper;
import com.yifu.cloud.plus.v1.check.service.TCheckApiNumService;
import com.yifu.cloud.plus.v1.check.service.TCheckIdCardService;
import com.yifu.cloud.plus.v1.check.service.TCheckLockService;
import com.yifu.cloud.plus.v1.check.utils.CheckIdCard;
import com.yifu.cloud.plus.v1.check.utils.ChecksUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
......@@ -144,7 +144,7 @@ public class TCheckIdCardServiceImpl extends ServiceImpl<TCheckIdCardMapper, TCh
// 调用API校验
if (nowApiNum < canApiNum) {
nowApiNum++;
CheckIdCard.checkIdCard(c);
ChecksUtil.checkIdCard(c);
c.setCreateUser(userId);
c.setCreateTime(LocalDateTime.now());
c.setType(CommonConstants.ONE_INT);
......
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.yifu.cloud.plus.v1.check.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.check.entity.TCheckMobile;
import com.yifu.cloud.plus.v1.check.mapper.TCheckMobileMapper;
import com.yifu.cloud.plus.v1.check.service.TCheckMobileService;
import com.yifu.cloud.plus.v1.check.utils.ChecksUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* 手机号码校验
*
* @author fxj
* @date 2022-06-20 17:29:03
*/
@Service
public class TCheckMobileServiceImpl extends ServiceImpl<TCheckMobileMapper, TCheckMobile> implements TCheckMobileService {
/**
* @Author fxj
* @Description 号码状态校验,单次请求上限100 多一个号码请以逗号分割
* @Date 19:18 2022/6/20
**/
@Override
public R<Map<String,TCheckMobile>> checkMobiles(String mobiles){
R<Map<String,TCheckMobile>> mobileMapR;
Map<String,TCheckMobile> checkMobileMap;
if (Common.isNotNull(mobiles)){
List<String> mobileList = Common.initStrToList(mobiles,CommonConstants.COMMA_STRING);
if (Common.isNotEmpty(mobileList) && mobileList.size() > CommonConstants.INTEGER_HUNDRED){
return R.failed(MsgUtils.getMessage(ErrorCodes.CHECKS_MOBILE_REQUEST_LIMIT_HUNDRED));
}
mobileMapR = ChecksUtil.checkMobile(mobiles);
if (Common.isEmpty(mobileMapR) && Common.isEmpty(mobileMapR.getData())){
return R.failed(MsgUtils.getMessage(ErrorCodes.CHECKS_MOBILE_REQUEST_ERROR));
}
checkMobileMap = mobileMapR.getData();
if (Common.isNotNull(mobileList) && Common.isNotNull(checkMobileMap)){
TCheckMobile checkMobile = null;
for (String mobile:mobileList){
if (Common.isEmpty(checkMobileMap.get(mobile))){
checkMobile = new TCheckMobile();
checkMobile.setType(CommonConstants.ONE_STRING);
checkMobile.setMobile(mobile);
checkMobile.setStatus(CommonConstants.TEN_STRING);
checkMobile.setMessage(Common.isEmpty(mobileMapR)?MsgUtils.getMessage(ErrorCodes.CHECKS_MOBILE_REQUEST_ERROR):mobileMapR.getMsg());
checkMobile.setChargesstatus(CommonConstants.ZERO_STRING);
checkMobile.setNumbertype(CommonConstants.EMPTY_STRING);
checkMobile.setArea(CommonConstants.EMPTY_STRING);
checkMobileMap.put(mobile,checkMobile);
}
}
mobileMapR.setData(checkMobileMap);
}
}else {
return R.failed(MsgUtils.getMessage(ErrorCodes.PARAM_NOT_EMPTY));
}
if (Common.isNotNull(checkMobileMap)){
this.saveBatch(checkMobileMap.values());
}
return mobileMapR;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.check.mapper.TCheckMobileMapper">
<resultMap id="tCheckMobileMap" type="com.yifu.cloud.plus.v1.check.entity.TCheckMobile">
<id property="id" column="id"/>
<result property="createTime" column="create_time"/>
<result property="createBy" column="create_by"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="createName" column="create_name"/>
<result property="type" column="type"/>
<result property="mobile" column="mobile"/>
<result property="area" column="area"/>
<result property="numbertype" column="numberType"/>
<result property="chargesstatus" column="chargesStatus"/>
<result property="status" column="status"/>
<result property="message" column="message"/>
</resultMap>
</mapper>
......@@ -197,4 +197,5 @@ public interface CommonConstants {
char ADD_CHAR = '+';
//int 4
int FOUR_INT = 4;
String TEN_STRING = "10";
}
......@@ -189,4 +189,16 @@ public interface ErrorCodes {
* 已存在该员工对应学历名称的学历信息
*/
String ARCHIVES_EMP_EDUCATION_EXISTING = "archives.emp.education.existing";
/**
* 参数不可为空
*/
String PARAM_NOT_EMPTY = "param.not.empty";
/**
* 校验请求异常
*/
String CHECKS_MOBILE_REQUEST_ERROR = "checks.mobile.request.error";
/**
* 单次号码状态校验请求上限100
*/
String CHECKS_MOBILE_REQUEST_LIMIT_HUNDRED = "checks.mobile.request.limit.hundred";
}
......@@ -53,7 +53,7 @@ public class YifuUser extends User {
private final String phone;
/**
* 系统内置标识 0 是 1 否
* 是否是系统内置(0是,1否)
*/
@Getter
private String systemFlag;
......
......@@ -48,6 +48,13 @@ archives.emp.reduced=\u5458\u5DE5\u5DF2\u51CF\u6863
archives.emp.work.record.existing=\u5DF2\u5B58\u5728\u5BF9\u5E94\u8EAB\u4EFD\u8BC1\u7684\u5DE5\u4F5C\u8BB0\u5F55\u4FE1\u606F
archives.emp.education.existing=\u5DF2\u5B58\u5728\u8BE5\u5458\u5DE5\u5BF9\u5E94\u5B66\u5386\u540D\u79F0\u7684\u5B66\u5386\u4FE1\u606F
param.not.empty=\u53C2\u6570\u4E0D\u53EF\u4E3A\u7A7A
checks.mobile.request.error=\u6821\u9A8C\u8BF7\u6C42\u5F02\u5E38
checks.mobile.request.limit.hundred=\u5355\u6B21\u53F7\u7801\u72B6\u6001\u6821\u9A8C\u8BF7\u6C42\u4E0A\u9650100
......
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