Search in sources :

Example 1 with WordCaptchaGetIt

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

the class WordCaptchaDialog method loadCaptcha.

private void loadCaptcha() {
    bottomTitle.setText("数据加载中......");
    bottomTitle.setTextColor(Color.BLACK);
    Map<String, Object> params = new HashMap<>();
    params.put("captchaType", "clickWord");
    JSONObject jsonObject = new JSONObject(params);
    RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
    Log.i("wuyan", "body:" + jsonObject);
    RetrofitUtils.getServerApi().getWordCaptchaAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<WordCaptchaGetIt>(mContext, true) {

        @Override
        public void onSuccess(WordCaptchaGetIt data) {
            baseImageBase64 = data.getOriginalImageBase64();
            token = data.getToken();
            key = data.getSecretKey();
            String wordStr = "";
            int j = 0;
            for (int i = 0; i < data.getWordList().size(); i++) {
                j++;
                wordStr += data.getWordList().get(i);
                if (j < data.getWordList().size()) {
                    wordStr += ",";
                }
            }
            wordView.setSize(data.getWordList().size());
            bottomTitle.setText("请依此点击【" + wordStr + "】");
            bottomTitle.setTextColor(Color.BLACK);
            wordView.setUp(ImageUtil.base64ToBitmap(baseImageBase64));
            initEvent();
        }

        @Override
        public void onFailure(Throwable e, String errorMsg) {
            bottomTitle.setText("加载失败,请刷新");
            bottomTitle.setTextColor(Color.RED);
            wordView.setSize(-1);
            Toast.makeText(mContext, errorMsg, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) WordCaptchaGetIt(com.example.verificationcodejavademo.model.WordCaptchaGetIt) RequestBody(okhttp3.RequestBody)

Aggregations

WordCaptchaGetIt (com.example.verificationcodejavademo.model.WordCaptchaGetIt)1 HashMap (java.util.HashMap)1 RequestBody (okhttp3.RequestBody)1 JSONObject (org.json.JSONObject)1