轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 终极进阶 查看主题

小程序带参数二维码生成 c#后台代码

发布者: 破天一剑 | 发布时间: 2018-1-10 03:20| 查看数: 7089| 评论数: 1|帖子模式

作者:w568273102,来自原文地址 
微信小程序获取小程序页面二维码API接口,通过后台post网址获取access_token方式,参数{"path": "pages/index/index?query=1", "width": 260},可以获得图片二进制流,直接打印二进制流为乱码

 
该二进制流直接保存成png图片,一下为本人所写的部分核心代码,需要引用using system.net 
/// url 网址 || param 参数

  1. public static string PostMoths(string url, string param)
  2. {
  3. string strURL = url;
  4. System.Net.HttpWebRequest request;
  5. request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
  6. request.Method = "POST";
  7. request.ContentType = "application/json;charset=UTF-8";
  8. string paraUrlCoded = param;
  9. byte[] payload;
  10. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  11. request.ContentLength = payload.Length;
  12. Stream writer = request.GetRequestStream();
  13. writer.Write(payload, 0, payload.Length);
  14. writer.Close();
  15. System.Net.HttpWebResponse response;
  16. response = (System.Net.HttpWebResponse)request.GetResponse();
  17. System.IO.Stream s;
  18. s = response.GetResponseStream();
  19. string StrDate = "";
  20. string strValue = "";
  21. byte[] tt = StreamToBytes(s);
  22. //将流保存在c盘test.png文件下
  23. System.IO.File.WriteAllBytes(@"c:\test.png", tt);
  24. }
  25. ///将数据流转为byte[]
  26. public static byte[] StreamToBytes(Stream stream)
  27. {
  28. List bytes = new List();
  29. int temp = stream.ReadByte();
  30. while (temp != -1)
  31. {
  32. bytes.Add((byte)temp);
  33. temp = stream.ReadByte();
  34. }
  35. return bytes.ToArray();
  36. }

生成的带参数二维码

最新评论

东方不坏 发表于 2022-5-9 06:34
源代码下载网易云音乐

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表