Esempio n. 1
0
def push_app_push_msg_2_client_by_id(id):
    # type: (int) -> None
    """推送消息给客户端
    """
    from flashsale.protocol import get_target_url
    from flashsale.xiaolumm import util_emoji
    from flashsale.push.app_push import AppPush
    from flashsale.protocol.models import APPFullPushMessge
    now = datetime.datetime.now()
    push_msg = get_app_push_msg_by_id(id)
    if now < push_msg.push_time or push_msg.status == APPFullPushMessge.SUCCESS:  # 定义的推送时间 没有到 推送状态是已经成功 都不推送
        return
    target_url = get_target_url(push_msg.target_url, push_msg.params)
    msg = util_emoji.match_emoji(push_msg.desc)  # 生成推送内容

    if push_msg.platform == APPFullPushMessge.PL_ALL:
        resp = AppPush.push_to_all(target_url, msg)
    elif push_msg.platform in [
            APPFullPushMessge.PL_IOS, APPFullPushMessge.PL_ANDROID
    ]:
        resp = AppPush.push_to_platform(push_msg.platform, target_url, msg)
    else:
        resp = AppPush.push_to_topic(push_msg.platform, target_url, msg)

    push_msg.result = resp
    success = resp.get('android', {}).get('result', None) or resp.get(
        'ios', {}).get('result', None)
    if success and success.lower() == 'ok':
        push_msg.status = APPFullPushMessge.SUCCESS  # 保存推送成功状态
    push_msg.save(update_fields=['status', 'modified'])

    logger.info({
        'action': 'dailypush.app_msg_push_2_client_by_id',
        'msg_id': id
    })
Esempio n. 2
0
 def _wrapper(mama):
     customer = mama.get_mama_customer()
     if not customer:
         return
     customer_id = customer.id
     target_url = get_target_url(protocal_constants.TARGET_TYPE_HOME_TAB_1)
     msg = None
     if message:
         msg = message
     else:
         mstpls = PushMsgTpl.objects.filter(id=6, is_valid=True)
         if mstpls.exists():
             mstpl = mstpls[0]
             msg = mstpl.get_emoji_content()
     if msg is not None:
         mipush_of_android.push_to_account(customer_id,
                                           {'target_url': target_url},
                                           description=msg)
         mipush_of_ios.push_to_account(customer_id,
                                       {'target_url': target_url},
                                       description=msg)
         logger.info({
             'action': 'push.mipush.push_msg_to_mama',
             'customer': customer_id,
             'msg': msg,
             'target_url': target_url,
         })
Esempio n. 3
0
    def handle(self, *args, **kwargs):
        platform = kwargs.get('platform') or 'ios'
        mipush = mipush_of_ios if platform == 'ios' else mipush_of_android
        push_type, target_type = args[:2]
        target_type = int(target_type)

        params = []
        for p in kwargs.get('params') or []:
            params.append(p.split('='))
        params = dict(params)
        target_url = get_target_url(target_type, params)
        print target_url

        if push_type == PUSH_BY_REGID:
            regid, desc = args[2:4]
            mipush.push_to_regid(regid.strip(), {'target_url': target_url},
                                 description=desc)
        elif push_type == PUSH_BY_ACCOUNT:
            customer_id, desc = args[2:4]
            customer_id = int(customer_id)
            mipush.push_to_account(customer_id, {'target_url': target_url},
                                   description=desc)
        elif push_type == PUSH_BY_TOPIC:
            topic, desc = args[2:4]
            mipush.push_to_topic(topic, {'target_url': target_url},
                                 description=desc)
        elif push_type == PUSH_ALL:
            desc = args[2]
            mipush.push_to_all({'target_url': target_url}, description=desc)
Esempio n. 4
0
def push_refund_app_msg(refend):
    """ 发送同意app推送 """
    customer_id = refend.buyer_id
    if customer_id:
        target_url = get_target_url(constants.TARGET_TYPE_REFUNDS)
        message = make_refund_message(refend)
        if message:
            mipush_of_android.push_to_account(customer_id,
                                              {'target_url': target_url},
                                              description=message)
            mipush_of_ios.push_to_account(customer_id,
                                          {'target_url': target_url},
                                          description=message)
