当前位置:网站首页>Wechat applet picture verification code display
Wechat applet picture verification code display
2022-06-23 23:52:00 【Results of persistence and effort】
I don't say much nonsense , Code up
One .html page
<canvas canvas-id="canvas" bindtap='change' style="width:90px;height: 30px;"></canvas>Two ,js Logic
var app = getApp();
var baseUrl = getApp().baseUrl;
var ctx;
Page({
data:{
text:""
},
onLoad: function(options) {
var that = this;
this.drawPic(that);
},
change: function() {
var that = this;
this.drawPic(that);
},
mobile(e) {
this.setData({
mobile: e.detail.value
})
},
randomNum(min, max) {
return Math.floor(Math.random() * (max - min) + min);
},
/** Generate a random color **/
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 + ")";
},
/** Draw verification code picture **/
drawPic(that) {
ctx = wx.createCanvasContext('canvas');
/** Draw the background color **/
ctx.fillStyle = this.randomColor(180, 240); // If the color is too dark, it may make you can't see clearly
ctx.fillRect(0, 0, 90, 28)
/** Draw text **/
var arr;
var text = '';
var str = 'ABCEFGHJKLMNPQRSTWXY123456789';
for (var i = 0; i < 4; i++) {
var txt = str[this.randomNum(0, str.length)];
ctx.fillStyle = this.randomColor(50, 160); // Randomly generate font colors
ctx.font = this.randomNum(20, 26) + 'px SimHei'; // Randomly generate font size
var x = 5 + i * 20;
var y = this.randomNum(20, 25);
var deg = this.randomNum(-20, 20);
// Modify the origin and rotation Angle
ctx.translate(x, y);
ctx.rotate(deg * Math.PI / 180);
ctx.fillText(txt, 5, 0);
text = text + txt;
// Restore the origin of coordinates and rotation Angle
ctx.rotate(-deg * Math.PI / 180);
ctx.translate(-x, -y);
}
/** Draw interference line **/
for (var i = 0; i < 4; i++) {
ctx.strokeStyle = this.randomColor(40, 180);
ctx.beginPath();
ctx.moveTo(this.randomNum(0, 90), this.randomNum(0, 28));
ctx.lineTo(this.randomNum(0, 90), this.randomNum(0, 28));
ctx.stroke();
}
/** Plot interference point **/
for (var i = 0; i < 20; i++) {
ctx.fillStyle = this.randomColor(0, 255);
ctx.beginPath();
ctx.arc(this.randomNum(0, 90), this.randomNum(0, 28), 1, 0, 2 * Math.PI);
ctx.fill();
}
ctx.draw(false, function() {
that.setData({
text: text
})
});
}
})
边栏推荐
- The group procurement management system of daily chemical supplies industry changes the traditional procurement mode and reduces the procurement cost
- B2B transaction management system of electronic components industry: improve the data-based driving ability and promote the growth of enterprise sales performance
- 2018/gan:self attention generating adversarial networks
- Tupu software intelligent wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment
- 工作中一些常用的工具函数
- How to achieve the turning effect of wechat video recording?
- Server2022 activation
- Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?
- Cross domain issues of the new version of Google browser
- Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
猜你喜欢

生成式对抗网络(GANs)及变体

Application of acrel-3000web power management system in Duba Expressway

如何保证高速公路供电可靠

docker 部署redis

Postman return value Chinese garbled????

老龄化下背景下,综合能效管理平台为医院保驾护航

PMP Exam related calculation formula summary! Must see before examination

这个高仿小米商城项目太惊艳了

再见,2020,这碗毒鸡汤,我先干了

Smart doc + Torna compatible version
随机推荐
Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)
【Try to Hack】masscan
图扑软件智慧风电:数字孪生 3D 风机智能设备运维
不同物体使用同一材质,有不同的表现
这个高仿小米商城项目太惊艳了
Thinking (86): master-slave realization idea
The group procurement management system of daily chemical supplies industry changes the traditional procurement mode and reduces the procurement cost
Stm32-------adc (voltage detection)
Postman返回值中文乱码????
【HackTheBox】 meow
AUTOCAD——总结CAD画圆角的三种方式
Unity text component space newline problem
Web site SSL certificate
log Network Execution Time
组合总数II[每个元素只能用一次 + 去重复解集]
How to achieve energy-saving and reasonable lighting control in order to achieve the "double carbon" goal
List<? Extensions T > and list <? Super T > difference
VS QT VTK 左下角显示同步小坐标轴
Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?
WPF效果之Expander+ListBox