分享一个国外的短信服务平台:【NEXMO】



  • NEXMO官网

    https://www.nexmo.com/

    短信验证码发送与验证实例


    api_key和api_secret替换成你自己的。


    import logging
    import requests
    
    api_key = "your_api_key"
    api_secret = "your_api_secret"
    brand = "Guaik"
    
    def sendVerifyCode(self,number):
        # param  : number 接收验证码的手机号
        # retval : 返回请求id,在验证的时候会用到
        request_id = None
        try:
            data = {"api_key":api_key,"api_secret":api_secret,"number":number,"brand":brand}
            headers = {'Content-Type': 'application/json'}
            r = requests.post("https://api.nexmo.com/verify/json",headers = headers, data = json.dumps(data))
            data = json.loads(r.text)
            if data["status"] == "0":
                request_id = data["request_id"]
        except Exception as e: logging.error(e)
        return request_id
    
    
    def checkCode(self,request_id,code):
        # param request_id : 请求id,在发送验证码成功时返回
        # param code       : 手机接收到的验证码
        # retval           : 验证成功返回True
        result = False
        try:
            data = {"api_key":api_key,"api_secret":api_secret,"request_id":request_id,"code":code}
            headers = {'Content-Type': 'application/json'}
            r = requests.post("https://api.nexmo.com/verify/check/json",headers = headers, data = json.dumps(data))
            data = json.loads(r.text)
            if data["status"] == "0":
                result = True
        except Exception as e: logging.error(e)
        return result
    
    


  • 国内用短信包,1毛一条吧,还行



  • 收费的,不过价格不贵。短信验证的签名不需要审核,你在brand中填什么它就给你显示什么,及时性还不错。



  • 不收费吧,及时性怎么样


Log in to reply