Ejemplo n.º 1
0
    def post(self):
        action = request.args.get("action")
        postJSON = json.loads(request.get_data())

        if action == "add":
            databaseOperations.replaceIntoDB("Events", postJSON)
        if action == "delete":
            databaseOperations.deleteFromDB("Events", postJSON)
        print(postJSON)
        return postJSON
Ejemplo n.º 2
0
    def get(self):
        wxAPI = WXAPPAPI(appid=APP_ID, app_secret=APP_SECRET)

        print("string is: ", request.query_string)

        # BLACK MAGIC
        ##############################################
        # FIXME: Flask request parser takes + as space
        encrypted_data = request.args.get("encryptedData").replace(" ", "+")
        iv = request.args.get("iv").replace(" ", "+")
        ##############################################

        code = request.args.get("code")

        # print(data)
        # loginJSON = json.loads(data)
        # code = loginJSON["code"]
        # encrypted_data = loginJSON["encryptedData"]
        # iv = loginJSON["iv"]

        print("\ncode is : ", code)
        print("\ndata is : ", encrypted_data)
        print("\niv is : ", iv)

        session_info = wxAPI.exchange_code_for_session_key(code=code)

        # 获取session_info 后

        session_key = session_info.get('session_key')
        crypt = WXBizDataCrypt(APP_ID, session_key)

        # encrypted_data 包括敏感数据在内的完整用户信息的加密数据
        # iv 加密算法的初始向量
        # 这两个参数需要js获取
        try:
            user_info = crypt.decrypt(encrypted_data, iv)
            postJSON = stringParsing.userInfo2SQL(user_info)
            databaseOperations.replaceIntoDB("Users", postJSON)
        except:
            user_info = {"openId": session_info.get('openid')}
        return user_info