wjc
2023-07-12 e604e1797744977f599dad9f543db3e7477fe115
app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java
@@ -3,14 +3,15 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.hdl.photovoltaic.ui.bean.LoginUserBean;
import com.hdl.photovoltaic.ui.bean.LoginUserRegionBean;
import com.hdl.photovoltaic.bean.HttpResponsePack;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.user.HDLLinkPMUser;
import com.hdl.linkpm.sdk.user.bean.HDLLoginBean;
import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean;
import com.hdl.linkpm.sdk.user.callback.ILoginCallBack;
import com.hdl.linkpm.sdk.user.callback.IRegionByAccountCallBack;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
import com.hdl.photovoltaic.internet.api.HttpApi;
import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import java.util.regex.Matcher;
@@ -46,27 +47,19 @@
     *
     * @param i_account 账号
     */
    public void regionByAccount(String i_account, CloudCallBeak<LoginUserRegionBean> cloudCallBeak) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("account", i_account);
        String full = AppConfigManage.getAPPRegionUrl() + HttpApi.POST_RegionByUserAccount;
        HttpClient.getInstance().requestFullHttp(full, jsonObject.toString(), true, true, new BaseSuccessFailureCallBeak() {
    public void regionByAccount(String i_account, CloudCallBeak<HDLUserRegionBean> cloudCallBeak) {
        HDLLinkPMUser.getInstance().regionByAccount(i_account, new IRegionByAccountCallBack() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
                if (httpResponsePack != null && httpResponsePack.getData() != null) {
                    Gson gson = new Gson();
                    String json = gson.toJson(httpResponsePack.getData());
                    LoginUserRegionBean loginUserRegionBean = new Gson().fromJson(json, LoginUserRegionBean.class);
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(loginUserRegionBean);
                    }
            public void onSuccess(HDLUserRegionBean regionBean) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(regionBean);
                }
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException error) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(error);
                }
            }
        });
@@ -76,39 +69,35 @@
     * 登录(B端账号)
     * 通过账号和密码
     *
     * @param account       手机或者邮箱
     * @param loginPwd      密码
     * @param cloudCallBeak -
     * @param account  手机或者邮箱
     * @param loginPwd 密码
     * @param callBack -
     */
    public void loginByPassword(String account, String loginPwd, CloudCallBeak<LoginUserBean> cloudCallBeak) {
    public void loginByPassword(String account, String loginPwd, ILoginCallBack callBack) {
        String requestUrl = HttpApi.POST_Login;
        JsonObject json = new JsonObject();
        json.addProperty("account", account);
        json.addProperty("loginPwd", loginPwd);
//        json.addProperty("platform", "APP");
        json.addProperty("grantType", "password");
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HDLLinkPMUser.getInstance().loginByPassword(account, loginPwd, new ILoginCallBack() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
                if (httpResponsePack != null && httpResponsePack.getData() != null) {
                    Gson gson = new Gson();
                    String json = gson.toJson(httpResponsePack.getData());
                    LoginUserBean loginUserBean = new Gson().fromJson(json, LoginUserBean.class);
                    saveUserData(loginUserBean);
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(loginUserBean);
                    }
            public void onSuccess(HDLLoginBean loginBean) {
                if (callBack != null) {
                    saveUserData(loginBean);
                    callBack.onSuccess(loginBean);
                }
            }
            @Override
            public void onFailure(Exception exception) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
            public void onFailure(HDLException error) {
                if (callBack != null) {
                    callBack.onFailure(error);
                }
            }
        });
    }
    /**
@@ -118,30 +107,26 @@
     * @param loginPwd      密码
     * @param cloudCallBeak -
     */
    public void refreshToken(String account, String loginPwd, CloudCallBeak<LoginUserBean> cloudCallBeak) {
    public void refreshToken(String account, String loginPwd, CloudCallBeak<HDLLoginBean> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Login;
        JsonObject json = new JsonObject();
        json.addProperty("grantType", "refresh_token");
//        json.addProperty("refreshToken", UserConfigManage.getInstance().getRefreshToken());
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(HttpResponsePack httpResponsePack) {
                if (httpResponsePack != null && httpResponsePack.getData() != null) {
                    Gson gson = new Gson();
                    String json = gson.toJson(httpResponsePack.getData());
                    LoginUserBean loginUserBean = new Gson().fromJson(json, LoginUserBean.class);
                    saveUserData(loginUserBean);
                    if (cloudCallBeak != null) {
                        cloudCallBeak.onSuccess(loginUserBean);
                    }
            public void onSuccess(String jsonStr) {
                Gson gson = new Gson();
                HDLLoginBean loginBean = gson.fromJson(jsonStr, HDLLoginBean.class);
//                    saveUserData(loginBean);
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(loginBean);
                }
            }
            @Override
            public void onFailure(Exception exception) {
            public void onFailure(HDLException e) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onFailure(exception);
                    cloudCallBeak.onFailure(e);
                }
            }
        });
@@ -170,7 +155,7 @@
    /**
     * 登录成功保存登录信息
     */
    private void saveUserData(LoginUserBean obj) {
    private void saveUserData(HDLLoginBean obj) {
        if (obj != null) {
            UserConfigManage.getInstance().setLogin(true);//是否登录
            UserConfigManage.getInstance().setAcceiptPolicy(true);//是否选择隐私政策