文档管理中心
API参考安全检测服务RESTUserDetect Service API获取虚假用户检测结果(中国大陆地区)

获取虚假用户检测结果(中国大陆地区)

功能介绍

您通过华为虚假用户检测服务,获取虚假用户检测的最终结果。

场景描述

您通过华为虚假用户检测服务,获取最终检测结果。

使用约束

检测虚假用户,仅在中国大陆地区使用。

接口原型

承载协议

HTTPS POST

接口方向

应用服务器->华为虚假用户检测服务器

接口URL

https://hirms.cloud.huawei.com.cn/rms/v1/userRisks/verifyNoCaptcha?appId={appId}

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

查询参数

展开

参数

是否必选

参数类型

描述

appId

String

您在AppGallery Connect平台上申请的应用appId。

请求参数

Request Header

Request Body

展开

参数

是否必选

参数类型

描述

accessToken

String

接入令牌AccessToken。可通过平台提供的接口获取,具体请参见客户端模式(Client Credentials)获取AccessToken。

response

String

App端虚假用户检测结果返回的响应。

请求示例

收起
自动换行
深色代码主题
复制
  1. POST https://{domain}/rms/v1/userRisks/verifyNoCaptcha?appId=******//{domain}:请参见站点信息
  2. {
  3. "response": "1_06684cfc0ce72baf3b7badeb651b667eb7c0a40b4724192c_1601302283856",
  4. "accessToken": "CgB6e3x9VDo9eewEj3/cCVt19xLg6Lnc4cOhqYRszjV7g2tnZwqHtvCd7fE7yFZe0RBN1zj4TacNOaJ+PuZuXjjg"
  5. }

响应参数

状态码为200

Response Header

展开

参数

是否必选

参数类型

描述

Content-Type

String

取值为:application/json。

Response Body

展开

参数

参数类型

描述

success

Boolean

检测结果,true代表真实用户,false代表虚假用户。

challenge_ts

String

responseToken生成时间(iSO格式为yyyy-MM-dd’T’HH:mm:ssZZ)。

apk_package_name

String

调用检测接口的客户端的包名。

error-codes

String

若接口调用异常,则会返回错误码。

isHuaweiDevice

Boolean

是否真实华为设备。

isBotBehavior

Boolean

疑似机器行为。

isEmulator

Boolean

疑似模拟器。

响应示例

收起
自动换行
深色代码主题
复制
  1. {
  2. "isEmulator": false,
  3. "apk_package_name": "com.example.mirror",
  4. "success": true,
  5. "challenge_ts": "2020-09-28T22:11:23+0800",
  6. "isBotBehavior": false,
  7. "isHuaweiDevice": true
  8. }

站点信息

调用虚假用户检测的服务端API时,在不同站点有不同的rootUrl。您应选择最近的站点访问。使用站点地址和后续章节中的接口URL拼接成完整的URL。

服务

站点信息{domain}

虚假用户检测

hirms.cloud.huawei.com.cn(中国大陆地区)

错误码

展开

状态码

错误码

描述

处理建议

200

0

成功。

-

missing-input-at

accessToken参数缺失。

在请求体中添加accessToken参数。

invalid-input-at

accessToken参数不合法。

检查accessToken参数是否合法。

missing-input-response

response参数缺失。

在请求体里面添加response参数。

invalid-input-response

response参数不合法。

检查response参数是否合法。

timeout-or-duplicate

response参数失效,已经过期或者已经被使用过。

注意

人机检测接口返回的responseToken有效期为2分钟,且只能被使用1次。

调用App端虚假用户检测接口以重新获取ResponseToken,并在有效期内使用该token。

current-site-not-support

非中国大陆地区不支持该方式调用。

-

调用示例

