Skip to content

Commit

Permalink
feat(microapp): 新增直播小玩法获取题库列表接口
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Mar 5, 2024
1 parent 5ba374d commit db5f38c
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.Webcast
public abstract class DouyinMicroAppWebcastResponse : CommonResponseBase, ICommonResponse
{
/// <summary>
/// 获取抖音小程序 API 返回的详细错误号
/// 获取抖音小程序 API 返回的错误码
/// </summary>
[Newtonsoft.Json.JsonProperty("errcode")]
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.Webcast
{
public static class DouyinMicroAppWebcastClientExecuteQuizExtensions
{
/// <summary>
/// <para>异步调用 [GET] /quiz/get 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/interaction/develop/server/live/get_quiz_list ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.WebcastQuizGetResponse> ExecuteWebcastQuizGetAsync(this DouyinMicroAppWebcastClient client, Models.WebcastQuizGetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "quiz", "get")
.WithHeader("x-token", request.AccessToken);

if (request.Level is not null)
flurlReq.SetQueryParam("level", request.Level.Value);

if (request.Type is not null)
flurlReq.SetQueryParam("type", request.Type.Value);

if (request.Number is not null)
flurlReq.SetQueryParam("num", request.Number.Value);

return await client.SendFlurlRequestAsJsonAsync<Models.WebcastQuizGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ public class Data
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
[Newtonsoft.Json.JsonProperty("errcode")]
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
public override long ErrorCode { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Newtonsoft.Json.JsonProperty("errmsg")]
[System.Text.Json.Serialization.JsonPropertyName("errmsg")]
public override string? ErrorMessage { get; set; }

/// <summary>
/// 获取或设置返回数据。
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ public class User
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
[Newtonsoft.Json.JsonProperty("errcode")]
[System.Text.Json.Serialization.JsonPropertyName("errcode")]
public override long ErrorCode { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Newtonsoft.Json.JsonProperty("errmsg")]
[System.Text.Json.Serialization.JsonPropertyName("errmsg")]
public override string? ErrorMessage { get; set; }

/// <summary>
/// 获取或设置麦位基本信息。
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.Webcast.Models
{
/// <summary>
/// <para>表示 [GET] /quiz/get 接口的请求。</para>
/// </summary>
public class WebcastQuizGetRequest : DouyinMicroAppWebcastRequest
{
/// <summary>
/// 获取或设置难度等级。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? Level { get; set; }

/// <summary>
/// 获取或设置题目类型。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? Type { get; set; }

/// <summary>
/// 获取或设置题目数量。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? Number { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.Webcast.Models
{
/// <summary>
/// <para>表示 [GET] /quiz/get 接口的响应。</para>
/// </summary>
public class WebcastQuizGetResponse : DouyinMicroAppWebcastResponse
{
public static class Types
{
public class Data
{
public static class Types
{
public class Quiz
{
/// <summary>
/// 获取或设置题目 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("id")]
[System.Text.Json.Serialization.JsonPropertyName("id")]
public string Id { get; set; } = default!;

/// <summary>
/// 获取或设置题目标题。
/// </summary>
[Newtonsoft.Json.JsonProperty("title")]
[System.Text.Json.Serialization.JsonPropertyName("title")]
public string Title { get; set; } = default!;

/// <summary>
/// 获取或设置题目选项列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("options")]
[System.Text.Json.Serialization.JsonPropertyName("options")]
public string[] OptionList { get; set; } = default!;

/// <summary>
/// 获取或设置题目答案下标。
/// </summary>
[Newtonsoft.Json.JsonProperty("answer")]
[System.Text.Json.Serialization.JsonPropertyName("answer")]
public int AnswerIndex { get; set; }
}
}

/// <summary>
/// 获取或设置题目列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("list")]
[System.Text.Json.Serialization.JsonPropertyName("list")]
public Types.Quiz[] QuizList { get; set; } = default!;
}
}

/// <summary>
/// 获取或设置返回数据。
/// </summary>
[Newtonsoft.Json.JsonProperty("data")]
[System.Text.Json.Serialization.JsonPropertyName("data")]
public Types.Data Data { get; set; } = default!;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"data": {
"list": [
{
"title": "题目1",
"options": [
"选项1",
"选项2",
"选项3",
"选项4"
],
"answer": 1,
"id": "EYDnokrgyVeOeFa"
},
{
"title": "题目2",
"options": [
"选项1",
"选项2",
"选项3",
"选项4"
],
"answer": 4,
"id": "TlL6LwvWapkoBMv"
}
]
}
}

0 comments on commit db5f38c

Please sign in to comment.