478 lines
13 KiB
Go
478 lines
13 KiB
Go
package app
|
||
|
||
import (
|
||
"bytes"
|
||
"case-admin-api/config"
|
||
"case-admin-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位)
|
||
}
|
||
|
||
// gtDoctorInfoByNameRequest 获取用户信息-Name-请求数据
|
||
type getDoctorInfoByNameRequest struct {
|
||
UserName string `json:"user_name"` // 姓名
|
||
Platform string `json:"platform"` // 所属平台
|
||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||
}
|
||
|
||
// GetDoctorInfoByMobileResponse 获取用户信息-手机号-返回数据
|
||
type GetDoctorInfoByMobileResponse struct {
|
||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||
Data *getDoctorInfoByMobileData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// GetDoctorInfoByUuidResponse 获取用户信息-uuid-返回数据
|
||
type GetDoctorInfoByUuidResponse struct {
|
||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||
Data *getDoctorInfoByUuidData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// GetDoctorInfoByUnionIdResponse 获取用户信息-UnionId-返回数据
|
||
type GetDoctorInfoByUnionIdResponse struct {
|
||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||
Data *getDoctorInfoByUnionIdData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// GetDoctorInfoByNameResponse 获取用户信息-Name-返回数据
|
||
type GetDoctorInfoByNameResponse struct {
|
||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||
Data []*getDoctorInfoByNameData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||
Success bool `json:"success"`
|
||
Message string `json:"message"`
|
||
}
|
||
|
||
// getDoctorInfoByMobileData 获取用户信息-手机号-data详细数据
|
||
type getDoctorInfoByMobileData 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:"省份"`
|
||
}
|
||
|
||
// getDoctorInfoByUuidData 获取用户信息-Uuid-data详细数据
|
||
type getDoctorInfoByUuidData 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:"省份"`
|
||
}
|
||
|
||
// getDoctorInfoByUnionIdData 获取用户信息-UnionId-data详细数据
|
||
type getDoctorInfoByUnionIdData 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:"省份"`
|
||
}
|
||
|
||
// getDoctorInfoByNameData 获取用户信息-Name-data详细数据
|
||
type getDoctorInfoByNameData 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 *GetDoctorInfoByMobileResponse, 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 *GetDoctorInfoByUuidResponse, 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 *GetDoctorInfoByUnionIdResponse, 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
|
||
}
|
||
|
||
// GetDoctorInfoByName 获取用户信息-Name
|
||
func GetDoctorInfoByName(userName string) (g *GetDoctorInfoByNameResponse, err error) {
|
||
// 准备要发送的 JSON 数据
|
||
requestData := getDoctorInfoByNameRequest{
|
||
UserName: userName,
|
||
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/getInfoByName"
|
||
|
||
// 创建 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 len(g.Data) == 0 {
|
||
return g, nil
|
||
}
|
||
|
||
return g, nil
|
||
}
|