| 1234567891011121314151617181920212223242526272829303132333435 |
- /**获取当前登录的ip */
- export async function getUserIP(callback) {
- await fetch('https://api.ipify.org?format=json').then(function (response) {
- return response.json();
- }).then(function (data) {
- callback(data.ip);
- }).catch(function (error) {
- console.log('Error:', error);
- })
- }
- // 获取当前登录的地理位置 经纬度
- export async function getUserLocation(ipInfo, callback) {
- await fetch(`https://ipapi.co/${ipInfo}/json`)
- .then(response => response.json())
- .then(data => {
- callback(data);
- // 打印地理位置信息 经纬度
- // console.log(data.latitude);
- // console.log(data.longitude);
- })
- .catch(error => console.log(error));
- }
- // 获取当前登录的地理 信息
- export async function getAddressLocation(ipInfo, callback) {
- await fetch(`https://qifu-api.baidubce.com/ip/geo/v1/district?ip=${ipInfo}`)
- .then(response => response.json())
- .then(res => {
- if (res.code === 'Success') {
- callback({ ...res.data, ip: res.ip });
- }
- })
- .catch(error => console.log(error));
- }
|