Example #1
0
 def __init__(self, appsecret_android, app_pkg_name, appsecret_ios, bundle_id):
     # Constants.use_official()
     # Constants.use_sandbox()
     self._appsecret_android = appsecret_android
     self._appsecret_ios = appsecret_ios
     self._bundle_id = bundle_id
     self._app_pkg_name = app_pkg_name
     self._sender_android = APISender(self._appsecret_android)
     self._sender_ios = APISender(self._appsecret_ios)
Example #2
0
def push_msg_to_ios(userid,usertoken, package_name, title, subtitle, body):
    APP_SecKey = r"XWd6+oOcSmliC4jJJsdrcw=="
    result_code = 0
    try:
        message_ios10 = PushMessage() \
            .restricted_package_name(package_name) \
            .aps_title(title) \
            .aps_subtitle(subtitle) \
            .aps_body(body) \
            .aps_mutable_content("1") \
            .sound_url("default") \
            .badge(1) \
            .category("action") \
            .extra({"key": "value"})

    except:
        print("get parameters value error ! ", sys.exc_info()[0])
        result_code = 1
        msg = "get parameters value error "
        result = {
            "msg": msg,
            "status": result_code
        }
        return result

    try:
        sender = APISender(APP_SecKey)

        recv_ios = sender.send_to_user_account(message_ios10.message_dict_ios(), userid)
        print(recv_ios)


        tools = APITools(APP_SecKey)
    except:
        print("send msg was failed ! ", sys.exc_info()[0])
        result_code = 1
        msg = "send msg was failed "
    finally:
        msg = "succecss"
        result = {
            "msg": msg,
            "status": result_code
        }
        return result
Example #3
0
def push_msg_to_android(userid,usertoken, package_name, title, description, pass_through,payload):
    APP_SecKey = r"lsoNVMUZH69YvcsLR6SHNQ=="
    result_code = 0
    try:


        # build android message
        message = PushMessage() \
            .restricted_package_name(package_name) \
            .title(title).description(description) \
            .pass_through(pass_through).payload(payload) \
            .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})

    except:
        print("get parameters value error ! ", sys.exc_info()[0])
        msg = "get parameters value error "
        result = {
            "msg": msg,
            "status": result_code
        }
        return result

    try:
        sender = APISender(APP_SecKey)
        recv = sender.send_to_user_account(message.message_dict(), userid)
        print(recv)

    except:
        print("send msg was failed ! ", sys.exc_info()[0])
        result_code = 1
        msg = "send msg was failed "
    finally:
        msg = "succecss"
        result = {
            "msg": msg,
            "status": result_code
        }
        return result
Example #4
0
# coding=utf-8
from time import mktime
from APISender import APISender
from django.conf import settings
from base.APIConstants import Constants
from base.APIMessage import PushMessage
from biz.constants import APP_JUMP_OBEJCT_NEWS, APP_JUMP_OBEJCT_HOT_VIDEO

if settings.ENVIRONMENT == settings.PRODUCTION:
    Constants.use_official()
else:
    Constants.use_sandbox()

android_sender = APISender(settings.XIAOMI_PUSH_APP_SECRET_ANDROID)
ios_sender = APISender(settings.XIAOMI_PUSH_APP_SECRET_IOS)


def broadcast_news(news):
    return broadcast_message(news.title,
                             f'{APP_JUMP_OBEJCT_NEWS}:{news.id}',
                             start_time=news.start_time,
                             end_time=news.end_time)


def broadcast_hot_video(hot_video):
    return broadcast_message(hot_video.name,
                             f'{APP_JUMP_OBEJCT_HOT_VIDEO}:{hot_video.id}',
                             start_time=hot_video.start_time,
                             end_time=hot_video.end_time)

Example #5
0
# coding=utf-8
from APISender import APISender
from base.APIMessage import *
from APITools import *
from APISubscribe import *

# push-demo
sender = APISender('APP_SECRET')

# build android message
message = PushMessage() \
    .restricted_package_name('package_name') \
    .title('这是一条测试消息').description('这是一条测试消息') \
    .pass_through(0).payload('payload') \
    .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})

# build ios message
message_ios = PushMessage() \
    .description("这是一条ios测试消息") \
    .sound_url("default") \
    .badge(1) \
    .category("action") \
    .extra({"key": "value"})

# build ios message
message_ios10 = PushMessage() \
    .aps_title("title") \
    .aps_subtitle("subtitle") \
    .aps_body("body") \
    .aps_mutable_content("1") \
    .sound_url("default") \
