Search in sources :

Example 1 with CaptchaCheckIt

use of com.example.verificationcodejavademo.model.CaptchaCheckIt in project captcha by anji-plus.

the class WordCaptchaDialog method checkCaptcha.

private void checkCaptcha(String cryptedStr) {
    Map<String, Object> params = new HashMap<>();
    params.put("captchaType", "clickWord");
    params.put("token", token);
    params.put("pointJson", AESUtil.encode(cryptedStr, key));
    JSONObject jsonObject = new JSONObject(params);
    RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
    Log.i("wuyan", "body:" + jsonObject);
    RetrofitUtils.getServerApi().checkAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<CaptchaCheckIt>(mContext, false) {

        @Override
        public void onSuccess(CaptchaCheckIt data) {
            bottomTitle.setText("验证成功");
            bottomTitle.setTextColor(Color.GREEN);
            wordView.ok();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    loadCaptcha();
                    dismiss();
                }
            }, 1000);
            if (mOnResultsListener != null) {
                String result = token + "---" + cryptedStr;
                mOnResultsListener.onResultsClick(AESUtil.encode(result, key));
            }
        }

        @Override
        public void onFailure(Throwable e, String errorMsg) {
            bottomTitle.setText("验证失败");
            bottomTitle.setTextColor(Color.RED);
            wordView.fail();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    // 刷新验证码
                    loadCaptcha();
                }
            }, 1000);
        }
    });
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) CaptchaCheckIt(com.example.verificationcodejavademo.model.CaptchaCheckIt) RequestBody(okhttp3.RequestBody)

Example 2 with CaptchaCheckIt

use of com.example.verificationcodejavademo.model.CaptchaCheckIt in project captcha by anji-plus.

the class BlockPuzzleDialog method checkCaptcha.

private void checkCaptcha(double sliderXMoved) {
    Point point = new Point();
    point.setY(5.0);
    point.setX(sliderXMoved);
    String pointStr = new Gson().toJson(point);
    Map<String, Object> params = new HashMap<>();
    params.put("captchaType", "blockPuzzle");
    params.put("token", token);
    params.put("pointJson", AESUtil.encode(pointStr, key));
    JSONObject jsonObject = new JSONObject(params);
    RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
    RetrofitUtils.getServerApi().checkAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<CaptchaCheckIt>(mContext, false) {

        @Override
        public void onSuccess(CaptchaCheckIt data) {
            dragView.ok();
            loadCaptcha();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    dismiss();
                }
            }, 1500);
            if (mOnResultsListener != null) {
                String result = token + "---" + pointStr;
                mOnResultsListener.onResultsClick(AESUtil.encode(result, key));
            }
        }

        @Override
        public void onFailure(Throwable e, String errorMsg) {
            dragView.fail();
            // 刷新验证码
            loadCaptcha();
        }
    });
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Point(com.example.verificationcodejavademo.model.Point) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) CaptchaCheckIt(com.example.verificationcodejavademo.model.CaptchaCheckIt) RequestBody(okhttp3.RequestBody)

Aggregations

CaptchaCheckIt (com.example.verificationcodejavademo.model.CaptchaCheckIt)2 HashMap (java.util.HashMap)2 RequestBody (okhttp3.RequestBody)2 JSONObject (org.json.JSONObject)2 Point (com.example.verificationcodejavademo.model.Point)1 Gson (com.google.gson.Gson)1