Ejemplo n.º 1
0
def process(req_buf):
    req_pkt = pack_utils.pre_decode(buf=req_buf)
    uin = req_pkt.uin

    usr = usr_info.query(uin)
    session = usr.get('session')

    req_pkt = pack_utils.decode(req_buf, '')
    req = Post.Request()
    req.ParseFromString(req_pkt.data)

    # TODO:
    access_token = bind_accounts.query_access_token(
        uin=req.base_request.uin,
        account_type='weixin.qq.com'
    )

    err_code, err_str, extra = timeline.post_multi(access_token, req.media_id, req.comment)
    logging.debug("try timeline post err = %d, %s" % (err_code, err_str))

    # construct post response
    resp = Post.Response()
    resp.id = 0

    if err_code == errors.ERR_NONE:
        resp.base_response.err_code = works_pb2.ERR_NONE
        resp.base_response.err_str = 'good luck'

    elif err_code == errors.ERR_ACCESS_TOKEN_EXPIRED:
        # access token expired, renew it
        resp.base_response.err_code, resp.base_response.err_str = bind_accounts.renew_access_token(uin)
        if resp.base_response.err_code == errors.ERR_NONE:
            access_token = bind_accounts.query_access_token(
                uin=req.base_request.uin,
                account_type='weixin.qq.com'
            )
            logging.debug("renewed user access token, %s" % access_token)

            # post again
            resp.base_response.err_code, resp.base_response.err_str, extra = timeline.post_multi(
                access_token, req.media_id, req.comment)

        else:
            # renew failed
            logging.debug("renewed user access token failed, err = %d, %s"
                          % (resp.base_response.err_code,
                             resp.base_response.err_str))

    else:
        resp.base_response.err_code = err_code
        resp.base_response.err_str = err_str

    resp_buf = pack_utils.encode(
        buf=resp.SerializeToString(),
        encrypt=Packet.CRYPT_NONE,
        key=session)

    return resp_buf
Ejemplo n.º 2
0
def process(req_buf):
    req_pkt = pack_utils.pre_decode(buf=req_buf)
    uin = req_pkt.uin

    usr = usr_info.query(uin)
    session = usr.get('session')

    req_pkt = pack_utils.decode(req_buf, '')
    req = Post.Request()
    req.ParseFromString(req_pkt.data)

    # TODO:
    access_token = bind_accounts.query_access_token(
        uin=req.base_request.uin, account_type='weixin.qq.com')

    err_code, err_str, extra = timeline.post_multi(access_token, req.media_id,
                                                   req.comment)
    logging.debug("try timeline post err = %d, %s" % (err_code, err_str))

    # construct post response
    resp = Post.Response()
    resp.id = 0

    if err_code == errors.ERR_NONE:
        resp.base_response.err_code = works_pb2.ERR_NONE
        resp.base_response.err_str = 'good luck'

    elif err_code == errors.ERR_ACCESS_TOKEN_EXPIRED:
        # access token expired, renew it
        resp.base_response.err_code, resp.base_response.err_str = bind_accounts.renew_access_token(
            uin)
        if resp.base_response.err_code == errors.ERR_NONE:
            access_token = bind_accounts.query_access_token(
                uin=req.base_request.uin, account_type='weixin.qq.com')
            logging.debug("renewed user access token, %s" % access_token)

            # post again
            resp.base_response.err_code, resp.base_response.err_str, extra = timeline.post_multi(
                access_token, req.media_id, req.comment)

        else:
            # renew failed
            logging.debug(
                "renewed user access token failed, err = %d, %s" %
                (resp.base_response.err_code, resp.base_response.err_str))

    else:
        resp.base_response.err_code = err_code
        resp.base_response.err_str = err_str

    resp_buf = pack_utils.encode(buf=resp.SerializeToString(),
                                 encrypt=Packet.CRYPT_NONE,
                                 key=session)

    return resp_buf
