当前位置: 首页 > news >正文

新闻类的网站有哪些类型如何查看一个网站的所有二级域名

新闻类的网站有哪些类型,如何查看一个网站的所有二级域名,做网站什么主题好做,图片设计软件有哪些图形验证码是网站安全防护的重要组成部分,能有效防止自动化脚本进行恶意操作,如何实现一个简单的运算图形验证码?本文封装了一个简单的js类,可以用于生成简单但安全的图形验证码。它支持自定义验证码样式,包括字体大小…

图形验证码是网站安全防护的重要组成部分,能有效防止自动化脚本进行恶意操作,如何实现一个简单的运算图形验证码?本文封装了一个简单的js类,可以用于生成简单但安全的图形验证码。它支持自定义验证码样式,包括字体大小、颜色以及干扰线的数量和样式。如下图。

核心js文件如下:

// mcaptcha.jsexport class Mcaptcha {constructor(options) {this.options = options;this.fontSize = 24;this.init();this.refresh();}init() {this.ctx = wx.createCanvasContext(this.options.el);this.ctx.setTextBaseline("middle");this.ctx.setFillStyle(this.randomColor(180, 240));}refresh() {var code = '';var num1 = this.randomNum(0, 9)var num2 = this.randomNum(0, 9)this.options.createCodeImg = code;code = num1 + '+' + num2 + '=?'this.options.num1 = num1;this.options.num2 = num2;let arr = [code]if (arr.length === 0) {arr = ['e', 'r', 'r', 'o', 'r'];};let offsetLeft = this.options.width * 0.6 / (arr.length - 1);let marginLeft = this.options.width * 0.2;arr.forEach((item, index) => {this.ctx.setFillStyle(this.randomColor(0, 180));let size = this.randomNum(24, this.fontSize);this.ctx.setFontSize(size);let dis = offsetLeft * index + marginLeft - size * 0.3;let deg = this.randomNum(-1, 1);this.ctx.translate(dis, this.options.height * 0.45);this.ctx.rotate(deg * Math.PI / 180);this.ctx.fillText(item, 2, this.randomNum(0,10));this.ctx.rotate(-deg * Math.PI / 180);this.ctx.translate(-20, -this.options.height * 0.6);})for (var i = 0; i < 4; i++) {this.ctx.strokeStyle = this.randomColor(40, 180);this.ctx.beginPath();this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height));this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height));this.ctx.stroke();}for (var i = 0; i < this.options.width / 4; i++) {this.ctx.fillStyle = this.randomColor(0, 255);this.ctx.beginPath();this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI);this.ctx.fill();}this.ctx.draw();}validate(code) {var code = Number(code)var v_code = this.options.num1 + this.options.num2if (code == v_code) {return true} else {this.refresh()return false}}randomNum(min, max) {return Math.floor(Math.random() * (max - min) + min);}randomColor(min, max) {let r = this.randomNum(min, max);let g = this.randomNum(min, max);let b = this.randomNum(min, max);return "rgb(" + r + "," + g + "," + b + ")";}
}

使用方法

以微信小程序为例,其他环境适当修改。

  1. 引入Mcaptcha.js
import Mcaptcha from './mcaptcha.js';

     2.初始化Mcaptcha实例

在你的页面的JS文件中,创建一个Mcaptcha实例,并传入相应的配置选项。

Page({onLoad: function() {new Mcaptcha({el: 'captchaCanvas', // canvas的IDwidth: 300, // canvas的宽度height: 150 // canvas的高度});}
});

      3.在WXML中添加Canvas元素

在页面的WXML文件中,添加一个Canvas元素,用于展示验证码。

<canvas canvas-id="captchaCanvas" style="width: 300px; height: 150px;"></canvas>

4.使用Mcaptcha实例生成验证码

调用Mcaptcha实例的refresh方法来生成验证码。

Page({// ...onShow: function() {// 假设mcaptcha是之前创建的Mcaptcha实例mcaptcha.refresh();}
});

5.验证用户输入

当用户输入验证码并提交时,调用Mcaptcha实例的validate方法进行验证

Page({// ...checkCaptcha: function(inputCode) {// 假设mcaptcha是之前创建的Mcaptcha实例if (mcaptcha.validate(inputCode)) {wx.showToast({title: '验证成功!',icon: 'success'});} else {wx.showToast({title: '验证失败,请重试。',icon: 'none'});}}
});

 Mcaptcha.js的核心方法

  • refresh(): 生成新的验证码,包括随机数字、运算符和干扰元素。
  • validate(code): 验证用户输入的验证码是否正确,返回布尔值。
  • randomNum(min, max): 生成指定范围内的随机数。
  • randomColor(min, max): 生成指定范围内的随机颜色。

http://www.yayakq.cn/news/35209/

相关文章:

  • 响应式网站用什么工具爬取wordpress文章
  • 靖江网站开发兰州出台9条优化措施
  • 网站备案的意思google外贸建站
  • 个人艺术作品网站建设策划书2024年阳性什么症状
  • 高校支付网站建设费需要入无形资产上海做外贸网站
  • 礼品网站建设策划网站参数设定
  • 基于php网站开发的参考文献专门为网站建设服务的公司
  • 专业做电子的外贸网站代理什么产品好做挣钱
  • 可以做水果的团购网站有哪些wordpress页面转移
  • 个体企业建网站德胜门网站建设
  • 制作介绍的网站自己开发一个wordpress主题
  • 百度网站推广网络兰州一键建站企业
  • 网站建设入门基础阿里云主机建网站
  • 长春网站建设报价黑龙江网站建设巨耀网络
  • php做旅游网站怎么修改自己的网站
  • 免费网站建设朋友交流什么网站做谷歌联盟好
  • 成都品牌网站建设电话网站制作属于什么专业
  • 北京哪个网站做兼职比较好网站描述怎么修改吗
  • 泉州刺桐古建筑公司网站制作app的网站哪个好
  • 怎么做网站才能吸引人网站建设方案实验报告
  • 哪里可以做公司网站互联网网站建设彭聪
  • 农家院网站素材天河建设网站哪个好
  • 成都手机网站建设哪家公司好做淘宝客网站需要多大空间
  • sns网站是什么高端网站的设计开发公司
  • 深圳网站设计 建设首选深圳市作一家设计软件官网
  • 网站 项目方案电影分享网站源码
  • 济南腾飞网络网站建设体验营销案例分析
  • 做导购类网站seo首页优化
  • 没有网站如何做cpa推广wordpress多站点 seo
  • 做公司的网站的需求有哪些wordpress后台极慢