你要传入的参数 例如: {"path":"pages/PersonalCenter/QrUserInfo/QrUserInfo"}&l..._c# 微信小程序码转成图片">
当前位置:   article > 正文

C# .net 后端 生成微信小程序图片 arrayBufferToBase64 转图片_c# 微信小程序码转成图片

c# 微信小程序码转成图片
  1. /// <summary>
  2. /// B接口-微信小程序带参数二维码的生成
  3. /// </summary>
  4. /// <param name="strJson"> 你要传入的参数 例如: {"path":"pages/PersonalCenter/QrUserInfo/QrUserInfo"}</param>
  5. /// <param name="token"></param>
  6. /// <returns></returns>
  7. public static string CreateWxCode(string strJson, string token)
  8. {
  9. string ret = string.Empty;
  10. try
  11. {
  12. string DataJson = string.Empty;
  13. string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token;
  14. ret = PostMoths(url, strJson);
  15. if (ret.Length > 0)
  16. {
  17. //对图片进行存储操作,下次可直接调用你存储的图片,不用再调用接口
  18. }
  19. }
  20. catch (Exception e)
  21. { ret = e.Message; }
  22. return ret;//返回图片地址
  23. }
  24. //请求处理,返回二维码图片
  25. public static string PostMoths(string url, string param)
  26. {
  27. string strURL = url;
  28. System.Net.HttpWebRequest request;
  29. request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
  30. request.Method = "POST";
  31. request.ContentType = "application/json;charset=UTF-8";
  32. string paraUrlCoded = param;
  33. byte[] payload;
  34. payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  35. request.ContentLength = payload.Length;
  36. Stream writer = request.GetRequestStream();
  37. writer.Write(payload, 0, payload.Length);
  38. writer.Close();
  39. System.Net.HttpWebResponse response;
  40. response = (System.Net.HttpWebResponse)request.GetResponse();
  41. System.IO.Stream s;
  42. s = response.GetResponseStream();//返回图片数据流
  43. byte[] tt = StreamToBytes(s);//将数据流转为byte[]
  44. string imgName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
  45. string patn = @"d:\" + imgName;
  46. System.IO.File.WriteAllBytes(patn + imgName, tt);
  47. return patn;
  48. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/942358
推荐阅读
相关标签
  

闽ICP备14008679号