记一次阿里云生产环境发布,中文验证码乱码的问题排查

前言

因近期多次发现生产环境短信服务多次被恶意攻击,为防止此事件再次发生,故进行本次验证码升级,降低被自动识别的成功率

问题场景

本次采用中文算数验证码,在本地开发环境和测试环境验证码都显示正常(测试环境也是阿里云服务器),当部署到生产环境后,进行更新内容验证时,发现验证码乱码。

问题排查(一)

查看线上服务器环境是否和本地一致,经过检查,都一致,排除环境不一致所导致的

问题排查(二)

查看服务器字符编码是否为UTF-8,结果即UTF-8

问题排查(三)

进行代码排查,查看验证码生成的工具类,发现Graphics2D在渲染图片的时候,设置了字体(Font),
如下面代码所示

public void drawRandomString(Graphics2D g,String randomvcch,int i){
    //Set the string font style
    g.setFont(font);
    //Set the color string
    int rc = random.nextInt(255);
    int gc = random.nextInt(255);
    int bc = random.nextInt(255);
    g.setColor(new Color(rc, gc, bc));
    //random string
    //Set picture in the picture of the text on the x, y coordinates, random offset value
    int x = random.nextInt(3);
    int y = random.nextInt(2);
    g.translate(x, y);
    //Set the font rotation angle
    int degree = new Random().nextInt() % 15;
    //Positive point of view
    g.rotate(degree * Math.PI / 180, 5+i*25, 20);
    //Character spacing is set to 15 px
    //Using the graphics context of the current font and color rendering by the specified string for a given text.
    //The most on the left side of the baseline of the characters in the coordinate system of the graphics context (x, y) location
    //str- to draw string.x - x coordinate.y - y coordinate.
    g.drawString(randomvcch, 5+i*25, 20);
    //Reverse Angle
    g.rotate(-degree * Math.PI / 180, 5+i*25, 20);
}

怀疑缺少中文字体,接下来查看服务器上是否有中文字体,发现果然缺少中文字体,然后进行中文字体安装,进行验证,验证码显示正常了,问题解决!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值