|
| 1 | +# coding: utf8 |
| 2 | +from datetime import datetime |
| 3 | + |
| 4 | +# 使用V1 API |
| 5 | +# from yunpian import ClientV1 |
| 6 | +# c = ClientV1('your api key') |
| 7 | + |
| 8 | +# 使用V2 API |
| 9 | +from yunpian import ClientV2 |
| 10 | +c = ClientV2('your api key') |
| 11 | + |
| 12 | +#### 账户API |
| 13 | +# V1/V2 查看账户信息 |
| 14 | +res = c.get_account() |
| 15 | + |
| 16 | +# V1/V2 修改账户信息 |
| 17 | +# res = c.modify_account('name', 'phone', 20) |
| 18 | + |
| 19 | + |
| 20 | +#### 模板API |
| 21 | +# V2 取默认模板 |
| 22 | +# res = c.get_default_sms_tpl() |
| 23 | + |
| 24 | +# V1/V2 添加模板 |
| 25 | +# res = c.create_sms_tpl('签名', '模板内容') |
| 26 | + |
| 27 | +# V1/V2 取模板 |
| 28 | +# res = c.get_sms_tpl(111111) |
| 29 | + |
| 30 | +# V1/V2 修改模板 |
| 31 | +# res = c.modify_sms_tpl(11111, '新签名', '新模板内容') |
| 32 | + |
| 33 | +# V1/V2 删除模板 |
| 34 | +# res = c.del_sms_tpl(111111) |
| 35 | + |
| 36 | + |
| 37 | +#### 短信API |
| 38 | +# V1 智能匹配模板发送; V2 单条发送 |
| 39 | +# res = c.send_sms('151xxxxxxxx', '【签名】短信内容') |
| 40 | + |
| 41 | +# V2 批量发送 |
| 42 | +# res = c.broadcast_sms(['151xxxxxxx1', '151xxxxxxx2'], '【签名】短信内容') |
| 43 | + |
| 44 | +# V1 批量个性化发送; V2 个性化发送; |
| 45 | +# 使用jobs方式配置任务 |
| 46 | +# res = c.send_multi_sms(jobs=[ |
| 47 | +# { |
| 48 | +# '151xxxxxxx1': '【签名1】短信内容1', |
| 49 | +# '151xxxxxxx2': '【签名2】短信内容2', |
| 50 | +# }, |
| 51 | +# { |
| 52 | +# '151xxxxxxx2': '【签名3】短信内容3', |
| 53 | +# '151xxxxxxx3': '【签名4】短信内容4', |
| 54 | +# }, |
| 55 | +# ]) |
| 56 | +# 使用流水线方式配置任务 |
| 57 | +# res = c.send_multi_sms( |
| 58 | +# mobiles=['151xxxxxxx1', '151xxxxxxx2', '151xxxxxxx2', '151xxxxxxx3'], |
| 59 | +# contents=['【签名1】短信内容1', '【签名2】短信内容2', '【签名3】短信内容3', '【签名4】短信内容4'] |
| 60 | +# ) |
| 61 | + |
| 62 | +# V1/V2 获取状态报告 |
| 63 | +# res = c.get_sms_status() |
| 64 | + |
| 65 | +# V1/V2 推送状态报告 |
| 66 | +# res = c.get_sms_reply() |
| 67 | + |
| 68 | +# V1/V2 查回复短信 |
| 69 | +# res = c.retrieve_sms_reply('2016-08-13 00:00:00', datetime.now(), 20) |
| 70 | + |
| 71 | +# V1/V2 查短信发送记录 |
| 72 | +# res = c.get_sms_send_record('2016-08-13 00:00:00', datetime.now(), 20) |
| 73 | + |
| 74 | +# V1/V2 查屏蔽词 |
| 75 | +# res = c.get_black_word('我是大傻逼') # "傻逼"是屏蔽词 |
| 76 | + |
| 77 | +# V1 指定模板发送; V2 指定模板单发 |
| 78 | +# res = c.send_tpl_sms('151xxxxxxxx', 11111, {'context': '模板上下文'}) |
| 79 | + |
| 80 | + |
| 81 | +#### 语音API |
| 82 | +# V1/V2 发送语音验证码 |
| 83 | +# res = c.voice_verification_code('151xxxxxxxx', 112233) |
| 84 | + |
| 85 | +# V1/V2 获取状态报告 |
| 86 | +# res = c.get_voice_verification_status() |
| 87 | + |
| 88 | + |
| 89 | +#### 流量API |
| 90 | +# V1/V2 查询流量包 |
| 91 | +# res = c.get_data_traffic() |
| 92 | + |
| 93 | +# V1/V2 流量包充值 |
| 94 | +# res = c.recharge_data_traffic('151xxxxxxxx', '1008601') |
| 95 | + |
| 96 | +# V1/V2 获取状态报告 |
| 97 | +# res = c.get_data_traffic_status() |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +# 读取返回值 |
| 103 | +data = res.json() |
0 commit comments