121 lines
5.9 KiB
C#
121 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 WX.CRM.BLL.TS;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WX.CRM.CRMServices.TS
|
|
{
|
|
public class TSSendRes
|
|
{
|
|
public void StartPush()
|
|
{
|
|
WX_TSADDFRIEND_BL bl = new WX_TSADDFRIEND_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.GetTsSendPici();//获取批次
|
|
|
|
|
|
DataTable scriptTable = bl.GetNewestScriptVersion();
|
|
string version = string.Empty;
|
|
string scriptName = string.Empty;
|
|
if (scriptTable != null && scriptTable.Rows.Count > 0)
|
|
{
|
|
version = scriptTable.Rows[0]["version"].ToString();
|
|
scriptName = scriptTable.Rows[0]["scriptname"].ToString();
|
|
}
|
|
//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();
|
|
LogHelper.Info("微信号:" + alias);
|
|
DataTable tuiResTable = bl.GetTsAddFriendRes(pici);
|
|
string content = string.Empty;
|
|
foreach (DataRow item in tuiResTable.Rows)
|
|
{
|
|
string resid = item["RESID"].ToString();
|
|
string phone = sHelper.decyptData(clientid, item["MOBILE"].ToString());
|
|
string validatemsg = item["validatemsg"].ToString();
|
|
if (string.IsNullOrEmpty(resid) || string.IsNullOrEmpty(phone))
|
|
{
|
|
continue;
|
|
}
|
|
content += phone + "," + resid + "," + validatemsg + "$";
|
|
}
|
|
//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+",\"timeslotstart\":\""+timeslotstart+"\",\"timeslotend\":\""+timeslotend+"\",\"timetype\":"+timetype+",\"version\":\""+version+"\",\"scriptName\":\""+scriptName+"\",\"alias\":\""+alias+"\",\"resource\":\""+content+"\"}"}
|
|
}
|
|
}
|
|
};
|
|
//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.UpdateSendResStutas(alias, pici, dateTime, isOk, result);
|
|
}
|
|
else
|
|
{
|
|
bl.UpdateSendResStutas(alias, pici, dateTime, isOk, result);
|
|
}
|
|
|
|
Thread.Sleep(200);
|
|
|
|
}
|
|
|
|
//Console.WriteLine("窝巢了:" + result);
|
|
//Console.ReadLine();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// {"ActionStatus":"OK","ErrorInfo":"","ErrorCode":0,"MsgTime":1515033067}
|
|
/// </summary>
|
|
public class ResultMsg
|
|
{
|
|
public string ActionStatus { get; set; }
|
|
public string ErrorInfo { get; set; }
|
|
public int ErrorCode { get; set; }
|
|
public long MsgTime { get; set; }
|
|
}
|
|
}
|