Commit 0f114240 authored by jwc's avatar jwc

运营商验证 + 代码优化

parent a594bfcd
package cn.zingfin.common.util;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
......@@ -10,6 +14,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -91,4 +96,26 @@ public class HttpUtil {
}
return pairs;
}
/**
* 用到的HTTP工具包:okhttp 3.13.1
* <dependency>
* <groupId>com.squareup.okhttp3</groupId>
* <artifactId>okhttp</artifactId>
* <version>3.13.1</version>
* </dependency>
*/
public static String postForm(String appCode, String url, Map<String, String> params) throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
FormBody.Builder formbuilder = new FormBody.Builder();
for (String key : params.keySet()) {
formbuilder.add(key, params.get(key));
}
FormBody body = formbuilder.build();
Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
Response response = client.newCall(request).execute();
System.out.println("返回状态码" + response.code() + ",message:" + response.message());
assert response.body() != null;
return response.body().string();
}
}
package cn.zingfin.common.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
/**
* @author jwc
* @date 2020/9/3 17:15
*/
public class HttpUtils {
/**
* get
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doGet(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpGet request = new HttpGet(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
/**
* post form
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param bodys
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
Map<String, String> bodys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (bodys != null) {
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
for (String key : bodys.keySet()) {
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
request.setEntity(formEntity);
}
return httpClient.execute(request);
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Put String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
/**
* Put stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
/**
* Delete
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public static HttpResponse doDelete(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return httpClient.execute(request);
}
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
StringBuilder sbUrl = new StringBuilder();
sbUrl.append(host);
if (!StringUtils.isBlank(path)) {
sbUrl.append(path);
}
if (null != querys) {
StringBuilder sbQuery = new StringBuilder();
for (Map.Entry<String, String> query : querys.entrySet()) {
if (0 < sbQuery.length()) {
sbQuery.append("&");
}
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
sbQuery.append(query.getValue());
}
if (!StringUtils.isBlank(query.getKey())) {
sbQuery.append(query.getKey());
if (!StringUtils.isBlank(query.getValue())) {
sbQuery.append("=");
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
}
}
}
if (0 < sbQuery.length()) {
sbUrl.append("?").append(sbQuery);
}
}
return sbUrl.toString();
}
private static HttpClient wrapClient(String host) {
HttpClient httpClient = new DefaultHttpClient();
if (host.startsWith("https://")) {
sslClient(httpClient);
}
return httpClient;
}
private static void sslClient(HttpClient httpClient) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] xcs, String str) {
}
public void checkServerTrusted(X509Certificate[] xcs, String str) {
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
} catch (KeyManagementException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
}
\ No newline at end of file
package cn.zingfin.common.util;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
/**
* @author chsm
* @version v1.0
* @since 2020/8/11 10:32
*/
public class RequestUtil {
public static Object getRequestParameter(String key) {
HttpServletRequest httpServletRequest = getHttpServletRequest();
return httpServletRequest.getParameter(key);
}
public static HttpServletRequest getHttpServletRequest() {
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
}
public static HttpServletResponse getHttpServletResponse() {
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getResponse();
}
}
package cn.zingfin.config;
import cn.zingfin.base.BaseOpenApiRequest;
import cn.zingfin.common.util.RequestUtil;
import cn.zingfin.constant.SystemErrorCodeEnum;
import cn.zingfin.exception.BizException;
import cn.zingfin.exception.OpenApiException;
import cn.zingfin.factory.ResponseDataHandleFactory;
import cn.zingfin.properties.OpenApiPlatformKey;
import cn.zingfin.sign.ResponseDataHandle;
import cn.zingfin.support.ResultMsg;
import cn.zingfin.util.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Title: SpringControllerAdvice
* <p>
* Description:
*
* @author 瞿宇龙
* @version V1.0
* @since 2019/8/19
*/
@ControllerAdvice
@Slf4j
public class SpringControllerAdvice {
@Resource
private ResponseDataHandleFactory responseDataHandleFactory;
@Resource
private OpenApiPlatformKey openApiPlatformKey;
/**
* 处理所有接口数据验证异常
*
* @param e
* @return
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
ResultMsg<Object> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
error(e);
BindingResult bindingResult = e.getBindingResult();
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
String returnMsg = fieldErrors.get(0).getDefaultMessage();
return ResultUtils.handleErrorMsg(returnMsg);
}
@ExceptionHandler(OpenApiException.class)
@ResponseBody
Map<String, String> handleOpenApiException(OpenApiException e) {
error(e);
BaseOpenApiRequest baseOpenApiRequest = new BaseOpenApiRequest();
baseOpenApiRequest.setAppPublicKey(openApiPlatformKey.getPublicKey());
baseOpenApiRequest.setMd5Key(openApiPlatformKey.getMdKey());
ResponseDataHandle responseDataHandle = responseDataHandleFactory.getResponseDataHandle(baseOpenApiRequest);
HttpServletResponse response = RequestUtil.getHttpServletResponse();
return responseDataHandle.handle(ResultMsg.builder()
.withErrorCode(e.getCode())
.withMsg(e.getMessage()).withSuccess(false).build(), response);
}
/**
* 业务异常统一处理
*
* @param e
* @return
*/
@ExceptionHandler(BizException.class)
@ResponseBody
ResultMsg bizException(BizException e) {
error(e);
return ResultMsg.builder()
.withErrorCode(e.getCode() == null ? SystemErrorCodeEnum.SYSTEM_ERROR.getCode() : e.getCode())
.withMsg(e.getMessage()).withSuccess(false).build();
}
@ExceptionHandler(Exception.class)
@ResponseBody
ResultMsg exception(Exception e) {
error(e);
return ResultMsg.builder().withErrorCode(SystemErrorCodeEnum.SYSTEM_ERROR.getCode()).
withMsg(SystemErrorCodeEnum.SYSTEM_ERROR.getMessage()).withSuccess(false).build();
}
private void error(Exception e) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String requestURI = request.getRequestURI();
log.error("{}请求出错,{}", requestURI, e.getMessage(), e);
}
}
package cn.zingfin.domain.model;
import lombok.Data;
/**
* @author jwc
* @date 2020/9/4 14:13
*/
@Data
public class PersonalMobileInfoModel {
//姓名
private String name;
//手机号
private String mobile;
//身份证号
private String idcard;
//验证结果 1:一致 2:不一致 3:无记录 -1:异常
private String res;
// 验证结果状态描述(与res状态码相对应)
private String description;
// 性别
private String sex;
// 生日
private String birthday;
// 地址
private String address;
}
......@@ -2,8 +2,11 @@ package cn.zingfin.domain.service;
import cn.zingfin.exception.OpenApiException;
import cn.zingfin.web.model.VerificationCompanyRequest;
import cn.zingfin.web.model.VerificationMobileRequest;
import cn.zingfin.web.model.VerificationPersonalRequest;
import java.io.IOException;
/**
* @author jwc
* @date 2020/9/2 15:27
......@@ -13,4 +16,7 @@ public interface VerificationService {
Boolean verificationCompany(VerificationCompanyRequest verificationCompanyRequest) throws OpenApiException;
Boolean verificationPersonal(VerificationPersonalRequest verificationPersonalRequest) throws OpenApiException;
Boolean personalMobile(VerificationMobileRequest verificationMobileRequest) throws IOException, OpenApiException;
}
......@@ -160,8 +160,9 @@ public class OcrServiceImpl implements OcrService {
}
} else {
// 表明请求整体处理失败,原因视具体的情况详细分析。
System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
throw new OpenApiException(OpenApiErrorCodeEnums.FAIL);
log.info("the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
return false;
// throw new OpenApiException(OpenApiErrorCodeEnums.FAIL);
}
}
return null;
......
......@@ -2,14 +2,21 @@ package cn.zingfin.domain.service.impl;
import cn.zingfin.common.enums.OpenApiErrorCodeEnums;
import cn.zingfin.common.util.HttpUtil;
import cn.zingfin.common.util.HttpUtils;
import cn.zingfin.domain.model.CompanyInfoModel;
import cn.zingfin.domain.model.PersonalMobileInfoModel;
import cn.zingfin.domain.service.VerificationService;
import cn.zingfin.exception.OpenApiException;
import cn.zingfin.web.model.VerificationCompanyRequest;
import cn.zingfin.web.model.VerificationMobileRequest;
import cn.zingfin.web.model.VerificationPersonalRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
......@@ -19,6 +26,7 @@ import java.util.Objects;
* @date 2020/9/2 15:28
*/
@Service
@Slf4j
public class VerificationServiceImpl implements VerificationService {
@Override
......@@ -49,6 +57,31 @@ public class VerificationServiceImpl implements VerificationService {
return handlePersonalResult(result);
}
@Override
public Boolean personalMobile(VerificationMobileRequest request) throws IOException, OpenApiException {
String url = "https://mobile3elements.shumaidata.com/mobile/verify_real_name";
String appCode = "572685145f914aa998184593083bf7a5";
Map<String, String> params = new HashMap<>();
params.put("idcard", request.getNumber());
params.put("mobile", request.getMobile());
params.put("name", request.getName());
String result = HttpUtil.postForm(appCode, url, params);
log.info("personalMobile:" + result);
return handlePersonalMobileResult(result);
}
private Boolean handlePersonalMobileResult(String result) throws OpenApiException {
JSONObject json = JSONObject.parseObject(result);
String code = json.getString("code");
if ("0".equals(code)) {
JSONObject data = json.getJSONObject("result");
PersonalMobileInfoModel personalMobileInfoModel = JSONObject.toJavaObject(data, PersonalMobileInfoModel.class);
return Objects.equals("1", personalMobileInfoModel.getRes());
}
return false;
// throw new OpenApiException(json.getString("message"));
}
private Boolean handlePersonalResult(String result) {
JSONObject json = JSONObject.parseObject(result);
String code = json.getString("code");
......
......@@ -6,6 +6,7 @@ import cn.zingfin.exception.OpenApiException;
import cn.zingfin.handle.OpenApiHandle;
import cn.zingfin.web.model.SmsRequest;
import cn.zingfin.web.model.VerificationCompanyRequest;
import cn.zingfin.web.model.VerificationMobileRequest;
import cn.zingfin.web.model.VerificationPersonalRequest;
import com.aliyuncs.exceptions.ClientException;
import io.swagger.annotations.Api;
......@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
......@@ -36,7 +38,7 @@ public class VerificationController {
@ApiOperation("企业验证")
@PostMapping("/v1/company")
public Map<String, String> company(HttpServletRequest request, HttpServletResponse response) throws ClientException, OpenApiException {
public Map<String, String> company(HttpServletRequest request, HttpServletResponse response) throws OpenApiException {
VerificationCompanyRequest verificationCompanyRequest = openApiHandle.execute(request, VerificationCompanyRequest.class);
Boolean isSuccess = verificationService.verificationCompany(verificationCompanyRequest);
return openApiHandle.returnHandle(isSuccess, response);
......@@ -44,10 +46,18 @@ public class VerificationController {
@ApiOperation("个人实名验证")
@PostMapping("/v1/personal")
public Map<String, String> personal(HttpServletRequest request, HttpServletResponse response) throws ClientException, OpenApiException {
public Map<String, String> personal(HttpServletRequest request, HttpServletResponse response) throws OpenApiException {
VerificationPersonalRequest verificationPersonalRequest = openApiHandle.execute(request, VerificationPersonalRequest.class);
Boolean isSuccess = verificationService.verificationPersonal(verificationPersonalRequest);
return openApiHandle.returnHandle(isSuccess, response);
}
@ApiOperation("个人手机号验证")
@PostMapping("/v1/personalMobile")
public Map<String, String> personalMobile(HttpServletRequest request, HttpServletResponse response) throws OpenApiException, IOException {
VerificationMobileRequest verificationMobileRequest = openApiHandle.execute(request, VerificationMobileRequest.class);
Boolean isSuccess = verificationService.personalMobile(verificationMobileRequest);
return openApiHandle.returnHandle(isSuccess, response);
}
}
package cn.zingfin.web.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author jwc
* @date 2020/9/4 9:45
*/
@Data
public class VerificationMobileRequest {
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "身份证号")
private String number;
@ApiModelProperty(value = "电话号码")
private String mobile;
}
......@@ -14,7 +14,7 @@ public class OcrIdCardTest {
// 对方的私钥
String appPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCm6xO5wJGSRvtEVvCaAPxRwOuc7RH4nT79KIXFzwRdjeBzIR78m/bSMv7hokmahTNiF7veI/8WD8EAz7E6VoXGatzbtGOVO3GEkd8hssAOw6t3dCfr5PNStS4qyjK0haEiya3LlKYowuFv5RLwmJYAqRHlCW73ala+mk3iDBYHfuLqAKhFn+zCE3kQQD7AWwkxWhf4IckQ6ymhPjsX/5pjJXfzNjhbf1pryugl23HNm4KQ+pEPDLvQ2vziOVEl6/6y7zKIf4pr/e9jq8T3ZX7T+AExunDAsToEqZP2ybdek9dJOHfJtobFZoFW6/2XTd2vHTBFUDoUbezS63Q1FAflAgMBAAECggEAcZH6/uT+ZyeyqOH6nN5Uz49TAJfxJVZgWEGtG1TqpHj3IX6Epd28h3K5J26TY/aDape5dMDLPAiGCnZGIOpj5Qgqs7Y+F3i1mTzjM/t6X9FUplc7Hm7N/BVYjza6X0eYxqGwhZbjo1JNryOOynMXhOWETnEntmH9GXzFxyrwBjJ4skUDK78I8vDmazj0hVj7VULWjhH0ufG17mDme7mVjJh1oOpCqEVoCqkMRHWsZg8o0bwYOczxoQG+T9vdR7K9GyLdFctFUGZNlZPsyDVcPrsC4IP+a8630YMxI06DBS/r8xTqS3Dh2YWcuNB0TQsUDg/nms+y+tT9fwFk1rX+9QKBgQD/eqFa+t+RLAkUbAvwLtDpgahtOkM7SnucuF101mnYff8LtjImZ//3pQltrHTRo++b1nWcVQcNb1rljuJ9Fgs9dzMP9DSnziYNcbAxUrcA0kTiDUOuOvxoVjvpGRkHKnEmXhZWQrhOP2sb15LpbDE6GBFs4xcIW8jat1cdem033wKBgQCnQjb2b88OgDssROf7GmXjUsSheeLshrxvf2dxiBomjtg0h9WKjP2ONoLKxwJNICBqvr1SbteIMQmw8/2QwCDvcx0JjNgkwuX6HabwmJ5qJFtn9wHB2gq1JZzoLvfwVr+uCVUF/EDciCqts08ynzYZoCbJ0LhTXdsQSDeGGRrIuwKBgQCcyIobRlhLRAXydXhCFsj4dCyDk7zMtyHzBKW93ROp23DYpCBUt4A7XxnRJ4OtX/jc3xjgLsIcOZlDxZMzBoMxXmSExu5FiNqLZ5ikPEm4hFHnlBJT6zkZYspze4aDgkVcMWNt3pYy1vKJbJtpCo+PQlP3ScnJxGIX72nT2l0KawKBgCrOioyV3xNiBEL3O7wLbIo6k7KUJFzOuwl6PPpUkATQSEthfGiiXv53uw+00UT19PX87S1cyvLDQiy0tW/HjGZcOtFH58W4z+0si55GIT0fIvm/wQZhDJ6CCt9tre0n9pTPNKB8iAkpHGsqWhmln839LBA4yAQmIDvRj8xVPoKjAoGBAP33PLwqJhVxgpG6uMhjmF3fEdTrrd40yEI0SnPHMRnQflbkXr+u6EOUWtVR4y5Buj0+ckNzIZXJ5k2GhpxT/vWmkEiOH4+WpTruQDuoa6S/nHP6QuP2AaGZyBDCfeTAWGp8i5HAsPSBdLyylgnmfkfQEVGZlEgUITjf31exJawu";
ScanRequest scanRequest = new ScanRequest();
scanRequest.setPictureUrl("https://zing-finance.oss-cn-hangzhou.aliyuncs.com/%E8%BA%AB%E4%BB%BD%E8%AF%81%E6%AD%A3%E9%9D%A2.jpg");
scanRequest.setPictureUrl("https://zing-finance.oss-cn-hangzhou.aliyuncs.com/%E8%BA%AB%E4%BB%BD%E8%AF%81%E6%AD%A3%E9%9D%A.jpg");
String md5 = "f5226bbba1eca51c03a56df636d44b1c";
DefaultClient defaultClient = new DefaultClient("http://common-api.atliangtian.com/", appPrivateKey, md5, myPublicKey, "1");
String testData = defaultClient.execute(scanRequest, "/open/api/ocr/v1/scanForIdCard");
......
package verification;
import cn.zingfin.common.util.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author jwc
* @date 2020/9/3 16:50
*/
public class MobilePersonal {
public static void main(String[] args) {
String host = "http://sjsys.market.alicloudapi.com";
String path = "/communication/personal/1979";
String method = "POST";
String appcode = "572685145f914aa998184593083bf7a5";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>();
bodys.put("idcard", "342921199302282819");
bodys.put("mobile", "18355551987");
bodys.put("name", "计万成");
try {
/**
* 重要提示如下:
* HttpUtils请从
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
* 下载
*
* 相应的依赖请参照
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
*/
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
System.out.println(response.toString());
//获取response的body
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
package verification;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @author jwc
* @date 2020/9/4 10:13
*/
public class ShumaiMobile {
public static void main(String[] args) throws IOException {
String url = "https://mobile3elements.shumaidata.com/mobile/verify_real_name";
String appCode = "572685145f914aa998184593083bf7a5";
Map<String, String> params = new HashMap<>();
params.put("idcard", "342921199302282819");
params.put("mobile", "18355551987");
params.put("name", "计万");
String result = postForm(appCode, url, params);
System.out.println(result);
}
/**
* 用到的HTTP工具包:okhttp 3.13.1
* <dependency>
* <groupId>com.squareup.okhttp3</groupId>
* <artifactId>okhttp</artifactId>
* <version>3.13.1</version>
* </dependency>
*/
public static String postForm(String appCode, String url, Map<String, String> params) throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
FormBody.Builder formbuilder = new FormBody.Builder();
for (String key : params.keySet()) {
formbuilder.add(key, params.get(key));
}
FormBody body = formbuilder.build();
Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
Response response = client.newCall(request).execute();
System.out.println("返回状态码" + response.code() + ",message:" + response.message());
assert response.body() != null;
return response.body().string();
}
}
package verification;
import cn.zingfin.exception.BizException;
import cn.zingfin.sign.DefaultClient;
import cn.zingfin.web.model.VerificationCompanyRequest;
import cn.zingfin.web.model.VerificationMobileRequest;
/**
* @author jwc
* @date 2020/9/4 14:27
*/
public class ShumaiMobileTest {
public static void main(String[] args) throws BizException {
String myPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApusTucCRkkb7RFbwmgD8UcDrnO0R+J0+/SiFxc8EXY3gcyEe/Jv20jL+4aJJmoUzYhe73iP/Fg/BAM+xOlaFxmrc27RjlTtxhJHfIbLADsOrd3Qn6+TzUrUuKsoytIWhIsmty5SmKMLhb+US8JiWAKkR5Qlu92pWvppN4gwWB37i6gCoRZ/swhN5EEA+wFsJMVoX+CHJEOspoT47F/+aYyV38zY4W39aa8roJdtxzZuCkPqRDwy70Nr84jlRJev+su8yiH+Ka/3vY6vE92V+0/gBMbpwwLE6BKmT9sm3XpPXSTh3ybaGxWaBVuv9l03drx0wRVA6FG3s0ut0NRQH5QIDAQAB";
// 对方的私钥
String appPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCm6xO5wJGSRvtEVvCaAPxRwOuc7RH4nT79KIXFzwRdjeBzIR78m/bSMv7hokmahTNiF7veI/8WD8EAz7E6VoXGatzbtGOVO3GEkd8hssAOw6t3dCfr5PNStS4qyjK0haEiya3LlKYowuFv5RLwmJYAqRHlCW73ala+mk3iDBYHfuLqAKhFn+zCE3kQQD7AWwkxWhf4IckQ6ymhPjsX/5pjJXfzNjhbf1pryugl23HNm4KQ+pEPDLvQ2vziOVEl6/6y7zKIf4pr/e9jq8T3ZX7T+AExunDAsToEqZP2ybdek9dJOHfJtobFZoFW6/2XTd2vHTBFUDoUbezS63Q1FAflAgMBAAECggEAcZH6/uT+ZyeyqOH6nN5Uz49TAJfxJVZgWEGtG1TqpHj3IX6Epd28h3K5J26TY/aDape5dMDLPAiGCnZGIOpj5Qgqs7Y+F3i1mTzjM/t6X9FUplc7Hm7N/BVYjza6X0eYxqGwhZbjo1JNryOOynMXhOWETnEntmH9GXzFxyrwBjJ4skUDK78I8vDmazj0hVj7VULWjhH0ufG17mDme7mVjJh1oOpCqEVoCqkMRHWsZg8o0bwYOczxoQG+T9vdR7K9GyLdFctFUGZNlZPsyDVcPrsC4IP+a8630YMxI06DBS/r8xTqS3Dh2YWcuNB0TQsUDg/nms+y+tT9fwFk1rX+9QKBgQD/eqFa+t+RLAkUbAvwLtDpgahtOkM7SnucuF101mnYff8LtjImZ//3pQltrHTRo++b1nWcVQcNb1rljuJ9Fgs9dzMP9DSnziYNcbAxUrcA0kTiDUOuOvxoVjvpGRkHKnEmXhZWQrhOP2sb15LpbDE6GBFs4xcIW8jat1cdem033wKBgQCnQjb2b88OgDssROf7GmXjUsSheeLshrxvf2dxiBomjtg0h9WKjP2ONoLKxwJNICBqvr1SbteIMQmw8/2QwCDvcx0JjNgkwuX6HabwmJ5qJFtn9wHB2gq1JZzoLvfwVr+uCVUF/EDciCqts08ynzYZoCbJ0LhTXdsQSDeGGRrIuwKBgQCcyIobRlhLRAXydXhCFsj4dCyDk7zMtyHzBKW93ROp23DYpCBUt4A7XxnRJ4OtX/jc3xjgLsIcOZlDxZMzBoMxXmSExu5FiNqLZ5ikPEm4hFHnlBJT6zkZYspze4aDgkVcMWNt3pYy1vKJbJtpCo+PQlP3ScnJxGIX72nT2l0KawKBgCrOioyV3xNiBEL3O7wLbIo6k7KUJFzOuwl6PPpUkATQSEthfGiiXv53uw+00UT19PX87S1cyvLDQiy0tW/HjGZcOtFH58W4z+0si55GIT0fIvm/wQZhDJ6CCt9tre0n9pTPNKB8iAkpHGsqWhmln839LBA4yAQmIDvRj8xVPoKjAoGBAP33PLwqJhVxgpG6uMhjmF3fEdTrrd40yEI0SnPHMRnQflbkXr+u6EOUWtVR4y5Buj0+ckNzIZXJ5k2GhpxT/vWmkEiOH4+WpTruQDuoa6S/nHP6QuP2AaGZyBDCfeTAWGp8i5HAsPSBdLyylgnmfkfQEVGZlEgUITjf31exJawu";
String md5 = "f5226bbba1eca51c03a56df636d44b1c";
VerificationMobileRequest request = new VerificationMobileRequest();
request.setMobile("18355551987");
request.setName("计万成");
request.setNumber("342921199302282819");
DefaultClient defaultClient = new DefaultClient("http://localhost:8080", appPrivateKey, md5, myPublicKey, "1");
String testData = defaultClient.execute(request, "/open/api/verification/v1/personalMobile");
System.out.println(testData);
}
}
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