case-api/extend/app/DoctorInfo.go
2025-03-07 16:57:28 +08:00

414 lines
9.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"bytes"
"case-api/config"
"case-api/utils"
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"time"
)
// getDoctorInfoByMobileRequest 获取用户信息-手机号-请求数据
type getDoctorInfoByMobileRequest struct {
Mobile string `json:"mobile"` // 手机号
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳10位
}
// getDoctorInfoByUuidRequest 获取用户信息-uuid-请求数据
type getDoctorInfoByUuidRequest struct {
Uuid string `json:"uuid"` // uuid
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳10位
}
// gtDoctorInfoByUnionIdRequest 获取用户信息-UnionId-请求数据
type getDoctorInfoByUnionIdRequest struct {
UnionId string `json:"unionid"` // 手机号
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳10位
}
// getDoctorInfoByTokenRequest 获取用户信息-token-请求数据
type getDoctorInfoByTokenRequest struct {
Token string `json:"token"` // token
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳10位
}
// GetDoctorInfoResponse 获取用户信息-返回数据
type GetDoctorInfoResponse struct {
Code int `json:"code"` // 接口调用状态。200正常其它值调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data *getDoctorInfoData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// getDoctorInfoData 获取用户信息-data详细数据
type getDoctorInfoData struct {
Uuid string `json:"uuid" description:"app唯一标识"`
OfficeName string `json:"office_name" description:"科室"`
RealName string `json:"realname" description:"姓名"`
HospitalUuid string `json:"hospital_uuid" description:"医院唯一标识"`
Mobile string `json:"mobile" description:"手机号"`
Photo string `json:"photo" description:"头像地址"`
CreateDate string `json:"weight" description:"create_date"`
PositionName string `json:"position_name" description:"职称"`
ProvName string `json:"prov_name" description:"省份"`
}
// GetDoctorInfoByMobile 获取用户信息-手机号
func GetDoctorInfoByMobile(mobile string) (g *GetDoctorInfoResponse, err error) {
// 准备要发送的 JSON 数据
requestData := getDoctorInfoByMobileRequest{
Mobile: mobile,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(requestData)
if err != nil {
return g, err
}
maps := make(map[string]interface{})
err = json.Unmarshal(jsonData, &maps)
if err != nil {
return g, err
}
// 获取请求签名
sign, err := GenSignature(maps)
if err != nil {
return g, err
}
// 准备请求体
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := config.C.App.ApiUrl + "/expert-api/getInfoByMobile"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
return g, err
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("sign", sign)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return g, err
}
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return g, err
}
// 检查响应状态码
if resp.StatusCode != 200 {
return g, errors.New("失败")
}
err = json.Unmarshal(body, &g)
if err != nil {
// json解析失败
return g, err
}
utils.LogJsonInfo("获取app数据返回", g)
if g.Code != 200 {
if g.Msg != "" {
return g, errors.New(g.Msg)
} else {
return g, errors.New("失败")
}
}
if g.Data == nil {
return g, errors.New("失败")
}
return g, nil
}
// GetDoctorInfoByUuid 获取用户信息-Uuid
func GetDoctorInfoByUuid(uuid string) (g *GetDoctorInfoResponse, err error) {
// 准备要发送的 JSON 数据
requestData := getDoctorInfoByUuidRequest{
Uuid: uuid,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(requestData)
if err != nil {
return g, err
}
maps := make(map[string]interface{})
err = json.Unmarshal(jsonData, &maps)
if err != nil {
return g, err
}
// 获取请求签名
sign, err := GenSignature(maps)
if err != nil {
return g, err
}
// 准备请求体
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := config.C.App.ApiUrl + "/expert-api/getInfoByUuid"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
return g, err
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("sign", sign)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return g, err
}
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return g, err
}
// 检查响应状态码
if resp.StatusCode != 200 {
return g, errors.New("失败")
}
err = json.Unmarshal(body, &g)
if err != nil {
// json解析失败
return g, err
}
utils.LogJsonInfo("获取app数据返回", g)
if g.Code != 200 {
if g.Msg != "" {
return g, errors.New(g.Msg)
} else {
return g, errors.New("失败")
}
}
if g.Data == nil {
return g, errors.New("失败")
}
return g, nil
}
// GetDoctorInfoByUnionId 获取用户信息-UnionId
func GetDoctorInfoByUnionId(unionId string) (g *GetDoctorInfoResponse, err error) {
// 准备要发送的 JSON 数据
requestData := getDoctorInfoByUnionIdRequest{
UnionId: unionId,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(requestData)
if err != nil {
return g, err
}
maps := make(map[string]interface{})
err = json.Unmarshal(jsonData, &maps)
if err != nil {
return g, err
}
// 获取请求签名
sign, err := GenSignature(maps)
if err != nil {
return g, err
}
// 准备请求体
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := config.C.App.ApiUrl + "/expert-api/getInfoByUnionid"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
return g, err
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("sign", sign)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return g, err
}
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return g, err
}
// 检查响应状态码
if resp.StatusCode != 200 {
return g, errors.New("失败")
}
err = json.Unmarshal(body, &g)
if err != nil {
// json解析失败
return g, err
}
utils.LogJsonInfo("获取app数据返回", g)
if g.Code != 200 {
if g.Msg != "" {
return g, errors.New(g.Msg)
} else {
return g, errors.New("失败")
}
}
if g.Data == nil {
return g, errors.New("失败")
}
return g, nil
}
// GetDoctorInfoByToken 获取用户信息-Token
func GetDoctorInfoByToken(token string) (g *GetDoctorInfoResponse, err error) {
// 准备要发送的 JSON 数据
requestData := getDoctorInfoByTokenRequest{
Token: token,
Platform: config.C.App.Platform,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
}
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(requestData)
if err != nil {
return g, err
}
maps := make(map[string]interface{})
err = json.Unmarshal(jsonData, &maps)
if err != nil {
return g, err
}
utils.LogJsonInfo("获取app数据参数", requestData)
// 获取请求签名
sign, err := GenSignature(maps)
if err != nil {
return g, err
}
// 准备请求体
requestBody := bytes.NewBuffer(jsonData)
// 设置请求 URL
url := config.C.App.ApiUrl + "/expert-api/getInfoByToken"
// 创建 POST 请求
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
return g, err
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
req.Header.Set("sign", sign)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return g, err
}
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return g, err
}
// 检查响应状态码
if resp.StatusCode != 200 {
return g, errors.New("失败")
}
err = json.Unmarshal(body, &g)
if err != nil {
// json解析失败
return g, err
}
utils.LogJsonInfo("获取app数据返回", g)
if g.Code != 200 {
if g.Msg != "" {
return g, errors.New(g.Msg)
} else {
return g, errors.New("失败")
}
}
if g.Data == nil {
return g, errors.New("失败")
}
return g, nil
}