当前位置:网站首页>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
})
});
}
})
边栏推荐
- EF Core中的三类事务(SaveChanges、DbContextTransaction、TransactionScope)
- Gbase observation: extended analytical database
- Loop caused by add of sublist in list
- Batch renaming of images by MATLAB
- 高仿書旗小說 Flutter 版,學起來
- 生成所有可能的二叉搜索树
- 【Bug】C# IQueryable里的元素更改不了值
- Cross domain issues of the new version of Google browser
- 复原IP地址[标准回溯+标准剪枝]
- 网站ssl证书
猜你喜欢

Stm32-------adc (voltage detection)

Docker deploy redis

EF Core中的三类事务(SaveChanges、DbContextTransaction、TransactionScope)

PMP Exam related calculation formula summary! Must see before examination

List<? Extensions T > and list <? Super T > difference

一款高仿腾讯漫画的漫画阅读类 APP

2. camera calibration

Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)

6月25日PMP考试敏捷怎么考?替你分忧解难
![The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format](/img/8c/b1535e03900d71b075f73f80030064.png)
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format
随机推荐
日化用品行业集团采购管理系统改变传统采购模式,降低采购成本
[proteus simulation] example of T6963C driving pg12864 (with Chinese and English display)
Postman返回值中文乱码????
Startup process analysis of APP performance optimization
The group procurement management system of daily chemical supplies industry changes the traditional procurement mode and reduces the procurement cost
GBASE观察:扩展分析型数据库
APP性能优化之启动流程分析
【Try to Hack】masscan
【 GBASE的那些事儿】系列直播活动第02期《GBase 8s高可用技术及案例分析法》
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format
Golang type assertion
Docker deploy redis
One person even broke up a Netease cloud music Cloud Village
Restore IP address [standard backtracking + standard pruning]
如何保证高速公路供电可靠
三维向量场中的通量
Thinking (87): Protocol encryption and compression
为实现“双碳”目标,应如何实现节能、合理的照明管控
Notepad++ practical function sharing (common methods for replacing the end and beginning of regular lines, text comparison function, etc.)
Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)