Skip to content

Commit 6deb238

Browse files
committed
添加小程序云开发http API 支持
1 parent 9da45e4 commit 6deb238

File tree

13 files changed

+510
-252
lines changed

13 files changed

+510
-252
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
python-weixin
22
-----
33
![Build Status](https://travis-ci.org/gusibi/python-weixin.svg?branch=master)
4-
![](https://img.shields.io/badge/version-0.4.3--dev-FF00CC.svg)
4+
![](https://img.shields.io/badge/version-0.5.0--dev-FF00CC.svg)
55
![](https://img.shields.io/github/forks/gusibi/python-weixin.svg)
66
![](https://img.shields.io/github/stars/gusibi/python-weixin.svg)
77
![](https://img.shields.io/github/issues/gusibi/python-weixin.svg)
@@ -35,11 +35,12 @@ Requires
3535
* pycryptodome
3636
```
3737

38-
### [快速入门](https://github.com/gusibi/python-weixin/wiki/%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B)
38+
### [快速入门](https://github.com/gusibi/python-weixin/wiki)
3939

4040
* [微信公众平台](https://github.com/gusibi/python-weixin/wiki/%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%B9%B3%E5%8F%B0)
4141
* [微信授权](https://github.com/gusibi/python-weixin/wiki/%E5%BE%AE%E4%BF%A1%E6%8E%88%E6%9D%83)
4242
* [微信支付](https://github.com/gusibi/python-weixin/wiki/%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98)
43+
* [微信小程序云开发](https://github.com/gusibi/python-weixin/wiki/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BA%91%E5%BC%80%E5%8F%91)
4344

4445
### 微信小程序使用示例:
4546

File renamed without changes.

example/example_db

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_id,age
2+
123,45
3+
456,21
File renamed without changes.
File renamed without changes.

example/wxapp_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! -*- coding: utf-8 -*-
2+
from os import environ
3+
4+
from weixin import WXAPPAPI
5+
6+
appid = environ.get("WXAPP_APPID", "appid")
7+
secret = environ.get("WXAPP_SECRET", "secret")
8+
9+
api = WXAPPAPI(appid=appid, app_secret=secret, grant_type="client_credential")
10+
token = api.client_credential_for_access_token().get("access_token")
11+
print(token)

example/wxapp_cloud_api.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#! -*- coding: utf-8 -*-
2+
from os import environ, path
3+
4+
from weixin import WxAppCloudAPI
5+
6+
appid = environ.get("WXAPP_APPID", "appid")
7+
secret = environ.get("WXAPP_SECRET", "secret")
8+
env = "test-68f865"
9+
10+
example_db = path.abspath(path.join(path.dirname(__file__), "./example_db"))
11+
12+
13+
app_cloud = WxAppCloudAPI(
14+
appid=appid, app_secret=secret, grant_type="client_credential"
15+
)
16+
token = app_cloud.client_credential_for_access_token().get("access_token")
17+
print(token)
18+
19+
cloud_api = WxAppCloudAPI(access_token=token)
20+
21+
# 获取库的集合信息
22+
db_info = cloud_api.db_collection_info(json_body={"env": env, "limit": 10})
23+
print(db_info)
24+
# 新建集合
25+
resp = cloud_api.db_collection_add(json_body={"env": env, "collection_name": "example"})
26+
print("new collection: ", resp)
27+
28+
# 获取库的集合信息
29+
db_info = cloud_api.db_collection_info(json_body={"env": env, "limit": 10})
30+
print("db info: ", db_info)
31+
32+
# 导入数据
33+
resp = cloud_api.db_migrate_import(
34+
json_body={
35+
"env": env,
36+
"collection_name": "example",
37+
"file_path": example_db,
38+
"file_type": 2,
39+
"stop_on_error": False,
40+
"conflict_mode": 2,
41+
}
42+
)
43+
print("db migrate import: ", resp)
44+
45+
# 数据库统计记录数量
46+
resp = cloud_api.db_count(
47+
json_body={"env": env, "query": 'db.collection("example").count()'}
48+
)
49+
print("count", resp)
50+
51+
# 插入数据
52+
resp = cloud_api.db_add(
53+
json_body={"env": env, "query": 'db.collection("example").add({data: [{age: 12}]})'}
54+
)
55+
print("add: ", resp)
56+
57+
id_list = resp.get("id_list")
58+
item_id = id_list[0]
59+
60+
# 数据库统计记录数量
61+
resp = cloud_api.db_count(
62+
json_body={"env": env, "query": 'db.collection("example").count()'}
63+
)
64+
print("count", resp)
65+
# 查询记录
66+
67+
resp = cloud_api.db_query(
68+
json_body={
69+
"env": env,
70+
"query": 'db.collection("example").where({_id: "%s"}).limit(10).skip(0).get()'
71+
% item_id,
72+
}
73+
)
74+
print("query: ", resp)
75+
76+
# 更新数据
77+
78+
resp = cloud_api.db_update(
79+
json_body={
80+
"env": env,
81+
"query": 'db.collection("example").where({_id: "%s"}).update({data: {age: _.inc(1)}})'
82+
% item_id,
83+
}
84+
)
85+
print("update: ", resp)
86+
87+
# 查询记录
88+
resp = cloud_api.db_query(
89+
json_body={
90+
"env": env,
91+
"query": 'db.collection("example").where({_id: "%s"}).limit(10).skip(0).get()'
92+
% item_id,
93+
}
94+
)
95+
print("query: ", resp)
96+
# 删除数据
97+
resp = cloud_api.db_delete(
98+
json_body={
99+
"env": env,
100+
"query": 'db.collection("example").where({_id: "%s"}).remove()' % item_id,
101+
}
102+
)
103+
print("remove: ", resp)
104+
105+
# 查询记录
106+
resp = cloud_api.db_query(
107+
json_body={
108+
"env": env,
109+
"query": 'db.collection("example").where({_id: "%s"}).limit(10).skip(0).get()'
110+
% item_id,
111+
}
112+
)
113+
print("query: ", resp)
114+
# 删除集合
115+
resp = cloud_api.db_collection_delete(
116+
json_body={"env": env, "collection_name": "example"}
117+
)
118+
119+
# 获取库的集合信息
120+
121+
db_info = cloud_api.db_collection_info(json_body={"env": env, "limit": 10})
122+
print("db info: ", db_info)

test_example.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

test_settings.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

weixin/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# -*- coding: utf-8 -*-
22

3-
__title__ = 'requests'
4-
__version__ = '0.2.3'
5-
__author__ = 'gusibi'
6-
__license__ = 'BSD'
3+
__title__ = "requests"
4+
__version__ = "0.2.3"
5+
__author__ = "gusibi"
6+
__license__ = "BSD"
77

88

99
from .bind import WeixinClientError, WeixinAPIError
10-
from .client import WeixinAPI, WeixinMpAPI, WXAPPAPI
10+
from .client import WeixinAPI, WeixinMpAPI, WXAPPAPI, WxAppCloudAPI
1111
from .response import WXResponse
1212
from .reply import WXReply

0 commit comments

Comments
 (0)