当前位置:网站首页>QR code generation of wechat applet with parameters
QR code generation of wechat applet with parameters
2022-07-28 17:21:00 【mojocube】
Use scenarios : Scan the generated applet code , Open the applet and adjust it to the specified page with parameters , For example, the purchase details page .
Usage method : Generate by calling the QR code interface of wechat applet .
Interface document :https://developers.weixin.qq.com/miniprogram/dev/api/qrcode.html
It can be seen from the document that , There are three ways to get the QR code of an applet , Let's take the method B For example , Method B It is suitable for business scenarios with a large number of codes .
The generator interface is shown in the figure :

Core code :
/// <summary>
/// adopt POST Get the applet code
/// </summary>
/// <param name="access_token"></param>
/// <param name="scene"> Parameters carried </param>
/// <param name="page"> Jump page </param>
private void GetQRCode(string access_token, string scene, string page)
{
string formUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + access_token;
string formData = "{\"scene\":\"" + scene + "\",\"page\":\"" + page + "\"}";
// Pay attention to the submitted code This side needs to be changed The default here is Default: Current system code
byte[] postData = System.Text.Encoding.UTF8.GetBytes(formData);
// Set parameters related to submission
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(formUrl) as System.Net.HttpWebRequest;
System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
request.Method = "POST";
request.KeepAlive = false;
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
request.ContentLength = postData.Length;
// Submit request data
System.IO.Stream outputStream = request.GetRequestStream();
outputStream.Write(postData, 0, postData.Length);
outputStream.Close();
System.Net.HttpWebResponse response;
System.IO.Stream responseStream;
response = request.GetResponse() as System.Net.HttpWebResponse;
responseStream = response.GetResponseStream();
BuildQRCode(responseStream);
}Show / Save image code :
/// <summary>
/// Create a picture
/// </summary>
/// <param name="stream"></param>
private void BuildQRCode(System.IO.Stream stream)
{
System.IO.MemoryStream outstream = new System.IO.MemoryStream();
const int bufferLen = 1024;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = stream.Read(buffer, 0, bufferLen)) > 0)
{
outstream.Write(buffer, 0, count);
}
Save to local disk
//System.Drawing.Image img = System.Drawing.Image.FromStream(outstream);
//img.Save(@"C:\2019\05\wx001.jpg");
// Direct output picture
Response.ClearContent();
Response.ContentType = "image/Png";
Response.BinaryWrite(outstream.ToArray());
}The attachment : Demo source code download
边栏推荐
- Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
- 解决SQL Server数据库独占的问题
- Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
- 一文了解 Kubernetes 中的服务发现
- Verilog 每日一题 (VL28 加减计数器)
- The practice of beego framework developed by goweb: Section 4 database configuration and connection
- Steps to configure V530 switch
- Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
- Ugui learning notes (III) summary of the use of each control
- Soft exam review summary
猜你喜欢

配置V530交换机步骤

influxdb2的使用

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low

Microservice Architecture - service registry and service gateway (6.8) (Reprint)

飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用

What does the service grid that has been popular for two years bring to microservices? (Reprinted)

Easypoi --- excel file export

火了 2 年的服务网格究竟给微服务带来了什么?(转载)

Introduction to vscade interface

The practice of beego framework developed by goweb: Section 4 database configuration and connection
随机推荐
Verilog 每日一题 (VL5 信号发生器)
Code implementation additive attention
net框架
Analysis of kubernetes service principle
Goweb开发之Iris框架实战:项目总结与回顾
Record the processing process of CEPH two RBDS that cannot be deleted
Difference between reconnaissance aircraft and early warning aircraft
Facet experience -- the development side of dragon game client
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Comprehensively design an oppe homepage -- page service part
Re10: are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
Function接口之andThen
配置V530交换机步骤
The 16th program design competition of Dalian University of Technology (Problem Solver)
Comprehensively design an oppe homepage -- after sales service of the page
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
Codeforces round 770 (Div. 2) F. Fibonacci additions (construction + difference)
Goweb开发之Beego框架实战:第四节 数据库配置及连接
2021年4月份自考
线性代数及矩阵论(七)