微信小程序获取二维码API
Posted 忧郁的小学生
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信小程序获取二维码API相关的知识,希望对你有一定的参考价值。
<%@ WebHandler Language="C#" Class="ce" %> using System; using System.Web; using System.Net; using System.Text; using System.IO; using System.Collections.Generic; using LitJson; using System.Web.Script.Serialization; public class ce : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; //微信access_tocke string ulr = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + this.access_token(); HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(ulr); //创建url request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; JsonData data = new JsonData(); data["path"] = "‘pages/index?query=1"; data["width"] = "430"; string json = data.ToJson(); byte[] load = Encoding.UTF8.GetBytes(json); request.ContentLength = load.Length; Stream writer = request.GetRequestStream(); writer.Write(load,0,load.Length); HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); byte[] mg = StreamToBytes(s); context.Response.BinaryWrite(mg); } public string access_token() { string urls = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=1111&secret=1111"; HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(urls); //请求api HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); string respText = ""; using (Stream resStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(resStream, Encoding.Default); respText = reader.ReadToEnd(); resStream.Close(); } javascriptSerializer Jss = new JavaScriptSerializer(); Dictionary<string, object> respDic = (Dictionary<string, object>)Jss.DeserializeObject(respText); //通过键access_token获取值 return respDic["access_token"].ToString(); } public static byte[] StreamToBytes(Stream stream) { List<byte> bytes = new List<byte>(); int temp = stream.ReadByte(); while (temp != -1) { bytes.Add((byte)temp); temp = stream.ReadByte(); } return bytes.ToArray(); } public bool IsReusable { get { return false; } } }
以上是关于微信小程序获取二维码API的主要内容,如果未能解决你的问题,请参考以下文章
微信小程序获取二维码(直接上代码)https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN