代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
微信生成带参数的二维码
作者:
振峰
/ 发布于
2017/11/9
/
843
微信生成带参数的二维码
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; using LitJson; /// <summary> /// Ticket 的摘要说明 /// </summary> public class Ticket { public Ticket() { // // TODO: 在此处添加构造函数逻辑 // } public static string GetewmPic( string scene_id) { string tocket = ""; string pic=""; if (Config.GetInstance().SystemSetting.Appid!=""&&Config.GetInstance().SystemSetting.seconid!="") { string appid = Config.GetInstance().SystemSetting.Appid;// "wx5955bd71e310a7b5"; string secret = Config.GetInstance().SystemSetting.seconid;// "2d6b6ec95cde8bc2908713bde4c92434"; string parm = "grant_type=client_credential&appid=" + appid + "&secret=" + secret + "";//2d6b6ec95cde8bc2908713bde4c92434 string url = "https://api.weixin.qq.com/cgi-bin/token"; string b = webRequestGet(url, parm); b = SubString1(b, "{\"access_token\":\"", "\",\"expires_in\":7200}");//acc_tonke string poster = "{\"action_name\": \"QR_LIMIT_SCENE\",\"action_info\": {\"scene\": { \"scene_id\": "+scene_id+" } }";//二维码永久请求格式 string tockes = GetPage("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + b + "", poster + ""); if(tockes.IndexOf("ticket")>-1) { JsonData bejson = JsonMapper.ToObject(tockes); tocket =(String)bejson["ticket"]; tocket = Uri.EscapeDataString(tocket);//TICKET必需UrlEncode } string Picurl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+tocket+""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Picurl); req.Proxy = null; req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0"; req.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.8,zh-hk;q=0.6,ja;q=0.4,zh;q=0.2"); req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; //HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse(); System.Drawing.Image img = System.Drawing.Image.FromStream(req.GetResponse().GetResponseStream()); string newfilename = "ewm_" + scene_id + ".jpg";//二维码图片路径 // string filepath = @"D:\网站项目\wsl\ewmPic\" + newfilename; string address = HttpContext.Current.Server.MapPath(SysConfig.ApplicationPath+"/ewmPic/"+newfilename); img.Save(address); pic = newfilename; } return pic; } public static string SubString1(string sourceStr, string beginStr, string endStr) { int begin = sourceStr.IndexOf(beginStr); if (begin == -1) return ""; int end = sourceStr.IndexOf(endStr, begin + beginStr.Length); if (end == -1 && end == begin + beginStr.Length) return ""; return sourceStr.Substring(begin + beginStr.Length, end - begin - beginStr.Length); } /// <summary> /// GET 提交调用抓取 /// </summary> /// <param name="url">提交地址</param> /// <param name="param">参数</param> /// <returns>string</returns> public static string webRequestGet(string url, string param) { byte[] bs = System.Text.Encoding.UTF8.GetBytes(param); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url + "?" + param); req.Method = "GET"; using (WebResponse wr = req.GetResponse()) { //在这里对接收到的页面内容进行处理 Stream strm = wr.GetResponseStream(); StreamReader sr = new StreamReader(strm, System.Text.Encoding.UTF8); string line; System.Text.StringBuilder sb = new System.Text.StringBuilder(); while ((line = sr.ReadLine()) != null) { sb.Append(line); } sr.Close(); strm.Close(); return sb.ToString(); } } public static string GetPage(string posturl, string postData) { Stream outstream = null; Stream instream = null; StreamReader sr = null; HttpWebResponse response = null; HttpWebRequest request = null; Encoding encoding = Encoding.UTF8; byte[] data = encoding.GetBytes(postData); // 准备请求... try { // 设置参数 request = WebRequest.Create(posturl) as HttpWebRequest; CookieContainer cookieContainer = new CookieContainer(); request.CookieContainer = cookieContainer; request.AllowAutoRedirect = true; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; outstream = request.GetRequestStream(); outstream.Write(data, 0, data.Length); outstream.Close(); //发送请求并获取相应回应数据 response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 instream = response.GetResponseStream(); sr = new StreamReader(instream, encoding); //返回结果网页(html)代码 string content = sr.ReadToEnd(); string err = string.Empty; return content; } catch (Exception ex) { string err = ex.Message; return string.Empty; } } }
试试其它关键字
同语言下
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
可能有用的
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
振峰
贡献的其它代码
(
9
)
.
判断用户输入的是否为IP地址
.
创建10个用户,并分别设置密码,密码要求10位且包含大
.
微信生成带参数的二维码
.
List〈string〉和string[]数组之间的相互转换
.
UDAF行列转换
.
查询所有本周,本月的数据
.
Jquery Ajax 调用 ashx 返回结果
.
XSD校验XML文件
.
在海量文本中找出某个单词的位置信息
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3