短信API客户端,使用https://easy sms.4simple.org服务发送简单的短信。

sms-api的Python项目详细描述


这个库允许轻松地向python应用程序添加sms文本消息。在中创建帐户 https://easysms.4simple.org获取您的api凭据。 代码示例

# Step #1 is import required API client class
from sms_api import SMS_Easy

# Step #2 is create an API client object using credential obtained from https://easysms.4simple.org/user/panel/
api_obj = SMS_Easy(user_id=21461, auth_token='39fecac595c24h34g35iu451a')


##########################################################################
#            HOW SEND AN SMS TEXT MESSAGE
##########################################################################

# Sending an SMS in just one line
result = api_obj.send_sms(to="1525315673", body="Hello Testing SMS API")

pid = -1
# Optionally, we can verify if SMS was accepted without errors.
if result.get("success") == "ok":
    print "SMS message was processed successfully. SMS processing id(pid) is: %s" % result.get("pid")
    pid = result.get("pid")
elif "error" in result:
    print "Error while try to send SMS due to: %s" % result.get("error")


##########################################################################
#            HOW CHECK ACCOUNT BALANCE
##########################################################################

# Just call function get_account_balance
result = api_obj.get_account_balance()

if isinstance(result, dict) and "error" in result:
    print "Error while try get account balance due to: %s" % result.get("error")
else:
    print "Your account balance is: %s" % result


##########################################################################
#            HOW CHECK SMS PROCESSING STATUS
##########################################################################

# Using the processing id (pid) returned when the SMS message was sent, just call this function.
result = api_obj.get_sms_status(pid)

if isinstance(result, dict) and "error" in result:
    print "Error while try get SMS processing status for pid %s, due to: %s" % (pid, result.get("error"))
else:
    print "SMS processing status for pid %s is %s" % (pid, result.get("status"))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
返回数组无效的java方法   异步Java CompletableFuture获取其请求   java是否可以像RDBMS那样使用视图?   java如何在屏幕上只运行一个片段?   java无法从Vertex jdbc查询中获取结果   java从jtable获取对象的正确方法   java Spring 3数据设备替代方案   Java BigDecimal:四舍五入到客户首选的数字和增量   JAVA主窗口没有出现,我必须左键单击主窗口。java并单击run查看它   Eclipse RCP中的java进程自定义设备事件   JavaEclipse一次又一次地构建代码(没有任何更改)?   java如何实现对象合并