Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
592be4e43e | ||
|
|
2920abbe17 |
Generated
+38
-21
@@ -4,27 +4,12 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="a7465ceb-8d86-4d89-899e-8242cccf605d" name="更改" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Pipfile" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Pipfile.lock" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/api/urls.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/api/views/__init__.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/urls.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/user/urls.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.name" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/chunyu_project.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/chunyu_project.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/apps.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/apps.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/models.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/tests.py" beforeDir="false" afterPath="$PROJECT_DIR$/app/tests.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/chunyu_project/asgi.py" beforeDir="false" afterPath="$PROJECT_DIR$/chunyu_project/asgi.py" afterDir="false" />
|
||||
<list default="true" id="a7465ceb-8d86-4d89-899e-8242cccf605d" name="更改" comment="test">
|
||||
<change afterPath="$PROJECT_DIR$/api/views/BaiduFanyiView.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/api/urls.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/views/GetIPDataView.py" beforeDir="false" afterPath="$PROJECT_DIR$/api/views/GetIPDataView.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/chunyu_project/settings.py" beforeDir="false" afterPath="$PROJECT_DIR$/chunyu_project/settings.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/chunyu_project/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/chunyu_project/urls.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/chunyu_project/wsgi.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/db.sqlite3" beforeDir="false" afterPath="$PROJECT_DIR$/api/views/GetIPDataView.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -135,6 +120,9 @@
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="StructureViewState">
|
||||
<option name="selectedTab" value="逻辑" />
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration>C:\Users\12914\AppData\Roaming\Subversion</configuration>
|
||||
</component>
|
||||
@@ -146,13 +134,42 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1774436691939</updated>
|
||||
<workItem from="1774436692980" duration="11637000" />
|
||||
<workItem from="1774474993123" duration="3364000" />
|
||||
<workItem from="1774474993123" duration="15275000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="test">
|
||||
<option name="closed" value="true" />
|
||||
<created>1774552086610</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1774552086610</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="test">
|
||||
<option name="closed" value="true" />
|
||||
<created>1774552113802</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1774552113802</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="test">
|
||||
<option name="closed" value="true" />
|
||||
<created>1774565193807</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1774565193807</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="test" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="test" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/chunyu_project$tests.coverage" NAME="tests 覆盖结果" MODIFIED="1774462107469" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/app" />
|
||||
</component>
|
||||
|
||||
+4
-3
@@ -1,7 +1,8 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from .views.GetIPDataView import GetIPData
|
||||
|
||||
from .views.GetIPDataView import GetIPDataView
|
||||
from .views.BaiduFanyiView import BaiduFanyiView
|
||||
urlpatterns = [
|
||||
path("getIpData/", GetIPData.as_view()),
|
||||
path("getIpData/", GetIPDataView.as_view()),
|
||||
path("baiduFanyi/", BaiduFanyiView.as_view()),
|
||||
]
|
||||
@@ -0,0 +1,48 @@
|
||||
from rest_framework.decorators import permission_classes
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
import requests
|
||||
import random
|
||||
import json
|
||||
from hashlib import md5
|
||||
|
||||
|
||||
def make_md5(s, encoding='utf-8'):
|
||||
return md5(s.encode(encoding)).hexdigest()
|
||||
|
||||
@permission_classes([AllowAny])
|
||||
class BaiduFanyiView(APIView):
|
||||
def post(self, request):
|
||||
print(request.data)
|
||||
|
||||
# Set your own appid/appkey.
|
||||
appid = '20220718001275847'
|
||||
appkey = 'CJHmvf7qGs3szQy32cMg'
|
||||
|
||||
from_lang = 'en'
|
||||
to_lang = 'zh'
|
||||
|
||||
endpoint = 'http://api.fanyi.baidu.com'
|
||||
path = '/api/trans/vip/translate'
|
||||
url = endpoint + path
|
||||
|
||||
query = request.data['q']
|
||||
|
||||
salt = random.randint(32768, 65536)
|
||||
sign = make_md5(appid + query + str(salt) + appkey)
|
||||
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
payload = {'appid': appid, 'q': query, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign}
|
||||
|
||||
r = requests.post(url, params=payload, headers=headers)
|
||||
result = r.json()
|
||||
|
||||
|
||||
return Response(result, status=status.HTTP_200_OK)
|
||||
@@ -6,7 +6,7 @@ from rest_framework.permissions import AllowAny
|
||||
|
||||
|
||||
@permission_classes([AllowAny])
|
||||
class GetIPData(APIView):
|
||||
class GetIPDataView(APIView):
|
||||
def get(self, request):
|
||||
ip_info = {
|
||||
'remote_addr': request.META.get('REMOTE_ADDR'),
|
||||
@@ -20,3 +20,5 @@ class GetIPData(APIView):
|
||||
}
|
||||
|
||||
return Response({"ip_info": ip_info}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ ALLOWED_HOSTS = ["*"]
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://localhost:3000", # 例如:您的React/Vue开发服务器
|
||||
"http://127.0.0.1:3000",
|
||||
"http://*",
|
||||
"https://*"
|
||||
]
|
||||
|
||||
# CORS设置
|
||||
|
||||
Reference in New Issue
Block a user