コード例 #1
0
ファイル: circle.py プロジェクト: hkg36/websockframework
    def POST(self):
        params=web.input()
        cid=int(params.get('cid'))
        from_uid=int(params.get("from_uid",1))
        roleids=[int(one) for one in params.get('roleid',"0").split(',')]
        if not cid:
            return 'need cid'
        content=params.get('content')
        if not content:
            return 'need content'

        with dbconfig.Session() as session:
            query_params=UserCircle.cid==cid
            if len(roleids)>0 and 0 not in roleids:
                query_params=and_(query_params,UserCircle.roleid.in_(roleids))
            allUser=session.query(UserCircle).filter(query_params).all()
            alluid=[one.uid for one in allUser]
            newmsgs=[]
            for to_uid in alluid:
                newmsg=Message()
                newmsg.toid=to_uid
                newmsg.fromid=from_uid
                newmsg.content=content
                newmsg=session.merge(newmsg)
                newmsgs.append(newmsg)
            session.commit()
            msgids=[]
            for newmsg in newmsgs:
                msgids.append(newmsg.msgid)
                json_msg=DefJsonEncoder.encode(newmsg.toJson())
                pusher.rawPush(body=json_msg,headers={},
                                                    routing_key='sys.message_to_notify')

            return DefJsonEncoder.encode({'msgid':msgids})
コード例 #2
0
ファイル: PhoneLogin.py プロジェクト: hkg36/websockframework
    def GET(self):
        params=web.input()
        phone=params.get('phone',None)
        code=params.get('code',None)
        if phone and code:
            vcode=dbconfig.memclient.get(str('vcode:%s'%phone))
            if vcode==code or (phone=="13067575127" and code=='99999'):
                with dbconfig.Session() as session:
                    user_info=session.query(datamodel.user.User).filter(datamodel.user.User.phone==phone).first()
                    if user_info is None:
                        user_info=datamodel.user.User()
                        user_info.phone=phone
                        user_info=session.merge(user_info)
                        session.commit()

                    dbconfig.memclient.delete(str('vcode:%s'%phone))
                    if int(params.get('cryptsession',0)):
                        session_id=BuildCryptSession(user_info.uid)
                        return DefJsonEncoder.encode({'sessionid':session_id,'ws':GetClientWSSite(),'wss':GetClientWSSSite()})
                    else:
                        session_id=GenSession()
                        TIMEOUTTIME=3600*24*5
                        time_out=time.time()+TIMEOUTTIME
                        dbconfig.redisdb.set(str('session:%s'%session_id),DefJsonEncoder.encode({'uid':user_info.uid}),ex=datetime.timedelta(days=180))
                        return DefJsonEncoder.encode({'sessionid':session_id,'timeout':time_out,'ws':GetClientWSSite(),'wss':GetClientWSSSite()})
            else:
                return DefJsonEncoder.encode({'error':'code error'})
        tpl=WebSiteBasePage.jinja2_env.get_template('PhoneLogin.html')
        return tpl.render()
コード例 #3
0
ファイル: circle.py プロジェクト: hkg36/websockframework
    def POST(self):
        params=web.input()
        cid=int(params.get('cid'))
        content=params.get('content')
        from_uid=int(params.get("from_uid",1))
        piclist=params.get('piclist','')
        if len(piclist):
            piclist=piclist.split(',')
        else:
            piclist=[]
        mid=None
        if params.get('mid'):
            mid=int(params.get('mid'))

        newpost=CirclePost()
        newpost.picture_list=piclist
        newpost.cid=cid
        newpost.uid=from_uid
        newpost.content=content
        newpost.mid=mid
        newpost.save()
        json_msg=DefJsonEncoder.encode(newpost.toJson())
        pusher.rawPush(body=json_msg,
                                            routing_key="sys.circle_new_board",headers={"type":"circle.newpost"})
        return DefJsonEncoder.encode({"postid":newpost.postid})
