ComplianceServer/oldcode/CRMServices/TS/TSCMDSend.cs

89 lines
4.4 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Net;
using System.Text;
using System.Threading;
using System.Web;
using WX.CRM.BLL.TS;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
namespace WX.CRM.CRMServices.TS
{
public class TSCMDSend
{
public void StartPush()
{
WX_TS_CMD_BL bl = new WX_TS_CMD_BL();
string clientid = Utility.GetSettingByKey("CRMClientKey");
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
string url = "https://console.tim.qq.com/v4/openim/sendmsg?usersig={0}&identifier={1}&sdkappid={2}&random={3}&contenttype=json";
//用户签名
string usersig = ConfigurationManager.AppSettings["yunim_usersig"] != null ? ConfigurationManager.AppSettings["yunim_usersig"].ToString() : "eJx1z09PgzAYx-E7r6LhitH*ATZMPJABRt3ColuyemmatmDjgApVBON7N*KScfG5-j7JN8*XAwBwd*unSy5E815bZgejXHANXAyxH7gXZ2CMloxbRlo5AeRDCDEJwrlSn0a3ivHCqvZPBYtwCX9vprRUtdWFPhkuK12j2d7JVzb1-g91upzGTbpf3SWrt30ncv8QC*r5tt4IKoexwCKJPJpVPHvEfdkMVy*eiXUa98tjPN4e05wsghLqQ0Dxfb99zvnQ1H31QOCYRclH26*puJklra7U6SdEMApRhF3n2-kBGp1YWA__";
string identifier = ConfigurationManager.AppSettings["yunim_identifier"] != null ? ConfigurationManager.AppSettings["yunim_identifier"].ToString() : "admin1";
string sdkappid = ConfigurationManager.AppSettings["yunim_appid"] != null ? ConfigurationManager.AppSettings["yunim_appid"].ToString() : "1400023565";
string random2 = new Random().Next(1000000, 2000000).ToString();
url = string.Format(url, usersig, identifier, sdkappid, random2);
DataTable table = bl.GetCmdPici();//获取批次
//LogHelper.Info("批次数量:" + table.Rows.Count );
foreach (DataRow row in table.Rows)
{
string timeslotend = row["timeslotend"].ToString();
string timeslotstart = row["timeslotstart"].ToString();
int timetype = Convert.ToInt32(row["timetype"]);
decimal pici = Convert.ToDecimal(row["pici"]);
string alias = row["alias"].ToString().Replace("-", "_").ToLower();
string jsontxt = row["jsontxt"].ToString();//json文本
string cmd = row["CMD"].ToString();
long random = new Random().Next(1000000, 2000000);
var msgobj = new
{
SyncOtherMachine = 1, //消息同步至发送方
From_Account = "admin1",
To_Account = alias + "_yun",
MsgRandom = random,
MsgTimeStamp = (long)Utility.ConvertDateTimeInt(DateTime.Now),
MsgBody = new List<object>()
{
new
{
MsgType= "TIMTextElem",
MsgContent=new {Text= "{\"cmd\":\""+cmd+"\",\"pici\":"+pici+",\"jsontxt\":\""+HttpUtility.UrlEncode(jsontxt)+"\",\"timeslotstart\":\""+timeslotstart+"\",\"timeslotend\":\""+timeslotend+"\",\"timetype\":"+timetype+",\"alias\":\""+alias+"\"}"}
}
}
};
//LogHelper.Info("content:" + content);
var para = JsonConvert.SerializeObject(msgobj);
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
//string result = webClient.UploadString(url, "POST", "{\"jobwxusername\" : \"Ashu|29|7 Years|.NET\"}");
string result = webClient.UploadString(url, "POST", para);
//LogHelper.Info("推送结果:"+ result);
ResultMsg resultMsg = JsonConvert.DeserializeObject<ResultMsg>(result);
DateTime dateTime = Utility.ConvertIntDateTime(resultMsg.MsgTime);
int isOk = 2;
ValidationErrors errors = new ValidationErrors();
if (resultMsg.ActionStatus.ToUpper() == "OK")
{
isOk = 1;
bl.UpdateSendStutas(pici, dateTime, isOk, result, ref errors);
}
else
{
bl.UpdateSendStutas(pici, dateTime, isOk, result, ref errors);
}
Thread.Sleep(200);
}
}
}
}