百度云网址:
https://cloud.baidu.com
身份验证的技术文档:
技术代码:
导入依赖:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.13</version>
<scope>compile</scope>
</dependency>
// JSONObject的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
// io流的依赖
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
//hutool
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
控制层:
/***
* 身份证验证上传图片接口
*/
@PostMapping ("identityToken/{param}")
public Result identityToken(@PathVariable("param")Integer param , MultipartFile file, HttpServletRequest request) throws IOException {
System.out.println("图片=="+file);
CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
return agentUserService.identityToken(user,file,param);
}
处理的事物层
Result identityToken(CereBuyerUser user, MultipartFile file,Integer param) throws IOException;
package com.example.demo.service.Impl;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.service.AgentUserService;
import com.example.demo.util.Base64Util;
import com.example.demo.util.FileUtil;
import com.example.demo.util.HttpUtils;
import okhttp3.*;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static com.example.demo.util.IdentityCardUtil.*;
@Service
public class AgentUserServiceImpl implements AgentUserService {
static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
@Value("${identity.url}")
private String identityUrl;
@Value("${identity.apiKey}")
private String apiKey;
@Value("${identity.secrtetKey}")
private String secrtetKey;
/**
* 身份验证
* @param
* @return
*/
@Override
public String identityToken(MultipartFile file, String param) throws IOException {
//获得身份验证token
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody