* 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.userinfo;
import com.huawei.accountkit.userinfo.req.GetAvatarAndNickNameByAccessTokenReq;
import com.huawei.accountkit.userinfo.resp.GetAvatarAndNickNameByAccessTokenResp;
import com.huawei.accountkit.util.CallUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
* 获取华为账号用户信息-获取头像昵称
*
* @author accountkit
* @since 2026-04-14
*/
public class GetAvatarAndNickNameByAccessTokenService {
private static final String URL = "https://account.cloud.huawei.com/rest.php?nsp_svc=GOpen.User.getInfo";
* 获取华为账号用户信息-获取头像昵称
*
* @param req GetUserInfoByQuickLoginReq
* @return GetUserInfoByQuickLoginResp
* @throws IOException IOException
*/
public static GetAvatarAndNickNameByAccessTokenResp call(GetAvatarAndNickNameByAccessTokenReq req)
throws IOException {
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> request = new ArrayList<>();
request.add(new BasicNameValuePair("access_token", req.getAccessToken()));
request.add(new BasicNameValuePair("getNickName",
Objects.isNull(req.getGetNickName()) ? null : String.valueOf(req.getGetNickName())));
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setEntity(new UrlEncodedFormEntity(request));
String res = CallUtils.remoteCall(httpPost);
return CallUtils.parseObject(res, GetAvatarAndNickNameByAccessTokenResp.class);
}
}