新增身份证实名认证接口
parent
380b93f5f8
commit
915f788103
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.cloud.background.domin.api;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.domin.api
|
||||
* @Project:cloud-background
|
||||
* @name:IdCard
|
||||
* @Date:2024/9/4 12:10
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IdCard {
|
||||
private String idcard;
|
||||
private String realname;
|
||||
private String orderid;
|
||||
|
||||
public String getIdcard() {
|
||||
return idcard;
|
||||
}
|
||||
|
||||
public void setIdcard(String idcard) {
|
||||
this.idcard = idcard;
|
||||
}
|
||||
|
||||
public String getRealname() {
|
||||
return realname;
|
||||
}
|
||||
|
||||
public void setRealname(String realname) {
|
||||
this.realname = realname;
|
||||
}
|
||||
|
||||
public String getOrderid() {
|
||||
return orderid;
|
||||
}
|
||||
|
||||
public void setOrderid(String orderid) {
|
||||
this.orderid = orderid;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.cloud.background.domin.apiresp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.domin.apiresp
|
||||
* @Project:cloud-background
|
||||
* @name:IdCardResp
|
||||
* @Date:2024/9/4 14:33
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IdCardResp {
|
||||
private String realname;
|
||||
private String idcard;
|
||||
private String orderid;
|
||||
private Integer res;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.muyu.cloud.background.api;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.api
|
||||
* @Project:cloud-background
|
||||
* @name:IdCard
|
||||
* @Date:2024/9/4 12:16
|
||||
*/
|
||||
|
||||
/**
|
||||
* 身份证实名认证
|
||||
*/
|
||||
@Configuration
|
||||
public class IdCard {
|
||||
public static Result findIdCard(com.muyu.cloud.background.domin.api.IdCard idCard) throws IOException {
|
||||
String apiKey = "3138002f3f09b27b6ebd21020fec45e7";
|
||||
String apiUrl = "http://op.juhe.cn/idcard/query";
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("key", apiKey);
|
||||
map.put("idcard", idCard.getIdcard());
|
||||
map.put("realname",idCard.getRealname());
|
||||
map.put("orderid", idCard.getOrderid());
|
||||
|
||||
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
public static String params(Map<String, String> map) {
|
||||
return map.entrySet().stream()
|
||||
.map(entry -> {
|
||||
try {
|
||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return entry.getKey() + "=" + entry.getValue();
|
||||
}
|
||||
})
|
||||
.collect(Collectors.joining("&"));
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.muyu.cloud.background.controller;
|
|||
import com.muyu.cloud.background.api.DateCalendar;
|
||||
import com.muyu.cloud.background.api.MobileLocation;
|
||||
import com.muyu.cloud.background.api.News;
|
||||
import com.muyu.cloud.background.domin.api.IdCard;
|
||||
import com.muyu.cloud.background.domin.api.MobileLocationdomain;
|
||||
import com.muyu.cloud.background.domin.api.Newsdomain;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
@ -12,6 +13,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.cloud.background.controller
|
||||
|
@ -68,6 +71,19 @@ public class ApiUserController {
|
|||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证实名认证
|
||||
* @param card
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/idcard")
|
||||
@Operation(summary = "实名认证查询",description = "身份证实名认证")
|
||||
public Result JavaGet(@Validated @RequestBody IdCard card) throws IOException {
|
||||
Result result = com.muyu.cloud.background.api.IdCard.findIdCard(card);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue