网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序 帶參數二維碼 C# asp.net 服務端程序

發布時間:2018-04-17 12:13 所屬欄目:小程序開發教程

作者:采購員乙,來自原文地址 
第一步 獲取access_token:

文檔如下:

http請求方式: GET 
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET 
代碼如下:

 

				
  1. string result = HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx***********d&secret=a*******************4");
  2. public static string HttpGet(string Url)
  3. {
  4. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
  5. request.Method = "GET";
  6. request.ContentType = "text/html;charset=UTF-8";
  7.  
  8.  
  9. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  10. Stream myResponseStream = response.GetResponseStream();
  11. StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
  12. string retString = myStreamReader.ReadToEnd();
  13. myStreamReader.Close();
  14. myResponseStream.Close();
  15.  
  16.  
  17.  
  18. return retString;
  19. }

其中****改成自己的。具體到微信公眾平臺小程序里設置開發設置里找。

第二步 獲取推廣二維碼

文檔:

https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN  POST 參數說明

參數 默認值 說明  path 不能為空,最大長度 128 字節  width 430 二維碼的寬度 代碼:

 

				
  1. public static void PostMoths(string access_token)
  2. {
  3. string _url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + access_token;
  4.  
  5.  
  6. string strURL = _url;
  7. System.NET.HttpWebRequest request;
  8. request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
  9. request.Method = "POST";
  10. request.ContentType = "application/json;charset=UTF-8";
  11. JsonData _data = new JsonData();
  12. _data["path"] = "pages/index?query=1";
  13. _data["width"] = "430";
  14.  
  15.  
  16. string _jso = _data.ToJson();
  17. //string paraUrlCoded = param;
  18. byte[] payload;
  19. //payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
  20. payload = System.Text.Encoding.UTF8.GetBytes(_jso);
  21. request.ContentLength = payload.Length;
  22. Stream writer = request.GetRequestStream();
  23. writer.Write(payload, 0, payload.Length);
  24. writer.Close();
  25. System.Net.HttpWebResponse response;
  26. response = (System.Net.HttpWebResponse)request.GetResponse();
  27. System.IO.Stream s;
  28. s = response.GetResponseStream();
  29. string StrDate = "";
  30. string strValue = "";
  31. byte[] tt = StreamToBytes(s);
  32. //將流保存在c盤test.png文件下
  33. System.IO.File.WriteAllBytes(@"d:\test.png", tt);
  34. }
  35. ///將數據流轉為byte[]
  36. public static byte[] StreamToBytes(Stream stream)
  37. {
  38. List<byte> bytes = new List<byte>();
  39. int temp = stream.ReadByte();
  40. while (temp != -1)
  41. {
  42. bytes.Add((byte)temp);
  43. temp = stream.ReadByte();
  44. }
  45. return bytes.ToArray();
  46. }

最后保存在d盤的圖片就是推廣二維碼,可以講服務器連接地址發給微信小程序,供微信小程序調用。



易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23585.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×