Esempio n. 1
0
    def sms_delivered(self):
        mobile = self.get_customer_mobile()
        if not mobile or self.delivery_msg_sent:
            return

        # all delivered, send ORDER_DELIVERED_TEMPLATE
        if self.is_all_delivered:
            bz_id = 'Order#%s-delivered' % self.pk
            data = '''{"url":"%s"}''' % self.public_url
            success, detail = send_cn_sms(bz_id, mobile,
                                          settings.ORDER_DELIVERED_TEMPLATE,
                                          data)
            if success:
                self.delivery_msg_sent = True
                self.save(update_fields=['delivery_msg_sent'])
                self.express_orders.all().update(delivery_sms_sent=True)
            return

        # part of parcels delivered, send PACKAGE_DELIVERED_TEMPLATE = 直邮包裹${track_id}已寄达,请注意查收。详情http://s.luotao.net${url}
        need_sms = self.express_orders.filter(is_delivered=True,
                                              delivery_sms_sent=False)
        track_ids = [x.track_id for x in need_sms]
        if track_ids:
            bz_id = 'OrderParcels#%s-delivered' % self.pk
            track_id = '%s' % track_ids[0] if len(
                track_ids) == 1 else '%s等%s箱' % (track_ids[0], len(track_ids))
            data = '''{"track_id":"%s", "url":"%s"}''' % (track_id,
                                                          self.public_url)
            success, detail = send_cn_sms(bz_id, mobile,
                                          settings.PACKAGE_DELIVERED_TEMPLATE,
                                          data)
            if success:
                need_sms.update(delivery_sms_sent=True)
Esempio n. 2
0
def send_verification_code(mobile):
    number = validate_cn_mobile(mobile)
    if number:
        country = 'CN'
    else:
        number = validate_au_mobile(mobile)
        if number:
            country = 'AU'
        else:
            return False, 'NUMBER_NOT_VALID'

    bz_id = 'Registeration#%s = %s' % (country, number)
    minute_ago = timezone.now() - relativedelta(seconds=60)
    if Sms.objects.filter(app_name=bz_id,
                          send_to=number,
                          success=True,
                          time__gte=minute_ago).exists():
        return False, 'TOO_FREQUENTLY'

    code = get_random_string(4, '1234567890')
    r.setex(number, EXPIRES_IN, code)

    if country == 'CN':
        data = '''{"code":"%s"}''' % code
        return send_cn_sms(bz_id, mobile, settings.VERIFICATION_CODE_TEMPLATE,
                           data)
    elif country == 'AU':
        content = '[%s] 验证码为 %s, 10分钟内有效.' % (settings.SITE_NAME, code)
        return send_au_sms(number, content, app_name=bz_id)
Esempio n. 3
0
    def sms_shipping(self):
        mobile = self.get_customer_mobile()
        if not mobile or self.shipping_msg_sent:
            return

        bz_id = 'Order#%s-sent' % self.pk
        data = '''{"url":"%s", "count":"%s"}''' % (self.public_url,
                                                   self.express_orders.count())
        template = settings.ORDER_SENT_PAID_TEMPLATE if self.is_paid else settings.ORDER_SENT_UNPAID_TEMPLATE
        success, detail = send_cn_sms(bz_id, mobile, template, data)
        if success:
            self.shipping_msg_sent = True
            self.save(update_fields=['shipping_msg_sent'])
Esempio n. 4
0
    def sms_delivered(self):
        mobile = self.order.get_customer_mobile()
        if not mobile or self.delivery_sms_sent:
            return

        bz_id = 'ExpressOrder#%s-delivered' % self.track_id
        data = '''{"track_id":"%s", "url":"%s"}''' % (self.track_id,
                                                      self.order.public_url)
        success, detail = send_cn_sms(bz_id, mobile,
                                      settings.PACKAGE_DELIVERED_TEMPLATE,
                                      data)
        if success:
            self.delivery_sms_sent = True
            self.save(update_fields=['delivery_sms_sent'])
Esempio n. 5
0
def task_send_cn_sms(business_id, phone_numbers, template_code, template_param=None):
    send_cn_sms(business_id, phone_numbers, template_code, template_param)