先去企业微信门户网站获得密钥和应用ID

创建一个静态工具类

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApp1
{
public static class SendWeChatMessage
{
private const string getTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}";
private const string sendMessageUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}";
private static readonly HttpClient httpClient = new HttpClient(); public async static Task<string> Send(WeChatParameter parameter)
{
string tokenUrl = string.Format(getTokenUrl, parameter.CorpId, parameter.CorpSecret);
var reponse = await httpClient.GetAsync(tokenUrl);
var str = await reponse.Content.ReadAsStringAsync();
var jObject = JObject.Parse(str);
var getTokenResult = jObject["errmsg"].ToString().ToLower();
var token = jObject["access_token"].ToString();
// jObject["errmsg"].ToString();
if (!getTokenResult.Equals("ok") || string.IsNullOrEmpty(token))
return "获取token失败";
string sendMsgUrl = string.Format(sendMessageUrl, token);
var sendContentModel = new
{
touser = parameter.Touser,
msgtype = parameter.MsgType,
agentid = parameter.AgentId,
text = new
{
content = parameter.Content
}
};
var sendContentStr = JsonConvert.SerializeObject(sendContentModel);
HttpContent content = new StringContent(sendContentStr, Encoding.UTF8);
var response = await httpClient.PostAsync(sendMsgUrl, content);
return await response.Content.ReadAsStringAsync();
} } public class WeChatParameter
{
public string CorpId { get; set; }
public string CorpSecret { get; set; }
public string Content { get; set; }
public string Touser { get; set; }
public string MsgType { get; set; } = "text";
public string AgentId { get; set; }
}
}

返回结果是json字符串,需要不同结果的同学可以自己修改一下返回类型。(当返回的结果中是“errmsg”:"ok",代表成功了)

C#给企业微信中的成员发送消息的更多相关文章

  1. XMLDocument 方法中实现post发送消息

    XMLDocument 方法中实现post发送消息

  2. 原创:【微信小程序】发送消息模板教程(后台以PHP示例)

    1.本教程对外开放,未经博主同意,禁止转载. 2.准备材料:1)公众号|小程序,添加选择的模板消息,2)在设置>开发设置页面,开通消息模板功能:如: 3.因为调用微信发送模板的接口是:https ...

  3. makeObjectsPerformSelector对数组中的对象发送消息执行对象中方法

    - (void)makeObjectsPerformSelector:(SEL)aSelector; - (void)makeObjectsPerformSelector:(SEL)aSelector ...

  4. Java企业微信开发_05_消息推送之发送消息(主动)

    一.本节要点 1.发送消息与被动回复消息 (1)流程不同:发送消息是第三方服务器主动通知微信服务器向用户发消息.而被动回复消息是 用户发送消息之后,微信服务器将消息传递给 第三方服务器,第三方服务器接 ...

  5. Java企业微信开发_04_消息推送之发送消息(主动)

    源码请见: Java企业微信开发_00_源码及资源汇总贴 一.本节要点 1.发送消息与被动回复消息 (1)流程不同:发送消息是第三方服务器主动通知微信服务器向用户发消息.而被动回复消息是 用户发送消息 ...

  6. Java发送企业微信应用消息

    1.发送消息与被动回复消息 (1)流程不同:发送消息是第三方服务器主动通知微信服务器向用户发消息.而被动回复消息是 用户发送消息之后,微信服务器将消息传递给 第三方服务器,第三方服务器接收到消息后,再 ...

  7. 参照企业微信审批业务,在Winform开发框架中工作流模块的实现业务审批

    目前微信的企业号已经切换到企业微信里面,这个是一个APP程序,提供了很丰富的企业应用,其中包括了业务审批处理,审批业务包括请假.报销.费用.出差等很多个审批场景,在Winform开发框架中工作流模块这 ...

  8. odoo发送信息到微信公众平台、企业微信

    目录 odoo发送信息到微信 @(odoo client.message.send_text) odoo发送信息到微信 在odoo平台中进行项目开发的时候有时会用到跟其他平台对接发送信息. 这里我写一 ...

  9. 【转】odoo 10的企业微信发送程序介绍

    本文介绍的微信发送程序不是独立的模块,是某企业应用的一部分, 源码可在京津冀odoo技术交流群的群共享中下载.   [1]基本配置 在work.weixin.qq.com上注册一个企业后,会得到企业的 ...

随机推荐

  1. 谁有好的oracle数据库学习书籍,麻烦提供一下,感激不尽

    作为一个IT人员,想深入学习一下oracle,以前都只是懂基本的语法,CRUD 数据库设计,数据库优化,底层完全不懂,哪位仁兄有好的书籍可以推荐一下,感激不尽.

  2. Odoo配置文件

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11189223.html

  3. OpenStack Train版 简单部署流程

    environment 1.网络平面 management(管理网络)→软件安装,组件通信 provider(提供实例网络)→:提供者网络:直接获取ip地址,实例之间直接互通   自服务网络(私有网络 ...

  4. 【洛谷P5331】 [SNOI2019]通信

    洛谷 题意: \(n\)个哨站排成一列,第\(i\)个哨站的频段为\(a_i\). 现在每个哨站可以选择: 直接连接到中心,代价为\(w\): 连接到前面某个哨站\(j(j<i)\),代价为\( ...

  5. ZooKeeper架构原理你学会了吗?

    Zookeeper是分布式一致性问题的工业解决方案,是Apache Hadoop下解决分布式一致性的一个组件,后被分离出来成为Apache的顶级项目. 工程来源:是雅虎公司内部项目,据说雅虎内部很多项 ...

  6. 201871010110-李华《面向对象程序设计(java)》第十周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...

  7. 【转】Spring的IOC原理(通俗易懂)

    1. IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由Ñ个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 如果我们打开机械式手表的后盖,就会看到与上 ...

  8. Visual Studio 2017 软件包及教程

    下载地址:https://files.cnblogs.com/files/yungle/VisualStudio2017.rar 安装教程:https://mp.weixin.qq.com/s?__b ...

  9. VIJOS-P1064 迎春舞会之数字舞蹈

    洛谷 P1538 迎春舞会之数字舞蹈 洛谷传送门 JDOJ 1245: VIJOS-P1064 迎春舞会之数字舞蹈 JDOJ传送门 Description ​ 在越来越讲究合作的时代,人们注意的更多的 ...

  10. USACO wormhole

    洛谷 P1444 [USACO1.3]虫洞wormhole https://www.luogu.org/problemnew/show/P1444 JDOJ 2386: USACO 2013 Dec ...