uniapp SMS monitoring (verification code) plug-in Ba-Sms

Introduction ( download address )

Ba-Sms is a plug-in for intercepting real-time SMS. It can filter SMS and get the content you want. It can be used for projects that need to automatically fill in SMS verification codes

  • Support to monitor the currently received SMS information
  • Support for filtering received text messages, and filter 4~8-digit verification codes by default
  • Support custom filter conditions (regular)

screenshot display

insert image description here

Instructions

quote

scriptIntroduce components in

	const baSms = uni.requireNativePlugin('Ba-Sms')

example

It can be called scripton (example reference, you can modify it according to your own business and calling method)

<script>
	const baSms = uni.requireNativePlugin('Ba-Sms')
	export default {
    
    
		data() {
    
    
			return {
    
    
				filterAddress: "10086",
				address: "10086",
				content: '【某某应用】验证码:708563。尊敬的用户,您正在...,我们不会向您索要此验证码,切勿告知他人!',
				msgList: []
			}
		},
		methods: {
    
    
			register() {
    
     //注册监听
				baSms.register({
    
    
					filterAddress: this.filterAddress, //需要过滤的短信地址,**注意**,如果是手机号,要以“+86”开头
					//regex: "(\\d{4,8})",正则表达式,默认为匹配4-8位的数字验证码
				}, res => {
    
    
					console.log(res);
					if (res.ok && res.result) {
    
    //监听短信接收,判断 res.result 有内容
						this.msgList.push(res.address + ":" + res.content);
						this.msgList.push("解析结果:" + res.result);
					}
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			unregister() {
    
     //注销监听
				baSms.unregister({
    
    }, res => {
    
    
					console.log(res);
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
			simulate() {
    
     //模拟短信,仅用于测试
				baSms.simulate({
    
    
					address: this.address,
					content: this.content
				}, res => {
    
    
					console.log(res);
					uni.showToast({
    
    
						title: res.msg,
						icon: "none",
						duration: 3000
					})
				});
			},
		}
	}
</script>

method list

name illustrate
register Register for SMS monitoring
unregister Log out of SMS monitoring
simulate Simulated SMS, for testing only

register method parameter

Register for SMS monitoring

attribute name type required Defaults illustrate
filterAddress String It is recommended to fill in ‘’ SMS address that needs to be filtered, '' is to monitor all SMS; you can only set the beginning, such as listening to 10086 SMS, you can write '100' indistinctly, and listen to all SMS starting with 100. Note that if it is a mobile phone number, it must start with "
+86 " beginning
regex String false ‘’ Regular expression to filter SMS content, by default filter 4~8 digit verification code, such as '(\d{4,8})'

Monitor parameters for receiving text messages

Judging that res.result has content, monitor the received SMS

attribute name type illustrate
address String SMS address
content String SMS original content
result String After the text message content is parsed, the result obtained, such as the verification code

simulate method parameter

Simulated SMS, for testing only

attribute name type required Defaults illustrate
address String true ‘’ SMS address
content String true ‘’ SMS content

Series plug-in

Image selection plugin Ba-MediaPicker ( documentation )

Image editing plugin Ba-ImageEditor ( documentation )

File picker plugin Ba-FilePicker ( documentation )

Application message notification plugin Ba-Notify ( documentation )

Apply the unread badge plugin Ba-Shortcut-Badge ( documentation )

Applying the Ba-Autoboot plugin ( documentation )

Scan code native plug-in (millisecond level, support multi-code) Ba-Scanner-G ( documentation )

Native plug-in for scanning code - new (can customize the interface version arbitrarily; support continuous scanning code; support setting scanning code format) Ba-Scanner ( documentation )

Dynamically modify the status bar, navigation bar background color, font color plug-in Ba-AppBar ( documentation )

Native sqlite local database management Ba-Sqlite ( documentation )

Android keep-alive plug-in (using a variety of mainstream technologies) Ba-KeepAlive ( documentation )

Android shortcut (desktop long press app icon) Ba-Shortcut ( documentation )

Custom image watermark (anywhere) Ba-Watermark ( documentation )

The closest image compression plug-in to WeChat is Ba-ImageCompressor ( documentation )

Video compression, video editing plug-in Ba-VideoCompressor ( documentation )

Dynamically switch application icons and names (such as New Year, National Day, etc.) Ba-ChangeIcon ( documentation )

Native Toast pop-up prompt (through all interfaces, through native; custom colors, icons) Ba-Toast ( documentation )

Image graffiti, brush Ba-ImagePaint ( documentation )

pdf reading (gesture zoom, display page number) Ba-Pdf ( documentation )

Sound reminder, vibration reminder, voice broadcast Ba-Beep ( documentation )

Websocket native service (automatic reconnection, heartbeat detection) Ba-Websocket ( documentation )

SMS monitoring (verification code) Ba-Sms ( documentation )

Smart Install (Automatic Upgrade) Ba-SmartUpgrade ( documentation )

Monitor system broadcast, custom broadcast Ba-Broadcast ( documentation )

Listen to notification bar messages (support whitelist, blacklist, filter) Ba-NotifyListener ( documentation )

Global graying, mourning graying (dynamic, support nvue, vue at the same time) Ba-Gray ( documentation )

Get Device Unique Identifier (OAID, AAID, IMEI, etc.) Ba-IdCode ( documentation )

Real-time positioning (system, background operation, support screen) plug-in Ba-Location ( documentation )

Guess you like

Origin blog.csdn.net/u013164293/article/details/128075054