package biz import ( "context" "customer/api/valuation" "database/sql" "github.com/go-kratos/kratos/v2/transport/grpc" "gorm.io/gorm" ) type CustomerWork struct { Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone,omitempty"` Name sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"name,omitempty"` Email sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"email,omitempty"` Wechat sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"wechat,omitempty"` CityID uint `gorm:"index;" json:"city_id"` } const CustomerSecret = "yourSecretKey" const CustomerDuration = 2 * 30 * 24 * 3600 type CustomerToken struct { Token string `gorm:"type:varchar(4095);" json:"token,omitempty"` TokenCreatedAt sql.NullTime `gorm:"" json:"tokenCreatedAt"` } type Customer struct { gorm.Model CustomerToken CustomerWork } type CustomerBiz struct { } func NewCustomerBiz() *CustomerBiz { return &CustomerBiz{} } func (cb *CustomerBiz) GetEstimatePrice(origin, destination string) (int64, error) { // 一,grpc 获取 conn, err := grpc.DialInsecure( context.Background(), grpc.WithEndpoint("localhost:9300"), ) if err != nil { return 0, nil } //关闭 defer func() { _ = conn.Close() }() // 2.2,发送获取验证码请求 client := valuation.NewValuationClient(conn) reply, err := client.GetEstimatePrice(context.Background(), &valuation.GetEstimatePriceReq{ Origin: origin, Destination: destination, }) if err != nil { return 0, err } return reply.Price, nil }