Esempio n. 5
0
def activity_open_red_packet_push(customer_id):
    """ 活动开红包推送 """
    msg = None
    tpls = PushMsgTpl.objects.filter(id=8, is_valid=True)
    if tpls.exists():
        tpl = tpls[0]
        msg = tpl.get_emoji_content()
    if msg:
        target_url = get_target_url(protocal_constants.TARGET_TYPE_HOME_TAB_1)
        mipush_of_android.push_to_account(customer_id,
                                          {'target_url': target_url},
                                          description=msg)
        mipush_of_ios.push_to_account(customer_id,
                                      {'target_url': target_url},
                                      description=msg)
Esempio n. 6
0
    def push_mama_ordercarry(cls, ordercarry):
        """
        有新的订单收益推送给小鹿妈妈
        """
        customer = get_mama_customer(ordercarry.mama_id)
        target_url = get_target_url(protocal_constants.TARGET_TYPE_VIP_HOME)
        msgtpl = PushMsgTpl.objects.filter(id=5, is_valid=True).first()
        msg    = ''
        if msgtpl:
            money = '%.2f' % ordercarry.carry_num_display()
            nick = ordercarry.contributor_nick
            msg = msgtpl.get_emoji_content().format(money, nick)

        if msg:
            cls.push(customer.id, target_url, msg)
Esempio n. 7
0
    def push_product_to_customer(cls, customer_id, modelproduct):
        """
        给用户推送商品
        """
        product_url = modelproduct.item_product.get_weburl()
        params = {'product_id': product_url}
        target_url = get_target_url(protocal_constants.TARGET_TYPE_PRODUCT, params=params)
        msg = None

        mstpl = PushMsgTpl.objects.filter(id=11, is_valid=True).first()
        if mstpl:
            msg = mstpl.get_emoji_content().format(modelproduct.name)

        if msg:
            cls.push(customer_id, target_url, msg)
Esempio n. 8
0
 def push_message_to_app(self, customer_id):
     """
     给用户客户端推送消息
     """
     site_url = 'http://m.xiaolumeimei.com/sale/promotion/xlsampleorder/'
     desc = choice(self.descs)
     target_url = get_target_url(TARGET_TYPE_WEBVIEW, {
         'is_native': 1,
         'url': site_url
     })
     mipush_of_android.push_to_account(customer_id,
                                       {'target_url': target_url},
                                       description=desc)
     mipush_of_ios.push_to_account(customer_id, {'target_url': target_url},
                                   description=desc)
Esempio n. 9
0
def user_coupon_release_push(customer_id, push_tpl_id=None, extra_content=None):
    """优惠券发放推送"""
    tpl = PushMsgTpl.objects.filter(id=push_tpl_id, is_valid=True).first()
    if not tpl:
        return
    tpl_content = tpl.tpl_content.format(extra_content) if extra_content else tpl.tpl_content
    msg = tpl.get_emoji_content(abs_content=tpl_content)
    if msg:
        target_url = get_target_url(protocal_constants.TARGET_TYPE_HOME_TAB_1)
        mipush_of_android.push_to_account(customer_id,
                                          {'target_url': target_url},
                                          description=msg)
        mipush_of_ios.push_to_account(customer_id,
                                      {'target_url': target_url},
                                      description=msg)
Esempio n. 10
0
def push_msg_to_topic_mama(message):
    """ 发送九张图更新app推送(批量) """
    target_url = get_target_url(protocal_constants.TARGET_TYPE_HOME_TAB_1)
    if message:
        mipush_of_android.push_to_topic(push_constants.TOPIC_XLMM_A,
                                        {'target_url': target_url},
                                        description=message)
        mipush_of_ios.push_to_topic(push_constants.TOPIC_XLMM_A,
                                    {'target_url': target_url},
                                    description=message)

        mipush_of_android.push_to_topic(push_constants.TOPIC_XLMM_VIP,
                                        {'target_url': target_url},
                                        description=message)
        mipush_of_ios.push_to_topic(push_constants.TOPIC_XLMM_VIP,
                                    {'target_url': target_url},
                                    description=message)