当前位置: 首页 > news >正文

建立链接网站模板拓客系统

建立链接网站模板,拓客系统,wordpress主体下载,西安网站建设xs029refer: http://ip-api.com/ 1.首先需要创建一个保存用户历史的登录的表,然后连接go 2.在用户登录的时候,获取用户的IP IP位置,在后端直接处理数据即可(不需要在前端传递数据) (1)增加路由&am…

refer: http://ip-api.com/

1.首先需要创建一个保存用户历史的登录的表,然后连接go

2.在用户登录的时候,获取用户的IP IP位置,在后端直接处理数据即可(不需要在前端传递数据)

(1)增加路由:

apiv1.POST("/history_login_logs", v1.AddHistoryLoginLog)

(2)在model里增加(例如:models/history_login_logs.go)
 

 func AddHistoryLoginLog(user_id int, ip_address string, ip_location string, login_at time.Time) bool {db.Create(&HistoryLoginLogs{UserId:    user_id,IpAddress: ip_address,IpLocation:   ip_location,LoginAt: login_at,})return true}


  (3) 在登录后的方法中增加(需要引入

import("time""io/ioutil""fmt""encoding/json"
)type Location struct {Status      string  `json:"status"`Country     string  `json:"country"`CountryCode string  `json:"countryCode"`Region      string  `json:"region"`RegionName  string  `json:"regionName"`City        string  `json:"city"`Zip         string  `json:"zip"`Lat         float64 `json:"lat"`Lon         float64 `json:"lon"`Timezone    string  `json:"timezone"`Isp         string  `json:"isp"`Org         string  `json:"org"`As          string  `json:"as"`Query       string  `json:"query"`
}...
ipAddress := c.ClientIP()
fmt.Println("== ip_address:", ipAddress)
resp, err := http.Get("http://ip-api.com/json/" + ipAddress + "?lang=zh-CN")
if err != nil {fmt.Println("Error:", err)return
}defer resp.Body.Close()body, err := ioutil.ReadAll(resp.Body)if err != nil {fmt.Println("Error:", err)return}var location Location
err = json.Unmarshal(body, &location)if err != nil {fmt.Println("Error:", err)return}fmt.Println("=== Location:", location)
City := location.CitycurrentTime := time.Now()
models.AddHistoryLoginLog(user.ID, ipAddress, City, currentTime)
...

  (4)增加action (例如:routers/api/v1/history_login_log.go)(需要引入import  "net/http"   "time"  "fmt")
 

type AddHistoryLoginLogRequest struct {UserID     int    `json:"user_id" binding:"required"`IPAddress  string `json:"ip_address" binding:"required"`City string `json:"ip_location" binding:"required"`CurrentTime time.Time `json:"login_at" binding:"required"`}func AddHistoryLoginLog(c *gin.Context) {var request AddHistoryLoginLogRequestif err := c.ShouldBindJSON(&request); err != nil {fmt.Println("== err: ", err)return}models.AddHistoryLoginLog(request.UserID, request.IPAddress, request.City, request.CurrentTime)}

3.在前端写一个展示的列表页面即可。(登录时间写现在的时间即可。)
例如:src/pages/HistoryLoginLog/index.jsx

import React, { Component } from 'react'
import { Table } from 'antd';
import axios from 'axios'
import Config from '@/settings'
import { getToken, removeToken } from '@/utils/auth'const columns = [{title: '登录名',dataIndex: 'user_id',key: 'user_id',render: text => <a>{text}</a>,},{title: '登陆时间',dataIndex: 'login_at',key: 'login_at',// 这里是进行时间的处理,转换为北京时间,格式为:2023/08/16 21:40render: text => {const dateObj = new Date(text);const localizedDate = dateObj.toLocaleString('zh-CN', {timeZone: 'Asia/Shanghai',year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',});return <span>{localizedDate}</span>;},},{title: '登陆ip',dataIndex: 'ip_address',key: 'ip_address',},{title: '登陆位置',dataIndex: 'ip_location',key: 'ip_locatio',}
];export default class CalculationPlan extends Component {state = {data: [],loading: true,}async fetchData() {try {const response = await axios.get(`${Config.BASE_URL}/api/v1/history_login_logs?token=${getToken()}`)if (response.data.message == "ok") {const sortedData = response.data.data.sort((a, b) => new Date(b.id) - new Date(a.id));this.setState({data: sortedData,loading: false,})}} catch (error) {console.error(error)removeToken()window.location.href = '/'}}componentDidMount() {this.fetchData()}render() {const { data, loading } = this.statereturn (<Table columns={columns} dataSource={data} loading={loading} />)}
}

http://www.yayakq.cn/news/314263/

相关文章:

  • 网站优化 福州建设个人网站教程
  • 网站开发公司更换如何开个公司网站
  • app制作过程和网站一样吗彩票网站的建设
  • 展示型网站建设模板重庆的公司
  • 做磁力解析网站重庆seo是什么
  • 合肥知名网站建设公司4c网络营销策略
  • 保亭住房和城乡建设局网站网站建设征求意见的通知
  • 上海seo网站优化建筑设计说明模板100字
  • 网站建设费无形资产小程序分销怎么做好分销
  • 深圳市网站建设外包公司网站开发合同存在的缺陷
  • 做翻译 网站吗如何开发微信小程序
  • 简单网站开发流程图手机网站多少钱一个
  • 国际网站模板sql 新建网站
  • 整站seo优化推广网络营销知识网站
  • 自己做个网站教程企业网站结构
  • 好看的企业网站首页淘宝官网首页注册账号
  • 广东省建设厅人才网站网页qq官网登录入口
  • 创新的赣州网站建设要制作自己的网站需要什么材料
  • 家用电器网站建设深圳市推广网站的公司
  • 山西网站建设营销qq淘宝网卖家中心入口
  • 东莞商城网站建设公司英文网站开发公司
  • 上海网站建设上海黄金建筑公司企业愿景平台
  • 建设网站要多久到账windows 做网站服务器吗
  • 团购网站策划地图 添加到网站
  • 自己做网站价格天津网站建设制作价格
  • 网站开发 毕业答辩ppt顺德手机网站设计信息
  • 用dw做网站怎么添加水平线淘宝网站建设杭州
  • 福州网站优化建设网站dns如何设置
  • 龙岗网站建设代理商上海网站建设加q.479185700
  • 淘宝联盟网站建设源码配资网站建设多少钱