-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathYoutuApiAccess.java
More file actions
84 lines (71 loc) · 2.98 KB
/
YoutuApiAccess.java
File metadata and controls
84 lines (71 loc) · 2.98 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* for http://open.youtu.qq.com/#/develop/tool-authentication
*/
package cn.colintree.aix.ApiAccess;
import java.io.UnsupportedEncodingException;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.YailList;
import cn.colintree.aix.ApiAccess.util.youtu.Base64Util;
import cn.colintree.aix.ApiAccess.util.youtu.MD5;
import cn.colintree.aix.ApiAccess.util.youtu.YoutuSign;
@DesignerComponent(version = BaiduApiAccess.EXTENSION_VERSION,
description = "for http://open.youtu.qq.com/#/develop/tool-authentication",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "aiwebres/tencent-favicon.ico")
@SimpleObject(external = true)
public class YoutuApiAccess extends AndroidNonvisibleComponent {
private final Form form;
public YoutuApiAccess(ComponentContainer container) {
super(container.$form());
form = container.$form();
}
@SimpleFunction
public String GetAuth(String appId, String secret_id, String secret_key) {
long now = System.currentTimeMillis() / 1000;
StringBuffer mySign = new StringBuffer();
int status = YoutuSign.appSign(appId, secret_id, secret_key, now+3600, null, mySign);
switch (status) {
case 0:
return mySign.toString();
default:
form.dispatchErrorOccurredEvent(this, "GetAuth", ErrorMessages.ERROR_EXTENSION_ERROR, 0, "YoutuApi", "fail generating("
+ (status==-1
? "empty secret_id or secret_key"
: (status==-2 ? "userid too long (>64)" : "unknown"))
+")");
return "";
}
}
@SimpleFunction
public static String MD5(String data) {
return MD5.stringToMD5(data);
}
@SimpleFunction
public static String Base64(String data) {
return Base64Util.encode(data.getBytes());
}
@SimpleFunction
public static String FormatString(String format, YailList arguments) {
Object[] args = new Object[arguments.size()];
for (int i = 0; i < args.length; i++) {
args[i] = arguments.getObject(i);
}
return String.format(format, args);
}
@SimpleFunction
public static int ByteLength(String text) {
return text.getBytes().length;
}
@SimpleFunction
public static int ByteLengthWithEncoding(String text, String encoding) throws UnsupportedEncodingException {
return text.getBytes(encoding).length;
}
}