


The example in this article shares the ASP.NET WeChat fan information interface viewing code for your reference. The specific content is as follows
WeChat Token entity class:
/// <summary> /// 微信Token实体类 /// </summary> public class WeChatTokenEntity { public string Access_token { get; set; } public string Expires_in { get; set; } }
User information entity class
/// <summary> /// 用户实体信息类 /// </summary> public class WeChatUserEntity { public string Subscribe { get; set; } public string Openid { get; set; } public string Nickname { get; set; } public string Sex { get; set; } public string City { get; set; } public string Province { get; set; } public string Country { get; set; } public string HeadImgUrl { get; set; } public string Subscribe_time { get; set; } public string Language { get; set; } }
WeChat auxiliary operation Class
public class WeChatDemo { /* * 步骤: * 1.通过appid和secret请求微信url,得到token * 2.通过access_token和openid得到用户信息(头像地址等) * 3.通过access_token和media_id得到用户发送的微信消息 * */ string appId = "wxxxxxxxxxxxxxx"; string appSecret = "1234567890-==687"; string wechatUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; public WeChatDemo() { } /// <summary> /// 获取token信息 /// </summary> /// <returns></returns> public WeChatTokenEntity GetWechatToken() { //请求的url地址 string tokenUrl = string.Format(wechatUrl, appId, appSecret); WeChatTokenEntity myToken; try { //声明并实例化一个WebClient对象 WebClient client = new WebClient(); //从执行url下载数据 byte[] pageData = client.DownloadData(tokenUrl); //把原始数据的byte数组转为字符串 string jsonStr = Encoding.Default.GetString(pageData); //初始化一个JavaScriptSerializer json解析器 //序列化注意:需要引用System.Web.Extensions JavaScriptSerializer jss = new JavaScriptSerializer(); //将字符串反序列化为Token对象 myToken = jss.Deserialize<WeChatTokenEntity>(jsonStr); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } return myToken; } /// <summary> /// 获取用户信息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <returns></returns> public WeChatUserEntity GetUserIfo(string accessToken, string openId) { WeChatUserEntity wue = new WeChatUserEntity(); string url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}"; url = string.Format(url, accessToken, openId); try { WebClient wc = new WebClient(); byte[] pageData = wc.DownloadData(url); string jsonStr = Encoding.UTF8.GetString(pageData); JavaScriptSerializer jss = new JavaScriptSerializer(); wue = jss.Deserialize<WeChatUserEntity>(jsonStr); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } return wue; } public string GetVoice(string accessToken, string mediaId) { string voiceAddress = string.Empty; string voiceUrl = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}"; voiceUrl = string.Format(voiceUrl, accessToken, mediaId); WebClient wc = new WebClient(); byte[] pageData = wc.DownloadData(voiceUrl); string jsonStr = Encoding.UTF8.GetString(pageData); //TODO:获取声音 voiceAddress = jsonStr; return voiceAddress; } /// <summary> /// 时间戳转为当前时间 /// </summary> /// <param name="timeStamp"></param> /// <returns></returns> public DateTime TimeStamp2DateTime(string timeStamp) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long time = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(time); return dtStart.Add(toNow); } }
Main program:
class Program { static void Main(string[] args) { WeChatDemo wcd = new WeChatDemo(); WeChatTokenEntity wte = wcd.GetWechatToken(); string token = wte.Access_token; string openId = "ogNVpt52xxxxxxxxxxxxxxxxxx"; Console.WriteLine("第一步:获得access_token:\n " + token + "\n"); Console.WriteLine("第二步:获得用户信息"); WeChatUserEntity user = wcd.GetUserIfo(token, openId); Console.WriteLine("\n昵称:" + user.Nickname); Console.WriteLine("国家:" + user.Country); Console.WriteLine("省份:" + user.Province); Console.WriteLine("城市:" + user.City); Console.WriteLine("语言:" + user.Language); Console.WriteLine("性别:" + user.Sex); Console.WriteLine("OpenId:" + user.Openid); Console.WriteLine("是否订阅:" + user.Subscribe); Console.WriteLine("时间:" + wcd.TimeStamp2DateTime(user.Subscribe_time)); Console.WriteLine("头像地址:" + user.HeadImgUrl); Console.WriteLine("\n第三步:获取微信声音地址"); string mediaId = "vwvnskvsldkvmsdlvkmdslkvmsld"; string voiceAddress = wcd.GetVoice(token, mediaId); Console.WriteLine("声音地址:" + voiceAddress); Console.Read(); } }
The running result is as shown in the figure:
The above is the entire content of this article. I hope it will be helpful to everyone's learning, and I hope everyone will support PHP. Chinese website.

Scrapy实现微信公众号文章爬取和分析微信是近年来备受欢迎的社交媒体应用,在其中运营的公众号也扮演着非常重要的角色。众所周知,微信公众号是一个信息和知识的海洋,因为其中每个公众号都可以发布文章、图文消息等信息。这些信息可以被广泛地应用在很多领域中,比如媒体报道、学术研究等。那么,本篇文章将介绍如何使用Scrapy框架来实现微信公众号文章的爬取和分析。Scr

微信公众号认证和不认证的区别在认证标识、功能权限、推送频率、接口权限和用户信任度等方面。详细介绍:1、认证标识,认证公众号会获得官方颁发的认证标识,即蓝色V标志,这个标志可以增加公众号的可信度和权威性,让用户更容易辨别真实的官方公众号;2、功能权限,认证公众号相比未认证的公众号拥有更多的功能和权限,例如认证公众号可以申请开通微信支付功能,实现在线支付和商业化运营等等。

如何使用Laravel开发一个基于微信公众号的在线点餐系统随着微信公众号的广泛应用,越来越多的企业开始将其作为在线营销的重要渠道。在餐饮行业中,开发一个基于微信公众号的在线点餐系统能够提高企业的效率和销售额。本文将介绍如何使用Laravel框架来开发一个这样的系统,并提供具体的代码示例。项目准备首先,需要确保已经在本地环境中安装好了Laravel框架。可以通

公众号每天不是只能发一篇文章,每次最多可以发表八篇文章,多篇文章的发布方法:1、点击左侧的“素材管理”,再点击“新建图文素材”开始编辑第一篇文章;2、编辑完第一篇文章之后,点击左侧第一篇文章下面的+号,点击“图文消息”即可编辑第二篇文章;3、做完多图文后,点击“保管并群发”即可完成多篇文章的发布。

Python是一种优雅的编程语言,拥有强大的数据处理和网络爬虫功能。在这个数字化时代,互联网上充满了大量的数据,爬虫已成为获取数据的重要手段,因此,Python爬虫在数据分析和挖掘方面有着广泛的应用。在本文中,我们将介绍如何使用Python爬虫来获取微信公众号文章信息。微信公众号是一种流行的社交媒体平台,用于在线发布文章,是许多公司和自媒体推广和营销的重要工

在当今互联网时代,微信公众号成为了越来越多企业的重要营销渠道。想要自己的微信公众号实现更多的功能,常常需要编写相应的接口。本文将以PHP语言为例,介绍如何构建一个微信公众号API接口。一、前置准备在编写微信公众号API接口之前,需要开发者拥有一个微信公众号的账号,并且在微信公众平台中申请开发者接口权限。申请成功后,可以获取到相关的开发者AppID和AppSe

随着微信公众号在社交网络中的逐渐普及,越来越多的开发者开始涉足微信公众号开发领域。在这其中,PHP作为一种常见的后端编程语言,也开始被广泛应用于微信公众号的开发中。本文将介绍PHP在微信公众号开发中的基础知识和常用技巧。一、PHP与微信公众号开发基础微信公众号开发微信公众号是指一种基于微信平台的互联网应用程序,可以为用户提供不同类型的服务和内容,如信息推送

随着互联网的普及和移动设备的广泛使用,微信公众号已经成为了企业营销必不可少的一部分。通过微信公众号,企业可以实现轻松地与用户互动,推广产品和服务,提高品牌知名度。为了更好地开发微信公众号应用,越来越多的开发者和企业选择使用Go语言来构建微信公众号应用。Go语言是一种由Google开发的编程语言,它的语法简洁,适合构建高性能、高并发的实时应用程序。在简单易用和


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
