Subversion Repositories SmartDukaan

Rev

Rev 37402 | Rev 37408 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37402 Rev 37407
Line 81... Line 81...
81
                    // Solver returned something that is not a captcha code (it was down
81
                    // Solver returned something that is not a captcha code (it was down
82
                    // for 46 days returning an nginx 502 page, which used to be submitted
82
                    // for 46 days returning an nginx 502 page, which used to be submitted
83
                    // to Vivo verbatim). Skip; this IMEI is picked up on the next run.
83
                    // to Vivo verbatim). Skip; this IMEI is picked up on the next run.
84
                    continue;
84
                    continue;
85
                }
85
                }
86
                this.getImeiActivation(captcha, httpClient, imeiActivationTimestampModel);
86
                this.getImeiActivation(captcha, httpClient, cookieStore, imeiActivationTimestampModel);
87
            }
87
            }
88
        }
88
        }
89
    }
89
    }
90
 
90
 
91
    /** A solved captcha: the code, plus the image it came from so the verdict can be reported. */
91
    /** A solved captcha: the code, plus the image it came from so the verdict can be reported. */
92
    static final class Captcha {
92
    static final class Captcha {
93
        final String code;
93
        final String code;
94
        final byte[] image;
94
        final byte[] image;
-
 
95
        final long fetchedAt;
95
 
96
 
96
        Captcha(String code, byte[] image) {
97
        Captcha(String code, byte[] image) {
97
            this.code = code;
98
            this.code = code;
98
            this.image = image;
99
            this.image = image;
-
 
100
            this.fetchedAt = System.currentTimeMillis();
99
        }
101
        }
100
    }
102
    }
101
 
103
 
102
    public Captcha getNewCaptcha(CloseableHttpClient httpClient, BasicCookieStore cookieStore) throws Exception {
104
    public Captcha getNewCaptcha(CloseableHttpClient httpClient, BasicCookieStore cookieStore) throws Exception {
103
        HttpGet request = new HttpGet("https://www.vivo.com/in/support/generatingCodes");
105
        HttpGet request = new HttpGet("https://www.vivo.com/in/support/generatingCodes");
Line 113... Line 115...
113
        String code = captchaService.getCaptchaCode(bytes);
115
        String code = captchaService.getCaptchaCode(bytes);
114
        return code == null ? null : new Captcha(code, bytes);
116
        return code == null ? null : new Captcha(code, bytes);
115
    }
117
    }
116
 
118
 
117
    public void getImeiActivation(Captcha captcha, CloseableHttpClient httpClient,
119
    public void getImeiActivation(Captcha captcha, CloseableHttpClient httpClient,
-
 
120
                                  BasicCookieStore cookieStore,
118
                                  ImeiActivationTimestampModel vivoImeiAndActivationTimeStampModel) throws Exception {
121
                                  ImeiActivationTimestampModel vivoImeiAndActivationTimeStampModel) throws Exception {
119
 
122
 
120
        String imei = vivoImeiAndActivationTimeStampModel.getSerialNumber();
123
        String imei = vivoImeiAndActivationTimeStampModel.getSerialNumber();
121
 
124
 
122
        List<NameValuePair> form = new ArrayList<>();
125
        List<NameValuePair> form = new ArrayList<>();
Line 136... Line 139...
136
        // Vivo is the only judge of whether our guess was right; status 0 means the
139
        // Vivo is the only judge of whether our guess was right; status 0 means the
137
        // captcha was wrong. Hand that back so the sample becomes training data.
140
        // captcha was wrong. Hand that back so the sample becomes training data.
138
        captchaService.reportVerdict(captcha.image, captcha.code, status != 0);
141
        captchaService.reportVerdict(captcha.image, captcha.code, status != 0);
139
 
142
 
140
        if (status == 0) {
143
        if (status == 0) {
-
 
144
            // Vivo refuses ~56% of submissions in production, but reading the stored
-
 
145
            // images by hand showed 9 of 10 carried the CORRECT code, and no external
-
 
146
            // replication reproduces it (IMEI, user-agent, session reuse, concurrency,
-
 
147
            // source IP and submit delay were all measured and ruled out). The old log
-
 
148
            // line recorded five words and discarded the evidence, so capture it:
-
 
149
            // the code submitted, the imei, how long fetch->submit actually took inside
-
 
150
            // this process, the session cookies held at submit time, and Vivo's reply.
-
 
151
            LOGGER.info("Vivo rejected captcha code={} imei={} elapsedMs={} cookies={} response={}",
-
 
152
                    captcha.code, imei, System.currentTimeMillis() - captcha.fetchedAt,
141
            LOGGER.info("Found invalid captcha");
153
                    cookieStore.getCookies(), imeiActivationJson);
142
            return;
154
            return;
143
        } else if (status == 2) {
155
        } else if (status == 2) {
144
            LOGGER.info("Received status 2 for {}, data {}", imei, data);
156
            LOGGER.info("Received status 2 for {}, data {}", imei, data);
145
            activatedImeiRepository.saveActivation(imei, null);
157
            activatedImeiRepository.saveActivation(imei, null);
146
            return;
158
            return;