diff --git a/hinghwa-dict-backend/HinghwaDict/settings.py b/hinghwa-dict-backend/HinghwaDict/settings.py index 96a9adbd..c1f2d502 100644 --- a/hinghwa-dict-backend/HinghwaDict/settings.py +++ b/hinghwa-dict-backend/HinghwaDict/settings.py @@ -9,6 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.0/ref/settings/ """ + import logging import os @@ -188,8 +189,12 @@ "token", ) # parameter of Tencent cos -COS_SECRET_ID = env.str("COS_SECRET_ID", "DEFAULT_COS_SECRET_ID") # 替换为用户的 secretId -COS_SECRET_KEY = env.str("COS_SECRET_KEY", "DEFAULT_COS_SECRET_KEY") # 替换为用户的 secretKey +COS_SECRET_ID = env.str( + "COS_SECRET_ID", "DEFAULT_COS_SECRET_ID" +) # 替换为用户的 secretId +COS_SECRET_KEY = env.str( + "COS_SECRET_KEY", "DEFAULT_COS_SECRET_KEY" +) # 替换为用户的 secretKey COS_BUCKET = env.str("COS_BUCKET", "DEFAULT_COS_BUCKET") # BucketName-APPID COS_REGION = env.str("COS_REGION", "DEFAULT_COS_REGION") diff --git a/hinghwa-dict-backend/HinghwaDict/urls.py b/hinghwa-dict-backend/HinghwaDict/urls.py index dfeaa239..1265acdc 100644 --- a/hinghwa-dict-backend/HinghwaDict/urls.py +++ b/hinghwa-dict-backend/HinghwaDict/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin from django.urls import path, include @@ -56,4 +57,5 @@ path("orders", include("rewards.orders.urls", namespace="rewards.orders")), path("lists", include("word.lists.urls", namespace="word.lists")), path("papers", include("quiz.paper.urls", namespace="quiz.papers")), + path("certs", include("quiz.cert.urls", namespace="quiz.certs")), ] diff --git a/hinghwa-dict-backend/article/migrations/0001_initial.py b/hinghwa-dict-backend/article/migrations/0001_initial.py index 4c36c095..0b1cb774 100644 --- a/hinghwa-dict-backend/article/migrations/0001_initial.py +++ b/hinghwa-dict-backend/article/migrations/0001_initial.py @@ -25,7 +25,9 @@ class Migration(migrations.Migration): ), ( "views", - models.IntegerField(default=0, editable=False, verbose_name="阅读量"), + models.IntegerField( + default=0, editable=False, verbose_name="阅读量" + ), ), ( "publish_time", @@ -39,7 +41,10 @@ class Migration(migrations.Migration): ), ("content", models.TextField(verbose_name="正文")), ("cover", models.URLField(verbose_name="图片地址")), - ("visibility", models.BooleanField(default=False, verbose_name="是否审核")), + ( + "visibility", + models.BooleanField(default=False, verbose_name="是否审核"), + ), ( "author", models.ForeignKey( @@ -78,7 +83,10 @@ class Migration(migrations.Migration): ), ), ("content", models.TextField(max_length=500, verbose_name="内容")), - ("time", models.DateTimeField(auto_now_add=True, verbose_name="评论时间")), + ( + "time", + models.DateTimeField(auto_now_add=True, verbose_name="评论时间"), + ), ( "article", models.ForeignKey( diff --git a/hinghwa-dict-backend/article/models.py b/hinghwa-dict-backend/article/models.py index 80cfc87f..33f44e9e 100644 --- a/hinghwa-dict-backend/article/models.py +++ b/hinghwa-dict-backend/article/models.py @@ -60,7 +60,10 @@ class Comment(models.Model): verbose_name="父评论", ) article = models.ForeignKey( - Article, on_delete=models.CASCADE, related_name="comments", verbose_name="评论文章" + Article, + on_delete=models.CASCADE, + related_name="comments", + verbose_name="评论文章", ) like_users = models.ManyToManyField( User, diff --git a/hinghwa-dict-backend/article/views.py b/hinghwa-dict-backend/article/views.py index dc271f0a..244e8042 100644 --- a/hinghwa-dict-backend/article/views.py +++ b/hinghwa-dict-backend/article/views.py @@ -80,7 +80,11 @@ def post(self, request) -> JsonResponse: article.save() content = f"我创建了文章(id={article.id}),请及时去审核" sendNotification( - article.author, None, content, title="【提醒】文章待审核", action_object=article + article.author, + None, + content, + title="【提醒】文章待审核", + action_object=article, ) return JsonResponse({"id": article.id}, status=200) @@ -165,7 +169,11 @@ def put(self, request, id) -> JsonResponse: article.save() content = f"我修改了文章(id={article.id}),请及时去审核" sendNotification( - article.author, None, content, title="【提醒】文章待审核", action_object=article + article.author, + None, + content, + title="【提醒】文章待审核", + action_object=article, ) return JsonResponse({}, status=200) diff --git a/hinghwa-dict-backend/music/migrations/0001_initial.py b/hinghwa-dict-backend/music/migrations/0001_initial.py index d0469150..242e7fbe 100644 --- a/hinghwa-dict-backend/music/migrations/0001_initial.py +++ b/hinghwa-dict-backend/music/migrations/0001_initial.py @@ -27,7 +27,10 @@ class Migration(migrations.Migration): ("title", models.CharField(max_length=100, verbose_name="曲名")), ("artist", models.CharField(max_length=100, verbose_name="作者")), ("cover", models.URLField(verbose_name="音乐封面地址")), - ("visibility", models.BooleanField(default=False, verbose_name="是否可见")), + ( + "visibility", + models.BooleanField(default=False, verbose_name="是否可见"), + ), ( "contributor", models.ForeignKey( diff --git a/hinghwa-dict-backend/quiz/cert/dto/cert.py b/hinghwa-dict-backend/quiz/cert/dto/cert.py new file mode 100644 index 00000000..55507f28 --- /dev/null +++ b/hinghwa-dict-backend/quiz/cert/dto/cert.py @@ -0,0 +1,17 @@ +from ...models import Cert +from user.dto.user_simple import user_simple + + +def cert_info(cert: Cert): + response = { + "level": cert.level, + "name": cert.name, + "place": cert.place, + "sequence": cert.sequence, + "grade": cert.grade, + "scores": cert.scores, + "time": cert.time, + "ID": cert.id, + "user": None if cert.user is None else user_simple(cert.user), + } + return response diff --git a/hinghwa-dict-backend/quiz/cert/forms.py b/hinghwa-dict-backend/quiz/cert/forms.py new file mode 100644 index 00000000..872a3ca0 --- /dev/null +++ b/hinghwa-dict-backend/quiz/cert/forms.py @@ -0,0 +1,8 @@ +from django import forms +from ..models import Cert + + +class CertForm(forms.ModelForm): + class Meta: + model = Cert + fields = ("level", "name", "place", "sequence", "grade", "scores") diff --git a/hinghwa-dict-backend/quiz/cert/urls.py b/hinghwa-dict-backend/quiz/cert/urls.py new file mode 100644 index 00000000..023555dd --- /dev/null +++ b/hinghwa-dict-backend/quiz/cert/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from django.views.decorators.csrf import csrf_exempt +from .view.cert_all import * +from .view.cert_single import * + +app_name = "quiz.certs" + +urlpatterns = [ + path("", csrf_exempt(AllCert.as_view())), + path("/", csrf_exempt(SingleCert.as_view())), +] diff --git a/hinghwa-dict-backend/quiz/cert/view/cert_all.py b/hinghwa-dict-backend/quiz/cert/view/cert_all.py new file mode 100644 index 00000000..fc847e8e --- /dev/null +++ b/hinghwa-dict-backend/quiz/cert/view/cert_all.py @@ -0,0 +1,56 @@ +import demjson +from django.http import JsonResponse +from django.views import View +from ...models import Cert +from ..forms import CertForm +from user.models import User +from ..dto.cert import cert_info +from utils.exception.types.bad_request import BadRequestException +from utils.token import token_pass +from utils.generate_id import generate_cert_id +from utils.exception.types.not_found import UserNotFoundException +from user.utils import get_user_by_id +from django.utils import timezone + + +class AllCert(View): + # QZ0502创建证书 + def post(self, request): + token_pass(request.headers, -1) + body = demjson.decode(request.body) + cert_form = CertForm(body["cert"]) + if not cert_form.is_valid(): + raise BadRequestException() + cert = cert_form.save(commit=False) + if body["user"] != "": + user = User.objects.filter(id=body["user"]) + if not user.exists(): + raise UserNotFoundException() + user = user[0] + cert.user = user + cert.id = generate_cert_id() + cert.time = timezone.now() + cert.save() + return JsonResponse(cert_info(cert), status=200) + + # QZ0501查询所有证书 + def get(self, request): + token_pass(request.headers) + result = [] + name = request.GET["name"] + name_set = Cert.objects.filter(name=name) + for name in name_set: + result.append(cert_info(name)) + if request.GET["user"]: + user_id = request.GET["user"] + users = Cert.objects.filter(user=get_user_by_id(user_id)) + for user in users: + result.append(cert_info(user)) + result = list(tuple(result)) + return JsonResponse( + { + "amount": len(result), + "certs": result, + }, + status=200, + ) diff --git a/hinghwa-dict-backend/quiz/cert/view/cert_single.py b/hinghwa-dict-backend/quiz/cert/view/cert_single.py new file mode 100644 index 00000000..15785508 --- /dev/null +++ b/hinghwa-dict-backend/quiz/cert/view/cert_single.py @@ -0,0 +1,17 @@ +from django.http import JsonResponse +from django.views import View +from ...models import Cert +from utils.token import token_pass +from utils.exception.types.not_found import CertNotFoundException +from ..dto.cert import cert_info + + +class SingleCert(View): + # QZ0503查询证书信息 + def get(self, request, id): + token_pass(request.headers) + cert = Cert.objects.filter(id=id) + if not cert.exists(): + raise CertNotFoundException() + cert = cert[0] + return JsonResponse({"cert": cert_info(cert)}, status=200) diff --git a/hinghwa-dict-backend/quiz/migrations/0001_initial.py b/hinghwa-dict-backend/quiz/migrations/0001_initial.py index 9bc08acc..b35463fd 100644 --- a/hinghwa-dict-backend/quiz/migrations/0001_initial.py +++ b/hinghwa-dict-backend/quiz/migrations/0001_initial.py @@ -26,7 +26,10 @@ class Migration(migrations.Migration): ), ("answer", models.IntegerField(default=0, verbose_name="答案序号")), ("explanation", models.TextField(verbose_name="答案解析")), - ("visibility", models.BooleanField(default=False, verbose_name="是否审核")), + ( + "visibility", + models.BooleanField(default=False, verbose_name="是否审核"), + ), ], options={ "verbose_name": "测试题", diff --git a/hinghwa-dict-backend/quiz/migrations/0004_quiz_paper.py b/hinghwa-dict-backend/quiz/migrations/0004_quiz_paper.py index a5ed03f2..72a57514 100644 --- a/hinghwa-dict-backend/quiz/migrations/0004_quiz_paper.py +++ b/hinghwa-dict-backend/quiz/migrations/0004_quiz_paper.py @@ -17,7 +17,9 @@ class Migration(migrations.Migration): fields=[ ( "title", - models.CharField(blank=True, max_length=50, verbose_name="试卷标题"), + models.CharField( + blank=True, max_length=50, verbose_name="试卷标题" + ), ), ( "id", diff --git a/hinghwa-dict-backend/quiz/migrations/0007_cert.py b/hinghwa-dict-backend/quiz/migrations/0007_cert.py new file mode 100644 index 00000000..babd6507 --- /dev/null +++ b/hinghwa-dict-backend/quiz/migrations/0007_cert.py @@ -0,0 +1,58 @@ +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("quiz", "0006_quiz_record"), + ] + + operations = [ + migrations.AlterField( + model_name="quizrecord", + name="paper", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="quiz_paper", + to="quiz.paperrecord", + verbose_name="所在答卷记录", + ), + ), + migrations.CreateModel( + name="Cert", + fields=[ + ("level", models.IntegerField(verbose_name="等级")), + ("name", models.CharField(max_length=20, verbose_name="参与者")), + ("place", models.CharField(max_length=100, verbose_name="地址")), + ("sequence", models.IntegerField(verbose_name="第几次认证")), + ("grade", models.CharField(max_length=20, verbose_name="等级")), + ( + "scores", + models.TextField(blank=True, default="[]", verbose_name="分数"), + ), + ("time", models.DateTimeField(max_length=20, verbose_name="时间")), + ( + "id", + models.CharField( + max_length=20, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="cert_user", + to=settings.AUTH_USER_MODEL, + verbose_name="证书用户", + ), + ), + ], + ), + ] diff --git a/hinghwa-dict-backend/quiz/models.py b/hinghwa-dict-backend/quiz/models.py index 72fce44f..efdb2800 100644 --- a/hinghwa-dict-backend/quiz/models.py +++ b/hinghwa-dict-backend/quiz/models.py @@ -16,7 +16,9 @@ class Quiz(models.Model): answer = models.IntegerField(default=0, verbose_name="答案序号", editable=True) explanation = models.TextField(verbose_name="答案解析") visibility = models.BooleanField(default=False, verbose_name="是否审核") - voice_source = models.URLField(max_length=200, verbose_name="播报语音链接", default="") + voice_source = models.URLField( + max_length=200, verbose_name="播报语音链接", default="" + ) type = models.CharField(blank=True, max_length=50, verbose_name="问题类型") def __str__(self): @@ -83,3 +85,21 @@ class QuizRecord(models.Model): correctness = models.BooleanField(verbose_name="是否正确") timestamp = models.DateTimeField(verbose_name="时间") id = models.CharField(max_length=20, verbose_name="ID", primary_key=True) + + +class Cert(models.Model): + user = models.ForeignKey( + User, + on_delete=models.CASCADE, + related_name="cert_user", + verbose_name="证书用户", + null=True, + ) + level = models.IntegerField(verbose_name="等级") + name = models.CharField(max_length=20, verbose_name="参与者") + place = models.CharField(max_length=100, verbose_name="地址") + sequence = models.IntegerField(verbose_name="第几次认证") + grade = models.CharField(max_length=20, verbose_name="等级") + scores = models.TextField(blank=True, default="[]", verbose_name="分数") + time = models.DateTimeField(max_length=20, verbose_name="时间") + id = models.CharField(max_length=20, verbose_name="ID", primary_key=True) diff --git a/hinghwa-dict-backend/rewards/migrations/0001_initial.py b/hinghwa-dict-backend/rewards/migrations/0001_initial.py index 20af86d7..16ecdc3e 100644 --- a/hinghwa-dict-backend/rewards/migrations/0001_initial.py +++ b/hinghwa-dict-backend/rewards/migrations/0001_initial.py @@ -26,7 +26,9 @@ class Migration(migrations.Migration): ), ( "details", - models.TextField(blank=True, max_length=200, verbose_name="商品详情"), + models.TextField( + blank=True, max_length=200, verbose_name="商品详情" + ), ), ( "id", diff --git a/hinghwa-dict-backend/user/dto/user_all.py b/hinghwa-dict-backend/user/dto/user_all.py index 72d441b9..619a58e0 100644 --- a/hinghwa-dict-backend/user/dto/user_all.py +++ b/hinghwa-dict-backend/user/dto/user_all.py @@ -30,9 +30,11 @@ def user_all(user: User) -> dict: response.update( { - "login_time": localtime(user.last_login).__format__("%Y-%m-%d %H:%M:%S") - if user.last_login - else "", + "login_time": ( + localtime(user.last_login).__format__("%Y-%m-%d %H:%M:%S") + if user.last_login + else "" + ), } ) return response diff --git a/hinghwa-dict-backend/user/migrations/0001_initial.py b/hinghwa-dict-backend/user/migrations/0001_initial.py index 07b1d529..59b6b9e0 100644 --- a/hinghwa-dict-backend/user/migrations/0001_initial.py +++ b/hinghwa-dict-backend/user/migrations/0001_initial.py @@ -26,11 +26,15 @@ class Migration(migrations.Migration): ), ( "wechat", - models.CharField(blank=True, max_length=128, verbose_name="微信标识码"), + models.CharField( + blank=True, max_length=128, verbose_name="微信标识码" + ), ), ( "qq", - models.CharField(blank=True, max_length=128, verbose_name="qq标识码"), + models.CharField( + blank=True, max_length=128, verbose_name="qq标识码" + ), ), ( "nickname", @@ -38,7 +42,9 @@ class Migration(migrations.Migration): ), ( "birthday", - models.DateField(blank=True, default="1970-1-1", verbose_name="生日"), + models.DateField( + blank=True, default="1970-1-1", verbose_name="生日" + ), ), ( "telephone", diff --git a/hinghwa-dict-backend/utils/exception/types/bad_request.py b/hinghwa-dict-backend/utils/exception/types/bad_request.py index a51bc061..bd23aa9f 100644 --- a/hinghwa-dict-backend/utils/exception/types/bad_request.py +++ b/hinghwa-dict-backend/utils/exception/types/bad_request.py @@ -54,6 +54,7 @@ class ReturnUsersNumException(BadRequestException): """ def __init__( - self, msg="请在return_users_num字段中加入请求的点赞人数,要求为正整数,或者不发送return_users_num字段" + self, + msg="请在return_users_num字段中加入请求的点赞人数,要求为正整数,或者不发送return_users_num字段", ): super().__init__(msg) diff --git a/hinghwa-dict-backend/utils/exception/types/not_found.py b/hinghwa-dict-backend/utils/exception/types/not_found.py index cfabea51..f5f1dd11 100644 --- a/hinghwa-dict-backend/utils/exception/types/not_found.py +++ b/hinghwa-dict-backend/utils/exception/types/not_found.py @@ -222,3 +222,15 @@ def __init__(self, id=""): super().__init__() self.status = 404 self.msg = "答题记录{}不存在!".format(id) + + +class CertNotFoundException(NotFoundException): + """ + 证书不存在异常 + parma id:证书id + """ + + def __init__(self, id=""): + super().__init__() + self.status = 404 + self.msg = "证书{}不存在!".format(id) diff --git a/hinghwa-dict-backend/utils/generate_id.py b/hinghwa-dict-backend/utils/generate_id.py index 8cc5a13b..ab25b440 100644 --- a/hinghwa-dict-backend/utils/generate_id.py +++ b/hinghwa-dict-backend/utils/generate_id.py @@ -3,7 +3,7 @@ from rewards.products.models.product import Product from rewards.orders.models.order import Order from word.models import List -from quiz.models import Paper, PaperRecord, QuizRecord +from quiz.models import Paper, PaperRecord, QuizRecord, Cert from quiz.models import Paper, PaperRecord @@ -85,3 +85,13 @@ def generate_quiz_record_id(): else: new_id = 1 return f"DT{new_id:06d}" + + +def generate_cert_id(): + last_cert_record = Cert.objects.order_by("-id").first() + if last_cert_record: + last_id = int(last_cert_record.id[4:]) + new_id = last_id + 1 + else: + new_id = 1 + return f"PLPT{new_id:010d}" diff --git a/hinghwa-dict-backend/website/migrations/0001_initial.py b/hinghwa-dict-backend/website/migrations/0001_initial.py index d6efe746..626c1587 100644 --- a/hinghwa-dict-backend/website/migrations/0001_initial.py +++ b/hinghwa-dict-backend/website/migrations/0001_initial.py @@ -20,8 +20,14 @@ class Migration(migrations.Migration): ), ), ("english", models.CharField(max_length=255, verbose_name="英文表达")), - ("mandarin", models.CharField(max_length=255, verbose_name="普通话表达")), - ("character", models.CharField(max_length=255, verbose_name="方言表达")), + ( + "mandarin", + models.CharField(max_length=255, verbose_name="普通话表达"), + ), + ( + "character", + models.CharField(max_length=255, verbose_name="方言表达"), + ), ("pinyin", models.CharField(max_length=255, verbose_name="方言拼音")), ], options={ @@ -41,9 +47,18 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("announcements", models.TextField(default="[]", verbose_name="本站公告")), - ("hot_articles", models.TextField(default="[]", verbose_name="热门文章")), - ("word_of_the_day", models.TextField(default="1", verbose_name="每日一词")), + ( + "announcements", + models.TextField(default="[]", verbose_name="本站公告"), + ), + ( + "hot_articles", + models.TextField(default="[]", verbose_name="热门文章"), + ), + ( + "word_of_the_day", + models.TextField(default="1", verbose_name="每日一词"), + ), ("carousel", models.TextField(default="[]", verbose_name="精品推荐")), ], options={ diff --git a/hinghwa-dict-backend/website/models.py b/hinghwa-dict-backend/website/models.py index 2b7d45ac..47916d09 100644 --- a/hinghwa-dict-backend/website/models.py +++ b/hinghwa-dict-backend/website/models.py @@ -3,10 +3,16 @@ class Website(models.Model): - announcements = models.TextField(verbose_name="本站公告", default="[]") # list[文章id] - hot_articles = models.TextField(verbose_name="热门文章", default="[]") # list[文章id] + announcements = models.TextField( + verbose_name="本站公告", default="[]" + ) # list[文章id] + hot_articles = models.TextField( + verbose_name="热门文章", default="[]" + ) # list[文章id] word_of_the_day = models.TextField(verbose_name="每日一词", default="1") # int - carousel = models.TextField(verbose_name="精品推荐", default="[]") # dict{id,source} + carousel = models.TextField( + verbose_name="精品推荐", default="[]" + ) # dict{id,source} class Meta: verbose_name_plural = "网页内容" diff --git a/hinghwa-dict-backend/word/application/views.py b/hinghwa-dict-backend/word/application/views.py index bbaac6fd..eb4199fd 100644 --- a/hinghwa-dict-backend/word/application/views.py +++ b/hinghwa-dict-backend/word/application/views.py @@ -106,7 +106,9 @@ def put(self, request, id) -> JsonResponse: """ WD0404 修改申请 """ - user = token_user(token_pass(request.headers, -1)) # user = 操作用户(仅限管理员) + user = token_user( + token_pass(request.headers, -1) + ) # user = 操作用户(仅限管理员) application = find_application(id) application.verifier = user feedback = None diff --git a/hinghwa-dict-backend/word/migrations/0001_initial.py b/hinghwa-dict-backend/word/migrations/0001_initial.py index 807c537e..00958b13 100644 --- a/hinghwa-dict-backend/word/migrations/0001_initial.py +++ b/hinghwa-dict-backend/word/migrations/0001_initial.py @@ -62,7 +62,9 @@ class Migration(migrations.Migration): ("annotation", models.TextField(blank=True, verbose_name="附注")), ( "mandarin", - models.TextField(blank=True, default="[]", verbose_name="对应普通话词语"), + models.TextField( + blank=True, default="[]", verbose_name="对应普通话词语" + ), ), ( "standard_ipa", @@ -70,13 +72,20 @@ class Migration(migrations.Migration): ), ( "standard_pinyin", - models.CharField(blank=True, max_length=30, verbose_name="标准拼音"), + models.CharField( + blank=True, max_length=30, verbose_name="标准拼音" + ), ), ( "views", - models.IntegerField(default=0, editable=False, verbose_name="访问量"), + models.IntegerField( + default=0, editable=False, verbose_name="访问量" + ), + ), + ( + "visibility", + models.BooleanField(default=False, verbose_name="是否审核"), ), - ("visibility", models.BooleanField(default=False, verbose_name="是否审核")), ( "contributor", models.ForeignKey( @@ -127,10 +136,15 @@ class Migration(migrations.Migration): ("pinyin", models.CharField(max_length=50, verbose_name="拼音")), ("county", models.CharField(max_length=100, verbose_name="县区")), ("town", models.CharField(max_length=100, verbose_name="乡镇")), - ("visibility", models.BooleanField(default=False, verbose_name="是否可见")), + ( + "visibility", + models.BooleanField(default=False, verbose_name="是否可见"), + ), ( "views", - models.IntegerField(default=0, editable=False, verbose_name="访问量"), + models.IntegerField( + default=0, editable=False, verbose_name="访问量" + ), ), ( "contributor", @@ -192,7 +206,9 @@ class Migration(migrations.Migration): ("annotation", models.TextField(blank=True, verbose_name="附注")), ( "mandarin", - models.TextField(blank=True, default="[]", verbose_name="对应普通话词语"), + models.TextField( + blank=True, default="[]", verbose_name="对应普通话词语" + ), ), ( "standard_ipa", @@ -200,7 +216,9 @@ class Migration(migrations.Migration): ), ( "standard_pinyin", - models.CharField(blank=True, max_length=30, verbose_name="标准拼音"), + models.CharField( + blank=True, max_length=30, verbose_name="标准拼音" + ), ), ( "contributor", diff --git a/hinghwa-dict-backend/word/migrations/0004_word_list.py b/hinghwa-dict-backend/word/migrations/0004_word_list.py index 6e517779..753ae1d7 100644 --- a/hinghwa-dict-backend/word/migrations/0004_word_list.py +++ b/hinghwa-dict-backend/word/migrations/0004_word_list.py @@ -41,11 +41,19 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("createTime", models.DateTimeField(blank=True, verbose_name="创建时间")), - ("updateTime", models.DateTimeField(blank=True, verbose_name="更新时间")), + ( + "createTime", + models.DateTimeField(blank=True, verbose_name="创建时间"), + ), + ( + "updateTime", + models.DateTimeField(blank=True, verbose_name="更新时间"), + ), ( "description", - models.CharField(blank=True, max_length=100, verbose_name="词单简介"), + models.CharField( + blank=True, max_length=100, verbose_name="词单简介" + ), ), ( "author", diff --git a/hinghwa-dict-backend/word/models.py b/hinghwa-dict-backend/word/models.py index ab193c98..30f587d3 100644 --- a/hinghwa-dict-backend/word/models.py +++ b/hinghwa-dict-backend/word/models.py @@ -25,7 +25,9 @@ class Word(models.Model): annotation = models.TextField(verbose_name="附注", blank=True) mandarin = models.TextField(verbose_name="对应普通话词语", blank=True, default="[]") standard_ipa = models.CharField(max_length=100, verbose_name="标准IPA", blank=True) - standard_pinyin = models.CharField(max_length=100, verbose_name="标准拼音", blank=True) + standard_pinyin = models.CharField( + max_length=100, verbose_name="标准拼音", blank=True + ) views = models.IntegerField(default=0, verbose_name="访问量", editable=False) visibility = models.BooleanField(default=False, verbose_name="是否审核") related_words = models.ManyToManyField( @@ -69,7 +71,10 @@ class Application(models.Model): ) reason = models.CharField(max_length=200, blank=True, verbose_name="理由") contributor = models.ForeignKey( - User, on_delete=models.CASCADE, related_name="applications", verbose_name="贡献者" + User, + on_delete=models.CASCADE, + related_name="applications", + verbose_name="贡献者", ) verifier = models.ForeignKey( User, @@ -86,12 +91,17 @@ class Application(models.Model): annotation = models.TextField(verbose_name="附注", blank=True) mandarin = models.TextField(verbose_name="对应普通话词语", blank=True, default="[]") standard_ipa = models.CharField(max_length=30, verbose_name="标准IPA", blank=True) - standard_pinyin = models.CharField(max_length=30, verbose_name="标准拼音", blank=True) + standard_pinyin = models.CharField( + max_length=30, verbose_name="标准拼音", blank=True + ) related_words = models.ManyToManyField( Word, related_name="related_applications", verbose_name="相关词汇", blank=True ) related_articles = models.ManyToManyField( - Article, related_name="related_applications", verbose_name="相关帖子", blank=True + Article, + related_name="related_applications", + verbose_name="相关帖子", + blank=True, ) def granted(self): @@ -127,7 +137,10 @@ class Meta: class Pronunciation(models.Model): word = models.ForeignKey( - Word, on_delete=models.CASCADE, related_name="pronunciation", verbose_name="词语" + Word, + on_delete=models.CASCADE, + related_name="pronunciation", + verbose_name="词语", ) source = models.URLField(verbose_name="来源") ipa = models.CharField(max_length=50, verbose_name="ipa") @@ -212,7 +225,10 @@ class Meta: class List(models.Model): name = models.CharField(blank=True, max_length=30, verbose_name="词单名称") author = models.ForeignKey( - User, on_delete=models.CASCADE, related_name="list_words", verbose_name="词单作者" + User, + on_delete=models.CASCADE, + related_name="list_words", + verbose_name="词单作者", ) words = models.ManyToManyField( Word, diff --git a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py index 78ec2bf8..7269b81c 100644 --- a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py +++ b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py @@ -17,13 +17,15 @@ def pronunciation_all(pronunciation: Pronunciation) -> dict: "county": pronunciation.county, "town": pronunciation.town, "visibility": pronunciation.visibility, - "verifier": { - "nickname": pronunciation.verifier.user_info.nickname, - "avatar": pronunciation.verifier.user_info.avatar, - "id": pronunciation.verifier.id, - } - if pronunciation.verifier - else None, + "verifier": ( + { + "nickname": pronunciation.verifier.user_info.nickname, + "avatar": pronunciation.verifier.user_info.avatar, + "id": pronunciation.verifier.id, + } + if pronunciation.verifier + else None + ), "granted": pronunciation.granted(), "upload_time": localtime(pronunciation.upload_time).strftime( "%Y-%m-%d %H:%M:%S" diff --git a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_normal.py b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_normal.py index aeecd696..8187cf7f 100644 --- a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_normal.py +++ b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_normal.py @@ -14,13 +14,15 @@ def pronunciation_normal(pronunciation: Pronunciation) -> dict: "county": pronunciation.county, "town": pronunciation.town, "visibility": pronunciation.visibility, - "verifier": { - "nickname": pronunciation.verifier.user_info.nickname, - "avatar": pronunciation.verifier.user_info.avatar, - "id": pronunciation.verifier.id, - } - if pronunciation.verifier - else None, + "verifier": ( + { + "nickname": pronunciation.verifier.user_info.nickname, + "avatar": pronunciation.verifier.user_info.avatar, + "id": pronunciation.verifier.id, + } + if pronunciation.verifier + else None + ), "granted": pronunciation.granted(), } return response diff --git a/hinghwa-dict-backend/word/pronunciation/urls.py b/hinghwa-dict-backend/word/pronunciation/urls.py index 86c19b8c..aebbf53c 100644 --- a/hinghwa-dict-backend/word/pronunciation/urls.py +++ b/hinghwa-dict-backend/word/pronunciation/urls.py @@ -15,8 +15,12 @@ path("/", csrf_exempt(ManagePronunciation.as_view())), path("/combine", combinePronunciationV2), path("/translate", translatePronunciation), - path("//visibility", csrf_exempt(ManageApproval.put)), # PUT PN0105 修改审核结果 - path("//examine", csrf_exempt(ManageApproval.as_view())), # POST PN0106 审核 + path( + "//visibility", csrf_exempt(ManageApproval.put) + ), # PUT PN0105 修改审核结果 + path( + "//examine", csrf_exempt(ManageApproval.as_view()) + ), # POST PN0106 审核 path("/ranking", csrf_exempt(PronunciationRanking.as_view())), # PN0205语音榜单 path("/", combinePronunciation), ] diff --git a/hinghwa-dict-backend/word/pronunciation/views.py b/hinghwa-dict-backend/word/pronunciation/views.py index 1ad7bc94..0dd8a86c 100644 --- a/hinghwa-dict-backend/word/pronunciation/views.py +++ b/hinghwa-dict-backend/word/pronunciation/views.py @@ -469,7 +469,7 @@ def translatePronunciation(request): Arg( [ os.path.join(settings.MEDIA_ROOT, "audio", "temp"), - os.path.join(settings.SAVED_PINYIN, "submit") + os.path.join(settings.SAVED_PINYIN, "submit"), # os.path.join(settings.BASE_DIR, "AudioCompare", "submit") ] ) diff --git a/hinghwa-dict-backend/word/word/views.py b/hinghwa-dict-backend/word/word/views.py index e2fc4590..e383a7b0 100644 --- a/hinghwa-dict-backend/word/word/views.py +++ b/hinghwa-dict-backend/word/word/views.py @@ -449,5 +449,7 @@ def post(self, request) -> JsonResponse: ] if len(result) > 100: result = result[:100] - return JsonResponse({"words": result, "msg": "请求的词语太多了,请更精确一些"}, status=400) + return JsonResponse( + {"words": result, "msg": "请求的词语太多了,请更精确一些"}, status=400 + ) return JsonResponse({"words": result}, status=200) diff --git a/tests/cert_200.json b/tests/cert_200.json new file mode 100644 index 00000000..7693cc64 --- /dev/null +++ b/tests/cert_200.json @@ -0,0 +1,2041 @@ +{ + "apifoxCli": "1.1.0", + "item": [ + { + "item": [ + { + "id": "4d897977-54ca-4d57-b02f-938b8e72a5e0", + "name": "LG0101 账号密码登录(登录用户admin)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "login" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "method": "POST", + "baseUrl": "http://127.0.0.1:8000", + "body": { + "mode": "raw", + "raw": "{\r\n \"username\": \"admin\",\r\n \"password\": \"testtest123\"\r\n}", + "type": "application/json" + }, + "type": "http" + }, + "response": [], + "event": [ + { + "listen": "test", + "script": { + "id": "postProcessors.0.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.token`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.environment.set(`token`, value);console.log('已设置环境变量【token】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【token】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + }, + { + "listen": "test", + "script": { + "id": "postProcessors.1.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.id`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.variables.set(`user_id`, value);console.log('已设置临时变量【user_id】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【user_id】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + } + ], + "responseDefinition": { + "id": 4183271, + "apiDetailId": 5318056, + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "token": { + "type": "string", + "mock": { + "mock": "@string" + }, + "title": "权" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "token", + "id" + ] + }, + "defaultEnable": true, + "projectId": 0, + "ordering": 1, + "unpackerId": "", + "unpackerSetting": "", + "createdAt": "2021-07-29T14:43:37.000Z", + "updatedAt": "2021-08-12T16:27:18.000Z", + "deletedAt": null, + "folderId": 0, + "schemaDefinitions": {} + }, + "requestDefinition": { + "jsonSchema": { + "type": "object", + "properties": { + "username": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "password": { + "type": "string", + "mock": { + "mock": "@string('lower', 1, 3)" + }, + "title": "密码" + } + }, + "required": [ + "username", + "password" + ] + } + }, + "metaInfo": { + "httpApiId": 5318056, + "httpApiCaseId": 135411171, + "httpApiName": "LG0101 账号密码登录", + "httpApiPath": "/login", + "httpApiMethod": "post", + "httpApiCaseName": "登录用户admin", + "id": "b5b86a5b-c478-4d71-88e1-74c8a7370a6d", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "e08e4faf-566e-4e1d-997d-24ab3ee166e3", + "name": "QZ0502 创建证书(无user)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "method": "POST", + "baseUrl": "http://127.0.0.1:8000", + "body": { + "mode": "raw", + "raw": "{\r\n \"cert\": {\r\n \"level\": 3,\r\n \"name\": \"yes\",\r\n \"place\": \"id labore eu irure\",\r\n \"sequence\": 1,\r\n \"scores\": [\r\n 85,\r\n 42,\r\n 36,\r\n 81,\r\n 58\r\n ],\r\n \"time\": \"2023-10-23\",\r\n \"grade\": \"ea eu\"\r\n },\r\n \"user\": \"\"\r\n}", + "generateMode": "normal", + "type": "application/json" + }, + "type": "http" + }, + "response": [], + "event": [ + { + "listen": "test", + "script": { + "id": "postProcessors.0.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.ID`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.environment.set(`cert_id`, value);console.log('已设置环境变量【cert_id】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【cert_id】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + } + ], + "responseDefinition": { + "createdAt": "2024-01-17T11:56:09.114Z", + "updatedAt": "2024-01-17T11:56:09.114Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "x-apifox-refs": {}, + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604673, + "tempId": "1701365743650", + "id": 35712287, + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": { + "type": "object", + "properties": { + "cert": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀" + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade" + ] + }, + "user": { + "type": [ + "integer", + "null" + ] + } + }, + "x-apifox-orders": [ + "cert", + "user" + ], + "required": [ + "cert", + "user" + ] + } + }, + "metaInfo": { + "httpApiId": 129604673, + "httpApiCaseId": 135412851, + "httpApiName": "QZ0502 创建证书", + "httpApiPath": "/certs", + "httpApiMethod": "post", + "httpApiCaseName": "无user", + "id": "6e52e4e6-3175-4536-9e6d-7d382c89ba50", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "45b534b1-fd5e-476a-82ee-602b1db69a73", + "name": "QZ0501 查询证书信息(QZ0501 查询证书信息)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs", + "{{cert_id}}" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "createdAt": "2024-01-17T12:00:56.992Z", + "updatedAt": "2024-01-17T12:00:56.992Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "cert": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + } + }, + "x-apifox-orders": [ + "cert" + ], + "required": [ + "cert" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604401, + "tempId": "1701365369736", + "id": 361899012, + "responseExamples": [], + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604401, + "httpApiCaseId": 135411221, + "httpApiName": "QZ0501 查询证书信息", + "httpApiPath": "/certs/{id}", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0501 查询证书信息", + "id": "ccfb2ddb-5779-4d30-9d39-fb5bb4d5d35c", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "e502cadc-b62e-448c-8ef2-07bbbb56fe4e", + "name": "QZ0503 查询所有证书(QZ0503 查询所有证书)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [ + { + "disabled": false, + "key": "name", + "value": "yes" + }, + { + "disabled": false, + "key": "user", + "value": "" + } + ], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "createdAt": "2024-01-17T12:01:04.715Z", + "updatedAt": "2024-01-17T12:01:04.715Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "certs": { + "type": "array", + "items": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + } + } + }, + "x-apifox-orders": [ + "certs" + ], + "required": [ + "certs" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604857, + "tempId": "1701371632576", + "id": 361919492, + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604857, + "httpApiCaseId": 135411220, + "httpApiName": "QZ0503 查询所有证书", + "httpApiPath": "/certs", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0503 查询所有证书", + "id": "f5c426ce-a8a1-4114-b784-538f3af6c13c", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "24a8e399-5037-471f-a117-ca1979385744", + "name": "QZ0502 创建证书(有user)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "method": "POST", + "baseUrl": "http://127.0.0.1:8000", + "body": { + "mode": "raw", + "raw": "{\r\n \"cert\": {\r\n \"level\": 1,\r\n \"name\": \"北海\",\r\n \"place\": \"ex sunt fugiat reprehenderit dolore\",\r\n \"sequence\": 1,\r\n \"scores\": [\r\n 93,\r\n 32,\r\n 23,\r\n 39,\r\n 73\r\n ],\r\n \"time\": \"2023-10-23\",\r\n \"grade\": \"fugiat non Lorem ex\"\r\n },\r\n \"user\": 1\r\n}", + "generateMode": "normal", + "type": "application/json" + }, + "type": "http" + }, + "response": [], + "event": [ + { + "listen": "test", + "script": { + "id": "postProcessors.0.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.ID`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.environment.set(`cert_id`, value);console.log('已设置环境变量【cert_id】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【cert_id】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + } + ], + "responseDefinition": { + "createdAt": "2024-01-17T11:56:09.114Z", + "updatedAt": "2024-01-17T11:56:09.114Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "x-apifox-refs": {}, + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604673, + "tempId": "1701365743650", + "id": 35712287, + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": { + "type": "object", + "properties": { + "cert": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀" + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade" + ] + }, + "user": { + "type": [ + "integer", + "null" + ] + } + }, + "x-apifox-orders": [ + "cert", + "user" + ], + "required": [ + "cert", + "user" + ] + } + }, + "metaInfo": { + "httpApiId": 129604673, + "httpApiCaseId": 135412852, + "httpApiName": "QZ0502 创建证书", + "httpApiPath": "/certs", + "httpApiMethod": "post", + "httpApiCaseName": "有user", + "id": "43ae1d5c-e283-4e0b-8a36-4f519820904d", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "618422fc-229b-428e-ad69-778a63534d58", + "name": "QZ0503 查询所有证书(QZ0503 查询所有证书)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [ + { + "disabled": false, + "key": "name", + "value": "" + }, + { + "disabled": false, + "key": "user", + "value": "1" + } + ], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "createdAt": "2024-01-17T12:01:04.715Z", + "updatedAt": "2024-01-17T12:01:04.715Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "certs": { + "type": "array", + "items": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + } + } + }, + "x-apifox-orders": [ + "certs" + ], + "required": [ + "certs" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604857, + "tempId": "1701371632576", + "id": 361919492, + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604857, + "httpApiCaseId": 135411373, + "httpApiName": "QZ0503 查询所有证书", + "httpApiPath": "/certs", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0503 查询所有证书", + "id": "8d8614b0-7dde-48f3-aaf4-9c3168427169", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "2636bfd6-ace5-44b3-865f-919794f1b798", + "name": "QZ0501 查询证书信息(QZ0501 查询证书信息)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs", + "{{cert_id}}" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "createdAt": "2024-01-17T12:00:56.992Z", + "updatedAt": "2024-01-17T12:00:56.992Z", + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "cert": { + "type": "object", + "properties": { + "level": { + "type": "integer", + "title": "等级", + "enum": [ + 1, + 2, + 3 + ], + "x-apifox": { + "enumDescriptions": { + "1": "初级", + "2": "中级", + "3": "高级" + } + } + }, + "name": { + "type": "string", + "title": "参与者" + }, + "place": { + "type": "string", + "title": "地址" + }, + "sequence": { + "type": "integer", + "title": "第几次认证", + "mock": { + "mock": "1" + } + }, + "scores": { + "type": "string", + "title": "分数", + "description": "暂时是固定五个分数" + }, + "time": { + "type": "string", + "title": "时间", + "mock": { + "mock": "@date(\"yyyy-MM-dd\")" + }, + "format": "date", + "examples": [ + "2023-10-23" + ] + }, + "grade": { + "type": "string", + "title": "等级", + "description": "优秀", + "readOnly": true + }, + "ID": { + "type": "string", + "title": "证书编号", + "mock": { + "mock": "@regexp(/PLPT01001\\d\\d\\d\\d\\d/)" + } + }, + "user": { + "anyOf": [ + { + "$ref": "#/definitions/1077996" + }, + { + "type": "null" + } + ] + } + }, + "x-apifox-refs": {}, + "x-apifox-orders": [ + "level", + "name", + "place", + "sequence", + "grade", + "scores", + "time", + "ID", + "user" + ], + "required": [ + "level", + "name", + "place", + "sequence", + "scores", + "time", + "grade", + "ID", + "user" + ] + } + }, + "x-apifox-orders": [ + "cert" + ], + "required": [ + "cert" + ] + }, + "defaultEnable": true, + "projectId": 404238, + "ordering": 1, + "apiDetailId": 129604401, + "tempId": "1701365369736", + "id": 361899012, + "responseExamples": [], + "schemaDefinitions": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + } + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604401, + "httpApiCaseId": 135411372, + "httpApiName": "QZ0501 查询证书信息", + "httpApiPath": "/certs/{id}", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0501 查询证书信息", + "id": "4dcda0b8-9018-416f-9896-2057612efef2", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + } + ], + "name": "QZ模块证书 200" + } + ], + "info": { + "name": "QZ模块证书 200" + }, + "dataSchemas": { + "1077996": { + "type": "object", + "properties": { + "nickname": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "avatar": { + "type": "string", + "mock": { + "mock": "@image('100x100')" + }, + "title": "头像" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "nickname", + "avatar", + "id" + ], + "title": "user_simple", + "name": "user_simple" + } + }, + "mockRules": { + "rules": [], + "enableSystemRule": true + }, + "environment": { + "id": 510825, + "name": "测试环境", + "baseUrl": "http://127.0.0.1:8000", + "baseUrls": { + "default": "http://127.0.0.1:8000" + }, + "variable": { + "id": "8d2852a1-daa8-4afc-90a0-6033f72310c9", + "name": "测试环境", + "values": [ + { + "type": "any", + "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOjEsImV4cCI6MTcwNjg3Mjc3Ny45NTAxNTR9.BSiV3vJPqdeARJL7V4l70yIZKb5eeev0VTmFMjq4QAw", + "key": "token", + "initialValue": "" + }, + { + "type": "any", + "value": "31", + "key": "quiz_id", + "initialValue": "" + }, + { + "type": "any", + "value": "16", + "key": "word_id_2", + "initialValue": "" + }, + { + "type": "any", + "value": "15", + "key": "word_id_1", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "token_2", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "word_id_3", + "initialValue": "" + }, + { + "type": "any", + "value": "2", + "key": "user_id", + "initialValue": "" + }, + { + "type": "any", + "value": "1", + "key": "article_id", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "comment_id_1", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "comment_id_2", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "like_num_2", + "initialValue": "" + }, + { + "type": "any", + "value": 6, + "key": "num_pre", + "initialValue": "" + }, + { + "type": "any", + "value": "7", + "key": "num_later", + "initialValue": "" + }, + { + "type": "any", + "value": "2", + "key": "id", + "initialValue": "2" + }, + { + "type": "any", + "value": "13", + "key": "music_id", + "initialValue": "13" + }, + { + "type": "any", + "value": "undefined", + "key": "rewards_id", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "undefined", + "key": "title_id", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "SP000011", + "key": "products_id", + "initialValue": "SP000011" + }, + { + "type": "any", + "value": "DD000004", + "key": "order_id", + "initialValue": "DD000004" + }, + { + "type": "any", + "value": "JL000039", + "key": "transaction_id", + "initialValue": "JL000039" + }, + { + "type": "any", + "value": "CD000015", + "key": "list_id", + "initialValue": "CD000015" + }, + { + "type": "any", + "value": "SJ000008", + "key": "paper_id", + "initialValue": "SJ000008" + }, + { + "type": "any", + "value": "undefined", + "key": "paper_count", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "DJ000014", + "key": "paper_record_id", + "initialValue": "DJ000014" + }, + { + "type": "any", + "value": "DT000016", + "key": "quiz_record_id", + "initialValue": "DT000016" + }, + { + "type": "any", + "value": "PLPT0000000033", + "key": "cert_id", + "initialValue": "PLPT0000000033" + } + ] + }, + "type": "normal", + "parameter": { + "header": [], + "query": [], + "body": [], + "cookie": [] + } + }, + "globals": { + "baseUrl": "", + "baseUrls": {}, + "variable": { + "id": "2840edfb-857f-4387-86f1-71a08aacf685", + "values": [] + }, + "parameter": { + "header": [], + "query": [], + "body": [], + "cookie": [] + } + }, + "isServerBuild": false, + "isTestFlowControl": false +} diff --git a/tests/cert_404.json b/tests/cert_404.json new file mode 100644 index 00000000..f02f6489 --- /dev/null +++ b/tests/cert_404.json @@ -0,0 +1,593 @@ +{ + "apifoxCli": "1.1.0", + "item": [ + { + "item": [ + { + "id": "e2263ea4-c07a-4fae-89f7-2ef4ac189ea0", + "name": "LG0101 账号密码登录(登录用户admin)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "login" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "method": "POST", + "baseUrl": "http://127.0.0.1:8000", + "body": { + "mode": "raw", + "raw": "{\r\n \"username\": \"admin\",\r\n \"password\": \"testtest123\"\r\n}", + "generateMode": "normal", + "type": "application/json" + }, + "type": "http" + }, + "response": [], + "event": [ + { + "listen": "test", + "script": { + "id": "postProcessors.0.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.token`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.environment.set(`token`, value);console.log('已设置环境变量【token】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【token】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + }, + { + "listen": "test", + "script": { + "id": "postProcessors.1.extractor", + "type": "text/javascript", + "exec": [ + "", + " if (JSON.setEnableBigInt) {", + " JSON.setEnableBigInt(undefined);", + " }", + " ", + " try{", + " ", + " const expression = pm.variables.replaceIn(`$.id`);", + " const JSONPath = require('jsonpath-plus').JSONPath;", + " const jsonData = pm.response.json();", + " let value = JSONPath({", + " json: jsonData,", + " path: expression,", + " wrap: false", + " });", + "", + " ", + " if (false && undefined !== undefined) {", + " if (Array.isArray(value)) {", + " value = Number(undefined) >= 0 ? value[undefined] : value[value.length + Number(undefined)];", + " } else {", + " value = undefined;", + " }", + " }", + " ", + " ", + " switch (typeof value) {", + " case 'object':", + " value = JSON.stringify(value);", + " break;", + " default:", + " value = String(value);", + " break;", + " }", + " ", + " pm.variables.set(`user_id`, value);console.log('已设置临时变量【user_id】,值为 【' + value + '】')", + " } catch(e) {", + " e.message = '提取变量【user_id】出错: ' + e.message;", + " throw e;", + " }", + " ", + " " + ] + } + } + ], + "responseDefinition": { + "id": 4183271, + "apiDetailId": 5318056, + "name": "成功", + "code": 200, + "contentType": "json", + "jsonSchema": { + "type": "object", + "properties": { + "token": { + "type": "string", + "mock": { + "mock": "@string" + }, + "title": "权" + }, + "id": { + "type": "integer", + "title": "用户id" + } + }, + "required": [ + "token", + "id" + ] + }, + "defaultEnable": true, + "projectId": 0, + "ordering": 1, + "unpackerId": "", + "unpackerSetting": "", + "createdAt": "2021-07-29T14:43:37.000Z", + "updatedAt": "2021-08-12T16:27:18.000Z", + "deletedAt": null, + "folderId": 0, + "schemaDefinitions": {} + }, + "requestDefinition": { + "jsonSchema": { + "type": "object", + "properties": { + "username": { + "type": "string", + "mock": { + "mock": "@cname" + }, + "title": "用户名" + }, + "password": { + "type": "string", + "mock": { + "mock": "@string('lower', 1, 3)" + }, + "title": "密码" + } + }, + "required": [ + "username", + "password" + ] + } + }, + "metaInfo": { + "httpApiId": 5318056, + "httpApiCaseId": 135413095, + "httpApiName": "LG0101 账号密码登录", + "httpApiPath": "/login", + "httpApiMethod": "post", + "httpApiCaseName": "登录用户admin", + "id": "7b9def38-bcc7-4782-8b15-3e5eaca483c0", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "932ef5b2-8b6b-42e3-8596-3b800a77e8fd", + "name": "QZ0501 查询证书信息(QZ0501 查询证书信息)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs", + "1" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "id": 69812670, + "createdAt": "2022-07-15T06:52:36.000Z", + "updatedAt": "2022-07-15T06:52:36.000Z", + "deletedAt": null, + "name": "不存在", + "apiDetailId": 0, + "projectId": 404238, + "code": 404, + "contentType": "json", + "ordering": 30, + "jsonSchema": {}, + "defaultEnable": false, + "folderId": 0, + "responseExamples": [], + "schemaDefinitions": {} + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604401, + "httpApiCaseId": 135413110, + "httpApiName": "QZ0501 查询证书信息", + "httpApiPath": "/certs/{id}", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0501 查询证书信息", + "id": "d6616120-c6e3-47ba-b53e-a317765f4adf", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + }, + { + "id": "11cf8ecf-8966-4451-b245-8ab31cf4a02a", + "name": "QZ0503 查询所有证书(QZ0503 查询所有证书)", + "request": { + "url": { + "protocol": "http", + "port": "8000", + "path": [ + "certs" + ], + "host": [ + "127", + "0", + "0", + "1" + ], + "query": [ + { + "disabled": false, + "key": "name", + "value": "" + }, + { + "disabled": false, + "key": "user", + "value": "1234" + } + ], + "variable": [] + }, + "header": [ + { + "key": "token", + "value": "{{token}}" + }, + { + "key": "User-Agent", + "value": "Apifox/1.0.0 (https://apifox.com)" + } + ], + "method": "GET", + "baseUrl": "http://127.0.0.1:8000", + "body": {}, + "type": "http" + }, + "response": [], + "event": [], + "responseDefinition": { + "id": 69812670, + "createdAt": "2022-07-15T06:52:36.000Z", + "updatedAt": "2022-07-15T06:52:36.000Z", + "deletedAt": null, + "name": "不存在", + "apiDetailId": 0, + "projectId": 404238, + "code": 404, + "contentType": "json", + "ordering": 30, + "jsonSchema": {}, + "defaultEnable": false, + "folderId": 0, + "responseExamples": [], + "schemaDefinitions": {} + }, + "requestDefinition": { + "jsonSchema": {} + }, + "metaInfo": { + "httpApiId": 129604857, + "httpApiCaseId": 135413108, + "httpApiName": "QZ0503 查询所有证书", + "httpApiPath": "/certs", + "httpApiMethod": "get", + "httpApiCaseName": "QZ0503 查询所有证书", + "id": "a2615834-7a46-4f5f-886a-37c8da5fdae2", + "type": "http" + }, + "type": "http", + "protocolProfileBehavior": { + "useWhatWGUrlParser": false, + "disableUrlEncoding": false + } + } + ], + "name": "QZ模块证书 404" + } + ], + "info": { + "name": "QZ模块证书 404" + }, + "dataSchemas": {}, + "mockRules": { + "rules": [], + "enableSystemRule": true + }, + "environment": { + "id": 510825, + "name": "测试环境", + "baseUrl": "http://127.0.0.1:8000", + "baseUrls": { + "default": "http://127.0.0.1:8000" + }, + "variable": { + "id": "40f13f65-07c0-4267-bfe2-5472eae734ec", + "name": "测试环境", + "values": [ + { + "type": "any", + "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOjEsImV4cCI6MTcwNjg3Mjc3Ny45NTAxNTR9.BSiV3vJPqdeARJL7V4l70yIZKb5eeev0VTmFMjq4QAw", + "key": "token", + "initialValue": "" + }, + { + "type": "any", + "value": "31", + "key": "quiz_id", + "initialValue": "" + }, + { + "type": "any", + "value": "16", + "key": "word_id_2", + "initialValue": "" + }, + { + "type": "any", + "value": "15", + "key": "word_id_1", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "token_2", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "word_id_3", + "initialValue": "" + }, + { + "type": "any", + "value": "2", + "key": "user_id", + "initialValue": "" + }, + { + "type": "any", + "value": "1", + "key": "article_id", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "comment_id_1", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "comment_id_2", + "initialValue": "" + }, + { + "type": "any", + "value": "", + "key": "like_num_2", + "initialValue": "" + }, + { + "type": "any", + "value": 6, + "key": "num_pre", + "initialValue": "" + }, + { + "type": "any", + "value": "7", + "key": "num_later", + "initialValue": "" + }, + { + "type": "any", + "value": "2", + "key": "id", + "initialValue": "2" + }, + { + "type": "any", + "value": "13", + "key": "music_id", + "initialValue": "13" + }, + { + "type": "any", + "value": "undefined", + "key": "rewards_id", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "undefined", + "key": "title_id", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "SP000011", + "key": "products_id", + "initialValue": "SP000011" + }, + { + "type": "any", + "value": "DD000004", + "key": "order_id", + "initialValue": "DD000004" + }, + { + "type": "any", + "value": "JL000039", + "key": "transaction_id", + "initialValue": "JL000039" + }, + { + "type": "any", + "value": "CD000015", + "key": "list_id", + "initialValue": "CD000015" + }, + { + "type": "any", + "value": "SJ000008", + "key": "paper_id", + "initialValue": "SJ000008" + }, + { + "type": "any", + "value": "undefined", + "key": "paper_count", + "initialValue": "undefined" + }, + { + "type": "any", + "value": "DJ000014", + "key": "paper_record_id", + "initialValue": "DJ000014" + }, + { + "type": "any", + "value": "DT000016", + "key": "quiz_record_id", + "initialValue": "DT000016" + }, + { + "type": "any", + "value": "PLPT0000000033", + "key": "cert_id", + "initialValue": "PLPT0000000033" + } + ] + }, + "type": "normal", + "parameter": { + "header": [], + "query": [], + "body": [], + "cookie": [] + } + }, + "globals": { + "baseUrl": "", + "baseUrls": {}, + "variable": { + "id": "2840edfb-857f-4387-86f1-71a08aacf685", + "values": [] + }, + "parameter": { + "header": [], + "query": [], + "body": [], + "cookie": [] + } + }, + "isServerBuild": false, + "isTestFlowControl": false +}