c 推送消息到微信服务器,使用c#程序,给微信发送实时推送消息,好用

根据需要给自己的微信发送消息,我主要用来做生产线的设备故障监控,出了问题立马知道问题在哪,省了很多事,用来做各种其他的事件、消息提醒也不错的

实现方式:采用捷易快信(原名飞鸽快信,用了4年了,最近改名了),每月总送1000条消息

1.注册帐户申请接口 http://jy.erpit.cn/

2.编码开发:

业务逻辑部分省略,自己实现,下面贴的是发送消息的部分代码,其中发送参数根据使用的消息模板自行修改对应

public void Run(int Line,string Name)

{

var appSettings = ConfigurationManager.AppSettings;

string ApiHost = appSettings["ApiHost"];

string Secret = appSettings["Secret"];

string Token = appSettings["Token"];

string TemplateId = appSettings["TemplateId"];

using (var client = new HttpClient())

{

client.BaseAddress = new Uri(ApiHost);

var requestJson = JsonConvert.SerializeObject(

new

{

template_id = TemplateId,

secret = Secret,

app_key = Token,

data = new

{

first = new

{

value = Line + "故障告警"

},

performance = new

{

value = Name

},

time = new

{

value = DateTime.Now.ToString()

},

remark = new

{

value = "请及时处理"

}

}

});

HttpContent httpContent = new StringContent(requestJson);

httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

var result = client.PostAsync("/api/message/send", httpContent).Result.Content.ReadAsStringAsync().Result;

//Log.Info(result);

}

参数说明:

参数名称

参数类型

描述

secret

String(必选)

系统分配给您的密钥,在用户中心查看

app_key

String(必选)

群组发消息对应app_key

template_id

String(必选)

消息模板ID

url

String(可选)

消息点击跳转链接,用于消息查看详情,可不填

data

Json(必选)

这是您的消息内容, 参照消息模板列表中的使用说明中的具体参数

返回说明(返回数据一律为JSON字符串):

返回示例:

{

"code":200,

"msg":"Ok",

"data":[

]

}

3.更详细的接口说明参见:http://jy.erpit.cn/wiki