Obtaining Fake User Detection Results (Outside the Chinese Mainland)

Function

Obtains the fake user detection result.

Scenario

You want to obtain the fake user detection result from the Huawei UserDetect server.

Restrictions

This API is only available outside the Chinese mainland.

Prototype

Protocol

HTTPS POST

Direction

App server > Huawei UserDetect server

URL

https://{domain}/rms/v1/userRisks/verify?appId={appId}

{domain}: For details, please refer to Site Information.

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Query Parameters

Parameter

Mandatory

Type

Description

appId

Yes

String

App ID applied in AppGallery Connect.

Request Parameters

Request Header

None.

Request Body

Parameter

Mandatory

Type

Description

accessToken

Yes

String

Access token. You can obtain an access token through the API provided by the open platform. For details, please refer to Client Credentials.

response

Yes

String

Token obtained from the fake user detection result returned to the app.

Request Example

POST https://{domain}/rms/v1/userRisks/verify?appId=******// For details about {domain}, please refer to Site Information.
{
"accessToken":"CV7Qxu7U0aqtFYxj9FIw2LcOaFpjsHBSHUz8lrGuTipIB2VJNUkBK630+WMCLxzti5xL
PxjYB6slP49sbc3vPY53XjM5",
"response":"1_76deea6daf1ce20995e2b55e4651a8d6f2ffa8a7a6dfe5ce_15907"
}

Response Parameters

The following tables describe the response parameters when the status code is 200.

Response Header

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Content type. The value is application/json.

Response Body

Parameter

Type

Description

success

Boolean

Fake user detection result. true: real user; false: fake user.

challenge_ts

String

Time when the response token is generated. (ISO format: yyyy-MM-dd'T'HH:mm:ssZZ)

apk_package_name

String

Package name of the app that calls the API.

error-codes

String

Error codes returned upon API call exception.

Response Example

HTTP/1.1 200 OK
Content-Type: application/json
{
"success":true,
"challenge_ts":"2020-05-29T15:32:53+0800",
"apk_package_name":"com.example.mockthirdapp"
}

Result Codes

Status Code

Result Code

Description

Solution

200

0

Success.

-

missing-input-at

The accessToken parameter is missing.

Add the accessToken parameter to the request body.

invalid-input-at

Invalid accessToken parameter.

Verify that the accessToken parameter is valid.

missing-input-response

The response parameter is missing.

Add the response parameter to the request body.

invalid-input-response

Invalid response parameter.

Verify that the response parameter is valid.

timeout-or-duplicate

The response parameter has expired or has been used.

注意

The response token returned by the UserDetect API is valid only within 2 minutes and can be used only once.

Call the UserDetect API again to obtain a new response token and use the token within the validity period.

current-site-not-support

This API cannot be called in the Chinese mainland.

-

Site Information

When you call the UserDetect server API, the value of rootUrl varies depending on the site. You need to select the nearest site, and generate the URL to access the API by concatenating the site's root URL and the API's URL.

Service

Site Information {domain}

UserDetect

hirms.cloud.huawei.asia (Asia and Africa)

hirms.cloud.huawei.lat (Latin America)

hirms.cloud.huawei.ru (Russia)

hirms.cloud.huawei.eu (Europe)

hirms.cloud.huawei.com.au (Oceania)

说明

The site for Africa will come soon. Developers in Africa can use the site for Asia now.

Call Example

/**
     * apply access token
     *
     * @param baseUrl   the address of OAUTH2
     * @param appId     app id
     * @param secretKey Secret Key
     */
    private static String applyAccessToken(String baseUrl, String appId, String secretKey) {
        HttpPost httpPostRequest = new HttpPost(baseUrl);
        httpPostRequest.setHeader("content-type", "application/x-www-form-urlencoded");
 
        List<NameValuePair> entityData = new ArrayList<>();
        entityData.add(new BasicNameValuePair("grant_type", "client_credentials"));
        entityData.add(new BasicNameValuePair("client_id", appId));
        entityData.add(new BasicNameValuePair("client_secret", secretKey));
        UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(entityData, StandardCharsets.UTF_8);
        httpPostRequest.setEntity(urlEncodedFormEntity);
 
        String response = execute(httpPostRequest);
        return JSON.parseObject(response).get("access_token").toString();
}
----------------------------------------------------
/**
     * get user detect result
     *
     * @param verifyUrl     https://{domain}/rms/v1/userRisks/verify?appId=******// For details about {domain}, please refer to Site Information.
     * @param appId         app id ""******""
     * @param accessToken   the access token which apply from OAUTH2 applyAccessToken get
     * @param responseToken the response token that returned by userDetection function
     */
    private String verifyUserRisks(String verifyUrl, String appId, String accessToken, String responseToken) {
        URIBuilder uriBuilder;
        URI uri;
        try {
            uriBuilder = new URIBuilder(verifyUrl);
            uriBuilder.addParameter("appId", appId);
            uri = uriBuilder.build();
        } catch (URISyntaxException e) {
            LOGGER.error("fail to create URI, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
            return "";
        }
 
        HttpPost httpPostRequest;
        httpPostRequest = new HttpPost(uri);
        httpPostRequest.addHeader("content-type", "application/json");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("accessToken", accessToken);
        jsonObject.put("response", JSONObject.parseObject(responseToken).get("response"));
        StringEntity entityData;
        try {
            entityData = new StringEntity(jsonObject.toString());
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("fail to new StringEntity, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
            return "";
        }
        httpPostRequest.setEntity(entityData);
 
        return execute(httpPostRequest);
    }
-------------------------------------------------------------------------
private static String execute(HttpPost httpPostRequest) {
        SSLContext sslcontext = null;
        try {
            sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType) {
                    return true;
                }
            }).build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            LOGGER.error("fail to build sslcontext, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
        }
        SSLConnectionSocketFactory sslConnectionSocketFactory =
                new SSLConnectionSocketFactory(sslcontext, null, null, new NoopHostnameVerifier());
 
        HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build();
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpPostRequest);
        } catch (IOException e) {
            LOGGER.error("fail to create HttpResponse, msg:{}, class:{}", e.getMessage(), e.getClass().getSimpleName());
            return "";
        }
 
        String responseContent = "";
        if (httpResponse.getStatusLine().getStatusCode() == SUCCESS_CODE) {
            HttpEntity httpEntity = httpResponse.getEntity();
            if (httpEntity != null) {
                try {
                    responseContent = EntityUtils.toString(httpEntity, "UTF-8");
                } catch (IOException e) {
                    LOGGER.error("fail to get the entity content as a String, msg:{}, class:{}", e.getMessage(),
                            e.getClass().getSimpleName());
                }
                try {
                    EntityUtils.consume(httpEntity);
                } catch (IOException e) {
                    LOGGER.error("fail to consume HttpEntity, msg:{}, class:{}", e.getMessage(),
                            e.getClass().getSimpleName());
                }
            }
        }
        return responseContent;
    }
搜索
请输入您想要搜索的关键词