122 lines
5.9 KiB
C#
122 lines
5.9 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 TSBatchMsgSend
|
|
{
|
|
public void StartPush()
|
|
{
|
|
WX_TS_BATCHMSG_BL bl = new WX_TS_BATCHMSG_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.GetTsMsgSendPici();//获取批次
|
|
|
|
|
|
|
|
//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 validatemsg = row["validatemsg"].ToString();//发送消息内容
|
|
//LogHelper.Info("微信号:" + alias);
|
|
DataTable tuiResTable = bl.GetTsMsgDetailByPici(pici);
|
|
string sendAlias = string.Empty;
|
|
foreach (DataRow item in tuiResTable.Rows)
|
|
{
|
|
string c_alias = item["alias"].ToString();
|
|
string c_nickname = item["nickname"].ToString();
|
|
string c_conremark = item["conremark"].ToString();
|
|
string c_username = item["username"].ToString();
|
|
decimal pkid = Convert.ToDecimal(item["rid"]);
|
|
|
|
if (!string.IsNullOrWhiteSpace(c_alias))
|
|
{
|
|
sendAlias += pkid + "," + HttpUtility.UrlEncode(c_alias) + ";";
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(c_nickname))
|
|
{
|
|
sendAlias += pkid + "," + HttpUtility.UrlEncode(c_nickname) + ";";
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(c_conremark))
|
|
{
|
|
sendAlias += pkid + "," + HttpUtility.UrlEncode(c_conremark) + ";";
|
|
}
|
|
else if (!c_username.StartsWith("wxid_"))
|
|
{
|
|
sendAlias += pkid + "," + HttpUtility.UrlEncode(c_username) + ";";
|
|
}
|
|
|
|
}
|
|
//LogHelper.Info("微信号:"+ alias+",数量:"+ tuiResTable.Rows.Count);
|
|
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= "{\"pici\":"+pici+",\"validatemsg\":\""+HttpUtility.UrlEncode(validatemsg)+"\",\"timeslotstart\":\""+timeslotstart+"\",\"timeslotend\":\""+timeslotend+"\",\"timetype\":"+timetype+",\"alias\":\""+alias+"\",\"tsbatchmsg\":\""+sendAlias+"\"}"}
|
|
}
|
|
}
|
|
};
|
|
//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;
|
|
if (resultMsg.ActionStatus.ToUpper() == "OK")
|
|
{
|
|
isOk = 1;
|
|
bl.UpdateSendMsgStutas(pici, dateTime, isOk, result);
|
|
}
|
|
else
|
|
{
|
|
bl.UpdateSendMsgStutas(pici, dateTime, isOk, result);
|
|
}
|
|
|
|
Thread.Sleep(200);
|
|
|
|
}
|
|
|
|
//Console.WriteLine("窝巢了:" + result);
|
|
//Console.ReadLine();
|
|
}
|
|
}
|
|
|
|
}
|