h5页面发送短信并填充内容
参考:https://blog.youkuaiyun.com/dhlg123/article/details/126095750
const visitorPhoneNbr = '159xxxxxx17'
var u = navigator.userAgent
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
// 安卓写法
if (isAndroid) {
// sms:后面跟收件人的手机号,body后接短信内容
// window.location.href='sms:188XXXXXXXX,134XXXXXXXX?body='+this.msg;
window.location.href = `sms:${visitorPhoneNbr}?body=${this.link}`
} else if (isIOS) {
// ios的写法
// window.location.href='sms:/open?addresses=134XXXXXXXX,182XXXXXXXX&body='+this.msg;
window.location.href = `sms:/open?addresses=${visitorPhoneNbr}&body=${this.link}`
}
computed: {
link() {
return `您好, 来访请点击链接获取通行码 \n${encodeURIComponent(
window.QR_CODE_LINK_IP
)}/xxxx/xxxxxxx?key=${encodeURIComponent(
this.token
)} \n如果上传人脸,可通过人脸识别进入。\n如果填写车牌,可通过车闸识别进入。`
}
}
因为我的填充内容是带链接的,链接会有#和+导致安卓系统短信填充的时候只填充了#前面的内容,加号转成了空格然后链接就不对了,ios系统填充正常;
解决办法将#转为%23,+转为%2B
字符转义https://www.cnblogs.com/eoalfj/p/11607246.html