user_MOC.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from fastapi import APIRouter, Form, Depends, HTTPException, Body
  2. from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
  3. from app.models.models import User, UserPydantic,User_information,User_point
  4. from app.api import deps
  5. from sqlalchemy.orm import Session
  6. from typing import Any, Dict, Optional
  7. import secrets
  8. from fastapi_login.exceptions import InvalidCredentialsException
  9. from fastapi_login import LoginManager
  10. from datetime import timedelta,datetime
  11. from app.config import settings
  12. from pathlib import Path
  13. from jose import jwt
  14. import emails
  15. from emails.template import JinjaTemplate
  16. import logging
  17. import bcrypt
  18. import smtplib
  19. from email.mime.text import MIMEText
  20. from google.oauth2 import id_token
  21. from google.auth.transport import requests
  22. from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
  23. from datetime import timedelta,datetime
  24. from app.log import my_log
  25. from Crypto.Cipher import Blowfish
  26. from Crypto import Random
  27. import requests
  28. user_MOC = APIRouter()
  29. @user_MOC.post("/get_user_data_from_MOC")
  30. async def get_user_data_from_MOC(authCode:str = None):
  31. try:
  32. api_url = "https://member.moc.gov.tw/MOCMC/T0001/ottGetAuthToken"
  33. # 定義請求參數
  34. params = {
  35. 'SYS_ID': 'CRAFT_NTCRI',
  36. 'SYS_PASSWORD': 'luZ2le0W',
  37. 'AuthCode': '839bd320-14cf-49fd-a52b-63d518256964',
  38. 'IS_DEV': 'Y'
  39. }
  40. cert_file_path = '/home/choozmo/certificate.pem'
  41. key_file_path = '/home/choozmo/private_key.pem'
  42. cert_files = (cert_file_path, key_file_path)
  43. ca_cert = '/var/www/ssl/eCA1_GTLSCA.crt'
  44. # 發送 GET 請求
  45. response = requests.get(api_url, params=params)
  46. # 定義 API 網址
  47. api_url = "https://member.moc.gov.tw/MOCMC/T0002/getMemberData"
  48. # 定義請求參數
  49. params = {
  50. 'SYS_ID': 'CRAFT_NTCRI',
  51. 'SYS_PASSWORD': 'luZ2le0W',
  52. 'AuthToken': '5a367872-faab-4e6a-bbbc-81691712ae6e',
  53. 'IS_DEV': 'Y'
  54. }
  55. response = requests.get(api_url, params=params)
  56. except Exception as e:
  57. return {"msg": str(e), "code": 500}