コード例 #4
0
ファイル: PhoneLogin.py プロジェクト: hkg36/websockframework
 def GET(self):
     params=web.input()
     phone=params['phone']
     if not dbconfig.memclient.add(str('sms_timeout:%s'%phone),'ok',time=60):
         return DefJsonEncoder.encode({"msg":"请等待60秒后再重新发送"})
     phonekey=str('vcode:%s'%phone)
     gcode=dbconfig.memclient.get(phonekey)
     if not gcode:
         gcode=str(random.randint(1000,9999))
         dbconfig.memclient.set(phonekey,gcode,time=60*60)
     if int(params.get('notsms',0))==0:
         pusher.sendCode(phone,gcode)
         return '{}'
     else:
         return DefJsonEncoder.encode({'code':gcode})
コード例 #5
0
ファイル: addpost.py プロジェクト: hkg36/websockframework
def run(gid,content=None,pictures=[],video=None,videolen=None,voice=None,voicelen=None,
    lat=None,lng=None):
    if not content and not pictures and not video and not voice:
        return Res(errno=2,error="not conent is not allow")
    newpost=GroupPost()
    newpost.gid=gid
    newpost.uid=BackEndEnvData.uid
    if content:
        newpost.content=content
    if pictures:
        newpost.pictures=pictures
    if video:
        newpost.video=video
        newpost.voicelen=videolen
    if voice:
        newpost.voice=voice
        newpost.voicelen=voicelen
    if lat is not None and lng is not None:
        newpost.position=[lng,lat]
    newpost.save()

    json_msg=DefJsonEncoder.encode(newpost.toJson())
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key="group.change",headers={"type":"group.newpost"},
                                        compression='gzip')

    return Res({'postid':newpost.postid})
