Пример #1
0
def call():
    args = request.args
    if not "code" in args:
        return "error"
    code = args["code"]
    from wechat.tools import get_accesstoken_by_code

    access_token, openid = get_accesstoken_by_code(code)

    resp = make_response(render_template("call.html"))
    resp.set_cookie("weopenid", openid)
    return resp
Пример #2
0
def add_pinid(pinid, code):
    from wechat.tools import get_accesstoken_by_code

    access_token, openid = get_accesstoken_by_code(code)

    from model.redisdb import RedisDB

    con = RedisDB().con
    openidlist = con.get("pinid2openid:%s" % pinid)
    openidlist = openidlist + ";" + openid
    con.set("pinid2openid:%s" % pinid, openidlist)

    return jsonify(res="00000")
Пример #3
0
def pin_success(pinid):
    args = request.args
    if not "code" in args:
        return "error"
    code = args["code"]
    from wechat.tools import get_accesstoken_by_code, get_web_user_info_by_token

    access_token, openid = get_accesstoken_by_code(code)
    data = get_web_user_info_by_token(access_token, openid)
    nickname = data["nickname"]
    headimgurl = data["headimgurl"]

    target = args["target"]
    time = args["time"]
    num = args["num"]
    return render_template(
        "pin_success.html", pinid=pinid, nickname=nickname, headimgurl=headimgurl, target=target, time=time, num=num
    )
Пример #4
0
def bind_success():
    args = request.args
    if not "code" in args:
        return "error"

    code = args["code"]

    cookies = request.cookies
    if not "wecode" in cookies:
        return "error"
    wecode = cookies["wecode"]

    from wechat.tools import get_accesstoken_by_code

    we_access_token, openid = get_accesstoken_by_code(wecode)

    import requests
    from config import UBER_ID, UBER_SECRET

    url = "https://login.uber.com.cn/oauth/v2/token"
    para = {
        "client_secret": UBER_SECRET,
        "client_id": UBER_ID,
        "grant_type": "authorization_code",
        "redirect_uri": "https://wull.me/bind",
        "code": code,
    }
    res = requests.post(url, data=para)
    import json

    data = json.loads(res.text)
    access_token = data["access_token"]
    print wecode, access_token
    from model.redisdb import RedisDB

    con = RedisDB().con
    con.set("weopenid2uber:%s" % openid, access_token)
    con.expire("weopenid2uber:%s" % openid, 3600)

    return render_template("bind_success.html")