| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Collections.Generic;
- using System.Web;
- using System.Web.Script.Serialization;
- using Utils;
- namespace SiteCore.Handler
- {
- public class GetMiniCode : BaseHandler, IHttpHandler
- {
- string appid = "wx20432512482565e9";
- string appsecret = "07492bc9cbbc5b303e5e135b4dccd6f0";
- public void ProcessRequest(HttpContext context)
- {
- con = context;
- CommonHelper.PageExpires();
- HttpHelper http = new HttpHelper();
- HttpResult hResult = null;
- object cat = WebCache.GetCache("at");
- if (cat == null)
- {
- HttpItem item = new HttpItem()
- {
- URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret
- };
- hResult = http.GetHtml(item);
- string html = hResult.Html;
- JavaScriptSerializer jss = new JavaScriptSerializer();
- Dictionary<string, object> jObj = jss.Deserialize<Dictionary<string, object>>(html);
- if (!jObj.ContainsKey("errcode"))
- {
- string at = jObj["access_token"].ToString();
- WebCache.AddCacheWithTime("at", at, 1.8);
- cat = at;
- }
- }
- if (cat != null)
- {
- string st = GetString("st");
- string pdata = "";
- string url = "";
- if (st == "a")
- {
- pdata = "{\"width\":520,\"line_color\":{\"r\":\"17\",\"g\":\"123\",\"b\":\"185\"},\"path\":\"pages/index\"}";
- url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=";
- }
- else
- {
- pdata = "{\"width\":520,\"path\":\"pages/index\"}";
- url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=";
- }
- HttpItem item = new HttpItem()
- {
- URL = url + cat,
- Method = "POST",
- Postdata = pdata,
- //Postdata = "scene=bbbb&page=pages/home/home",
- ResultType = ResultType.Byte,
- Accept = "image/webp,image/*,*/*;q=0.8",
- ContentType = "application/json"
- };
- //HttpItem item = new HttpItem()
- //{
- // URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + cat,
- // Method = "POST",
- // Postdata = "{\"scene\":\"s" + bid + "\",\"width\":450,\"line_color\":{\"r\":\"17\",\"g\":\"123\",\"b\":\"185\"},\"path\":\"pages/home/home?bid=" + bid + "&btime=" + DateTime.Now.ToString("HHmm") + "\"}",
- // //Postdata = "scene=bbbb&page=pages/home/home",
- // ResultType = ResultType.Byte,
- // Accept = "image/webp,image/*,*/*;q=0.8",
- // ContentType = "application/json"
- //};
- hResult = http.GetHtml(item);
- if (hResult.Html.IndexOf("errcode") != -1)
- {
- return;
- }
- con.Response.ClearContent(); //需要输出图象信息 要修改HTTP头
- con.Response.ContentType = "image/bmp";
- con.Response.BinaryWrite(hResult.ResultByte);
- con.Response.End();
- }
- }
- }
- }
|