예제 #1
0
파일: models.py 프로젝트: stden/colortek
 def send_message(self):
     message = unicode(self.text)
     if self.provider == "smsdirect":
         sms = SMSDirect()
         mid = sms.submit_message(message, self.phone, reload=True)
         if hasattr(mid, "http_error"):
             self.mid = None
             if mid == "900":
                 self.status = "3"
             elif mid == "300":
                 self.status = "4"
             elif mid == "400":
                 self.status = "5"
             else:
                 self.status = "2"
                 self.resend = True
                 self.resend_count += 1
                 self.save()
         else:
             if mid.isdigit():
                 self.mid = mid
                 self.resend = False
                 self.save()
             else:
                 # message have not send
                 self.resend = True
                 self.resend_count += 1
                 self.save()
         # status = sms.status
         # self.status = status
         self.save()
     elif self.provider == "smstwo":
         sms = SmsTwo(user=settings.SMS_TWO_USER, password=settings.SMS_TWO_PASSWORD)
         sms.send_message(phone=self.phone, message=message)
         response = sms._response.body  # read()
         mid = re.findall(re.compile(r"Message_ID=(\d+)", re.U), response)
         mid = mid[0] if len(mid) else mid
         logger.info("recieve response from server: %s" % response)
         if mid:
             self.mid = mid
             self.resend = False
             self.save()
         else:
             self.resend = True
             self.resend_count += 1
             self.save()
     elif self.provider == "disms":
         sms = DiSMS(user=settings.DI_SMS_USER, password=settings.DI_SMS_PASSWORD)
         sms.send_message(phone=self.phone, message=message)
         if hasattr(sms, "last_id"):
             self.mid = sms.last_id
         else:
             self.resend = True
             self.resend_count += 1
             self.save()
     return self
예제 #2
0
파일: models.py 프로젝트: stden/colortek
 def update_status(self):
     if self.provider == "smsdirect":
         c = SMSDirect()
         status = c.get_status_message(mid=self.mid)
         if status and not hasattr(c, "http_error"):
             self.status = status if status in chain(*SMS_STATUS_DELIVERY) else "2"
         elif hasattr(c, "http_error"):
             if status == "900":
                 self.status = 3
             elif status == "300":
                 self.status = "4"
             elif status == "401":
                 self.status = "4"
             elif status == "-1":
                 self.status = "2"
         self.save()
     elif self.provider == "smstwo":
         c = SmsTwo(user=settings.SMS_TWO_USER, password=settings.SMS_TWO_PASSWORD)
         raw_status = c.sms_status2(mid=self.mid)
         status = re.findall(re.compile(r"Status: (\w+)", re.U | re.M | re.I), raw_status)
         status = status[0] if len(status) else "unknown"
         if status == "unknown":
             self.status = "2"
         elif status == "delivered":
             self.status = "0"
         elif status == "not delivered":
             self.status = "1"
         else:
             c.status = "unknown"
         self.save()
     elif self.provider == "disms":
         c = DiSMS()
         status = c.get_status(smsid=self.mid)
         if status == "1":
             self.status = "6"
         elif status == "1":
             self.status = "7"
         elif status == "2":
             self.status = "1"  # not delivered
         elif status == "3":
             self.status = "0"  # delivered
         self.save()
     return self