Ejemplo n.º 1
0
def pushMsgToSingle(sender, receiver, message):
    '''
    push message uploaded from sender to receiver
    sender and receiver are User objects,
    message is string
    '''
    push = IGeTui(HOST, APPKEY, MASTERSECRET)
    trasmission_data = TransmissionTemplate()
    trasmission_data.transmissionType = 1
    trasmission_data.appId = APPID
    trasmission_data.appKey = APPKEY
    trasmission_data.transmissionContent = makeMessage(sender, receiver, message)
    trasmission_data.setPushInfo("", 2, "", "", "", "", "", 1)

    igt_message = IGtSingleMessage()
    igt_message.isOffline = True
    igt_message.offlineExpireTime = 1000 * 3600 * 12
    igt_message.data = trasmission_data
    igt_message.pushNetWorkType = 2

    igt_target = Target()
    igt_target.appId = APPID
    igt_target.clientId = receiver.cid

    ret = push.pushMessageToSingle(igt_message, igt_target)
    return ret
Ejemplo n.º 2
0
def pushMsgToSingle_dispatch(receiver, action, meta, data):
    '''
    push message uploaded from sender to receiver
    sender and receiver are User objects,
    message is string
    '''
    def makeMessage_generic(receiver, action, meta, data):
        msg_body = {
            'action': action,
            'meta': meta,
            'data': data,
        }
        return json.dumps(msg_body)


    push = IGeTui(HOST, APPKEY, MASTERSECRET)
    trasmission_data = TransmissionTemplate()
    trasmission_data.transmissionType = 1
    trasmission_data.appId = APPID
    trasmission_data.appKey = APPKEY
    trasmission_data.transmissionContent = makeMessage_generic(receiver, action, meta, data)
    trasmission_data.setPushInfo("", 2, "", "", "", "", "", "", 1)

    igt_message = IGtSingleMessage()
    igt_message.isOffline = True
    igt_message.offlineExpireTime = 1000 * 3600 * 12
    igt_message.data = trasmission_data
    igt_message.pushNetWorkType = 2

    igt_target = Target()
    igt_target.appId = APPID
    igt_target.clientId = receiver.cid

    ret = push.pushMessageToSingle(igt_message, igt_target)
    return ret
Ejemplo n.º 3
0
def pushGetuiMessageToSingle(cid, content, title, text):
    push = IGeTui(getuiHost, getuiAppKey, getuiMasterSecret)

    template = NotificationTemplateDemo(content, title, text)

    message = IGtSingleMessage()
    message.isOffline = True
    message.offlineExpireTime = 1000 * 3600 * 12
    message.data = template
    message.pushNetWorkType = 1

    target = Target()
    target.appId = getuiAppId
    target.clientId = cid

    ret = push.pushMessageToSingle(message, target)
    print ret
Ejemplo n.º 4
0
def pushMessageToSingle():
    # http的接口
    # push = IGeTui(None, APPKEY, MASTERSECRET,False)
    # https的接口
    # push = IGeTui(None, APPKEY, MASTERSECRET,True)
    # 根据HOST区分是https还是http
    push = IGeTui(HOST, APPKEY, MASTERSECRET)
    # 消息模版:
    # 1.TransmissionTemplate:透传功能模板
    # 2.LinkTemplate:通知打开链接功能模板
    # 3.NotificationTemplate:通知透传功能模板
    # 4.NotyPopLoadTemplate:通知弹框下载功能模板

    #     template = NotificationTemplateDemo()
    # template = LinkTemplateDemo()
    # 新建一个推送模版, 以链接模板为例子,就是说在通知栏显示一条含图标、标题等的通知,用户点击可打开您指定的网页
    template = LinkTemplate()
    template.appId = APPID
    template.appKey = APPKEY
    template.title = u"欢迎使用个推 gs!"
    template.text = u"这是一条single推送消息"
    template.logo = ""
    template.url = "http://www.baidu.com"
    template.transmissionType = 1
    template.transmissionContent = ''
    template.isRing = True
    template.isVibrate = True
    template.isClearable = True
    # template = NotyPopLoadTemplateDemo()
    #     iOS setAPNInfo
    apnpayload = APNPayload()
    apnpayload.badge = 4
    apnpayload.sound = "sound"
    apnpayload.addCustomMsg("payload", "payload")
    #     apnpayload.contentAvailable = 1
    #     apnpayload.category = "ACTIONABLE"

    alertMsg = DictionaryAlertMsg()
    alertMsg.body = 'body'
    alertMsg.actionLocKey = 'actionLockey'
    alertMsg.locKey = 'lockey'
    alertMsg.locArgs = ['locArgs']
    alertMsg.launchImage = 'launchImage'
    # iOS8.2以上版本支持
    #     alertMsg.title = 'Title'
    #     alertMsg.titleLocArgs = ['TitleLocArg']
    #     alertMsg.titleLocKey = 'TitleLocKey'
    apnpayload.alertMsg = alertMsg
    template.setApnInfo(apnpayload)

    message = IGtSingleMessage()
    message.isOffline = True
    message.offlineExpireTime = 1000 * 3600 * 12
    message.data = template
    # message.pushNetWorkType = 2

    target = Target()
    target.appId = APPID
    target.clientId = CID

    try:
        ret = push.pushMessageToSingle(message, target)
        print ret
    except RequestException, e:
        requstId = e.getRequestId()
        ret = push.pushMessageToSingle(message, target, requstId)
        print ret