Example #6
0
def push_msg_to_android(userid,usertoken, send_packagename, send_title, send_msg, send_msg_desc, send_pass_through):
    APP_SecKey = r"lsoNVMUZH69YvcsLR6SHNQ=="
    result_code = 0
    try:

        #设置app的包名packageName
        #package_name = "com.domain.operationrobot"
        package_name = send_packagename
        #设置在通知栏展示的通知的标题
        title = send_title.replace("'", '')
        #设置要发送的消息内容, 不允许全是空白字符
        msg = send_msg.replace("'", '')
        #设置在通知栏展示的通知描述
        msg_desc = send_msg_desc.replace("'", '')
        #1表示透传, 0表示通知栏, 默认通知栏
        pass_through = int(send_pass_through)

        # build android message
        message = PushMessage() \
            .restricted_package_name(package_name) \
            .title(title).description(msg_desc) \
            .pass_through(pass_through).payload(msg) \
            .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})

    except:
        print("get parameters value error ! ", sys.exc_info()[0])
        msg = "get parameters value error "
        result = {
            "msg": msg,
            "status": result_code
        }
        return result

    try:
        sender = APISender(APP_SecKey)
        recv = sender.send(message.message_dict(), userid)
        print(recv)
        tools = APITools(APP_SecKey)
        # 查询消息状态
        print(tools.query_message_status('msg_id').data)
        # 验证reg_id是否无效
        print(tools.validate_reg_ids(['reg_id1', 'reg_id2']))
        # 获取无效reg_id
        print(tools.query_invalid_reg_ids())
        # 获取无效alias
        print(tools.query_invalid_aliases())
        # 获取设备订阅topic
        print(tools.query_device_topics('package_name', 'reg_id'))
        print(tools.query_device_presence('package_name', ['reg_id1', 'reg_id2']))
        # 获取设备设置alias
        print(tools.query_device_aliases('package_name', 'reg_id'))
        # 检查定时任务是否存在
        print(tools.check_schedule_job_exist('msg_id'))
    except:
        print("send msg was failed ! ", sys.exc_info()[0])
        result_code = 1
        msg = "send msg was failed "
    finally:
        result = {
            "msg": msg,
            "status": result_code
        }
        return result
Example #7
0
def push_msg_to_ios(userid,usertoken, send_packagename, send_title, send_key, send_value, send_msg_desc):
    APP_SecKey = r"XWd6+oOcSmliC4jJJsdrcw=="
    result_code = 0
    try:

        #设置app的包名packageName
        #package_name = "com.domain.operationrobot"
        package_name = send_packagename
        #设置在通知栏展示的通知的标题
        title = send_title.replace("'", '')
        #自定义键值对, 控制客户端行为
        send_key = send_key.replace("'", '')

        #设置在通知栏展示的通知描述
        msg_desc = send_msg_desc.replace("'", '')
    except:
        print("get parameters value error ! ", sys.exc_info()[0])
        result_code = 1
        msg = "get parameters value error "
        result = {
            "msg": msg,
            "status": result_code
        }
        return result

    try:
        sender = APISender(APP_SecKey)
        message_ios = PushMessage() \
            .description(msg_desc) \
            .sound_url("default") \
            .badge(1) \
            .extra({send_key: send_value})
        recv_ios = sender.send(message_ios.message_dict_ios(), userid)
        print(recv_ios)


        tools = APITools(APP_SecKey)
        # 查询消息状态
        print(tools.query_message_status('msg_id').data)
        # 验证reg_id是否无效
        print(tools.validate_reg_ids(['reg_id1', 'reg_id2']))
        # 获取无效reg_id
        print(tools.query_invalid_reg_ids())
        # 获取无效alias
        print(tools.query_invalid_aliases())
        # 获取设备订阅topic
        print(tools.query_device_topics('package_name', 'reg_id'))
        print(tools.query_device_presence('package_name', ['reg_id1', 'reg_id2']))
        # 获取设备设置alias
        print(tools.query_device_aliases('package_name', 'reg_id'))
        # 检查定时任务是否存在
        print(tools.check_schedule_job_exist('msg_id'))
    except:
        print("send msg was failed ! ", sys.exc_info()[0])
        result_code = 1
        msg = "send msg was failed "
    finally:
        result = {
            "msg": msg,
            "status": result_code
        }
        return result
Example #8
0
# coding=utf-8
from APISender import APISender
from base.APIMessage import *
from APITools import *
from APISubscribe import *

# push-demo
sender = APISender('APP_SECRET')

# build android message
message = PushMessage() \
    .restricted_package_name('PACKAGE_NAME') \
    .title('这是一条测试消息').description('这是一条测试消息') \
    .pass_through(0).payload('payload') \
    .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})

# build ios message
message_ios = PushMessage() \
    .description("这是一条ios测试消息") \
    .sound_url("default") \
    .badge(1) \
    .category("action") \
    .extra({"key": "value"})

# build ios message
message_ios10 = PushMessage() \
    .aps_title("title") \
    .aps_subtitle("subtitle") \
    .aps_body("body") \
    .aps_mutable_content("1") \
    .sound_url("default") \
