From f5f9d439cfc6b45acc486ec52ed7a0288e92d189 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期四, 08 六月 2023 20:34:39 +0800 Subject: [PATCH] 2023年06月08日20:34:33 --- app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java | 134 ++++++++++++++++++++++++++++++-------------- 1 files changed, 91 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java index 63c9ae5..27b8699 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java @@ -1,6 +1,20 @@ package com.hdl.photovoltaic.other; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.hdl.photovoltaic.bean.LoginBean; +import com.hdl.photovoltaic.bean.LoginUserRegionBean; +import com.hdl.photovoltaic.bean.ResponsePack; +import com.hdl.photovoltaic.config.ConfigManagement; +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; +import java.util.regex.Pattern; + /** * 鐧婚檰鐣岄潰鐨勯�昏緫 */ @@ -22,55 +36,89 @@ /** - * 鍒濆鍖栬处鍙风殑Url鍖哄煙鍦板潃(鍙兘鐘舵�佺爜:Sucess NotAccount NotNetWork) + * 鍒濆鍖栬处鍙风殑Url鍖哄煙鍦板潃(鍙兘鐘舵�佺爜:Success NotAccount NotNetWork) * - * @param i_account - * @return + * @param i_account 璐﹀彿 */ - private void InitAccoutRegionInfo(String i_account) { -// String regionUrl = this.GetAccoutRegionInfo(i_account); -// -// -// if (regionUrl == null) { -// return AccountStatu.NotNetWork; -// } -// if (regionUrl == string.Empty) { -// return AccountStatu.NotAccount; -// } -// -// return AccountStatu.Sucess; + public void regionByAccount(String i_account, CloudCallBeak<LoginUserRegionBean> cloudCallBeak) { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("account", i_account); + String full = ConfigManagement.getAPPRegionUrl() + HttpApi.POST_RegionByUserAccount; + HttpClient.getInstance().requestFullHttp(full, jsonObject.toString(), true, true, new BaseSuccessFailureCallBeak() { + @Override + public void onSuccess(ResponsePack responsePack) { + if (responsePack.getData() != null) { + Gson gson = new Gson(); + String json = gson.toJson(responsePack.getData()); + LoginUserRegionBean loginUserRegionBean = new Gson().fromJson(json, LoginUserRegionBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(loginUserRegionBean); + } else { + cloudCallBeak.onFailure(new Exception()); + } + } + } + + @Override + public void onFailure(Exception exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); } /** - * 鑾峰彇璐﹀彿鎵�鍦ㄥ尯鍩� + * 鐧诲綍 + * 閫氳繃璐﹀彿鍜屽瘑鐮� * - * @param account - * @param callBack - * @return https://nearest.hdlcontrol.com/smart-footstone/region/regionByUserAccount + * @param account 鎵嬫満鎴栬�呴偖绠� + * @param loginPwd 瀵嗙爜 + * @param cloudCallBeak - */ -// public Disposable regionByAccount(String account, IRegionByAccountCallBack callBack) { -// String requestUrl = HDLLinkPMSdk.getInitUrl() + HttpApi.POST_RegionByUserAccount; -// return HxHttp.builder() -// .url(requestUrl) -// .params("account", account) -// .build() -// .post() -// .subscribeWith(new HDLResponse<HDLUserRegionBean>() { -// @Override -// public void onResponse(HDLUserRegionBean response) { -// if (callBack != null) { -// callBack.onSuccess(response); -// } -// } -// -// @Override -// public void onFailure(HDLException e) { -// HDLExceptionSubmitUtils.submit(requestUrl, account, e); -// if (callBack != null) { -// callBack.onFailure(e); -// } -// } -// }); + public void loginByPassword(String account, String loginPwd, CloudCallBeak<LoginBean> cloudCallBeak) { + 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() { + @Override + public void onSuccess(ResponsePack responsePack) { + if (responsePack.getData() != null) { + Gson gson = new Gson(); + String json = gson.toJson(responsePack.getData()); + LoginBean loginBean = new Gson().fromJson(json, LoginBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(loginBean); + } else { + cloudCallBeak.onFailure(new Exception()); + } + } + } + + @Override + public void onFailure(Exception exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); + } + + + public boolean isPhone(String phone) { + Pattern p = Pattern.compile("^((13[0-9])|(14[0|5|6|7|9])|(15[0-3])|(15[5-9])|(16[6|7])|(17[2|3|5|6|7|8])|(18[0-9])|(19[1|8|9]))\\d{8}$"); + Matcher m = p.matcher(phone); + return m.matches(); + } + + public boolean isMailbox(String mailbox) { + String regex = "^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$"; + return mailbox.matches(regex); + } + + } -- Gitblit v1.8.0