欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

java中怎么實現(xiàn)動態(tài)口令登錄

java中怎么實現(xiàn)動態(tài)口令登錄,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

10余年的赤峰網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整赤峰建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“赤峰網(wǎng)站設(shè)計”,“赤峰網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。

1.實現(xiàn)一個ItsClient 客戶端用來實例化調(diào)用驗證功能

public class ItsClient {private static final String routing = "/v1.0/sectoken/otp_validation";// ! HTTPS消息驗證地址private String httpsVerifyUrl = "";// ! otp ipAddrprivate String ipAddr = "";// ! otp portprivate String port = "";// ! otp appIDprivate String appID = "";// ! otp appKeyprivate String appKey = "";// ! 錯誤碼private int errorCode = 0;// ! 錯誤消息private String errorMessage = "";TreeMap<Integer, String> errorCodeTable = new TreeMap<Integer, String>() {{put(200, "請求成功");put(400, "輸入不合法,比如請求數(shù)據(jù)不是json");put(401, "AppID不合法");put(402, "指紋不合法");put(410, "非法用戶,驗證otp時,傳入的uid有誤,找不到用戶");put(411, "錯誤的otp");put(412, "一個周期內(nèi)動態(tài)口令只能使用一次");put(413, "已達(dá)一個周期內(nèi)最大嘗試次數(shù)");put(500, "ITS服務(wù)器內(nèi)部錯誤");put(601, "參數(shù)錯誤");put(602, "sha1簽名失敗");put(603, "操作json失敗");put(604, "url訪問錯誤:");put(605, "較驗返回指紋失敗");}};public ItsClient() {this.ipAddr = ItsConf.GetIpAddr();this.port = ItsConf.GetPort();this.appID = ItsConf.GetOtpAppID();this.appKey = ItsConf.GetOtpAppKey();httpsVerifyUrl = "https://" + this.ipAddr + ':' + this.port + routing;}//獲取錯誤信息public String GetErrorMessage() {return this.errorMessage;}  //獲取錯誤碼public int GetErrorCode() {return this.errorCode;}public void SetError(int errorCode, String extMessage) {this.errorCode = errorCode;this.errorMessage = this.errorCodeTable.get(this.errorCode).toString() + extMessage;}public static String SHA1(String decript) throws NoSuchAlgorithmException {String ret = "";MessageDigest sha1 = MessageDigest.getInstance("SHA1");byte[] sha1bytes = sha1.digest(decript.getBytes());if (sha1bytes != null) {ret = new BASE64Encoder().encode(sha1bytes);}return ret;}public String EncodeJson(TreeMap<String, String> map) {JSONObject jmap = new JSONObject(map);return jmap.toString();}public TreeMap<String, Object> DecodeJson(String jsonStr) throws ParseException {JSONObject jsonObject = new JSONObject(jsonStr);TreeMap<String, Object> retMap = new TreeMap<String, Object>();Iterator<String> iter = jsonObject.keys();String key = null;Object value = null;while (iter.hasNext()) {key = iter.next();value = jsonObject.get(key);retMap.put(key, value);}return retMap;}public String BuildQueryStr(TreeMap<String, String> params) {String queryStr = "";Iterator<String> itr = params.keySet().iterator();while (itr.hasNext()) {String key = itr.next();queryStr += (key + "=" + params.get(key).toString() + "&");}return queryStr.substring(0, queryStr.length() - 1);}public boolean IsEmptyOrNull(String param) {return param == null || param.length() <= 0;}/** * @brief 驗證otp * @param uid ITS主賬號UID或已配置的從賬號 * @param otp 需要驗證的動態(tài)口令 * @return bool true: 成功, false: 失敗 */@SuppressWarnings("serial")public boolean AuthOtp(final String uid, final String otp) {if (IsEmptyOrNull(this.ipAddr) || IsEmptyOrNull(this.port) || IsEmptyOrNull(this.appID)|| IsEmptyOrNull(this.appKey) || IsEmptyOrNull(uid) || IsEmptyOrNull(otp)) {SetError(601, "");return false;}TreeMap<String, String> params = new TreeMap<String, String>() {{put("app_id", appID);put("app_key", appKey);put("uid", uid);put("otp", otp);}};String qureyStr = this.BuildQueryStr(params);String fingerprint = "";try {fingerprint = SHA1(qureyStr);} catch (Exception ex) {ex.printStackTrace();SetError(602, ex.getMessage());return false;}params.remove("app_key");params.put("fingerprint", fingerprint);String postStr = "";try {postStr = EncodeJson(params);} catch (Exception ex) {ex.printStackTrace();SetError(603, "json encode" + ex.getMessage());return false;}HttpsClient conn = null;String res = "";try {conn = new HttpsClient();res = conn.post(this.httpsVerifyUrl, postStr); // 訪問接口調(diào)取返回結(jié)果} catch (Exception ex) {ex.printStackTrace();SetError(604, ex.getMessage());return false;}TreeMap<String, Object> ret = null;try {ret = DecodeJson(res);} catch (Exception ex) {ex.printStackTrace();SetError(603, "json decode " + ex.getMessage());return false;}int retCode = (Integer) ret.get("status");if (200 != retCode) {SetError(retCode, "");return false;}return true;}}

2.實現(xiàn)一個HttpsClient 請求工具

public class HttpsClient {  final static HostnameVerifier doNotVerifier = new HostnameVerifier() {    public boolean verify(String hostname, SSLSession session) {      return true;    }  };  /**  * @brief 發(fā)送請求  * @param httpsUrl 請求的地址  * @param postStr 請求的數(shù)據(jù)  * @throws Exception  */  public String post(String httpsUrl, String postStr) throws Exception {    HttpsURLConnection conn = null;    StringBuffer recvBuff = new StringBuffer();    String resData = "";    try {      conn = (HttpsURLConnection) (new URL(httpsUrl)).openConnection();      conn.setHostnameVerifier(doNotVerifier);      conn.setDoInput(true);      conn.setDoOutput(true);      conn.setRequestMethod("POST");      conn.setRequestProperty("Content-Type", " application/json");      conn.setRequestProperty("Content-Length", String.valueOf(postStr.getBytes("utf-8").length));      conn.setUseCaches(false);      //設(shè)置為utf-8可以解決服務(wù)器接收時讀取的數(shù)據(jù)中文亂碼問題      conn.getOutputStream().write(postStr.getBytes("utf-8"));      conn.getOutputStream().flush();      conn.getOutputStream().close();      BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));      String line;      while ((line = in.readLine()) != null) {        recvBuff.append(line);      }      resData = recvBuff.toString();      return resData;    } catch (MalformedURLException ex) {      throw ex;    } catch (IOException ex) {      throw ex;    } catch (Exception ex) {      throw ex;    }  }}

3.實現(xiàn)Its一個配置用來配置Its服務(wù)器信息接口訪問地址

public class ItsConf {// ITS服務(wù)器地址 1.1.1.1 或 xxx.xxx.com的形式private static String ipAddr = "";// ITS服務(wù)器端口private static String port = "";// OTP服務(wù)的AppIDprivate static String otpAppID = "";// OTP服務(wù)的AppKeyprivate static String otpAppKey = "";public static String GetIpAddr() {return ipAddr;}public static String GetPort() {return port;}public static String GetOtpAppID() {return otpAppID;}public static String GetOtpAppKey() {return otpAppKey;}}

4.接下來就是LoginContorller 完成口令認(rèn)證

//username 用戶名//code動態(tài)口令密碼ItsClient itsClient = new ItsClient();if(itsClient.AuthOtp(username, code)){//認(rèn)證成功,跳轉(zhuǎn)頁面}

看完上述內(nèi)容,你們掌握java中怎么實現(xiàn)動態(tài)口令登錄的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前標(biāo)題:java中怎么實現(xiàn)動態(tài)口令登錄
網(wǎng)頁鏈接:http://aaarwkj.com/article18/igijgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、域名注冊網(wǎng)站改版、網(wǎng)站營銷、品牌網(wǎng)站建設(shè)移動網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
91最新精品丝袜国产在线| 99久久精品国产熟女拳交| 亚洲免费视频一二三区| 少妇高潮视频在线观看| 日韩精品毛片精品一区到三区| 欧美高清一区二区三区不卡 | 91九色视频免费观看| 日韩欧美国产精品一区二区三区| 97视频观看免费观看| 丝袜啪啪啪麻豆白虎内射| 亚洲国产成人av精品精品国产自 | 国内精日韩欧中文的话| 国一区二区三区四区av| 蜜桃一区二区三区免费| 日日爱欧美精品亚洲成| 亚洲av产在线精品亚洲第| 亚洲香蕉av在线一区二区三区| 国产一区在线视频无卡顿| 羞羞的视频免费观看在线| 亚洲国产99在线精品一区| 人妻系列日本在线播放| 男人的天堂av免费看看| 久久综合亚洲鲁鲁五月天| 亚洲精品久久麻豆蜜桃| 黄片在线免费在线播放| 欧美亚洲另类激情另类的| 中文字幕国产精品综合一区| 水牛av影视亚洲精品| 人妻一区二区三区免看| 亭亭丁香激情五月涩久久| 青青草原在线视频观看| 美女呻吟被爽到高潮在线| 国语自产拍在线观看不卡| 日本经典三级视频在线观看| 青青草免费公开视频久久| 乱熟av一区二区三区| 可以免费在线看的av网站| 国产高清白丝免费在线观看| 中文字幕乱码高清免费| 日韩一区二区电影在线| 国产又粗又长又爽网站|