收起
自动换行
深色代码主题
复制
  1. /**
  2. * apply access token
  3. *
  4. * @param baseUrl the address of OAUTH2
  5. * @param grantType authorization type
  6. * @param appId app id
  7. * @param secretKey Secret Key
  8. */
  9. private static String applyAccessToken(String baseUrl, String grantType, String appId, String secretKey)
  10. throws CommonException {
  11. HttpPost httpPostRequest = new HttpPost(baseUrl);
  12. httpPostRequest.setHeader("content-type", "application/x-www-form-urlencoded");
  13. List<NameValuePair> entityData = new ArrayList<>();
  14. entityData.add(new BasicNameValuePair("grant_type", grantType));
  15. entityData.add(new BasicNameValuePair("client_id", appId));
  16. entityData.add(new BasicNameValuePair("client_secret", secretKey));
  17. UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(entityData, StandardCharsets.UTF_8);
  18. httpPostRequest.setEntity(urlEncodedFormEntity);
  19. String accessToken;
  20. String response = getHttpResponseContent(httpPostRequest);
  21. try {
  22. JSONObject res = JSON.parseObject(response);
  23. accessToken = res.get("access_token").toString();
  24. } catch (Exception e) {
  25. LOGGER.warn("fail to apply access token");
  26. throw new CommonException("false", "fail to apply access token");
  27. }
  28. LOGGER.info("access token: {}", accessToken);
  29. return accessToken;
  30. }
  31. ------------------------------------------------------------------------------------------------------
  32. /**
  33. * get user detect result
  34. *
  35. * @param appId app id "******"
  36. * @param supplier request parameter
  37. */
  38. private String getverifyNoCaptchaResult(String verifyUrl, String appId, Supplier<JSONObject> supplier) throws
  39. CommonException {
  40. URIBuilder uriBuilder;
  41. try {
  42. uriBuilder = new URIBuilder(verifyUrl);
  43. } catch (URISyntaxException e) {
  44. LOGGER.error("fail to new URIBuilder, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
  45. throw new CommonException("false", "client-fail-new-URIBuilder");
  46. }
  47. uriBuilder.addParameter("appId", appId);
  48. HttpPost httpPostRequest;
  49. try {
  50. httpPostRequest = new HttpPost(uriBuilder.build());
  51. } catch (URISyntaxException e) {
  52. LOGGER.warn("fail to new HttpPost, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
  53. throw new CommonException("false", "client-fail-new-HttpPost");
  54. }
  55. httpPostRequest.addHeader("content-type", "application/json");
  56. httpPostRequest.addHeader("X-Client-Version", "1.0.1.102");
  57. StringEntity entityData;
  58. try {
  59. entityData = new StringEntity(supplier.get().toString());
  60. } catch (UnsupportedEncodingException e) {
  61. LOGGER.warn("fail to new StringEntity, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
  62. throw new CommonException("false", "client-fail-new-StringEntity");
  63. }
  64. httpPostRequest.setEntity(entityData);
  65. return getHttpResponseContent(httpPostRequest);
  66. }
  67. --------------------------------------------------------------------------------------------------
  68. private static String getHttpResponseContent(HttpPost httpPostRequest) throws CommonException {
  69. SSLContext sslcontext;
  70. try {
  71. sslcontext = SSLContexts.custom().loadTrustMaterial(null, (chain, authType) -> true).build();
  72. } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
  73. LOGGER.error("fail to build sslcontext, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
  74. throw new CommonException("false", "fail to build sslcontext");
  75. }
  76. SSLConnectionSocketFactory sslsf =
  77. new SSLConnectionSocketFactory(sslcontext, null, null, new NoopHostnameVerifier());
  78. HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
  79. HttpResponse httpResponse;
  80. try {
  81. httpResponse = httpClient.execute(httpPostRequest);
  82. } catch (IOException e) {
  83. LOGGER.error("fail to get HttpResponse, msg:{}, class:{}, url: {}", e.getMessage(),
  84. e.getClass().getSimpleName(), httpPostRequest.getURI());
  85. throw new CommonException("false", "client-fail-get-HttpResponse");
  86. }
  87. if (httpResponse.getStatusLine().getStatusCode() != SUCCESS_CODE) {
  88. LOGGER.warn(httpResponse.toString());
  89. throw new CommonException("false", "response is not 200");
  90. }
  91. String responseContent = "";
  92. HttpEntity httpEntity = httpResponse.getEntity();
  93. if (httpEntity != null) {
  94. try {
  95. responseContent = EntityUtils.toString(httpEntity, "UTF-8");
  96. } catch (IOException e) {
  97. LOGGER.warn("fail to gain responseContent, msg:{}, class:{}", e.getMessage(),
  98. e.getClass().getSimpleName());
  99. }
  100. try {
  101. EntityUtils.consume(httpEntity);
  102. } catch (IOException e) {
  103. LOGGER.warn("fail to consume HttpEntity, msg:{}, class:{}", e.getMessage(),
  104. e.getClass().getSimpleName());
  105. }
  106. }
  107. LOGGER.info("responseContent: {}, url: {}", responseContent, httpPostRequest.getURI());
  108. return responseContent;
  109. }
在 API参考 中进行搜索
请输入您想要搜索的关键词