更新记录
1.0.0(2025-06-07)
初始化
平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | - | - | 4.4 | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | - | - | - |
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | 5.0 | - | - | - |
xtf-phonestate
android 来去电监听 监听实时短信,读取历史短信
由于系统限制 部分手机无法读取验证码
插件测试使用方法
1.选择试用,绑定要试用的项目appid,
2.选择后下载到对应的本地项目,
3.按照文档 -》把插件引入项目(即 import { onGetSms, onListenerSms, removeSmsListener,onStartListenerPhone } from '@/uni_modules/xtf-phonestate'; 需要先引入),
4.发布-》云打包-》选择制作基座-》打包等基座制作完成
5.运行 -》 运行到手机或模拟器-》运行到Androidapp基座-》选择使用自定义基座运行-》选择手机-》运行
6.之前若安装过基座 ,请卸载之前的基座
uniappx
复制代码<template>
<view>
<button type="primary" style="margin: 10rpx;" @click="onClick(0)">开启实时短信监听</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(1)">取消实时短信监听</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(2)">读取近一月短信</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(3)">来去电监听</button>
</view>
</template>
<script>
import { SMSData, SmsOption, onGetSms, onListenerSms, removeSmsListener,onStartListenerPhone } from '@/uni_modules/xtf-phonestate';
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
onClick(id:number){
if(id==0){
onListenerSms(function(b:SMSData[]){
console.log(b);
})
}else if(id==1){
removeSmsListener();
}else if(id==2){
onGetSms({
startDate:"2025-03-01",
callback(res:SMSData[]) {
console.log(res,res.length);
}
} as SmsOption)
}else if(id==3){
onStartListenerPhone(function(state:number,msg:string){
console.log(state,msg)
})
}
},
}
}
</script>
uniapp
复制代码<template>
<view>
<button type="primary" style="margin: 10rpx;" @click="onClick(0)">开启实时短信监听</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(1)">取消实时短信监听</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(2)">读取近一月短信</button>
<button type="primary" style="margin: 10rpx;" @click="onClick(3)">来去电监听</button>
</view>
</template>
<script>
import { onGetSms, onListenerSms, removeSmsListener,onStartListenerPhone } from '@/uni_modules/xtf-phonestate';
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
onClick(id){
if(id==0){
onListenerSms(function(b){
console.log(b);
})
}else if(id==1){
removeSmsListener();
}else if(id==2){
onGetSms({
startDate:"2025-03-01",
callback(res) {
console.log(res,res.length);
}
} as SmsOption)
}else if(id==3){
onStartListenerPhone(function(state,msg){
console.log(state,msg)
})
}
},
}
}
</script>
参数介绍
复制代码export type SMSData = {
smsId?:number, // 短信id
sender?:string,// 短信发送者手机号
content?:string,// 短信内容
date?:number,// 短信日期
type?:number,// 短信类型
selfChange?:boolean
}
export type SmsOption = {
startDate?:string, // 开始日期 格式为2025-06-07
endDate?:string,// 结束日期 格式为2025-06-07
type?:number,// 1 为收件 2 发送
callback?:(s:SMSData[])=>void // 回调发送结果
}