using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Threading.Tasks;
|
|
namespace DingDingMsg
|
{
|
class Program
|
{
|
|
static DBHelper oCN = new DBHelper();
|
static DataSet dt = new DataSet();
|
static async Task Main(string[] args)
|
{
|
string appKey = "dingrsrzhdyn3mlaof95";
|
string appSecret = "RAqH6YtZnPLCpDbuqfaYQkKkVtVdS0wqfC8I26X6qiS-8eoCJCNrzx3fubGND4Sq";
|
Console.WriteLine("Hello World!");
|
while (true)
|
{
|
Console.WriteLine("Hello World!1");
|
//查数据
|
string sql = "select a.HInterID,a.HReceiveMan 接收人,c.HDingDingUserID 钉钉id,b.HDescription 内容 from OA_ErrMsgBackBillSub2" +
|
" a inner join OA_ErrMsgBackBillMain b on a.HInterID=b.HInterID left join Gy_Czygl c " +
|
"on a.HReceiveMan = c.Czymc where HSendFlag = '0' order by a.HInterID";
|
dt = oCN.RunProcReturn(sql, "OA_ErrMsgBackBillSub2");
|
if (dt.Tables[0].Rows.Count > 0)
|
{
|
string HContext = "";
|
|
|
for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
|
{
|
HContext = dt.Tables[0].Rows[i]["内容"].ToString();
|
string HName = dt.Tables[0].Rows[i]["钉钉id"].ToString();
|
string Stares = dt.Tables[0].Rows[i]["接收人"].ToString();
|
|
MSG msg = new MSG();
|
|
//获取企业的access_token的值
|
string response = msg.GetAccessToken(appKey, appSecret);
|
JObject responseJson = JObject.Parse(response);
|
// 获取access_token的值
|
string accessToken = responseJson["accessToken"].ToString();
|
|
//调用方法发送消息
|
string agentId = "3118119317";//钉钉后台建立的小程序id
|
string userIdList = HName;//钉钉人员的id
|
string deptIdList = "0"; // 空字符串表示不指定部门
|
string toAllUser = "false";
|
string message = HContext;
|
|
// 调用方法发送消息
|
response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message);
|
ResponseData responseData = JsonConvert.DeserializeObject<ResponseData>(response);
|
if (responseData.errcode == 0)
|
{
|
//更新状态
|
string sql1 = "update OA_ErrMsgBackBillSub2 set HSendFlag='1' where HReceiveMan in ('" + Stares + "')";
|
oCN.RunProc(sql1);
|
Console.WriteLine(sql1);
|
}
|
else
|
{
|
Console.WriteLine(responseData.errcode);
|
//Console.WriteLine();
|
}
|
|
}
|
|
|
|
}
|
|
// 等待一分钟
|
await Task.Delay(TimeSpan.FromMinutes(1));
|
}
|
|
}
|
//public static (string, string,string) Get_User()
|
//{
|
// //查询数据库子表所有信息
|
// string sql = "select a.HReceiveMan 接收人,c.HDingDingUserID 钉钉id,b.HDescription 内容 from OA_ErrMsgBackBillSub2 a left join OA_ErrMsgBackBillMain b on a.HInterID=b.HInterID left join Gy_Czygl c on a.HReceiveMan=c.Czymc where HSendFlag = '0'";
|
// dt = oCN.RunProcReturn(sql, "OA_ErrMsgBackBillSub2");
|
// if (dt.Tables[0].Rows.Count>0)
|
// {
|
// string HContext = dt.Tables[0].Rows[0]["内容"].ToString();
|
// List<string> HNames = new List<string>();
|
// List<string> StaresList = new List<string>();
|
|
// for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
|
// {
|
// string HName = dt.Tables[0].Rows[i]["钉钉id"].ToString();
|
// string Stares = dt.Tables[0].Rows[i]["接收人"].ToString();
|
// HNames.Add(HName);
|
// StaresList.Add(Stares);
|
|
// }
|
// string concatenatedNames = string.Join(",", HNames);
|
// string concatenatedStares = string.Join("','", StaresList);
|
// return (concatenatedNames, HContext, concatenatedStares);
|
// }
|
|
// return ("1","1","1");
|
//}
|
|
public class ResponseData
|
{
|
public int errcode { get; set; }
|
public string errmsg { get; set; }
|
public long task_id { get; set; }
|
public string request_id { get; set; }
|
}
|
}
|
}
|