Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9a4fbd

Browse files
author
jasonelchen
committed
更新 API 文档
1 parent 8748b11 commit c9a4fbd

File tree

1 file changed

+256
-83
lines changed

1 file changed

+256
-83
lines changed

API.md

Lines changed: 256 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,40 @@
1414

1515
### API
1616

17-
#### Conf::setServerHost(string $serverHost)
18-
19-
该静态方法用于设置使用本 SDK 的业务服务器的主机名,如 `www.qcloud.la`,该主机需要外网可访问。
20-
21-
##### 参数
22-
23-
- `$serverHost` - 业务服务器的主机名
24-
25-
##### 返回值
26-
27-
`void`
28-
29-
#### Conf::setAuthServerUrl(string $authServerUrl)
30-
31-
该静态方法用于指定鉴权服务器服务地址,如 `http://mina.auth.com`
32-
33-
##### 参数
34-
35-
- `$authServerUrl` - 鉴权服务器服务地址
36-
37-
##### 返回值
38-
39-
`void`
40-
41-
#### Conf::setTunnelServerUrl(string $tunnelServerUrl)
42-
43-
该静态方法用于指定信道服务器服务地址,如 `https://ws.qcloud.com`
44-
45-
##### 参数
46-
47-
- `$tunnelServerUrl` - 信道服务器服务地址
48-
49-
##### 返回值
50-
51-
`void`
52-
53-
#### Conf::setTunnelSignatureKey(string $tunnelSignatureKey)
54-
55-
该静态方法用于指定和信道服务器通信的签名密钥,如 `9f338d1f0ecc37d25ac7b161c1d7bf72` ,该密钥需要保密。
56-
57-
##### 参数
58-
59-
- `$tunnelSignatureKey` - 通信签名密钥
60-
61-
##### 返回值
62-
63-
`void`
64-
65-
#### Conf::setNetworkTimeout(int $networkTimeout)
66-
67-
该静态方法用于设置网络请求超时时长(单位:毫秒),默认值为 30,000 毫秒,即 30 秒。
68-
69-
##### 参数
70-
71-
- `$networkTimeout` - 网络请求超时时长
72-
73-
##### 返回值
74-
75-
`void`
76-
7717
#### Conf::setup(array $config)
7818

79-
可以使用本方法批量设置以上所有配置
19+
可以使用本方法批量设置所有配置
8020

8121
##### 参数
8222

83-
- `$config` 支持的配置选项如下:
84-
- `ServerHost` - 业务服务器的主机名
85-
- `AuthServerUrl` - 鉴权服务器服务地址
86-
- `TunnelServerUrl` - 信道服务器服务地址
87-
- `TunnelSignatureKey` - 通信签名密钥
88-
- `NetworkTimeout` - 网络请求超时时长(单位:毫秒)
23+
- `appId` - 可选。微信小程序的 App id
24+
- `appSecret` - 可选。微信小程序的 App secret
25+
- `useQcloudLogin` - 必填。是否使用腾讯云代理登录小程序。会话登录需要使用小程序的 App id 和 App secret 来解密用户信息,腾讯云提供使用腾讯云 App id 和 App secret 代理请求微信进行解密。如果该项为 `false`,则需填写微信小程序 App id 和 App secret。默认为 `true`
26+
- `mysql` - 必填。MySQL 配置。不填则使用小程序解决方案分配机器中默认的 MySQL,若使用自行部署的 MySQL 数据库,则需提供一个类型为 `object` 的配置,具体配置项如下:
27+
- `host` - 必填。MySQL 主机名
28+
- `user` - 必填。MySQL 用户名
29+
- `db` - 必填。MySQL 数据库名
30+
- `pass` - 必填。MySQL 密码,若使用了腾讯云微信小程序解决方案,开发环境下,MySQL 的初始密码为您的微信小程序 appid
31+
- `port` - 选填。MySQL 端口(默认:3306)
32+
- `char` - 选填。MySQL 编码
33+
- `cos` - 必填。腾讯云对象存储配置信息,用于上传模块使用。
34+
- `region` - 必填。COS 的地域
35+
- `fileBucket` - 必填。COS 的 bucket 名
36+
- `uploadFolder` - 必填。COS 上传文件夹名
37+
- `maxSize` - 选填。COS 上传最大大小,默认 5M (单位:M)
38+
- `field` - 选填。COS 上传是 field 名称,默认为 `file`
39+
- `serverHost` - 必填。当前服务器的 hostname
40+
- `tunnelServerUrl` - 必填。信道服务器地址
41+
- `tunnelSignatureKey` - 必填。信道服务签名密钥
42+
- `qcloudAppId` - 必填。腾讯云 AppId
43+
- `qcloudSecretId` - 必填。腾讯云 SecretId
44+
- `qcloudSecretKey` - 必填。腾讯云 SecretKey
45+
- `wxMessageToken` - 必填。微信客服消息通知 token
46+
- `wxLoginExpires` - 可选。微信登录态有效期,默认 7200 秒(单位:秒)
47+
48+
**如果购买了腾讯云小程序解决方案,配置项中 `serverHost`, `tunnelServerUrl`, `tunnelSignatureKey`, `qcloudAppId`, `qcloudSecretId`, `qcloudSecretKey`, `wxMessageToken` 由腾讯云自动下发到您的服务器上。**
49+
50+
自动下发的 SDK 配置文件地址: `/data/release/sdk.config.json`
8951

