Browse Source

增加短信推送

chenjunkai 6 years ago
parent
commit
ad10c26727
1 changed files with 40 additions and 1 deletions
  1. 40 1
      Controller/UserController.py

+ 40 - 1
Controller/UserController.py

@@ -560,6 +560,7 @@ class v2authCodeView(TemplateView):
     def ValidationError(self, request_dict, response):
     def ValidationError(self, request_dict, response):
         email = request_dict.get('email', None)
         email = request_dict.get('email', None)
         phone = request_dict.get('phone', None)
         phone = request_dict.get('phone', None)
+        country_code = request_dict.get('country_code', None)
         if email is not None:
         if email is not None:
             email = email.strip()
             email = email.strip()
             # 阿里云的发送邮箱的调用方法
             # 阿里云的发送邮箱的调用方法
@@ -568,7 +569,11 @@ class v2authCodeView(TemplateView):
             # return self.emailCode(email, response)
             # return self.emailCode(email, response)
         elif phone is not None:
         elif phone is not None:
             phone = phone.strip()
             phone = phone.strip()
-            return self.phoneCode(phone, response)
+            if country_code is None:
+                return self.phoneCode(phone, response)
+            else:
+                country_code = str(country_code.strip())
+                return self.phoneCodeV2(country_code, phone, response)
         else:
         else:
             return response.json(444)
             return response.json(444)
 
 
@@ -670,6 +675,40 @@ class v2authCodeView(TemplateView):
         else:
         else:
             return response.json(10, res["Message"])
             return response.json(10, res["Message"])
 
 
+    def phoneCodeV2(self, country_code, phone, response):
+        dataValid = DataValid()
+        if dataValid.mobile_validate(phone) is not True:
+            return response.json(107)
+        reds = RedisObject()
+        identifyingCode = reds.get_data(key=phone + '_identifyingCode')
+        if identifyingCode:
+            return response.json(90)
+        user_qs = Device_User.objects.filter(username=phone)
+        phone_qs = Device_User.objects.filter(phone=phone)
+        if user_qs.exists() or phone_qs.exists():
+            return response.json(101)
+        identifyingCode = RandomStr(6, True)
+        if country_code == '86':
+            # 国内短信推送模板
+            temp_msg = 'SMS_151600991'
+            rec_phone = phone
+        else:
+            # 国际短信推送模板
+            temp_msg = 'SMS_172165867'
+            rec_phone = country_code + phone
+        # if ph
+        # 发送手机验证码
+        aliSms = AliSmsObject()
+        res = aliSms.send_code_sms(phone=rec_phone, code=identifyingCode, sign_name='Ansjer',
+                                   temp_msg=temp_msg)
+        print(res)
+        if res["Code"] == "OK":
+            if reds.set_data(key=phone + '_identifyingCode', val=identifyingCode, expire=60) is not True:
+                return response.json(10, '生成缓存系统错误')
+            return response.json(0)
+        else:
+            return response.json(10, res["Message"])
+
 
 
 # 验证码注册
 # 验证码注册
 class v2registerView(TemplateView):
 class v2registerView(TemplateView):