def process(req_buf):
    req_pkt = pack_utils.pre_decode(buf=req_buf)
    uin = req_pkt.uin

    usr = usr_info.query(uin)
    session = usr.get('session')
    logging.info('session=%s, uin=%d' % (session, uin))

    req_pkt = pack_utils.decode(buf=req_buf, key=session)
    req = UpdateWeChatAccount.Request()
    req.ParseFromString(req_pkt.data)

    # update from wechat server
    _info = token.authorize_code(req.code)

    # prepare for return
    resp = UpdateWeChatAccount.Response()
    resp.bind_account.openid = _info.get('openid')
    resp.bind_account.type = 'weixin.qq.com'
    resp.bind_account.access_token = _info.get('access_token')
    resp.bind_account.refresh_token = _info.get('refresh_token')
    resp.bind_account.expires_in = _info.get('expires_in')
    resp.bind_account.display = _info.get('display')

    # update server side record
    bind_accounts.update(
        uin=req.base_request.uin,
        openid=resp.bind_account.openid,
        account_type=resp.bind_account.type,
        access_token=resp.bind_account.access_token,
        refresh_token=resp.bind_account.refresh_token,
        expires_in=resp.bind_account.expires_in,
        display=resp.bind_account.display
    )

    resp.base_response.err_code = works_pb2.ERR_NONE
    resp_buf = pack_utils.encode(
        buf=resp.SerializeToString(),
        encrypt=Packet.CRYPT_NONE,
        key=session,
        uin=req_pkt.uin
    )
    return resp_buf
def process(req_buf):
    req_pkt = pack_utils.pre_decode(buf=req_buf)
    uin = req_pkt.uin

    usr = usr_info.query(uin)
    session = usr.get('session')
    logging.info('session=%s, uin=%d' % (session, uin))

    req_pkt = pack_utils.decode(buf=req_buf, key=session)
    req = UpdateWeChatAccount.Request()
    req.ParseFromString(req_pkt.data)

    # update from wechat server
    _info = token.authorize_code(req.code)

    # prepare for return
    resp = UpdateWeChatAccount.Response()
    resp.bind_account.openid = _info.get('openid')
    resp.bind_account.type = 'weixin.qq.com'
    resp.bind_account.access_token = _info.get('access_token')
    resp.bind_account.refresh_token = _info.get('refresh_token')
    resp.bind_account.expires_in = _info.get('expires_in')
    resp.bind_account.display = _info.get('display')

    # update server side record
    bind_accounts.update(uin=req.base_request.uin,
                         openid=resp.bind_account.openid,
                         account_type=resp.bind_account.type,
                         access_token=resp.bind_account.access_token,
                         refresh_token=resp.bind_account.refresh_token,
                         expires_in=resp.bind_account.expires_in,
                         display=resp.bind_account.display)

    resp.base_response.err_code = works_pb2.ERR_NONE
    resp_buf = pack_utils.encode(buf=resp.SerializeToString(),
                                 encrypt=Packet.CRYPT_NONE,
                                 key=session,
                                 uin=req_pkt.uin)
    return resp_buf
Ejemplo n.º 5
0
def process(req_buf):
    req_pkt = pack_utils.pre_decode(buf=req_buf)
    uin = req_pkt.uin

    usr = usr_info.query(uin)
    session = usr.get('session')

    req_pkt = pack_utils.decode(buf=req_buf, key=session)
    req = GetWeChatUploadToken.Request()
    req.ParseFromString(req_pkt.data)

    resp = GetWeChatUploadToken.Response()
    resp.base_response.err_code = works_pb2.ERR_NONE
    resp.token = token.get_token()

    resp_buf = pack_utils.encode(
        buf=resp.SerializeToString(),
        encrypt=Packet.CRYPT_NONE,
        key=session,
        uin=uin
    )
    return resp_buf
Ejemplo n.º 6
0
def process(req_buf):
    private_key = rsa.PrivateKey(
        11176276734117980437, 65537, 6939363295624337393, 12879322847, 867768971)

    req_pkt = pack_utils.decode(buf=req_buf, key=private_key)
    auth_req = Auth.Request()
    auth_req.ParseFromString(req_pkt.data)

    logging.debug('request username = %s, password = %s' % (auth_req.username, auth_req.password))

    auth_resp = Auth.Response()
    auth_resp.base_response.err_code = works_pb2.ERR_NONE
    auth_resp.base_response.err_str = 'good luck'
    auth_resp.uin = 100000
    auth_resp.session_key = 'hello'

    resp_buf = pack_utils.encode(
        buf=auth_resp.SerializeToString(),
        cookie='',
        encrypt=Packet.CRYPT_NONE,
        key='password')
    return resp_buf
