Skip to content

Commit 10c70ba

Browse files
committed
fixed: correct field name for capcha validation result's field
1 parent fe8ff6b commit 10c70ba

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

core/src/main/java/cn/leancloud/gson/GeneralFieldMappingObjectAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public T read(JsonReader jsonReader) throws IOException {
8989
jsonReader.peek();
9090
try {
9191
Field field = result.getClass().getDeclaredField(identifyFieldName);
92+
if (null == valueType || null == field) {
93+
continue;
94+
}
9295
field.setAccessible(true);
9396
Object value = null;
9497
if (valueType.equals(String.class)) {

core/src/main/java/cn/leancloud/gson/GsonWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class GsonWrapper {
3636
put("captcha_url", String.class);
3737
}};
3838
static final Map<String, Type> captchaValidateResultFields = new HashMap<String, Type>() {{
39-
put("validateToken", String.class);
39+
put("validate_token", String.class);
4040
}};
4141

4242
static final Gson gson = new GsonBuilder().serializeNulls()

core/src/test/java/cn/leancloud/sms/LCSMSTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package cn.leancloud.sms;
22

33
import cn.leancloud.Configure;
4+
import cn.leancloud.LCLogger;
5+
import cn.leancloud.core.LeanCloud;
46
import cn.leancloud.types.LCNull;
57
import io.reactivex.Observer;
68
import io.reactivex.disposables.Disposable;
9+
import io.reactivex.functions.Consumer;
710
import junit.framework.Test;
811
import junit.framework.TestCase;
912
import junit.framework.TestSuite;
@@ -194,4 +197,60 @@ public void onComplete() {
194197
}
195198
});
196199
}
200+
201+
public void testCaptcha() throws Exception {
202+
final CountDownLatch latch = new CountDownLatch(1);
203+
testSuccess = false;
204+
LCCaptchaOption option = new LCCaptchaOption();
205+
option.setWidth(85);
206+
option.setHeight(40);
207+
LCCaptcha.requestCaptchaInBackground(option).subscribe(new Observer<LCCaptchaDigest>() {
208+
@Override
209+
public void onSubscribe(Disposable disposable) {
210+
211+
}
212+
213+
@Override
214+
public void onNext(LCCaptchaDigest lcCaptchaDigest) {
215+
System.out.println("Succeed to got digest: " + lcCaptchaDigest.getCaptchaUrl());
216+
LCCaptcha.verifyCaptchaCodeInBackground("znca", lcCaptchaDigest).subscribe(new Observer<LCCaptchaValidateResult>() {
217+
@Override
218+
public void onSubscribe(Disposable disposable) {
219+
220+
}
221+
222+
@Override
223+
public void onNext(LCCaptchaValidateResult lcCaptchaValidateResult) {
224+
System.out.println("Succeed to got validateResult: " + lcCaptchaValidateResult);
225+
testSuccess = true;
226+
latch.countDown();
227+
}
228+
229+
@Override
230+
public void onError(Throwable throwable) {
231+
throwable.printStackTrace();
232+
latch.countDown();
233+
}
234+
235+
@Override
236+
public void onComplete() {
237+
238+
}
239+
});
240+
}
241+
242+
@Override
243+
public void onError(Throwable throwable) {
244+
throwable.printStackTrace();
245+
latch.countDown();
246+
}
247+
248+
@Override
249+
public void onComplete() {
250+
251+
}
252+
});
253+
latch.await();
254+
assertTrue(testSuccess);
255+
}
197256
}

0 commit comments

Comments
 (0)