Skip to content

Commit

Permalink
add sms_ch
Browse files Browse the repository at this point in the history
  • Loading branch information
songfei9315 committed Jun 6, 2019
1 parent a69fbef commit f582d64
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

# 7.2.5 (2019-06-06)
* 添加sms

# 7.2.4 (2019-04-01)
* 默认导入region类

Expand Down
98 changes: 98 additions & 0 deletions examples/sms_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import QiniuMacAuth
from qiniu import Sms


access_key = 'bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW'
secret_key = 'pCav6rTslxP2SIFg0XJmAw53D9PjWEcuYWVdUqAf'

# 初始化Auth状态
q = QiniuMacAuth(access_key, secret_key)

# 初始化Sms
sms = Sms(q)

"""
#创建签名
signature = 'abs'
source = 'website'
req, info = sms.createSignature(signature, source)
print(req,info)
"""

"""
#查询签名
audit_status = ''
page = 1
page_size = 20
req, info = sms.querySignature(audit_status, page, page_size)
print(req, info)
"""

"""
编辑签名
id = 1136530250662940672
signature = 'sssss'
req, info = sms.updateSignature(id, signature)
print(req, info)
"""

"""
#删除签名
signature_id= 1136530250662940672
req, info = sms.deleteSignature(signature_id)
print(req, info)
"""

"""
#创建模版
name = '06-062-test'
template = '${test}'
type = 'notification'
description = '就测试啊'
signature_id = '1131464448834277376'
req, info = sms.createTemplate(name, template, type, description, signature_id)
print(req, info)
"""

"""
#查询模版
audit_status = ''
page = 1
page_size = 20
req, info = sms.queryTemplate(audit_status, page, page_size)
print(req, info)
"""

"""
#编辑模版
template_id = '1136589777022226432'
name = '06-06-test'
template = 'hi,你好'
description = '就测试啊'
signature_id = '1131464448834277376'
req, info = sms.updateTemplate(template_id, name, template, description, signature_id)
print(info)
"""

"""
#删除模版
template_id = '1136589777022226432'
req, info = sms.deleteTemplate(template_id)
print(req, info)
"""

"""
#发送短信
"""
template_id = ''
mobiles = []
parameters = {}
req, info = sms.sendMessage(template_id, mobiles, parameters)
print(req, info)




5 changes: 2 additions & 3 deletions qiniu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# flake8: noqa

__version__ = '7.2.4'
__version__ = '7.2.5'

from .auth import Auth, QiniuMacAuth

Expand All @@ -25,7 +25,6 @@
from .services.processing.cmd import build_op, pipe_cmd, op_save
from .services.compute.app import AccountClient
from .services.compute.qcos_api import QcosClient

from .services.sms.sms import Sms
from .services.pili.rtc_server_manager import RtcServer, get_room_token

from .utils import urlsafe_base64_encode, urlsafe_base64_decode, etag, entry
6 changes: 2 additions & 4 deletions qiniu/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import hmac
import time
from hashlib import sha1

from requests.auth import AuthBase

from .compat import urlparse, json, b
from .utils import urlsafe_base64_encode

Expand Down Expand Up @@ -266,8 +264,8 @@ def token_of_request(
data += "\n"

if content_type and content_type != "application/octet-stream" and body:
data += body.decode(encoding='UTF-8')

# data += body.decode(encoding='UTF-8')
data += body
return '{0}:{1}'.format(self.__access_key, self.__token(data))

def qiniu_headers(self, headers):
Expand Down
46 changes: 44 additions & 2 deletions qiniu/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import qiniu.auth
from . import __version__


_sys_info = '{0}; {1}'.format(platform.system(), platform.machine())
_python_ver = platform.python_version()

Expand All @@ -24,7 +25,7 @@ def __return_wrapper(resp):
return None, ResponseInfo(resp)
resp.encoding = 'utf-8'
ret = resp.json(encoding='utf-8') if resp.text != '' else {}
if ret is None: # json null
if ret is None: # json null
ret = {}
return ret, ResponseInfo(resp)

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


def _post_with_qiniu_mac_and_headers(url, data, auth, headers):
return _post(url, data, None, qiniu.auth.QiniuMacRequestsAuth(auth), headers)


def _put_with_auth(url, data, auth):
return _put(url, data, None, qiniu.auth.RequestsAuth(auth))

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


def _put_with_qiniu_mac_and_headers(url, data, auth, headers):
return _put(url, data, None, qiniu.auth.QiniuMacRequestsAuth(auth), headers)


def _post_with_qiniu_mac(url, data, auth):
qn_auth = qiniu.auth.QiniuMacRequestsAuth(
auth) if auth is not None else None
timeout = config.get_default('connection_timeout')

try:
r = requests.post(
url,
Expand All @@ -148,6 +156,23 @@ def _get_with_qiniu_mac(url, params, auth):
return __return_wrapper(r)


def _get_with_qiniu_mac_and_headers(url, params, auth, headers):
try:
post_headers = _headers.copy()
if headers is not None:
for k, v in headers.items():
post_headers.update({k: v})
r = requests.get(
url,
params=params,
auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None,
timeout=config.get_default('connection_timeout'),
headers=post_headers)
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)


def _delete_with_qiniu_mac(url, params, auth):
try:
r = requests.delete(
Expand All @@ -161,6 +186,23 @@ def _delete_with_qiniu_mac(url, params, auth):
return __return_wrapper(r)


def _delete_with_qiniu_mac_and_headers(url, params, auth, headers):
try:
post_headers = _headers.copy()
if headers is not None:
for k, v in headers.items():
post_headers.update({k: v})
r = requests.delete(
url,
params=params,
auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None,
timeout=config.get_default('connection_timeout'),
headers=post_headers)
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)


class ResponseInfo(object):
"""七牛HTTP请求返回信息类
Expand Down
Empty file added qiniu/services/sms/__init__.py
Empty file.
Loading

0 comments on commit f582d64

Please sign in to comment.