Ejemplo n.º 1
0
        /// <summary>
        /// 生成二维码
        /// 获取请求创建二维码结果
        /// </summary>
        /// <returns>返回图片地址</returns>
        public static string CreateEwm(int scene_id, string fileType)
        {
            var AppToken = WebHelp.GetMode(ConfigSiteUri + "/Token/Index?k=kFHhsasd77askdVJ28GNAS88ASN5jGJAISJDjsdj8sdf46");

            var time = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            //_Logger.Error("AppToken:" + AppToken, new Exception());

            string  strTiket        = WebHelp.PostMode("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + AppToken, "{\"action_name\":\"QR_LIMIT_SCENE\",\"action_info\":{\"scene\":{\"scene_id\":" + scene_id + "}}}");
            dynamic objTiket        = JsonConvert.DeserializeObject(strTiket);
            string  tiket           = objTiket.ticket.ToString();
            var     createEwmResult = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + HttpUtility.UrlEncode(tiket);
            var     imgArray        = GetImgByte(createEwmResult); // 获取二维码
            string  files           = Convert.ToBase64String(imgArray);

            WebClient           clientObj = new WebClient();
            NameValueCollection PostVars  = new NameValueCollection();

            //var fileName = scene_id;
            //这些主要是提交的参数和值
            PostVars.Add("File", fileType);
            PostVars.Add("FileName", scene_id.ToString());
            PostVars.Add("FileByte", files);
            //Post访问接口,返回转为byte[]的josn字符串
            byte[] byRemoteInfo = clientObj.UploadValues(FilesUri + "/Upload/FileUploadEwm.aspx", "POST", PostVars);
            string resultstring = Encoding.Default.GetString(byRemoteInfo);

            var    objAll = JsonConvert.DeserializeObject <ImgResult>(resultstring);
            string code   = objAll.Code;      //返回代码 10000成功,其他失败

            if (code == "10000")
            {
                return(objAll.Uri);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 2
0
 public static string GetAccessToken()
 {
     return(WebHelp.GetMode(ConfigSiteUri + "/Token/Index?k=kFHhsasd77askdVJ28GNAS88ASN5jGJAISJDjsdj8sdf46"));
 }