Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 7x 7x 7x 7x 1x 6x 6x 6x 6x | export interface GetSmsUrlOptions { /** 手机号 */ phoneNumber?: string /** 消息 */ message?: string /** 用户代理 */ userAgent?: string } /** * 获取短信链接。 * * @param options 选项 * @see https://stackoverflow.com/questions/6480462/how-to-pre-populate-the-sms-body-text-via-an-html-link */ export function getSmsUrl(options: GetSmsUrlOptions): string { const phoneNumber = options.phoneNumber || '' const message = options.message || '' let url = `sms:${phoneNumber}` if (!message) { return url } const userAgent = options.userAgent || navigator.userAgent const separator = /iphone|ipad|ipod|macintosh/i.test(userAgent) ? '&' : '?' url += `${separator}body=${encodeURIComponent(message)}` return url } |