|
@@ -10,26 +10,17 @@ import com.zanxiang.game.module.mybatis.mapper.UserCardMapper;
|
|
|
import com.zanxiang.game.module.sdk.constant.RegexConstant;
|
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserCardUpdateParam;
|
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
|
-import com.zanxiang.game.module.sdk.pojo.result.CardCheckResult;
|
|
|
-import com.zanxiang.game.module.sdk.pojo.result.IpCheckResult;
|
|
|
+import com.zanxiang.game.module.sdk.service.IAliApiService;
|
|
|
import com.zanxiang.game.module.sdk.service.IUserCardService;
|
|
|
import com.zanxiang.game.module.sdk.service.IUserService;
|
|
|
-import com.zanxiang.module.util.JsonUtil;
|
|
|
-import com.zanxiang.module.util.exception.BaseException;
|
|
|
import com.zanxiang.module.util.pojo.ResultVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.LinkedMultiValueMap;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-import org.springframework.web.util.UriComponentsBuilder;
|
|
|
import reactor.util.function.Tuple2;
|
|
|
-import reactor.util.function.Tuples;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
@@ -37,7 +28,6 @@ import java.time.LocalDateTime;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.GregorianCalendar;
|
|
|
-import java.util.UUID;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -54,7 +44,7 @@ public class UserCardServiceImpl extends ServiceImpl<UserCardMapper, UserCard> i
|
|
|
private IUserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
+ private IAliApiService aliApiService;
|
|
|
|
|
|
/**
|
|
|
* 服务器域名
|
|
@@ -89,9 +79,9 @@ public class UserCardServiceImpl extends ServiceImpl<UserCardMapper, UserCard> i
|
|
|
//阿里实名认证
|
|
|
Tuple2<Boolean, String> tuple2;
|
|
|
if (this.serverUrl.contains("test")) {
|
|
|
- tuple2 = this.authenticationCheck(cardName, cardId);
|
|
|
+ tuple2 = aliApiService.authenticationCheck(cardName, cardId);
|
|
|
} else {
|
|
|
- tuple2 = this.userCardCheck(cardName, cardId);
|
|
|
+ tuple2 = aliApiService.userCardCheck(cardName, cardId);
|
|
|
}
|
|
|
//实名认证失败
|
|
|
if (!tuple2.getT1()) {
|
|
@@ -177,81 +167,4 @@ public class UserCardServiceImpl extends ServiceImpl<UserCardMapper, UserCard> i
|
|
|
return sex;
|
|
|
}
|
|
|
|
|
|
- private Tuple2<Boolean, String> authenticationCheck(String cardName, String cardId) {
|
|
|
- String host = "https://dskj.market.alicloudapi.com/platform/check/verified";
|
|
|
- String appCode = "f395b1587fc04a49a975f908660fb1e9";
|
|
|
- String url = host + "?certCode=" + cardId + "&realName=" + cardName;
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.set("Authorization", "APPCODE " + appCode);
|
|
|
- headers.set("X-Ca-Nonce", UUID.randomUUID().toString());
|
|
|
- HttpEntity httpEntity = new HttpEntity<>(headers);
|
|
|
- CardCheckResult result;
|
|
|
- try {
|
|
|
- String resultStr = restTemplate.postForObject(url, httpEntity, String.class);
|
|
|
- result = JsonUtil.toObj(resultStr, CardCheckResult.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("请求阿里实名认证接口异常(OLD), cardName : {}, cardId : {}, e : {}", cardName, cardId, e.getMessage());
|
|
|
- throw new BaseException("请求阿里实名认证接口异常");
|
|
|
- }
|
|
|
- if (result == null || !result.isSuccess()) {
|
|
|
- log.error("请求阿里实名认证接口返回值为空(OLD), cardName : {}, cardId : {}, result : {}", cardName, cardId, JsonUtil.toString(result));
|
|
|
- throw new BaseException("实名认证失败");
|
|
|
- }
|
|
|
- return Tuples.of(result.isPast(), Strings.EMPTY);
|
|
|
- }
|
|
|
-
|
|
|
- private Tuple2<Boolean, String> userCardCheck(String cardName, String cardId) {
|
|
|
- String url = "https://eid.shumaidata.com/eid/check";
|
|
|
- String appCode = "f395b1587fc04a49a975f908660fb1e9";
|
|
|
- //请求头
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("Authorization", "APPCODE " + appCode);
|
|
|
- MultiValueMap<String, String> requestParams = new LinkedMultiValueMap<>();
|
|
|
- requestParams.add("name", cardName);
|
|
|
- requestParams.add("idcard", cardId);
|
|
|
- CardCheckResult result;
|
|
|
- try {
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST,
|
|
|
- new HttpEntity<>(requestParams, headers), String.class);
|
|
|
- String body = responseEntity.getBody();
|
|
|
- result = JsonUtil.toObj(body, CardCheckResult.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("请求阿里实名认证接口异常(NEW), cardName : {}, cardId : {}, e : {}", cardName, cardId, e.getMessage());
|
|
|
- throw new BaseException("请求阿里实名认证接口异常");
|
|
|
- }
|
|
|
- if (result == null || result.isFail()) {
|
|
|
- log.error("请求阿里实名认证接口返回值为空(NEW),cardName : {},cardId : {}, result : {}", cardName, cardId, JsonUtil.toString(result));
|
|
|
- throw new BaseException("实名认证失败");
|
|
|
- }
|
|
|
- log.error("实名认证结果, result : {}", JsonUtil.toString(result));
|
|
|
- return Tuples.of(result.past(), result.getAddress());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public IpCheckResult userIpCheck(String ip) {
|
|
|
- String url = "https://ipcity.market.alicloudapi.com/ip/city/query";
|
|
|
- String appCode = "f395b1587fc04a49a975f908660fb1e9";
|
|
|
- //构造请求参数
|
|
|
- UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(url).queryParam("ip", ip);
|
|
|
- //请求头
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.set("Authorization", "APPCODE " + appCode);
|
|
|
- RequestEntity<Object> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, uriBuilder.build().toUri());
|
|
|
- //请求
|
|
|
- IpCheckResult result;
|
|
|
- try {
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.exchange(requestEntity, String.class);
|
|
|
- String body = responseEntity.getBody();
|
|
|
- result = JsonUtil.toObj(body, IpCheckResult.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("请求阿里ip检测接口异常, ip : {}, e : {}", ip, e.getMessage());
|
|
|
- throw new BaseException("请求阿里ip监测接口异常");
|
|
|
- }
|
|
|
- if (result == null || result.isFail()) {
|
|
|
- log.error("请求阿里ip检测接口返回值为空, ip : {}, result : {}", ip, JsonUtil.toString(result));
|
|
|
- throw new BaseException("请求阿里ip检测接口返回值为空");
|
|
|
- }
|
|
|
- log.error("ip检测结果, result : {}", JsonUtil.toString(result));
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|