Beispiel #1
0
 public WeChatManagerTests()
 {
     #region 测试代码--微信Token
     string           resStr     = "{\"access_token\":\"zWtGZHO2EHfig-nBhIUb0XtQrh88kqDXV4RalOUvZi22tFELCKieW30O85aQafsH8DOKX1HS-J1Scb7Bdi7jShgrLg4Jc8_sBxcFuqYnGyf5QplcIZLXwOt7tHlcxDKEJPFaAIAXDT\",\"expires_in\":7200}";
     WeChatTokenModel tempTokenM = ConvertManager.JsonToModel <WeChatTokenModel>(resStr);
     WebCacheManager.Set("MATERALWECHATTOKENKEY", tempTokenM, DateTimeOffset.Now.AddSeconds(tempTokenM.expires_in - 60));
     #endregion
 }
        public HttpResponseMessage GetValidateCode()
        {
            VerifyCodeManager vcMa = new VerifyCodeManager();

            /*背景是否为图片还是纯色*/
            vcMa.TextConfigM.BackIsImage = true;
            /*背景图片路径(BackIsImage==true时生效)*/
            vcMa.TextConfigM.ImageBackgroundPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\Images\ValidateCode";
            /*背景颜色库(BackIsImage==false时生效)*/
            vcMa.TextConfigM.BackgroundColors.Add(Color.Ivory);
            /*值颜色库*/
            vcMa.TextConfigM.ValueColors.Add(Color.Red);
            /*文本库(AllowRandomChinese==true时失效)*/
            vcMa.TextConfigM.TextLibrary = new List <string>
            {
                //"abcdefghijklmnopqrstuvwxyz",
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                "0123456789"
            };
            //vcMa.TextConfigM.TextLibrary.Add("陈明旭中华人民共和国");
            /*采用随机中文模式*/
            vcMa.TextConfigM.AllowRandomChinese = false;
            /*值数量*/
            vcMa.TextConfigM.ValueCount = 4;
            /*混淆数量*/
            vcMa.TextConfigM.ConfusionCount = 10;
            /*混淆模式*/
            vcMa.TextConfigM.ImageObfuscationTypes = new List <VerifyCodeImageObfuscationType>
            {
                /*假值混淆*/
                VerifyCodeImageObfuscationType.FalseValue,
                /*条纹混淆*/
                VerifyCodeImageObfuscationType.Stripe
            };
            /*图片大小*/
            vcMa.TextConfigM.ImageSize = new Size(120, 30);
            /*字体大小*/
            vcMa.TextConfigM.FontSize = 18;
            /*获取验证码*/
            VerifyCodeModel vcM = vcMa.GetVeifyCodeModel();

            if (vcM.Images.Count > 0)
            {
                /*验证码的值存入缓存中*/
                WebCacheManager.Set(ApplicationManager.VALIDATECODEKEY + vcM.Value, vcM.Value, DateTimeOffset.Now.AddMinutes(5));
                using (MemoryStream ms = new MemoryStream())
                {
                    vcM.Images[0].Save(ms, ImageFormat.Jpeg);
                    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(ms.ToArray())
                    };
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                    return(result);
                }
            }
            return(null);
        }