Explorar o código

fix mysqldb problem by install mysqlclient

conradlan %!s(int64=3) %!d(string=hai) anos
pai
achega
08d9d35b0b
Modificáronse 7 ficheiros con 12 adicións e 85 borrados
  1. 0 75
      linepay_test.py
  2. 9 9
      main.py
  3. 2 0
      requiremnets.txt
  4. 0 0
      sql/crud.py
  5. 1 1
      sql/database.py
  6. 0 0
      sql/models.py
  7. 0 0
      sql/schemas.py

+ 0 - 75
linepay_test.py

@@ -1,75 +0,0 @@
-import requests
-import json
-import base64
-import hashlib
-import hmac
-import uuid
-
-# sandbox
-url = "https://sandbox-api-pay.line.me"
-# url_path = "/v3/payments/request"
-transactionId=2021101400692705810
-orderId=1
-url_path = "/v3/payments/" + str(transactionId) + "/confirm"
-
-# # production
-# url = "https://api-pay.line.me"
-ChannelId = 1656522171
-ChannelSecret = 'd6d37304bc39496025519366b9c0ab44'
-nonce = uuid.uuid4()
-
-def line_Signature(ChannelSecret, payload, nonce, url_path):
-  signature = hmac.new(
-      ChannelSecret.encode('utf-8'),
-      msg=(ChannelSecret + url_path + json.dumps(payload) + str(nonce)).encode('utf-8'),
-      digestmod=hashlib.sha256
-    ).digest()
-  return base64.b64encode(signature)
-
-
-
-# payload={
-#     "amount": 100,
-#     "currency": "TWD",
-#     "orderId":1,
-#     "packages" : [
-#         {
-#             "id" : "1",
-#             "amount": 100,
-#             "products" : [
-#                 {
-#                     "id" : "PEN-B-001",
-#                     "name" : "Pen Brown",
-#                     "imageUrl" : "https://pay-store.line.com/images/pen_brown.jpg",
-#                     "quantity" : 2,
-#                     "price" : 50
-#                 }
-#             ]
-#         }
-#     ],
-#     "redirectUrls" : {
-#         "confirmUrl" : "https://pay-store.line.com/order/payment/confirm",
-#         "cancelUrl" : "https://pay-store.line.com/order/payment/cancel"
-#     }
-# }
-payload={
-    "amount": 100,
-    "currency": "TWD"
- }
-
-
-
-headers = {
-  'Content-Type': 'application/json',
-  'X-LINE-ChannelId': str(ChannelId),
-  'X-LINE-Authorization-Nonce': str(nonce),
-  'X-LINE-Authorization': line_Signature(ChannelSecret, payload, nonce, url_path)
-}
-
-response = requests.request("POST", url + url_path, headers=headers, data=json.dumps(payload))
-
-
-
-
-
-print(response.text)

+ 9 - 9
main.py

@@ -12,16 +12,16 @@ from starlette.responses import HTMLResponse
 from sqlalchemy.orm import Session
 from fastapi.encoders import jsonable_encoder
 
-from .database import get_db_session
-from .crud import create_order, get_order, get_orders
-from .schemas import order_info_linepay as orderSechmas
+from sql.database import get_db_session
+from sql.crud import create_order, get_order, get_orders
+from sql.schemas import order_info_linepay as orderSechmas
 
 
 
 
 # dotenv
-dotenv_path = join(dirname(__file__),'./env/.env')
-# dotenv_path = join(dirname(__file__),'./env/test.env') ## sandbox
+# dotenv_path = join(dirname(__file__),'./env/.env')
+dotenv_path = join(dirname(__file__),'./env/test.env') ## sandbox
 load_dotenv(dotenv_path)
 
 # logger (TBD)
@@ -33,8 +33,8 @@ templates = Jinja2Templates(directory="templates")
 LINE_PAY_CHANNEL_ID = os.environ.get("LINE_PAY_CHANNEL_ID")
 LINE_PAY_CHANNEL_SECRET = os.environ.get("LINE_PAY_CHANNEL_SECRET")
 LINE_PAY_REQEST_BASE_URL = "https://{}".format(os.environ.get("HOST_NAME"))
-line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=False)
-# line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=True)
+# line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=False)
+line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=True)
 
 # CACHE
 CACHE = {}
@@ -44,12 +44,12 @@ app = FastAPI()
 
 
 @app.get('/')
-def hellow():
+def hello():
     return {"Hello" : "World"}
 
 ## Request
 @app.post('/request', response_class=HTMLResponse)
-async def pay_request(userinfo: schemas.UserInfo, db: Session = Depends(get_db)):
+async def pay_request():
     order_id = str(uuid.uuid4())
     amount = 1200
     currency = "TWD"

+ 2 - 0
requiremnets.txt

@@ -12,7 +12,9 @@ idna==3.3
 Jinja2==3.0.2
 line-pay==0.2.0
 MarkupSafe==2.0.1
+mysqlclient==2.0.3
 pydantic==1.8.2
+PyMySQL==1.0.2
 python-dotenv==0.19.1
 PyYAML==6.0
 requests==2.26.0

+ 0 - 0
crud.py → sql/crud.py


+ 1 - 1
database.py → sql/database.py

@@ -4,7 +4,7 @@ from sqlalchemy.orm import sessionmaker
 
 
 ## ENV LOAD
-SQLALCHEMY_DATABASE_URL = 'mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4'
+SQLALCHEMY_DATABASE_URL = 'mysql://choozmo:pAssw0rd@db.ptt.cx:3306/dbname?charset=utf8mb4'
 
 engine = create_engine(SQLALCHEMY_DATABASE_URL)
 SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

+ 0 - 0
models.py → sql/models.py


+ 0 - 0
schemas.py → sql/schemas.py