def send_message(phone, code, template_id): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = phone datas = (code, '5') resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '17859717522' data = (1234, 5) resp = sdk.sendMessage(tid, mobile, data) print(resp)
def send_msg_notice(to_phone, name, unread_num, customer_url): sdk = SmsSDK(accId, accToken, appId) tid = '893433' mobile = to_phone datas = (name, unread_num, customer_url) resp = sdk.sendMessage(tid, mobile, datas) return resp
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '容联云通讯创建的模板' mobile = '手机号1,手机号2' datas = ('变量1', '变量2') resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_sms(self, mobile, sms_code): """发送短信""" try: with flask_app.app_context(): sdk = SmsSDK(current_app.config.get("SMS_ACCOUNT_ID"), current_app.config.get("SMS_ACCOUNT_TOKEN"), current_app.config.get("SMS_APP_ID")) ret = sdk.sendMessage( current_app.config.get("SMS_TEMPLATE_ID"), mobile, (sms_code, current_app.config.get("SMS_EXPIRE_TIME") // 60)) result = json.loads(ret) if result["statusCode"] == "000000": pipe = redis.pipeline() pipe.multi() # 开启事务 # 保存短信记录到redis中 pipe.setex("sms_%s" % mobile, current_app.config.get("SMS_EXPIRE_TIME"), sms_code) # 进行冷却倒计时 pipe.setex("int_%s" % mobile, current_app.config.get("SMS_INTERVAL_TIME"), "_") pipe.execute() # 提交事务 else: current_app.log.error("短信发送失败!\r\n%s" % ret) raise Exception except Exception as exc: # 重新尝试执行失败任务 print(self.request.retries) # 本次执行的次数 self.retry(exc=exc, countdown=3, max_retries=5)
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '15904925186' datas = ('变量1', '变量2') resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_msg_code(to_phone, msg_code): sdk = SmsSDK(accId, accToken, appId) tid = '893451' mobile = to_phone datas = (msg_code, '5') resp = sdk.sendMessage(tid, mobile, datas) return resp
def send_message(mobile, sms_code): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobiles = f'{mobile}' datas = (f'{sms_code}', '1') resp = sdk.sendMessage(tid, mobiles, datas) print(resp)
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '18370850448' datas = ("1234", '5') resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(mobile, code): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = mobile datas = (code, '5') resp = sdk.sendMessage(tid, mobile, datas) resp = json.loads(resp) return resp
def send_message(): # 创建容联云 实例对象 sdk = SmsSDK(accId, accToken, appId) tid = '1' # 这个是发送的短信模板 只能是1 mobile = '17614321583' # 给那些手机发送验证码,只能是测试手机号。 datas = ('666', 5) # 您的验证码为{1}请于{2}分钟内输入。 # 发送验证短信。 resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '18168580698' datas = ('786567', '5') resp = sdk.sendMessage(tid, mobile, datas) # print(resp) # print("1") return resp
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '18222287109, 15870879568' # datas 验证码 过期时间单位分钟 datas = ('1234', '5') resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = '18646175116' # datas 验证码 过期时间 单位是分钟 datas = ('1234', '5') resp = sdk.sendMessage(tid, mobile, datas) print(type(resp)) print(resp)
def send_message(): # 1. 创建荣联云 实例对象 sdk = SmsSDK(accId, accToken, appId) tid = '1' # 我们发送短信的模板,值 只能是 1 因为我们是测试用户 mobile = '18310820688' #'手机号1,手机号2' 给哪些手机号发送验证码,只能是测试手机号 datas = ('666999', 5) # ('变量1', '变量2') 涉及到模板的变量 # 您的验证码为{1},请于{2} 分钟内输入 # 您的验证码为666999,请于5 分钟内输入 # 2. 发送短信 sdk.sendMessage(tid, mobile, datas)
def send_message(): accId = '8a216da874af5fff0174b997014c04eb' accToken = '91ca470532d049d9ae2bc3726d9036c4' appId = '8a216da874af5fff0174b997025604f2' sdk = SmsSDK(accId, accToken, appId) tid = '1' # mobile = '18168580698' datas = (sms_code, round(constants.SMS_CODE_REDIS_EXPIRES / 60)) resp = sdk.sendMessage(tid, mobile, datas) # print(resp) return resp
def send_message(): # 1. 创建容联云 实例对象 sdk = SmsSDK(accId, accToken, appId) # 我们发送短信的模板 值只能是1 tid = '1' # 给那些手机发送验证码 只能是测试手机号 mobile = '15735404103' # 涉及到模板的变量---> 您的验证码为{1}, 请于{2}分钟内输入 datas = ('666999', 5) # 2. 发送短信 resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(phone): sdk = SmsSDK(accId, accToken, appId) tid = '1' mobile = phone code = str(random.randint(1000,9999)) #缓存 设置键为 phone 值为code 过期时间180秒 # cache.set(phone, code) # print(cache.get(phone)) datas = (code, '1') resp = sdk.sendMessage(tid, mobile, datas) resp = json.loads(resp) return resp,code
def celery_send_sms_code(mobile, sms_code): print(11111111111111111111111111111) accId = '8aaf0708762cb1cf0176c60392973587' accToken = 'a099e3b6a8a14e09bae6d133051decb9' appId = '8aaf0708762cb1cf0176c603936b358e' sdk = SmsSDK(accId, accToken, appId) print(22222222222222222222222222222) tid = '1' # 因为是测试用户 所以我们发送短信的模板只能是1 mobile = f'{mobile}' datas = (sms_code, 10) # 涉及到模板的变量 # 您的验证码为 1 请于 2 分钟内输入 resp = sdk.sendMessage(tid, mobile, datas) print(resp)
def send_message(mobile, sms_num): accId = '8aaf0708762cb1cf0176c6070ab33598' accToken = '0508e0f81c46417fa5aa248e917effbc' appId = '8aaf0708762cb1cf0176c6070b99359f' # 1. 创建容联云 实例对象 sdk = SmsSDK(accId, accToken, appId) # 我们发送短信的模板 值只能是1 tid = '1' # 给那些手机发送验证码 只能是测试手机号 mobile = mobile # 涉及到模板的变量---> 您的验证码为{1}, 请于{2}分钟内输入 datas = (sms_num, 5) # 2. 发送短信 sdk.sendMessage(tid, mobile, datas)
def celery_send_sms_code(mobile, sms_code): accId = '8a216da8762cb4570176c60593ba35ec' accToken = '514a8783b8c2481ebbeb6a814434796f' appId = '8a216da8762cb4570176c605948c35f2' # 9.1. 创建荣联云 实例对象 sdk = SmsSDK(accId, accToken, appId) tid = '1' # 我们发送短信的模板,值 只能是 1 因为我们是测试用户 mobile = '%s' % mobile # '手机号1,手机号2' 给哪些手机号发送验证码,只能是测试手机号 datas = (sms_code, 10) # ('变量1', '变量2') 涉及到模板的变量 # 您的验证码为{1},请于{2} 分钟内输入 # 您的验证码为666999,请于5 分钟内输入 # 9.2. 发送短信 sdk.sendMessage(tid, mobile, datas)
def celery_send_message(mobile, data): accId = '8aaf07086162578ab6fe06b0' accToken = '3b9e8ef5ec5848b48f0eb0862f0c' appId = '8aaf0708162578ab75206b6' # 1. 创建荣联云 实例对象 sdk = SmsSDK(accId, accToken, appId) tid = '1' # 我们发送短信的模板,值 只能是 1 因为我们是测试用户 mobile = mobile # '手机号1,手机号2' 给哪些手机号发送验证码,只能是测试手机号 datas = (data, 5) # ('变量1', '变量2') 涉及到模板的变量 # 您的验证码为{1},请于{2} 分钟内输入 # 您的验证码为666999,请于5 分钟内输入 # 2. 发送短信 sdk.sendMessage(tid, mobile, datas)
def celery_send_sms_code(mobile, sms_code): accId = '8aaf07086246778ab6fe06b0' accToken = '3b9e8ef5ec5848b483fe3f0ef0c' appId = '8aaf0708624670f20162578206b6' # 9.1. 创建荣联云 实例对象 sdk = SmsSDK(accId, accToken, appId) tid = '1' # 我们发送短信的模板,值 只能是 1 因为我们是测试用户 mobile = '%s' % mobile # '手机号1,手机号2' 给哪些手机号发送验证码,只能是测试手机号 datas = (sms_code, 10) # ('变量1', '变量2') 涉及到模板的变量 # 您的验证码为{1},请于{2} 分钟内输入 # 您的验证码为666999,请于5 分钟内输入 # 9.2. 发送短信 sdk.sendMessage(tid, mobile, datas)
def __new__(cls, *args, **kwargs): # 单例模式-判断CCP类有没有意见创建好的对象,有则返回,没有创建 if cls.instance is None: obj = super(CCP, cls).__new__(cls) obj.sdk = SmsSDK(accId, accToken, appId) cls.instance = obj return cls.instance
def get(self, request, mobile): # 1. 生成验证码 sms_code = str(randint(0, 999999)).zfill(6) # 2. 存redis redis_conn = get_redis_connection('verify_sms_codes') redis_conn.setex('sms_{}'.format(mobile), time_limit * 60, sms_code) # 3. 容联云发送验证码 sdk = SmsSDK(accId, accToken, appId) datas = (sms_code, str(time_limit)) resp = sdk.sendMessage(tid, str(mobile), datas) try: resp = json.loads(resp) except: resp = {'statusCode': '172001'} # 4. response return Response({"code": 200})
def __new__(cls): # 判断CCP有没有已经创建好的对象,如果没有,创建一个对象,并且保存 # 如果有,则将保存的对象返回 if cls.instance is None: obj = super().__new__(cls) obj.sdk = SmsSDK(accId, accToken, appId) cls.instance = obj return cls.instance
def __new__(cls, *args, **kwargs): # 判断是否存在类属性_instance,_instance是类CCP的唯一对象,即单例 if not hasattr(CCP, "_instance"): cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs) cls._instance.rest = SmsSDK(constants.ACCOUNT_SID, constants.ACCOUNT_TOKEN, constants.APP_ID) return cls._instance
def __new__(cls): # 判断CCP类有没有已经创建好的对象,如果没有,创建一个对象,并且保存 # 如果有,则将保存的对象直接返回 if cls.instance is None: obj = super(CCP2, cls).__new__(cls) obj.sdk = SmsSDK(accId=accountSid, accToken=accountToken, appId=appId) cls.instance = obj return cls.instance
def __new__(cls, *args, **kwargs): # 单例模式 # 1. 判断类属性是否已经被赋值 if cls.instance is None: obj = super(SMS, cls).__new__(cls) obj.sdk = SmsSDK(accId, accToken, appId) cls.instance = obj # 2. 返回类属性的单例引用 return cls.instance
def __new__(cls, *args, **kwargs): """ 定义单例的初始化方法 :return: 单例 """ # 判断单例是否存在:_instance属性中存储的就是单例 if not hasattr(cls, "_instance"): cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs) cls._instance.setAccount = SmsSDK(_accountSid, _accountToken, _appId) #返回单例 return cls._instance