Ejemplo n.º 7
0
req_buf = pack_utils.encode(
    buf=post_req.SerializeToString(), key=public_key, cookie='cookie', version=client_ver,
    device_id='0123456789ABCDEF',
    encrypt=pack_utils.Packet.CRYPT_NONE, func_id=works_pb2.FUNCID_POST, ret_code=0, uin=uin)

print req_buf

import httplib

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
# conn = httplib.HTTPConnection("throughglass.sourceforge.net")
conn = httplib.HTTPConnection("192.168.1.105:8080")
conn.request("POST", "/cgi-bin/post.py", req_buf, headers)
response = conn.getresponse()

if response.status == 200:
    resp_buf = response.read()

else:
    print('error code: %d' % response.status)
    exit(response.status)

conn.close()

print('[%s]' % resp_buf)
resp_pkt = pack_utils.decode(buf=resp_buf, key='password')

post_resp = works_pb2.Post.Response()
post_resp.ParseFromString(resp_pkt.data)

print('ret code: %d, id: %d' % (post_resp.base_response.err_code, post_resp.id))
Ejemplo n.º 8
0
from ye2pack.pack_pb2 import Packet


def generate_username(device_id):
    user = '******' + hashlib.md5(device_id).hexdigest()
    return user


def generate_session():
    return time.time()


private_key = ''

req_buf = sys.stdin.read()
req_pkt = pack_utils.decode(req_buf, private_key)

# register device
req = RegisterDevice.Request()
req.ParseFromString(req_pkt.data)

device_id = req.device_id

# generate username
username = generate_username(device_id)
session = generate_session()

logging.debug("register device=%s, username=%s, session=%s",
              (req.device_id, username, session))

#
Ejemplo n.º 9
0
from ye2pack.pack_pb2 import Packet
from ye2pack.works_pb2 import UpdateAccounts
from model import usr_info, bind_accounts

print "Content-Type: text/plain;charset=utf-8"
print

#
req_buf = sys.stdin.read()
req_pkt = pack_utils.pre_decode(buf=req_buf)
uin = req_pkt.uin

usr = usr_info.query(uin)
session = usr.get('session')

req_pkt = pack_utils.decode(buf=req_buf, key=session)
req = UpdateAccounts.Request()
req.ParseFromString(req_pkt.data)

for ba in req.bind_accounts:
    bind_accounts.update(uin=req.base_request.uin,
                         openid=ba.openid,
                         account_type=ba.type,
                         access_token=ba.access_token,
                         refresh_token=ba.refresh_token,
                         expires_in=ba.expires_in,
                         extra=ba.extra)

resp = UpdateAccounts.Response()
resp.base_response.err_code = works_pb2.ERR_NONE
resp_buf = pack_utils.encode(buf=resp.SerializeToString(),
                            key='asdf',
                            uin=req.base_request.uin)

import httplib

headers = {
    "Content-type": "application/x-www-form-urlencoded",
    "Accept": "text/plain"
}
# conn = httplib.HTTPConnection("throughglass.sourceforge.net")
conn = httplib.HTTPConnection("192.168.1.105:8080")
conn.request("POST", "/cgi-bin/update_wechat_account.py", req_buf, headers)
response = conn.getresponse()

if response.status == 200:
    resp_buf = response.read()

else:
    print('error code: %d' % response.status)
    exit(response.status)

conn.close()

print('[%s]' % resp_buf)
resp_pkt = pack_utils.decode(buf=resp_buf, key='password')

resp = UpdateWeChatAccount.Response()
resp.ParseFromString(resp_pkt.data)

print('ret code: %d' % resp.base_response.err_code)
Ejemplo n.º 11
0
from ye2pack.pack_pb2 import Packet


def generate_username(device_id):
    user = '******' + hashlib.md5(device_id).hexdigest()
    return user


def generate_session():
    return time.time()


private_key = ''

req_buf = sys.stdin.read()
req_pkt = pack_utils.decode(req_buf, private_key)

# register device
req = RegisterDevice.Request()
req.ParseFromString(req_pkt.data)

device_id = req.device_id

# generate username
username = generate_username(device_id)
session = generate_session()

logging.debug("register device=%s, username=%s, session=%s", (req.device_id, username, session))

#
cnx = mysql.connector.connect(**model.config.rw_config)