Skip to content

Commit 947a0bb

Browse files
authored
Merge pull request #338 from songfei9315/master
add sms_ch
2 parents a69fbef + 2547fb7 commit 947a0bb

File tree

7 files changed

+356
-9
lines changed

7 files changed

+356
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
# 7.2.5 (2019-06-06)
4+
* 添加sms
5+
36
# 7.2.4 (2019-04-01)
47
* 默认导入region类
58

examples/sms_test.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# -*- coding: utf-8 -*-
2+
# flake8: noqa
3+
4+
from qiniu import QiniuMacAuth
5+
from qiniu import Sms
6+
7+
8+
access_key = ''
9+
secret_key = ''
10+
11+
# 初始化Auth状态
12+
q = QiniuMacAuth(access_key, secret_key)
13+
14+
# 初始化Sms
15+
sms = Sms(q)
16+
17+
"""
18+
#创建签名
19+
signature = 'abs'
20+
source = 'website'
21+
req, info = sms.createSignature(signature, source)
22+
print(req,info)
23+
"""
24+
25+
"""
26+
#查询签名
27+
audit_status = ''
28+
page = 1
29+
page_size = 20
30+
req, info = sms.querySignature(audit_status, page, page_size)
31+
print(req, info)
32+
"""
33+
34+
"""
35+
编辑签名
36+
id = 1136530250662940672
37+
signature = 'sssss'
38+
req, info = sms.updateSignature(id, signature)
39+
print(req, info)
40+
"""
41+
42+
"""
43+
#删除签名
44+
signature_id= 1136530250662940672
45+
req, info = sms.deleteSignature(signature_id)
46+
print(req, info)
47+
"""
48+
49+
"""
50+
#创建模版
51+
name = '06-062-test'
52+
template = '${test}'
53+
type = 'notification'
54+
description = '就测试啊'
55+
signature_id = '1131464448834277376'
56+
req, info = sms.createTemplate(name, template, type, description, signature_id)
57+
print(req, info)
58+
"""
59+
60+
"""
61+
#查询模版
62+
audit_status = ''
63+
page = 1
64+
page_size = 20
65+
req, info = sms.queryTemplate(audit_status, page, page_size)
66+
print(req, info)
67+
"""
68+
69+
"""
70+
#编辑模版
71+
template_id = '1136589777022226432'
72+
name = '06-06-test'
73+
template = 'hi,你好'
74+
description = '就测试啊'
75+
signature_id = '1131464448834277376'
76+
req, info = sms.updateTemplate(template_id, name, template, description, signature_id)
77+
print(info)
78+
"""
79+
80+
"""
81+
#删除模版
82+
template_id = '1136589777022226432'
83+
req, info = sms.deleteTemplate(template_id)
84+
print(req, info)
85+
"""
86+
87+
"""
88+
#发送短信
89+
"""
90+
template_id = ''
91+
mobiles = []
92+
parameters = {}
93+
req, info = sms.sendMessage(template_id, mobiles, parameters)
94+
print(req, info)
95+
96+
97+
98+

qiniu/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# flake8: noqa
1111

12-
__version__ = '7.2.4'
12+
__version__ = '7.2.5'
1313

1414
from .auth import Auth, QiniuMacAuth
1515

@@ -25,7 +25,6 @@
2525
from .services.processing.cmd import build_op, pipe_cmd, op_save
2626
from .services.compute.app import AccountClient
2727
from .services.compute.qcos_api import QcosClient
28-
28+
from .services.sms.sms import Sms
2929
from .services.pili.rtc_server_manager import RtcServer, get_room_token
30-
3130
from .utils import urlsafe_base64_encode, urlsafe_base64_decode, etag, entry

qiniu/auth.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import hmac
44
import time
55
from hashlib import sha1
6-
76
from requests.auth import AuthBase
8-
97
from .compat import urlparse, json, b
108
from .utils import urlsafe_base64_encode
119

