|
@@ -884,7 +884,7 @@ namespace TEAMModelOS.SDK.Models
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public static async Task<string> CreateMoofenExam(IHttpClientFactory _httpClient, JsonElement json)
|
|
|
|
|
|
+ public static async Task<string> CreateMoofenExam(IHttpClientFactory _httpClient, JsonElement json,DingDing _ding)
|
|
{
|
|
{
|
|
string content = string.Empty;
|
|
string content = string.Empty;
|
|
try {
|
|
try {
|
|
@@ -928,10 +928,9 @@ namespace TEAMModelOS.SDK.Models
|
|
dict.Add("signKey", "TMD");
|
|
dict.Add("signKey", "TMD");
|
|
var keys = dict.Keys.OrderBy(x => x);
|
|
var keys = dict.Keys.OrderBy(x => x);
|
|
var parmas = string.Join("&", keys.Select(x => $"{x}={dict[x]}"));
|
|
var parmas = string.Join("&", keys.Select(x => $"{x}={dict[x]}"));
|
|
- var signtime = DateTimeOffset.UtcNow.GetGMTTime(8).ToUnixTimeSeconds();
|
|
|
|
- parmas = $"{parmas}&signtime={signtime}";
|
|
|
|
- string sign = Md5Hash.Encrypt(parmas);
|
|
|
|
- dict.Add("signtime", $"{signtime}");
|
|
|
|
|
|
+ //var signtime = DateTimeOffset.UtcNow.GetGMTTime(8).ToUnixTimeSeconds();
|
|
|
|
+ //parmas = $"{parmas}&signtime={signtime}";
|
|
|
|
+ string sign = Md5Hash.Encrypt(parmas);
|
|
dict.Add("sign", $"{sign}");
|
|
dict.Add("sign", $"{sign}");
|
|
dict.Remove("signKey");
|
|
dict.Remove("signKey");
|
|
//var pkeys = dict.Keys;
|
|
//var pkeys = dict.Keys;
|
|
@@ -940,13 +939,13 @@ namespace TEAMModelOS.SDK.Models
|
|
var httpClient = _httpClient.CreateClient();
|
|
var httpClient = _httpClient.CreateClient();
|
|
var request = new HttpRequestMessage
|
|
var request = new HttpRequestMessage
|
|
{
|
|
{
|
|
- Method = new HttpMethod("POST"),
|
|
|
|
|
|
+ Method = new HttpMethod("POST"),
|
|
RequestUri = new Uri(url),
|
|
RequestUri = new Uri(url),
|
|
- Content = new FormUrlEncodedContent(dict)
|
|
|
|
|
|
+ Content = new StringContent(JsonConvert.SerializeObject(dict))
|
|
};
|
|
};
|
|
// 设置请求头中的Content-Type
|
|
// 设置请求头中的Content-Type
|
|
// httpClient.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
// httpClient.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
- var mediaTypeHeader = new MediaTypeHeaderValue("application/x-www-form-urlencoded")
|
|
|
|
|
|
+ var mediaTypeHeader = new MediaTypeHeaderValue("application/json")
|
|
{
|
|
{
|
|
CharSet = "UTF-8"
|
|
CharSet = "UTF-8"
|
|
};
|
|
};
|
|
@@ -963,11 +962,73 @@ namespace TEAMModelOS.SDK.Models
|
|
|
|
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- return "";
|
|
|
|
|
|
+ await _ding.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},ThirdService/CreateMoofenExam()\n{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
|
|
}
|
|
}
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static async Task<List<stuAns>> CreateMoofenExamResult(IHttpClientFactory _httpClient, JsonElement json, DingDing _ding)
|
|
|
|
+ {
|
|
|
|
+ string content = string.Empty;
|
|
|
|
+ List<stuAns> ans = new();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, string> dict = new Dictionary<string, string>();
|
|
|
|
+ if (json.TryGetProperty("examCode", out JsonElement examCode) && !string.IsNullOrWhiteSpace($"{examCode}"))
|
|
|
|
+ {
|
|
|
|
+ dict.Add("examName", $"{examCode}");
|
|
|
|
+ }
|
|
|
|
+ if (json.TryGetProperty("subjects", out JsonElement subjects) && subjects.ValueKind.Equals(JsonValueKind.Array))
|
|
|
|
+ {
|
|
|
|
+ dict.Add("subjects", $"{subjects}");
|
|
|
|
+ }
|
|
|
|
+ dict.Add("signKey", "TMD");
|
|
|
|
+ var keys = dict.Keys.OrderBy(x => x);
|
|
|
|
+ var parmas = string.Join("&", keys.Select(x => $"{x}={dict[x]}"));
|
|
|
|
+ //var signtime = DateTimeOffset.UtcNow.GetGMTTime(8).ToUnixTimeSeconds();
|
|
|
|
+ //parmas = $"{parmas}&signtime={signtime}";
|
|
|
|
+ string sign = Md5Hash.Encrypt(parmas);
|
|
|
|
+ dict.Add("sign", $"{sign}");
|
|
|
|
+ dict.Remove("signKey");
|
|
|
|
+ //var pkeys = dict.Keys;
|
|
|
|
+ string url = "https://www.moofen.net/oss/esi/exam/tmodel/result";
|
|
|
|
+ //parmas = string.Join("&", pkeys.Select(x => $"{x}={dict[x]}"));
|
|
|
|
+ var httpClient = _httpClient.CreateClient();
|
|
|
|
+ var request = new HttpRequestMessage
|
|
|
|
+ {
|
|
|
|
+ Method = new HttpMethod("POST"),
|
|
|
|
+ RequestUri = new Uri(url),
|
|
|
|
+ Content = new StringContent(JsonConvert.SerializeObject(dict))
|
|
|
|
+ };
|
|
|
|
+ // 设置请求头中的Content-Type
|
|
|
|
+ // httpClient.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
+ var mediaTypeHeader = new MediaTypeHeaderValue("application/json")
|
|
|
|
+ {
|
|
|
|
+ CharSet = "UTF-8"
|
|
|
|
+ };
|
|
|
|
+ httpClient.Timeout = new TimeSpan(0, 0, 10);
|
|
|
|
+ request.Content.Headers.ContentType = mediaTypeHeader;
|
|
|
|
+ HttpResponseMessage response = await _httpClient.CreateClient().SendAsync(request);
|
|
|
|
+ if (response.StatusCode.Equals(HttpStatusCode.OK))
|
|
|
|
+ {
|
|
|
|
+ content = await response.Content.ReadAsStringAsync();
|
|
|
|
+
|
|
|
|
+ var data = content.ToObject<JsonElement>();
|
|
|
|
+ if (data.TryGetProperty("data", out JsonElement _data))
|
|
|
|
+ {
|
|
|
|
+ ans = _data.ToObject<List<stuAns>>();
|
|
|
|
+ return ans;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ await _ding.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},ThirdService/CreateMoofenExamResult()\n{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
|
+ }
|
|
|
|
+ return ans;
|
|
|
|
+ }
|
|
|
|
+
|
|
/* private class item
|
|
/* private class item
|
|
{
|
|
{
|
|
public string questionNo { get; set; }
|
|
public string questionNo { get; set; }
|
|
@@ -988,5 +1049,15 @@ namespace TEAMModelOS.SDK.Models
|
|
public string code { get; set; }
|
|
public string code { get; set; }
|
|
public double value { get; set; }
|
|
public double value { get; set; }
|
|
}
|
|
}
|
|
|
|
+ public class stuAns {
|
|
|
|
+ public string stuId { get; set; }
|
|
|
|
+ public List<moofenAns> scoreData { get; set; } = new List<moofenAns>();
|
|
|
|
+ }
|
|
|
|
+ public class moofenAns
|
|
|
|
+ {
|
|
|
|
+ public double questionNo { get; set; }
|
|
|
|
+ public double score { get; set; }
|
|
|
|
+ public string answer { get; set; }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|