|
|
@@ -4,6 +4,7 @@ using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
using System.Diagnostics;
|
|
|
using System.Net.Mail;
|
|
|
using System.Text.Json;
|
|
|
+using System.Text.Json.Serialization;
|
|
|
|
|
|
namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
{
|
|
|
@@ -43,6 +44,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
/// OA通知Secret
|
|
|
/// </summary>
|
|
|
private readonly string GroupStatus_Corpsecret = "7J_ST3jTPzbZpFwl7ttToTVufjEx6O2wuApvKHxt2Ak"; // OA通知Secret
|
|
|
+ private readonly string Journal_Corpsecret = "l2lZbyLfyickVLdgi2bwVTevE-0UuZWpbNPrCbNhst0"; //汇报 凭证密钥
|
|
|
|
|
|
private readonly DateTime _1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
|
private readonly JobPostRepository _jobPostRep;
|
|
|
@@ -68,6 +70,7 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
/// 4:通讯录同步
|
|
|
/// 5:审批
|
|
|
/// 6:团组状态通知
|
|
|
+ /// 7:汇报
|
|
|
/// </param>
|
|
|
/// <returns></returns>
|
|
|
private async Task<Access_TokenView> GetTokenAsync(int applicationType)
|
|
|
@@ -106,6 +109,11 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
access_Token.corpsecret = GroupStatus_Corpsecret;
|
|
|
cacheName = "GroupStatus_Access_Token";
|
|
|
}
|
|
|
+ else if (applicationType == 7) //汇报
|
|
|
+ {
|
|
|
+ access_Token.corpsecret = Journal_Corpsecret;
|
|
|
+ cacheName = "Journal_Access_Token";
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
tokenResult.errmsg = "未识别应用类型Id!";
|
|
|
@@ -393,13 +401,13 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
if (dto.ToEmails == null) return new EmailResult() { errcode = -1, errmsg = "收件人邮箱列表不能为空" };
|
|
|
if (string.IsNullOrEmpty(dto.Subject)) return new EmailResult() { errcode = -1, errmsg = "邮件主题不能为空" };
|
|
|
if (string.IsNullOrEmpty(dto.Body)) return new EmailResult() { errcode = -1, errmsg = "邮件内容不能为空" };
|
|
|
-
|
|
|
+
|
|
|
// 当前内容大小
|
|
|
long currentSize = GetUtf8ByteSize(dto.Body);
|
|
|
// 文件处理
|
|
|
var attachments = new List<Domain.ViewModels.QiYeWeChat.Attachment>();
|
|
|
var files = dto.Files;
|
|
|
- if (files != null && files.Length > 0)
|
|
|
+ if (files != null && files.Length > 0)
|
|
|
{
|
|
|
if (files.Length > 200) return new EmailResult() { errcode = -1, errmsg = "附件个数不能超过200个" };
|
|
|
|
|
|
@@ -423,7 +431,8 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
var feilName = $"{fileNameWithoutExtension}{extension}";
|
|
|
|
|
|
currentSize += GetUtf8ByteSize(base64String);
|
|
|
- attachments.Add(new Domain.ViewModels.QiYeWeChat.Attachment() {
|
|
|
+ attachments.Add(new Domain.ViewModels.QiYeWeChat.Attachment()
|
|
|
+ {
|
|
|
file_name = feilName,
|
|
|
content = base64String
|
|
|
});
|
|
|
@@ -1655,6 +1664,101 @@ namespace OASystem.API.OAMethodLib.QiYeWeChatAPI
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ #region 汇报
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 批量获取汇报记录单号
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="startTime">开始时间</param>
|
|
|
+ /// <param name="endTime">结束时间</param>
|
|
|
+ /// <param name="cursor"></param>
|
|
|
+ /// <param name="limit"></param>
|
|
|
+ /// <param name="filters"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JournalRecordListView> GetJournalRecordListAsync(DateTime startTime, DateTime endTime, int cursor = 0, int limit = 10, List<JournalFilter> filters = null)
|
|
|
+ {
|
|
|
+ JournalRecordListView result = new JournalRecordListView();
|
|
|
+
|
|
|
+ long starttime = (long)(startTime - _1970).TotalSeconds;
|
|
|
+ long endtime = (long)(endTime - _1970).TotalSeconds;
|
|
|
+
|
|
|
+ //获取汇报数据 token (Type = 7)
|
|
|
+ Access_TokenView access_Token = await GetTokenAsync(7);
|
|
|
+ if (access_Token.errcode != 0)
|
|
|
+ {
|
|
|
+ result.errcode = access_Token.errcode;
|
|
|
+ result.errmsg = string.Format("【企业微信】【获取汇报记录单号】【Token】【Msg】{0}", access_Token.errmsg);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ string url = string.Format("/cgi-bin/oa/journal/get_record_list?access_token={0}", access_Token.access_token);
|
|
|
+
|
|
|
+ JournalRecordList_Request req = new JournalRecordList_Request()
|
|
|
+ {
|
|
|
+ starttime = starttime,
|
|
|
+ endtime = endtime,
|
|
|
+ cursor = cursor,
|
|
|
+ limit = limit,
|
|
|
+ filters = filters
|
|
|
+ };
|
|
|
+
|
|
|
+ var options = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
|
|
+ options.Converters.Add(new JsonStringEnumConverter());
|
|
|
+ var json = System.Text.Json.JsonSerializer.Serialize(req, options);
|
|
|
+ var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
+ var create_Req = await _httpClient.PostAsync(url, content);
|
|
|
+ var stringResponse = await create_Req.Content.ReadAsStringAsync();
|
|
|
+
|
|
|
+ result = System.Text.Json.JsonSerializer.Deserialize<JournalRecordListView>(stringResponse,
|
|
|
+ new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取汇报记录详情
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="journaluuid"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JournalDetailView> GetJournalRecordDetailAsync(string journaluuid)
|
|
|
+ {
|
|
|
+ JournalDetailView result = new JournalDetailView();
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(journaluuid))
|
|
|
+ {
|
|
|
+ result.errmsg = "journaluuid为空!";
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取汇报数据 token (Type = 7)
|
|
|
+ Access_TokenView access_Token = await GetTokenAsync(7);
|
|
|
+ if (access_Token.errcode != 0)
|
|
|
+ {
|
|
|
+ result.errcode = access_Token.errcode;
|
|
|
+ result.errmsg = string.Format("【企业微信】【获取汇报详情】【Token】【Msg】{0}", access_Token.errmsg);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ string url = string.Format("/cgi-bin/oa/journal/get_record_detail?access_token={0}", access_Token.access_token);
|
|
|
+
|
|
|
+ var req = new
|
|
|
+ {
|
|
|
+ journaluuid = journaluuid
|
|
|
+ };
|
|
|
+
|
|
|
+ var json = System.Text.Json.JsonSerializer.Serialize(req);
|
|
|
+ var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
+ var create_Req = await _httpClient.PostAsync(url, content);
|
|
|
+ var stringResponse = await create_Req.Content.ReadAsStringAsync();
|
|
|
+
|
|
|
+ result = System.Text.Json.JsonSerializer.Deserialize<JournalDetailView>(stringResponse,
|
|
|
+ new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region hook机器人
|
|
|
|
|
|
|