|
加载sdk同google,稍显复杂,telegram麻烦在登录时有机器人部分,需要配置机器人
项目存在多线路,机器人名字时域名拼接: newHost = window.location.host;
botName = newHost.split('.').join('')+'xxxxxBot';
const script = document.createElement('script');
script.src = 'https://telegram.org/js/telegram-widget.js?22';
script.async = true;
script.setAttribute('data-telegram-login',botName);
script.setAttribute('data-size','large');
script.setAttribute('data-userpic','false');
script.setAttribute('data-radius','20');
// script.setAttribute('data-onauth','onTelegramAuth(user)');
script.setAttribute('data-request-access','write');document.getElementById('telegram').appendChild(script);window.onTelegramAuth = this.onTelegramAuth;
script.setAttribute('data-onauth', 'window.onTelegramAuth(user)');
onTelegramAuth 方法就是从telegram那边获取到的信息,同样,有一个参数user,我们将user进行JSON.stringify一下传递给后端,后端解析获取到用户信息。 |
|