-
Notifications
You must be signed in to change notification settings - Fork 5
/
CallbackTest.java
57 lines (49 loc) · 2.51 KB
/
CallbackTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ai.bianjie.avatasdktest;
import ai.bianjie.avatasdk.util.CallbackUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import static ai.bianjie.avatasdk.model.onCallbackRes.*;
public class CallbackTest {
public String callback(HttpServletRequest r) {
try {
String result = CallbackUtils.OnCallback(APIVersionV1, "", null, r, new CallbackUtils.APP() {
@Override
public void onCallback(String version, String kind, Object object) throws Exception {
System.out.println(version);
System.out.println(r.getHeader("X-Signature"));
System.out.println(r.getHeader("X-Timestamp"));
// Add your app logic here
//throw new CallbackUtils.AppException("error occurred in the app method");
if (object instanceof onCallbackResV1) {
// V1 版本回调结果
onCallbackResV1 v1Res = (onCallbackResV1) object;
System.out.println(v1Res);
Object nftObj = JSON.parseObject(v1Res.getNft(), NftV1.class);
NftV1 nftRes = (NftV1) nftObj;
System.out.println(nftRes.getClassId());
} else if (object instanceof onCallbackResNative) {
// V2 及以上版本原生模块接口回调结果
onCallbackResNative nativeRes = (onCallbackResNative) object;
System.out.println(nativeRes.getNft().getId());
} else if (object instanceof onCallbackResEVM) {
// V2 及以上版本 EVM 模块接口回调结果
onCallbackResEVM evmRes = (onCallbackResEVM) object;
System.out.println(evmRes.getNft().getId());
} else {
// 处理其他类型或默认情况
throw new Exception("Object is of unknown type");
}
}
});
if (result.equals("SUCCESS")) {
System.out.println("回调推送成功");
} else
System.out.println("回调推送失败");
return result; // 向 Avata 服务器返回结果
} catch (Exception e) {
e.printStackTrace();
return "FAILED"; // 向 Avata 服务器返回结果
}
}
}