惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 愚

Revit:二开使用Sqlite保存本地数据,并配合EF6等ORM框架 Revity:查找并修改类型参数和实例参数 复习一下UML Revit:ElementFilter过滤器基类 Revit:Element、Reference、ReferenceIntersector、ReferenceWithContext的理解 Revit:使用代码如何发出选点、选对象指令 Reivt:过滤器FilteredElementIterator,采集器FilteredElementCollector Revit:Transaction事务 Revit:弄清楚Application、UIApplication、UIDocument 、Document、DocumentSet之间的关系 Revit:IExternalCommand和IExternalApplication的区别 什么是假程序员 若我有一天 聊聊面试官那些事。。分享我的个人看法,认同的顶一顶。。。 提供一个中国身份证号码判断的类 分享一个自己写的取中国农历相关数据的类。包含:农历年月日,生肖,星座,年龄,天干,地支等方法 从结亲网 的架构谈起,谈什么架构, 我理解的架构。我想很多人理解的架构应该可能比较 狭义 解决:百度编辑器UEditor,怎么将图片保存到图片服务器,或者上传到ftp服务器的问题(如果你正在用UE,这篇文章值得你看下) (原创)面向对象的系统对接接口编写。第5篇(完结) (原创)面向对象的系统对接接口编写。第4篇
面向对象的全套“企业微信”api接口的代码实现,网上太多“面向过程”微信api接口的代码,这个开源给需要的人用
· 2017-03-14 · via 博客园 - 愚

有段时间没有写文章了。

一直以来,微信的热门是看得到的,很多人都需要与微信的api对接。

今天我这里就分享全套的企业微信api接口的代码。

关于微信api,网上已经有很多实现的了。

但是我今天之所以还写这个,是因为网上基本上找不到面向对象的api接口实现的编程,几乎都是“面向过程”的。

本文章的代码,也许能带给你极大的方便,以及非常方便的扩展和应用。

1.如下图,在你的业务逻辑层中,将本文章附件的Weixin代码文件夹整套放进去

2.在你的页面中,类似于下图,插入下面的代码即可实现调用。

下图例子是以“创建成员”的请求为例子写的。

创建成员的API说明:http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%88%90%E5%91%98#.E5.88.9B.E5.BB.BA.E6.88.90.E5.91.98

3.到这里就完成了调用了。其它的api方式请依样画葫芦

4.附上整套源文件代码,猛击才能下载

5.文件中有个代码是发起http请求的。该文件不在源包中。

在这里贴出代码,请直接复制即可

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace HXL.Common.Helper
{
    public static class Http
    {
        public static string Get(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            //request.ContentType = "text/html;charset=gb2312";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
            string retString = streamReader.ReadToEnd();
            streamReader.Close();
            responseStream.Close();

            return retString;
        }
        
        /// <summary>
        /// 用于发送微信post请求
        /// 其中data是格式化后的json格式。值形如:{"name":"21312","parentid":1,"order":11,"id":19}
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string HttpPost(string url, string data)
        {
            string retString = string.Empty;

            byte[] byteArray = Encoding.UTF8.GetBytes(data);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }
    }
}