@@ -266,8 +264,8 @@ def token_of_request(
266264
data += "\n"
267265

268266
if content_type and content_type != "application/octet-stream" and body:
269-
data += body.decode(encoding='UTF-8')
270-
267+
# data += body.decode(encoding='UTF-8')
268+
data += body
271269
return '{0}:{1}'.format(self.__access_key, self.__token(data))
272270

273271
def qiniu_headers(self, headers):

qiniu/http.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import qiniu.auth
1010
from . import __version__
1111

12+
1213
_sys_info = '{0}; {1}'.format(platform.system(), platform.machine())
1314
_python_ver = platform.python_version()
1415

@@ -24,7 +25,7 @@ def __return_wrapper(resp):
2425
return None, ResponseInfo(resp)
2526
resp.encoding = 'utf-8'
2627
ret = resp.json(encoding='utf-8') if resp.text != '' else {}
27-
if ret is None: # json null
28+
if ret is None: # json null
2829
ret = {}
2930
return ret, ResponseInfo(resp)
3031

@@ -110,6 +111,10 @@ def _post_with_auth_and_headers(url, data, auth, headers):
110111
return _post(url, data, None, qiniu.auth.RequestsAuth(auth), headers)
111112

112113

114+
def _post_with_qiniu_mac_and_headers(url, data, auth, headers):
115+
return _post(url, data, None, qiniu.auth.QiniuMacRequestsAuth(auth), headers)
116+
117+
113118
def _put_with_auth(url, data, auth):
114119
return _put(url, data, None, qiniu.auth.RequestsAuth(auth))
115120

@@ -118,11 +123,14 @@ def _put_with_auth_and_headers(url, data, auth, headers):
118123
return _put(url, data, None, qiniu.auth.RequestsAuth(auth), headers)
119124

120125

126+
def _put_with_qiniu_mac_and_headers(url, data, auth, headers):
127+
return _put(url, data, None, qiniu.auth.QiniuMacRequestsAuth(auth), headers)
128+
129+
121130
def _post_with_qiniu_mac(url, data, auth):
122131
qn_auth = qiniu.auth.QiniuMacRequestsAuth(
123132
auth) if auth is not None else None
124133
timeout = config.get_default('connection_timeout')
125-
126134
try:
127135
r = requests.post(
128136
url,
@@ -148,6 +156,23 @@ def _get_with_qiniu_mac(url, params, auth):
148156
return __return_wrapper(r)
149157

150158

159+
def _get_with_qiniu_mac_and_headers(url, params, auth, headers):
160+
try:
161+
post_headers = _headers.copy()
162+
if headers is not None:
163+
for k, v in headers.items():
164+
post_headers.update({k: v})
165+
r = requests.get(
166+
url,
167+
params=params,
168+
auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None,
169+
timeout=config.get_default('connection_timeout'),
170+
headers=post_headers)
171+
except Exception as e:
172+
return None, ResponseInfo(None, e)
173+
return __return_wrapper(r)
174+
175+
151176
def _delete_with_qiniu_mac(url, params, auth):
152177
try:
153178
r = requests.delete(
@@ -161,6 +186,23 @@ def _delete_with_qiniu_mac(url, params, auth):
161186
return __return_wrapper(r)
162187

163188

189+
def _delete_with_qiniu_mac_and_headers(url, params, auth, headers):
190+
try:
191+
post_headers = _headers.copy()
192+
if headers is not None:
193+
for k, v in headers.items():
194+
post_headers.update({k: v})
195+
r = requests.delete(
196+
url,
197+
params=params,
198+
auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None,
199+
timeout=config.get_default('connection_timeout'),
200+
headers=post_headers)
201+
except Exception as e:
202+
return None, ResponseInfo(None, e)
203+
return __return_wrapper(r)
204+
205+
164206
class ResponseInfo(object):
165207
"""七牛HTTP请求返回信息类
166208

qiniu/services/sms/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)