Browse Source

first commit

panweitong 2 years ago
commit
992d52da61

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 21 - 0
.idea/jingshiblocklyX-backend.iml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="Flask">
+    <option name="enabled" value="true" />
+  </component>
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/venv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TemplatesService">
+    <option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
+    <option name="TEMPLATE_FOLDERS">
+      <list>
+        <option value="$MODULE_DIR$/../jingshiblocklyX-backend\templates" />
+      </list>
+    </option>
+  </component>
+</module>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (jingshiblocklyX-backend)" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/jingshiblocklyX-backend.iml" filepath="$PROJECT_DIR$/.idea/jingshiblocklyX-backend.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

BIN
__pycache__/app.cpython-38.pyc


+ 87 - 0
app.py

@@ -0,0 +1,87 @@
+from flask import Flask
+import flask
+from alibabacloud_dingtalk.oauth2_1_0.client import Client as dingtalkoauth2_1_0Client
+from alibabacloud_tea_openapi import models as open_api_models
+from alibabacloud_dingtalk.oauth2_1_0 import models as dingtalkoauth_2__1__0_models
+from alibabacloud_tea_util.client import Client as UtilClient
+from alibabacloud_tea_util import models as util_models
+
+import dingtalk.api
+
+import json
+
+app = Flask(__name__)
+
+
+@app.route('/')
+def hello_world():
+    return 'flask_test is running!!!'
+
+
+@app.route('/getAccessToken')
+def login():
+    config = open_api_models.Config()
+    config.protocol = 'https'
+    config.region_id = 'central'
+    client = dingtalkoauth2_1_0Client(config)
+    # get_sso_access_token_request = dingtalkoauth_2__1__0_models.GetSsoAccessTokenRequest(
+    #     corpid='dingf113ce959247d417ee0f45d8e4f7c288',
+    #     sso_secret='09wTCSVdQMXDcqxGImreaAvvCfIF0BxfZsp393l_s9_XR5JZxcw3ha3zEm1LPq8e'
+    # )
+    get_access_token_request = dingtalkoauth_2__1__0_models.GetAccessTokenRequest(
+        app_key='dingsdbwmwnnnywdnk8e',
+        app_secret='N8KZDtMQJWlTp-24s1TgN_jcHTf69SsyIaMyG0zwr7HlG7JY0cYIdVTbH4wwL8Rz'
+    )
+    response = {}
+    try:
+        # access_token = client.get_sso_access_token(get_sso_access_token_request).body
+        access_token = client.get_access_token(get_access_token_request).body
+        print(access_token)
+        response = {"accessToken": access_token.access_token, "expireIn": access_token.expire_in}
+        return json.dumps(response)
+    except Exception as err:
+        if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
+            # err 中含有 code 和 message 属性,可帮助开发定位问题
+            pass
+    return json.dumps(response)
+
+
+@app.route('/getUserInfo', methods=['POST'])
+def get_user_info():
+    json_data = flask.request.json
+    code = json_data["code"]
+    accessToken = json_data["accessToken"]
+    response = {}
+    # config = open_api_models.Config()
+    # config.protocol = 'https'
+    # config.region_id = 'central'
+    # client = dingtalkoauth2_1_0Client(config)
+    # get_sso_user_info_headers = dingtalkoauth_2__1__0_models.GetSsoUserInfoHeaders()
+    # get_sso_user_info_headers.x_acs_dingtalk_access_token = json_data["accessToken"]
+    # get_sso_user_info_request = dingtalkoauth_2__1__0_models.GetSsoUserInfoRequest(
+    #     code=json_data["code"]
+    # )
+    # response = {}
+    # try:
+    #     user_info = client.get_sso_user_info_with_options(get_sso_user_info_request, get_sso_user_info_headers,
+    #                                                       util_models.RuntimeOptions()).body
+    #     print(user_info)
+    #     return json.dumps(user_info)
+    # except Exception as err:
+    #     if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
+    #         # err 中含有 code 和 message 属性,可帮助开发定位问题
+    #         print(err.code)
+    #         print(err.message)
+    #         pass
+    req = dingtalk.api.OapiV2UserGetuserinfoRequest("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo")
+    req.code = code
+    try:
+        response = req.getResponse(accessToken)
+        print(response)
+    except Exception as e:
+        print(e)
+    return json.dumps(response)
+
+
+if __name__ == '__main__':
+    app.run()