9052
##### 返回值
9153

@@ -113,11 +75,12 @@
11375

11476
```php
11577
array(
116-
'code' => 0,
117-
'message' => 'ok',
118-
'data' => array(
78+
'loginState' => 1,
79+
'userinfo' => array(
80+
// 第三方 key
81+
'skey' => 'fy89ayri3h2ifs'
11982
// 微信用户信息
120-
'userInfo' => array(...),
83+
'userinfo' => array(...),
12184
),
12285
)
12386
```
@@ -126,9 +89,8 @@ array(
12689

12790
```php
12891
array(
129-
'code' => -1,
130-
'message' => '失败原因',
131-
'data' => array(),
92+
'loginState' => 0,
93+
'error' => '失败原因'
13294
)
13395
```
13496

@@ -146,11 +108,9 @@ array(
146108

147109
```php
148110
array(
149-
'code' => 0,
150-
'message' => 'ok',
151-
'data' => array(
111+
'loginState' => 1,
112+
'userinfo' => array(
152113
// 微信用户信息
153-
'userInfo' => array(...),
154114
),
155115
)
156116
```
@@ -159,9 +119,8 @@ array(
159119

160120
```php
161121
array(
162-
'code' => -1,
163-
'message' => '失败原因',
164-
'data' => array(),
122+
'loginState' => 0,
123+
'error' => '失败原因'
165124
)
166125
```
167126

@@ -179,15 +138,23 @@ array(
179138

180139
```php
181140
interface ITunnelHandler {
141+
/*----------------------------------------------------------------
142+
* 初始化时传入用户信息
143+
*----------------------------------------------------------------
144+
* @param array $userinfo 用户信息
145+
*----------------------------------------------------------------
146+
*/
147+
public function __construct ($userinfo);
148+
182149
/*----------------------------------------------------------------
183150
* 在客户端请求 WebSocket 信道连接之后会调用该方法
184151
* 此时可以把信道 ID 和用户信息关联起来
185152
*----------------------------------------------------------------
186153
* @param string $tunnelId 信道 ID
187-
* @param array $userInfo 微信用户信息
154+
* @param string $tunnelUrl 信道地址
188155
*----------------------------------------------------------------
189156
*/
190-
public function onRequest($tunnelId, $userInfo);
157+
public function onRequest($tunnelId, $tunnelUrl);
191158

192159
/*----------------------------------------------------------------
193160
* 在客户端成功连接 WebSocket 信道服务之后会调用该方法
@@ -327,3 +294,209 @@ array(
327294
'message' => '失败原因',
328295
)
329296
```
297+
298+
## MySQL
299+
300+
### 命名空间
301+
302+
`QCloud_WeApp_SDK\Mysql`
303+
304+
### API
305+
306+
#### MySQL::getInstance()
307+
308+
获取 SDK 连接数据库实例,这个是个 [PDO 连接实例](http://php.net/manual/zh/class.pdo.php)
309+
310+
##### 参数
311+
312+
313+
314+
##### 返回值
315+
316+
返回 PDO Instance
317+
318+
#### Mysql::insert($tableName, $data)
319+
320+
向数据库中插入数据
321+
322+
##### 参数
323+
324+
- `$tableName` - 要操作的数据表名(必填)
325+
- `$data` - 要插入的数据(key-value 的 array 类型)
326+
327+
##### 返回值
328+
329+
受影响的行数(数值类型)。
330+
331+
##### 示例
332+
333+
```php
334+
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
335+
336+
DB::insert('tableName', [
337+
'nickname' => 'Jason',
338+
'age' => 21
339+
]);
340+
```
341+
342+
#### Mysql::select($tableName[, $columns = ['*'], $conditions = '', $operator = 'and', $suffix = ''])
343+
344+
从数据库中查询多条数据
345+
346+
##### 参数
347+
348+
- `$tableName` - 要操作的数据表名(必填)
349+
- `$columns` - 查询出来的列名
350+
- `$conditions` - 查询条件,支持 string、array 和 key-value array 类型
351+
- `$operator` - 条件之间的操作符
352+
- `$suffix` - SQL 语句的后缀,可以用来插入 order、limit 等
353+
354+
##### 返回值
355+
356+
返回一个包含结果集中所有行的数组。
357+
358+
##### 示例
359+
360+
```php
361+
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
362+
363+
// 条件为字符串
364+
$rows = DB::select('tableName', 'nickname = Jason');
365+
366+
// 条件为数组
367+
$rows = DB::select('tableName', ['nickname = Jason']);
368+
369+
// 条件为 key-value 数组
370+
$rows = DB::select('tableName', ['nickname' => 'Jason']);
371+
372+
// 查询结果
373+
// $rows > [['nickname' => 'Jason','age' => 21]]
374+
```
375+
376+
#### Mysql::row($tableName[, $columns = ['*'], $conditions = '', $operator = 'and', $suffix = ''])
377+
378+
从数据库中查询单条数据
379+
380+
##### 参数
381+
382+
- `$tableName` - 要操作的数据表名(必填)
383+
- `$columns` - 查询出来的列名
384+
- `$conditions` - 查询条件,支持 string、array 和 key-value array 类型
385+
- `$operator` - 条件之间的操作符
386+
- `$suffix` - SQL 语句的后缀,可以用来插入 order、limit 等
387+
388+
##### 返回值
389+
390+
返回一个包含结果集中所有行的第一行。
391+
392+
##### 示例
393+
394+
```php
395+
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
396+
397+
// 条件为字符串
398+
$rows = DB::row('tableName', 'nickname = Jason');
399+
400+
// 条件为数组
401+
$rows = DB::row('tableName', ['nickname = Jason']);
402+
403+
// 条件为 key-value 数组
404+
$rows = DB::row('tableName', ['nickname' => 'Jason']);
405+
406+
// 查询结果
407+
// $rows > ['nickname' => 'Jason','age' => 21]
408+
```
409+
410+
#### Mysql::update($tableName, $updates[, $conditions = '', $operator = 'and', $suffix = ''])
411+
412+
从数据库中查询单条数据
413+
414+
##### 参数
415+
416+
- `$tableName` - 要操作的数据表名(必填)
417+
- `$updates` - 更新的数据对象
418+
- `$conditions` - 查询条件,支持 string、array 和 key-value array 类型
419+
- `$operator` - 条件之间的操作符
420+
- `$suffix` - SQL 语句的后缀,可以用来插入 order、limit 等
421+
422+
##### 返回值
423+
424+
受影响的行数(数值类型)。
425+
426+
##### 示例
427+
428+
```php
429+
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
430+
431+
// 条件为字符串
432+
$rows = DB::update('tableName', ['age' => 22], 'nickname = Jason');
433+
434+
// 条件为数组
435+
$rows = DB::update('tableName', ['age' => 22], ['nickname = Jason']);
436+
437+
// 条件为 key-value 数组
438+
$rows = DB::update('tableName', ['age' => 22], ['nickname' => 'Jason']);
439+
440+
// 查询结果
441+
// $rows > 1
442+
```
443+
444+
#### Mysql::delete($tableName, $conditions[, $operator = 'and', $suffix = ''])
445+
446+
从数据库中删除数据
447+
448+
##### 参数
449+
450+
- `$tableName` - 要操作的数据表名(必填)
451+
- `$conditions` - 查询条件,支持 string、array 和 key-value array 类型
452+
- `$operator` - 条件之间的操作符
453+
- `$suffix` - SQL 语句的后缀,可以用来插入 order、limit 等
454+
455+
##### 返回值
456+
457+
受影响的行数(数值类型)。
458+
459+
##### 示例
460+
461+
```php
462+
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
463+
464+
// 条件为字符串
465+
$rows = DB::delete('tableName', 'nickname = Jason');
466+
467+
// 条件为数组
468+
$rows = DB::delete('tableName', ['nickname = Jason']);
469+
470+
// 条件为 key-value 数组
471+
$rows = DB::delete('tableName', ['nickname' => 'Jason']);
472+
473+
// 查询结果
474+
// $rows > 1
475+
```
476+
477+
## COS 对象储存 SDK
478+
479+
### 命名空间
480+
481+
`QCloud_WeApp_SDK\Cos`
482+
483+
### API
484+
485+
#### CosAPI::getInstance()
486+
487+
获取 COS 初始化实例
488+
489+
##### 参数
490+
491+
492+
493+
##### 示例
494+
495+
```php
496+
use \QCloud_WeApp_SDK\Cos\CosAPI as Cos;
497+
498+
$cosClient = Cos::getInstance();
499+
$cosClient->upload('mybucket', 'test.txt', 'Hello World')->toArray();
500+
```
501+
502+
更多关于 `Cos::getInstance()` 返回 COS 实例的 API,可以查看 [COS PHP SDK V5 文档](https://github.com/tencentyun/cos-php-sdk-v5)

0 commit comments

Comments
 (0)