YYour NameAccount Kit
c647687bAdd on Jun 10History
/*
 * Copyright (c) 2026 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.huawei.accountkit.realname;

import com.huawei.accountkit.realname.req.GetUserAgeRangeReq;
import com.huawei.accountkit.realname.resp.GetUserAgeRangeResp;
import com.huawei.accountkit.util.CallUtils;

import org.apache.http.client.methods.HttpPost;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 获取用户实名年龄段
 *
 * @author accountkit
 * @since 2026-04-14
 */
public class GetUserAgeRangeService {
    private static final String URL = "https://account-realname-api.cloud.huawei.com/openrealname/v6/realname-info/get";

    /**
     * 获取用户实名年龄段
     * 
     * @param req GetUserAgeRangeReq
     * @return GetUserAgeRangeResp
     * @throws IOException IOException
     */
    public static GetUserAgeRangeResp call(GetUserAgeRangeReq req) throws IOException {
        HttpPost httpPost = new HttpPost(URL);
        httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
        httpPost.setHeader("Authorization", "Bearer " + req.getAccessToken());
        Map<String, Object> reqBody = new HashMap<>();
        reqBody.put("clientId", req.getClientId());
        httpPost.setEntity(CallUtils.wrapJsonEntity(reqBody));

        String res = CallUtils.remoteCallAccountApi(httpPost);

        return CallUtils.parseObject(res, GetUserAgeRangeResp.class);
    }
}