Example #9
0
class MiPush2:
    def __init__(self, appsecret_android, app_pkg_name, appsecret_ios,
                 bundle_id, debug_mode):
        # Constants.use_official()
        # Constants.use_sandbox()
        self._appsecret_android = appsecret_android
        self._appsecret_ios = appsecret_ios
        self._bundle_id = bundle_id
        self._app_pkg_name = app_pkg_name
        self._debug_mode = debug_mode
        self._sender_android = APISender(self._appsecret_android)
        self._sender_ios = APISender(self._appsecret_ios)

    def send_to_alias_android(self,
                              str_uids,
                              title,
                              desc,
                              payload,
                              pass_through=0):
        message = PushMessage().restricted_package_name(
            self._app_pkg_name).payload(payload).pass_through(pass_through)
        if pass_through == 0:
            message = message.title(title).description(desc).notify_type(
                1).extra_element(
                    Constants.extra_param_sound_uri,
                    "android.resource://com.xiaomaoqiu.pet/raw/beep")
        recv = self._sender_android.send_to_alias(message.message_dict(),
                                                  str_uids)
        logging.debug("on send_to_alias_android recv:%s", recv)

    def send_to_alias_ios(self, str_uids, desc, extras):

        logging.info("on send_%s,dict:%s", desc, extras)
        message = PushMessage().description(extras).sound_url("default").badge(
            1).category("action").title("test_title")
        # recv = self._sender1.send_to_alias(message.message_dict_ios(), str_uids)
        recv = self._sender_ios.send_to_alias(message.message_dict_ios(),
                                              str_uids)
        logging.debug("on send_to_alias_ios recv:%s", recv)

    def send_to_useraccount_android(self,
                                    str_uids,
                                    title,
                                    desc,
                                    payload,
                                    pass_through=0):
        message = PushMessage().restricted_package_name(
            self._app_pkg_name).payload(payload).pass_through(pass_through)
        if pass_through == 0:
            message = message.title(title).description(desc)
        recv = self._sender_android.send_to_user_account(
            message.message_dict(), str_uids)
        logging.debug("on send_to_useraccount_android recv:%s", recv)

    def send_to_useraccount_ios(self, str_uids, payload, extra):
        message = PushMessage().description(payload).sound_url(
            "default").badge(0).category("action").title("test_title").extra(
                extra)
        # recv = self._sender1.send_to_alias(message.message_dict_ios(), str_uids)
        logging.debug("ios_push_useraccount_message:%s" %
                      message.message_dict_ios())
        recv = self._sender_ios.send_to_user_account(
            message.message_dict_ios(), str_uids)
        logging.debug("on send_to_alias_ios recv:%s", recv)

    def test_send_to_useraccount_ios(self, str_uids, extras):
        message = PushMessage().description(extras).sound_url("default").badge(
            1).category("action").title("test_title")
        # recv = self._sender1.send_to_alias(message.message_dict_ios(), str_uids)
        recv = self._sender_ios.send_to_user_account(
            message.message_dict_ios(), str_uids)
        logging.debug("on send_to_alias_ios recv:%s", recv)

    def test_send_to_alias_ios(self, str_uids, extras):
        dict = json.loads(extras)

        message = PushMessage().description(extras).sound_url("default").badge(
            1).category("action").title("test_title")
        # recv = self._sender1.send_to_alias(message.message_dict_ios(), str_uids)
        recv = self._sender_ios.send_to_alias(message.message_dict_ios(),
                                              str_uids)
        logging.debug("on send_to_alias_ios recv:%s", recv)
Example #10
0
# coding=utf-8
from APISender import APISender
from base.APIMessage import *
from base.APIConstants import Constants
from APITools import *
from APISubscribe import *
from tweetapi.config import APP_SECRET
# push-demo
Constants.use_official()
sender = APISender(APP_SECRET)

# build android message
# message = PushMessage() \
#     .restricted_package_name('package_name') \
#     .title('run run run').description('run run run') \
#     .pass_through(0).payload('payload') \
#     .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})
#
# # send message android
# recv = sender.send(message.message_dict(), 'RED_ID')
# print recv


tools = APITools(APP_SECRET)
# print tools.query_message_status('msg_id').data
# print tools.validate_reg_ids(['REG_ID', 'RED_ID1'])
# print tools.query_invalid_reg_ids()
# print tools.query_invalid_aliases()
# print tools.query_device_topics('package_name', 'RED_ID')
# print tools.query_device_presence('package_name', ['REG_ID', 'test'])
# print tools.query_device_aliases('package_name', 'REG_ID')
Example #11
0
# coding=utf-8
from APISender import APISender
from base.APIMessage import *
from APITools import *
from APISubscribe import *

# push-demo
sender = APISender('lsoNVMUZH69YvcsLR6SHNQ==')

# build android message
message = PushMessage() \
    .restricted_package_name('PACKAGE_NAME') \
    .title('这是一条测试消息').description('这是一条测试消息') \
    .pass_through(0).payload('payload') \
    .extra({Constants.extra_param_notify_effect: Constants.notify_launcher_activity})

# build ios message
message_ios = PushMessage() \
    .description("这是一条ios测试消息") \
    .sound_url("default") \
    .badge(1) \
    .category("action") \
    .extra({"key": "value"})

# build ios message
message_ios10 = PushMessage() \
    .aps_title("title") \
    .aps_subtitle("subtitle") \
    .aps_body("body") \
    .aps_mutable_content("1") \
    .sound_url("default") \