Skip to content

Commit 874eed3

Browse files
committed
文档工作
1 parent 29949ff commit 874eed3

26 files changed

+403
-56
lines changed

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LICENSE - "MIT License"
2+
3+
Copyright (c) 2016 by Tencent Cloud
4+
5+
Permission is hereby granted, free of charge, to any person
6+
obtaining a copy of this software and associated documentation
7+
files (the "Software"), to deal in the Software without
8+
restriction, including without limitation the rights to use,
9+
copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following
12+
conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
腾讯云微信小程序服务端 SDK - Java
2+
=================================
3+
4+
本 SDK 是[腾讯云微信小程序一站式解决方案](https://github.com/tencentyun/weapp-solution)(下文简称「解决方案」)的组成部分。业务服务器可通过本 SDK 为小程序客户端提供云端服务支持,包括:
5+
6+
1. 登录态鉴权服务
7+
2. 信道服务
8+
9+
## SDK 获取
10+
11+
本项目遵守 [MIT](LICENSE) 协议,可以直接[下载 SDK 源码](https://github.com/tencentyun/weapp-java-server-sdk/archive/master.zip)进行修改、编译和发布。
12+
13+
> 如果从[腾讯云微信小程序控制台](https://console.qcloud.com/la)购买解决方案并选择 Java 语言,则分配的业务服务器里已经部署了本 SDK 和 Demo 的发行版本。
14+
15+
## 使用示例(Servlet)
16+
17+
> TODO
18+
19+
## API
20+

com.qcloud.weapp.demo/src/com/qcloud/weapp/demo/servlet/TunnelServlet.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.json.JSONObject;
1414

1515
import com.qcloud.weapp.ConfigurationException;
16-
import com.qcloud.weapp.Logger;
1716
import com.qcloud.weapp.authorization.UserInfo;
1817
import com.qcloud.weapp.tunnel.EmitError;
1918
import com.qcloud.weapp.tunnel.EmitResult;
@@ -97,10 +96,8 @@ public void onTunnelMessage(Tunnel tunnel, TunnelMessage message) {
9796

9897
@Override
9998
public void onTunnelClose(Tunnel tunnel) {
100-
Logger.log("onTunnelClose()");
10199
UserInfo leaveUser = null;
102100
if (userMap.containsKey(tunnel.getTunnelId())) {
103-
Logger.log("contains()");
104101
leaveUser = userMap.get(tunnel.getTunnelId());
105102
userMap.remove(tunnel.getTunnelId());
106103
}
@@ -110,7 +107,6 @@ public void onTunnelClose(Tunnel tunnel) {
110107
peopleMessage.put("total", room.getTunnelCount());
111108
peopleMessage.put("leave", new JSONObject(leaveUser));
112109
} catch (JSONException e) {
113-
Logger.log("error: " + e.getMessage());
114110
e.printStackTrace();
115111
}
116112
broadcast("people", peopleMessage);
@@ -131,7 +127,6 @@ private void broadcast(String messageType, JSONObject messageContent) {
131127
onTunnelClose(Tunnel.getById(invalidInfo.getTunnelId()));
132128
}
133129
} catch (EmitError e) {
134-
Logger.log("broadcast error: " + e.getMessage());
135130
// 如果消息发送发生异常,这里可以进行错误处理或者重试的逻辑
136131
e.printStackTrace();
137132
}

com.qcloud.weapp.sdk/doc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 26cccbbc406e80022b96677d9b55ddfe01c2463a
1+
Subproject commit addf77bb0e8b8ca68ecd35c7d51432b65d370985

com.qcloud.weapp.sdk/src/com/qcloud/weapp/Configuration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44
package com.qcloud.weapp;
55

6-
// TODO: Auto-generated Javadoc
76
/**
8-
* The Class Configuration.
7+
* 表示 SDK 配置
8+
* @see com.qcloud.weapp.ConfigurationManager
9+
* @see <a target="_blank" href="https://github.com/tencentyun/weapp-solution/wiki/%E6%9C%8D%E5%8A%A1%E7%AB%AF-SDK-%E9%85%8D%E7%BD%AE">服务端 SDK 配置</a>
910
*/
1011
public class Configuration {
1112

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.qcloud.weapp;
22

3+
/**
4+
* 表示配置时产生的异常
5+
* */
36
public class ConfigurationException extends Exception {
47
private static final long serialVersionUID = 570042088042301018L;
58

6-
public ConfigurationException(String message) {
9+
ConfigurationException(String message) {
710
super(message);
811
}
912
}

com.qcloud.weapp.sdk/src/com/qcloud/weapp/ConfigurationManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@
77
import org.json.JSONException;
88
import org.json.JSONObject;
99

10+
/**
11+
* 配置管理,使用该类进行 SDK 配置
12+
* */
1013
public class ConfigurationManager {
1114

1215
private static Configuration currentConfiguration;
16+
17+
/**
18+
* 获取当前的 SDK 配置
19+
* */
1320
public static Configuration getCurrentConfiguration() throws ConfigurationException {
1421
if (currentConfiguration == null) {
1522
throw new ConfigurationException("SDK 还没有进行配置,请调用 ConfigurationManager.setup() 方法配置 SDK");
1623
}
1724
return currentConfiguration;
1825
}
1926

27+
/**
28+
* 使用指定的配置初始化 SDK
29+
*
30+
* @param configuration 配置
31+
* @see <a target="_blank" href="https://github.com/tencentyun/weapp-solution/wiki/%E6%9C%8D%E5%8A%A1%E7%AB%AF-SDK-%E9%85%8D%E7%BD%AE">服务端 SDK 配置</a>
32+
* */
2033
public static void setup(Configuration configuration) throws ConfigurationException {
2134
if (configuration == null) {
2235
throw new ConfigurationException("配置不能为空");
@@ -28,6 +41,12 @@ public static void setup(Configuration configuration) throws ConfigurationExcept
2841
currentConfiguration = configuration;
2942
}
3043

44+
/**
45+
* 从配置文件初始化 SDK
46+
*
47+
* @param configFilePath 配置文件的路径
48+
* @see <a target="_blank" href="https://github.com/tencentyun/weapp-solution/wiki/%E6%9C%8D%E5%8A%A1%E7%AB%AF-SDK-%E9%85%8D%E7%BD%AE">服务端 SDK 配置</a>
49+
* */
3150
public static void setupFromFile(String configFilePath) throws JSONException, ConfigurationException {
3251
JSONObject configs = new JSONObject(getConfigJson(configFilePath));
3352
Configuration configuration = new Configuration();

com.qcloud.weapp.sdk/src/com/qcloud/weapp/Hash.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
import java.security.MessageDigest;
44

5+
/**
6+
* 工具类,用于计算哈希值(SDK 内部使用)
7+
* */
58
public class Hash {
69

10+
/**
11+
* 计算字符串的 sha1 哈希值
12+
* */
713
public static String sha1(String str) {
814
return compute(str, "SHA-1");
915
}
1016

17+
/**
18+
* 计算字符串的 md5 哈希值
19+
* */
1120
public static String md5(String str) {
1221
return compute(str, "MD5");
1322
}

com.qcloud.weapp.sdk/src/com/qcloud/weapp/HttpRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.util.regex.Matcher;
1212
import java.util.regex.Pattern;
1313

14+
/**
15+
* 用于创建网络请求,SDK 内部使用
16+
* */
1417
public class HttpRequest {
1518

1619
public interface ConnectionProvider {

com.qcloud.weapp.sdk/src/com/qcloud/weapp/authorization/AuthorizationAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.qcloud.weapp.ConfigurationManager;
1212
import com.qcloud.weapp.HttpRequest;
1313

14-
public class AuthorizationAPI {
14+
class AuthorizationAPI {
1515

1616
private String getAPIUrl() throws ConfigurationException {
1717
return ConfigurationManager.getCurrentConfiguration().getAuthServerUrl();

0 commit comments

Comments
 (0)