你要传入的参数 例如: {"path":"pages/PersonalCenter/QrUserInfo/QrUserInfo"}&l..._c# 微信小程序码转成图片">
赞
踩
-
-
-
- /// <summary>
- /// B接口-微信小程序带参数二维码的生成
- /// </summary>
- /// <param name="strJson"> 你要传入的参数 例如: {"path":"pages/PersonalCenter/QrUserInfo/QrUserInfo"}</param>
- /// <param name="token"></param>
- /// <returns></returns>
- public static string CreateWxCode(string strJson, string token)
- {
- string ret = string.Empty;
- try
- {
- string DataJson = string.Empty;
- string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token;
- ret = PostMoths(url, strJson);
- if (ret.Length > 0)
- {
- //对图片进行存储操作,下次可直接调用你存储的图片,不用再调用接口
- }
- }
- catch (Exception e)
- { ret = e.Message; }
- return ret;//返回图片地址
- }
-
- //请求处理,返回二维码图片
- public static string PostMoths(string url, string param)
- {
- string strURL = url;
- System.Net.HttpWebRequest request;
- request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
- request.Method = "POST";
- request.ContentType = "application/json;charset=UTF-8";
- string paraUrlCoded = param;
- byte[] payload;
- payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
- request.ContentLength = payload.Length;
- Stream writer = request.GetRequestStream();
- writer.Write(payload, 0, payload.Length);
- writer.Close();
- System.Net.HttpWebResponse response;
- response = (System.Net.HttpWebResponse)request.GetResponse();
- System.IO.Stream s;
- s = response.GetResponseStream();//返回图片数据流
- byte[] tt = StreamToBytes(s);//将数据流转为byte[]
- string imgName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
- string patn = @"d:\" + imgName;
- System.IO.File.WriteAllBytes(patn + imgName, tt);
- return patn;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。