コード例 #6
0
def RequestWork(params,body,reply_queue):
    post=json.loads(body)
    touid=params['uid']
    with dbconfig.Session() as session:
        to_push=DefJsonEncoder.encode({"push":True,
                                    "type":params['type'],
                                    "data":post
                                })
        conn=session.query(ConnectionInfo).filter(ConnectionInfo.uid==touid).first()
        if conn:
            QueueWork.producer.publish(body=to_push,delivery_mode=2,headers={"connid":conn.connection_id},
                                          routing_key=conn.queue_id,
                                          compression='gzip',
                                          exchange="front_end")
        else:
            iosdev=session.query(IOSDevice).filter(IOSDevice.uid==touid).first()
            #print 'ios device:',len(iosdevices)
            push_word=None
            #print push_word
            if push_word:
                if iosdev.is_debug:
                    publish_debug_exchange.publish("body",headers={"message":push_word,
                      "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                else:
                    publish_release_exchange.publish("body",headers={"message":push_word,
                      "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                session.query(IOSDevice).filter(IOSDevice.uid==touid).update({IOSDevice.badge:IOSDevice.badge+1},False)
                session.commit()
コード例 #7
0
ファイル: user.py プロジェクト: hkg36/websockframework
 def GET(self):
     params=web.input()
     sessionid=params['sessionid']
     uiddata=DecodeCryptSession(sessionid)
     if uiddata:
         return DefJsonEncoder.encode({'uid':uiddata['uid']})
     return dbconfig.redisdb.get('session:'+params['sessionid'])
コード例 #8
0
def RequestWork(params, body, reply_queue):
    post = json.loads(body)
    uid = post["uid"]
    with dbconfig.Session() as session:
        phonelist = session.query(PhoneBook).filter(PhoneBook.uid == uid).all()
        phones = []
        for pinfo in phonelist:
            phones.append(pinfo.phone)
        fds = session.query(FriendList).filter(FriendList.uid == uid).all()
        friendids = []
        for fd in fds:
            friendids.append(fd.friendid)

        if friendids:
            users = session.query(User).filter(and_(User.phone.in_(phones), not_(User.uid.in_(friendids)))).all()
        else:
            users = session.query(User).filter(User.phone.in_(phones)).all()
        userlist = []
        for u in users:
            userlist.append(u.toJson(showphone=True))
        conn = session.query(ConnectionInfo).filter(ConnectionInfo.uid == uid).first()
    to_push = DefJsonEncoder.encode({"push": True, "type": "fromphonebook", "data": {"users": userlist}})
    QueueWork.producer.publish(
        body=to_push,
        delivery_mode=2,
        headers={"connid": conn.connection_id},
        routing_key=conn.queue_id,
        compression="gzip",
        exchange="front_end",
    )
コード例 #9
0
ファイル: user.py プロジェクト: hkg36/websockframework
    def GET(self):
        params=web.input()
        phone=params['phone']
        if len(phone)<6:
            return 'phone too short'
        with dbconfig.Session() as session:
            users=session.query(User).filter(User.phone.like(phone+'%')).all()
            alluser=[one.toJson() for one in users]

            web.header('Content-Type', 'text/plain')
            return DefJsonEncoder.encode(alluser)
コード例 #10
0
def RequestWork(params,body,reply_queue):
    post=json.loads(body)
    gid=post['gid']
    with dbconfig.Session() as session:
        userlist=session.query(GroupMember).filter(GroupMember.gid==gid).all()
        uids=set([one.uid for one in userlist])

        allconn=session.query(ConnectionInfo).filter(ConnectionInfo.uid.in_(list(uids))).all()
        to_push=DefJsonEncoder.encode({"push":True,
                                    "type":params['type'],
                                    "data":post
                                })
        online_uids=set()
        queue_group={}
        for conn in allconn:
            online_uids.add(conn.uid)
            connids=queue_group.get(conn.queue_id,None)
            if connids is None:
                connids=[]
                queue_group[conn.queue_id]=connids
            connids.append(conn.connection_id)
        for conn_id in queue_group:
            QueueWork.producer.publish(body=to_push,delivery_mode=2,headers={"connid":"$".join(queue_group[conn_id])},
                                          routing_key=conn_id,
                                          compression='gzip',
                                          exchange="front_end")
        offline_uids=list(uids-online_uids)
        #print "offline_uids",offline_uids
        if len(offline_uids)>0:
            iosdevices=session.query(IOSDevice).filter(IOSDevice.uid.in_(offline_uids)).all()
            #print 'ios device:',len(iosdevices)
            group_info=session.query(Group).filter(Group.gid==gid).first()
            user_info=GetUserInfo(post['uid'])
            push_word=None
            if params['type']=="group.newpost":
                push_word=u"%s在%s"%(user_info['user']['nick'],group_info.group_name)
                if 'content' in post:
                    if len(post['content'])>20:
                        push_word+=u"说 %s..."%(post['content'][0:20])
                    else:
                        push_word+=u"说 %s"%(post['content'])
                elif 'pictures' in post:
                    push_word+=u"发了几张图片"
            #print push_word
            if push_word:
                for iosdev in iosdevices:
                    if iosdev.is_debug:
                        publish_debug_exchange.publish("body",headers={"message":push_word,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                    else:
                        publish_release_exchange.publish("body",headers={"message":push_word,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                session.query(IOSDevice).filter(IOSDevice.uid.in_(offline_uids)).update({IOSDevice.badge:IOSDevice.badge+1},False)
                session.commit()
コード例 #11
0
ファイル: user.py プロジェクト: hkg36/websockframework
    def POST(self):
        params=web.input(from_uid=1)
        from_uid=int(params.get('from_uid',1))
        to_uid=int(params.get('to_uid',0))
        if not to_uid:
            return 'need to_uid'
        content=params.get('content')
        if not content:
            return 'need content'

        with dbconfig.Session() as session:
            newmsg=Message()
            newmsg.toid=to_uid
            newmsg.fromid=from_uid
            newmsg.content=content
            newmsg=session.merge(newmsg)
            session.commit()

            json_msg=DefJsonEncoder.encode(newmsg.toJson())
            pusher.rawPush(body=json_msg,headers={},
                                                routing_key='sys.message_to_notify')
            return DefJsonEncoder.encode({'msgid':newmsg.msgid})
コード例 #12
0
def RequestWork(params,body,reply_queue):
    post=json.loads(body)
    cid=post['cid']
    with dbconfig.Session() as session:
        uids=GetGroupUser(cid)

        allconn=session.query(ConnectionInfo).filter(ConnectionInfo.uid.in_(list(uids))).all()
        to_push=DefJsonEncoder.encode({"push":True,
                                    "type":params['type'],
                                    "data":post
                                })
        online_uids=set()
        queue_group={}
        for conn in allconn:
            online_uids.add(conn.uid)
            connids=queue_group.get(conn.queue_id,None)
            if connids is None:
                connids=[]
                queue_group[conn.queue_id]=connids
            connids.append(conn.connection_id)
        for conn_id in queue_group:
            QueueWork.producer.publish(body=to_push,delivery_mode=2,headers={"connid":"$".join(queue_group[conn_id])},
                                          routing_key=conn_id,
                                          compression='gzip',
                                          exchange="front_end")
        offline_uids=list(uids-online_uids)
        #print "offline_uids",offline_uids
        if len(offline_uids)>0:
            iosdevices=session.query(IOSDevice).filter(IOSDevice.uid.in_(offline_uids)).all()
            #print 'ios device:',len(iosdevices)
            cdef=GetCircleDef(cid)
            push_word=None
            if params['type']=="circle.newboard":
                if len(post['board'])>50:
                    push_word=u"%s %s..."%(cdef.name,post['board'][0:50])
                else:
                    push_word=u"%s %s"%(cdef.name,post['board'])
            if params['type']=="circle.newpost":
                user=GetUserInfo(post['uid'])
                push_word=u"%s在%s发了新动态"%(user.nick,cdef.name)
            #print push_word
            if push_word:
                for iosdev in iosdevices:
                    if iosdev.is_debug:
                        publish_debug_exchange.publish("body",headers={"message":push_word,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                    else:
                        publish_release_exchange.publish("body",headers={"message":push_word,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                session.query(IOSDevice).filter(IOSDevice.uid.in_(offline_uids)).update({IOSDevice.badge:IOSDevice.badge+1},False)
                session.commit()
コード例 #13
0
ファイル: addreply.py プロジェクト: hkg36/websockframework
def run(postid,content):
    newpost=GroupPost.objects(postid=postid).first()
    newreply=ReplyRecord()
    newreply.uid=BackEndEnvData.uid
    newreply.content=content
    newpost.replys.append(newreply)
    newpost.save()

    json_msg=DefJsonEncoder.encode({'reply':newreply.toJson(),"gid":newpost.gid,'postid':newpost.postid})
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key="group.change",headers={"type":"group.newreply"},
                                        compression='gzip')

    return Res({"post":newreply.toJson()})
コード例 #14
0
ファイル: addreply.py プロジェクト: hkg36/websockframework
def run(postid,content):
    newpost=CirclePost.objects(postid=postid).first()
    newreply=ReplyRecord()
    newreply.uid=BackEndEnvData.uid
    newreply.content=content
    newpost.replys.append(newreply)
    newpost.save()

    json_msg=DefJsonEncoder.encode({"reply":newreply.toJson(),
                                                        "postid":postid,
                                                        "cid":newpost.cid})
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key="sys.circle_new_board",headers={"type":"circle.newreply"},
                                        compression='gzip')
    return Res({"post":newreply.toJson()})
コード例 #15
0
ファイル: addpost.py プロジェクト: hkg36/websockframework
def run(cid,content,pictures=[],mid=None):
    if isinstance(pictures,list)==False:
        pictures=[pictures]
    newpost=CirclePost()
    newpost.picture_list=pictures
    newpost.cid=cid
    newpost.uid=BackEndEnvData.uid
    newpost.content=content
    newpost.mid=mid
    newpost.save()
    json_msg=DefJsonEncoder.encode(newpost.toJson())
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key="sys.circle_new_board",headers={"type":"circle.newpost"},
                                        compression='gzip')
    return Res({"postid":newpost.postid})
コード例 #16
0
ファイル: circle.py プロジェクト: hkg36/websockframework
 def POST(self):
     params=web.input()
     cid=int(params.get('cid'))
     board=params.get('board')
     with dbconfig.Session() as session:
         cdef=session.query(CircleDef).filter(CircleDef.cid==cid).first()
         cdef.board=board
         cdef=session.merge(cdef)
         cbhistory=CircleBoardHistory()
         cbhistory.cid=cid
         cbhistory.board=board
         cbhistory=session.merge(cbhistory)
         session.commit()
         pusher.rawPush(routing_key="sys.circle_new_board",headers={"type":"circle.newboard"},body=DefJsonEncoder.encode(cbhistory.toJson()))
     return DefJsonEncoder.encode({"cid":cid,"board":board})
コード例 #17
0
def RequestWork(params, body, reply_queue):
    post = json.loads(body)
    toid = post["toid"]
    with dbconfig.Session() as session:
        conn = session.query(ConnectionInfo).filter(ConnectionInfo.uid == toid).first()
        if conn:
            to_push = DefJsonEncoder.encode({"push": True, "type": "newmsg", "data": {"message": post}})
            QueueWork.producer.publish(
                body=to_push,
                delivery_mode=2,
                headers={"connid": conn.connection_id},
                routing_key=conn.queue_id,
                compression="gzip",
                exchange="front_end",
            )
        else:
            iosdev = session.query(IOSDevice).filter(IOSDevice.uid == toid).first()
            if iosdev:
                user = session.query(User).filter(User.uid == post["fromid"]).first()
                allword = None
                if post.get("content", None):
                    content = post["content"]
                    if content.startswith("sticker_126"):
                        allword = u"%s发了一个表情" % (user.nick)
                    else:
                        allword = u"%s:%s" % (user.nick, post["content"])
                elif post.get("picture", None):
                    allword = u"%s发了一张图片" % (user.nick)
                elif post.get("video", None):
                    allword = u"%s发了一段视频" % (user.nick)
                elif post.get("voice", None):
                    allword = u"%s发了一段音频" % (user.nick)
                elif post.get("lat", None):
                    allword = u"%s发了一个位置" % (user.nick)
                if allword:
                    if iosdev.is_debug:
                        publish_debug_exchange.publish(
                            "body", headers={"message": allword, "uhid": iosdev.device_token, "badge": iosdev.badge + 1}
                        )
                    else:
                        publish_release_exchange.publish(
                            "body", headers={"message": allword, "uhid": iosdev.device_token, "badge": iosdev.badge + 1}
                        )

                    iosdev.badge = iosdev.badge + 1
                    iosdev = session.merge(iosdev)
                    session.commit()
コード例 #18
0
ファイル: likepost.py プロジェクト: hkg36/websockframework
def run(postid):
    post=CirclePost.objects(postid=postid).first()
    for one in post.likes:
        if one.uid==BackEndEnvData.uid:
            return Res({'like':one.toJson()})
    newlike=LikeRecord()
    newlike.uid=BackEndEnvData.uid
    post.likes.append(newlike)
    post.save()

    json_msg=DefJsonEncoder.encode({"like":newlike.toJson(),"postid":post.postid,"cid":post.cid})
    BackEndEnvData.queue_producer.publish(body=json_msg,
                                        headers={"uid":post.uid,"type":"circle.post.newlike"},
                                        delivery_mode=2,
                                        routing_key='sys.push_to_user',
                                        compression='gzip')

    return Res({'like':newlike.toJson()})
コード例 #19
0
def RequestWork(params, body, reply_queue):
    event = json.loads(body)
    toid = event["touid"]
    eo = LoadEvent(event)
    if eo is None:
        return
    with dbconfig.Session() as session:
        conn = session.query(ConnectionInfo).filter(ConnectionInfo.uid == toid).first()
        if conn:
            to_push = DefJsonEncoder.encode({"push": True, "type": "event", "data": {"event": eo}})
            QueueWork.producer.publish(
                body=to_push,
                delivery_mode=2,
                headers={"connid": conn.connection_id},
                routing_key=conn.queue_id,
                compression="gzip",
                exchange="front_end",
            )
コード例 #20
0
ファイル: invite_code.py プロジェクト: hkg36/websockframework
def run(cid,roleid):
    with dbconfig.Session() as session:
        self_uc=session.query(UserCircle).filter(and_(UserCircle.uid==BackEndEnvData.uid,UserCircle.cid==cid)).first()
        if self_uc is None:
            return Res(errno=2,error="not in circle")
        if roleid!=self_uc.roleid:
            circles=session.query(CircleRole).filter(and_(CircleRole.cid==cid,CircleRole.roleid.in_((roleid,self_uc.roleid)))).all()
            self_level=0
            to_set_level=10000000
            for ci in circles:
                if ci.roleid==roleid:
                    to_set_level=ci.level
                elif ci.roleid==self_uc.roleid:
                    self_level=ci.level
            if self_level<to_set_level:
                return Res(errno=2,error="level too low")

        vcode=GenSession(8)
        dbconfig.memclient.set("circleinvite:"+vcode,DefJsonEncoder.encode({"uid":BackEndEnvData.uid,"cid":cid,"roleid":roleid}),time=45*60)
        return Res({"vcode":vcode})
コード例 #21
0
ファイル: invite.py プロジェクト: hkg36/websockframework
def run(phone,nick,headpic=None,sex=None,birthday = None,marriage = 0,height = 0,position = None,join_cid=None,join_roleid=None):
    with dbconfig.Session() as session:
        user=session.query(User).filter(User.phone==phone).first()
        if user is not None:
            return Res({'user':user.toJson()},errno=2002,error=u"手机号对应的用户已存在")
    uinl=UserInviteLog.objects(uid=BackEndEnvData.uid,phone=phone).first()
    if uinl is None:
        uinl=UserInviteLog()
        uinl.uid=BackEndEnvData.uid
    uinl.nick=nick
    uinl.phone=phone
    if headpic:
        uinl.headpic=headpic
    if sex:
        uinl.sex=sex
    if birthday:
        uinl.birthday=birthday
    if marriage:
        uinl.marriage=marriage
    if height:
        uinl.height=height
    if position:
        uinl.position=position
    if join_cid:
        uinl.join_cid=join_cid
        with dbconfig.Session() as session:
            cdef=session.query(CircleDef).filter(CircleDef.cid==join_cid).first()
        uinl.join_roleid= cdef.default_roleid

    if (uinl.sms_send_time is None or (datetime.datetime.now()-uinl.sms_send_time).days>1):
        uinl.sms_send_time=datetime.datetime.now()

        userself=session.query(User).filter(User.uid==BackEndEnvData.uid).first()
        json_msg=DefJsonEncoder.encode({'phone':str(phone),
                                        "content":u"手机号%s(%s)的用户邀请你一起玩『来信』,点这里下载 http://t.cn/RvYAd47 "%(userself.phone,userself.nick)})
        BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                          exchange='sys.sms',routing_key='sms.ad',compression='gzip')
    uinl.save()
    return Res({})
コード例 #22
0
def AddLikeNotify(postlike):
    json_msg=DefJsonEncoder.encode(postlike.toJson())
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key='sys.newlike',
                                        compression='gzip')
コード例 #23
0
                return params,resbody
                #return params,'no function'
            try:
                BackEndEnvData.reply_queue=reply_queue
                BackEndEnvData.connection_id=params.get('connid')
                BackEndEnvData.client_ip=params.get('cip')
                if params.get("uid"):
                    BackEndEnvData.uid=int(params.get('uid'))
                result=mfunc(**function_params)
                if result is None:
                    return
                #result['push']=False
                if 'cdata' in request and isinstance(result,dict):
                    result['cdata']=request['cdata']
                if isinstance(result,(dict,list)):
                    return params,DefJsonEncoder.encode(result)
                elif isinstance(result,basestring):
                    return params,result
            except BaseException,e:
                return params,traceback.format_exc()
    return params,"error"

if __name__ == '__main__':
    function_list=LoadProcFunctionList()

    config_model='configs.frontend'
    opts, args=getopt.getopt(sys.argv[1:],'c:',
                             ['config='])
    for k,v in opts:
        if k in ('-c','--config'):
            config_model=v
コード例 #24
0
def AddMessageTrans(newmessage):
    json_msg=DefJsonEncoder.encode(newmessage)
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key='sys.message_to_notify',
                                        compression='gzip')
コード例 #25
0
def AddPhoneBookUpdated(uid):
    json_msg=DefJsonEncoder.encode({'uid':uid})
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key='sys.user_phonebook_update',
                                        compression='gzip')
コード例 #26
0
def AddEventNotify(event):
    json_msg=DefJsonEncoder.encode(event.toJson())
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key='sys.event',
                                        compression='gzip')
コード例 #27
0
def AddReplyNotify(reply):
    json_msg=DefJsonEncoder.encode(reply.toJson())
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                        routing_key='sys.newreply',
                                        compression='gzip')
コード例 #28
0
def AddSMS(phone,code):
    json_msg=DefJsonEncoder.encode({'phone':str(phone),"content":u"您的来信验证码为:%s,请在5分钟内输入完成验证。【莱福思】"%str(code)})
    BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2,
                                          exchange='sys.sms',routing_key='sms.code',compression='gzip')
コード例 #29
0
def RequestWork(params,body,reply_queue):
    #print body
    post=json.loads(body)
    toids={post['uid'],post['recommend_uid']}
    product_name=post['desc'] if 'desc' in post else post['productdesc']
    with dbconfig.Session() as session:
        conns=session.query(ConnectionInfo).filter(ConnectionInfo.uid.in_(list(toids))).all()
        if len(conns)>0:
            to_push=DefJsonEncoder.encode({"push":True,
                                        "type":"paylog",
                                        "data":{
                                            "log":post
                                        }
                                    })
            for conn in conns:
                toids.remove(conn.uid)
                QueueWork.producer.publish(body=to_push,delivery_mode=2,headers={"connid":conn.connection_id},
                                              routing_key=conn.queue_id,
                                              compression='gzip',
                                              exchange="front_end")
        iosdevs=session.query(IOSDevice).filter(IOSDevice.uid.in_(list(toids))).all()
        if len(iosdevs)>0:
            try:
                if post['paystate']==1:
                    allword=u"订单[%s] %.2f元,已支付成功,详情可查看订单历史"%(product_name,float(post['amount'])/100)
                else:
                    allword=u"订单[%s] %.2f元,支付失败,详情可查看订单历史"%(product_name,float(post['amount'])/100)
                for iosdev in iosdevs:
                    if iosdev.is_debug:
                        publish_debug_exchange.publish("body",headers={"message":allword,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                    else:
                        publish_release_exchange.publish("body",headers={"message":allword,
                          "uhid":iosdev.device_token,"badge":iosdev.badge+1})
                    iosdev.badge=iosdev.badge+1
                    iosdev=session.merge(iosdev)
                session.commit()
            except Exception,e:
                pass

        if post['paystate']!=1:
            return
        user_info=session.query(User).filter(User.uid==post['uid']).first()
        if user_info is None:
            #print 'user not found'
            return

        msg_content=u"%s(%s) 预订了 %s (%s 支付%.2f元)"%(user_info.phone,user_info.nick,product_name,
                                                          time.strftime("%m-%d %H:%M",time.localtime(post['create_time'])),float(post['amount'])/100)

        to_sendsms=session.query(StoreSmsNotify).filter(or_(StoreSmsNotify.mid==0,StoreSmsNotify.mid==None,StoreSmsNotify.mid==post['mid'])).all()
        for ssn in to_sendsms:
            QueueWork.producer.publish(DefJsonEncoder.encode({'content':msg_content,'phone':ssn.phone}),routing_key='sms.code',exchange='sys.sms')

        to_notifys=session.query(StoreWeixinNotify).filter(or_(StoreWeixinNotify.mid==0,StoreWeixinNotify.mid==None,StoreWeixinNotify.mid==post['mid'])).all()
        to_weixin_user=set()
        for noti_one in to_notifys:
            to_weixin_user.add(noti_one.openid)
        if len(to_weixin_user)==0:
            return
        send_weixin.publish(DefJsonEncoder.encode({
            'weixin_users':list(to_weixin_user),
            'content':msg_content
        }))
コード例 #30
0
def AddPostPublish(newpost):
    json_post=DefJsonEncoder.encode(newpost)
    BackEndEnvData.queue_producer.publish(body=json_post,delivery_mode=2,
                                      routing_key='sys.post_to_notify',
                                      compression='gzip')