def tencentSendMesaage(employee, gestName, employeeNumber): ## Enum{0: 普通短信, 1: 营销短信} sms_type = 0 template_id = 151036 params = [] params.append(employee) params.append(employeeNumber) ssender = SmsSingleSender(appid, appkey) try: sendStr = "Hello, " + employee + ". " + gestName + " is here to see you. Please meet them at the door." print(sendStr) print(employeeNumber) result = ssender.send(sms_type, 86, employeeNumber, sendStr) #result = ssender.send(sms_type, 86, employeeNumber,"Hello,search.jcr is here to see you. Please meet them at the door.") # 签名参数未提供或者为空时,会使用默认签名发送短信 #result = ssender.send_with_param(86, employeeNumber,template_id, params) except HTTPError as e: print(e) except Exception as e: print(e) print('tencnet:{}'.format(result).decode('unicode_escape'))
def sendSms(phone_numbers): ssender = SmsSingleSender(appid, appkey) code = randomNumber() msg = f'{code}为您的验证码' result = ssender.send(0, 86, phone_numbers, msg) conn = Open_Redis().getConn(7) conn.set(phone_numbers, str(code), 60) print('返回值') print(result) code = code if result.get('result') == 0 else False return code
def send_sms(): sms_type = 0 # Enum{0: 普通短信, 1: 营销短信} ssender = SmsSingleSender("", "") try: result = ssender.send(sms_type, 86, "1831110xxxx", "啊,这是一条测试短信,抓取科一考试信息的时间段", extend="", ext="456") finally: pass
def sendCode(code, phone_number): ssender = SmsSingleSender(appid, appkey) phone_number = str(phone_number) try: result = ssender.send(0, 86, phone_number, '你的验证码为:' + code + ',请于5分钟内填写。如非本人操作,请忽略本短信。') except HTTPError as e: print(e) except Exception as e: print(e) print(result) return result['result']
def sing_sender(phone_number, verifycode): appid = USERVERIFYCODE_CONFIG['appid'] appkey = USERVERIFYCODE_CONFIG['appkey'] template_id = USERVERIFYCODE_CONFIG['template_id'] params = [str(verifycode), str(USERVERIFYCODE_CONFIG['expirtime'])] ssender = SmsSingleSender(appid, appkey) try: result = ssender.send(0, 86, str(phone_number), "您的验证码是:" + str(verifycode) + ",请于" + str( USERVERIFYCODE_CONFIG['expirtime']) + "分钟内填写。如非本人操作,请忽略本短信。") return result except HTTPError as e: return e except Exception as e: return e
def send_msg(phone_num, msg): sms_type = 0 # Enum{0: 普通短信, 1: 营销短信} ssender = SmsSingleSender(appid, appkey) try: result = ssender.send(sms_type, 86, phone_num, f"您的登陆验证码为:{msg},请在2分钟内填写。", extend="", ext="") except HTTPError as e: print(e) except Exception as e: print(e) print(result)
def sms_send(mobile, send_type="register"): if send_type == "register": try: phone_numbers = [mobile] sms_str = random_str(6) cache.set(mobile, sms_str) appid = 1400076616 appkey = '09763fbca1dc0c93de646671f07082ff' template_id = 97608 tel = 'testNum' params = [sms_str, 3, tel] ssender = SmsSingleSender(appid, appkey) result = ssender.send(86, phone_numbers[0], template_id, params) if result == 0: cache.set(phone_numbers, sms_str, 60 * 15) return result except Exception as e: print(e)
def main(): phone_numbers,Message = get_finally_name() time.sleep(60) # 需要发送短信的手机号码 print(phone_numbers,end="") for i in range(len(Message)): message = Message[i] print(message) sms_type = 0 # Enum{0: 普通短信, 1: 营销短信} ssender = SmsSingleSender(appid, appkey) try: result = ssender.send(sms_type, 86, phone_numbers[i], message, extend="", ext="") except HTTPError as e: print(e) except Exception as e: print(e) print(i+1,result)
def send_sms(self, phone, mail): # 仅发送短信给单个用户 msg = 'test content'.format(mail) if isinstance(phone, int): phone = str(phone) ssender = SmsSingleSender(self.appid, self.appkey) try: # result = ssender.send(self.sms_type, 86, phone, msg, extend="", ext="") except HTTPError as e: print(e) self.lg.logger.info("Sms class HTTPError: %s", e) except Exception as e: print(e) self.lg.logger.info("Sms class Exception: %s", e) print('Sms send result:', result['errmsg']) self.lg.logger.info("Sms send result: %s", result) return result['errmsg']
from qcloudsms_py import SmsSingleSender
# 短信应用 SDK AppID appid = 1400009099 # SDK AppID 以1400开头 # 短信应用 SDK AppKey appkey = "9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad" # 需要发送短信的手机号码 phone_numbers = ["21212313123", "12345678902", "12345678903"] # 短信模板ID,需要在短信控制台中申请 template_id = 7839 # NOTE: 这里的模板 ID`7839`只是示例,真实的模板 ID 需要在短信控制台中申请 # 签名 sms_sign = "腾讯云" # NOTE: 签名参数使用的是`签名内容`,而不是`签名ID`。这里的签名"腾讯云"只是示例,真实的签名需要在短信控制台中申请 from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError sms_type = 0 # Enum{0: 普通短信, 1: 营销短信} ssender = SmsSingleSender(appid, appkey) try: result = ssender.send(sms_type, 86, phone_numbers[0], "【腾讯云】您的验证码是: 5678", extend="", ext="") except HTTPError as e: print(e) except Exception as e: print(e) print(result)
from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError # 短信应用SDK AppID app_id = 1400207953 # SDK AppID是1400开头 # 短信应用SDK AppKey app_key = "dcf8015432958a158b0a40b0c45e6706" # 需要发送短信的手机号码 phone_numbers = ["13336980260"] # 短信模板ID,需要在短信应用中申请 template_id = 324429 # NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请 # 签名 sms_sign = "明明如月" # NOTE: 这里的签名"腾讯云"只是一个示例,真实的签名需要在短信控制台中申请,另外签名参数使用的是`签名内容`,而不是`签名ID` sms_type = 0 # Enum{0: 普通短信, 1: 营销短信} s_sender = SmsSingleSender(app_id, app_key) try: result = s_sender.send(sms_type, 86, phone_numbers[0], "【腾讯云】您的验证码是: 5678") print(result) except HTTPError as e: print(e) except Exception as e: print(e)
class TencentSms(object): def __init__(self): self.appid = "" self.key = "" self.app = None self.ssender = None def init_from_app(self, app): self.appid = app.config['SMS_APP_ID'] self.key = app.config['SMS_APP_KEY'] self.app = app self.ssender = SmsSingleSender(self.appid, self.key) def send_single(self, phone_number, content): try: result = self.ssender.send(0, 86, phone_number, content, extend="", ext="") return result except HTTPError as e: print(e) except Exception as e: print(e) def _send_templateid(self, phone_number, params, template_id): result = {} try: result = self.ssender.send_with_param( 86, phone_number, template_id, params, extend="", ext="") # 签名参数未提供或者为空时,会使用默认签名发送短信 except HTTPError as e: print_exc(limit=5) except Exception as e: print_exc(limit=5) return result def send_sms(self, phone, params, verify_type): if verify_type == 'mch_register': result = self.send_mch_register(phone, params) elif verify_type == 'add_phone': result = self.send_add_phone(phone, params) elif verify_type == 'reset_pass': result = self.send_reset(phone, params) else: result = self.send_withdraw(phone, params) return result def send_add_phone(self, phone_number, params): result = self._send_templateid( phone_number, params, self.app.config['TELEPHONE_TEMPLATE_ID']) return result def send_reset(self, phone_number, params): result = self._send_templateid(phone_number, params, self.app.config['RESET_TEMPLATE_ID']) return result def send_mch_register(self, phone_number, params): result = self._send_templateid(phone_number, params, self.app.config['MERCHANT_TEMPLATE_ID']) return result def send_withdraw(self, phone_number, params): result = self._send_templateid(phone_number, params, self.app.config['WITHDRAW_TEMPLATE_ID']) return result
appid = 1400088485 appkey = "86268a0cb01a9cb6ce86efe0cf328669" phone_numbers = ["13880608926"] template_id = 7839 from qcloudsms_py import SmsSingleSender from qcloudsms_py.httpclient import HTTPError ssender = SmsSingleSender(appid, appkey) try: result = ssender.send(0, 86, phone_numbers[0], "测试短信,普通单发,深圳,小明,上学。") except HTTPError as e: print(e) except Exception as e: print(e) print(result)