This commit is contained in:
2025-03-07 16:57:28 +08:00
parent 93ab56f580
commit 83fa2cc789
181 changed files with 14333 additions and 0 deletions
+413
View File
@@ -0,0 +1,413 @@
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
}
+127
View File
@@ -0,0 +1,127 @@
package app
import (
"bytes"
"case-api/config"
"case-api/utils"
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"time"
)
// getHospitalByIdenRequest 获取医院信息-uuid-请求数据
type getHospitalByUuidRequest struct {
HospitalUuid string `json:"hospital_uuid"` // 医院uuid
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
// GetHospitalByUuidResponse 获取医院信息-uuid-返回数据
type GetHospitalByUuidResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data *getHospitalByUuidData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// getHospitalByUuidData 获取医院信息-uuid-data详细数据
type getHospitalByUuidData struct {
Uuid string `json:"uuid" description:"医院唯一标识"`
Name string `json:"name" description:"科室"`
Level string `json:"level" description:"等级"`
ProvName string `json:"prov_name" description:"省份"`
ExpertNum int `json:"expert_num" description:"医生数量"`
}
// GetHospitalByUuid 获取医院信息-uuid
func GetHospitalByUuid(hospitalIden string) (g *GetHospitalByUuidResponse, err error) {
// 准备要发送的 JSON 数据
requestData := getHospitalByUuidRequest{
HospitalUuid: hospitalIden,
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/getHospitalByUuid"
// 创建 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
}
+120
View File
@@ -0,0 +1,120 @@
package app
import (
"bytes"
"case-api/config"
"case-api/utils"
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"time"
)
// ReportUserScoreRequest 上报用户积分
type ReportUserScoreRequest struct {
BonuspointsNote string `json:"bonuspoints_note"` // 积分发放原因(互动病例-完成阅读;互动病例-阅读时间满足;互动病例-优质留言)
UserUuid string `json:"user_uuid"` // 用户uuid
Bonuspoints string `json:"bonuspoints"` // 添加积分
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
// ReportUserScoreResponse 上报用户积分-返回数据
type ReportUserScoreResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data ReportUserScoreData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// ReportUserScoreData 上报用户积分-data详细数据
type ReportUserScoreData struct {
}
// ReportUserScore 上报用户积分
func ReportUserScore(bonuspointsNote, userUuid string, bonuspoints int) (g *ReportUserScoreResponse, err error) {
// 准备要发送的 JSON 数据
requestData := ReportUserScoreRequest{
BonuspointsNote: bonuspointsNote,
UserUuid: userUuid,
Bonuspoints: strconv.Itoa(bonuspoints),
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/addBonusPoints"
// 创建 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("失败")
}
}
return g, nil
}
+86
View File
@@ -0,0 +1,86 @@
package app
import (
"case-api/config"
"case-api/utils"
"encoding/json"
"sort"
"strings"
)
//const (
// apiUrl = "https://dev-wx.igandan.com" // 接口地址
// secretKey = "RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^" // 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
// platform = "suanyisuan" // 所属平台
// imagePrefix = "https://dev-doc.igandan.com/app" // 图片地址前缀
//)
// GenSignature 生成签名信息
func GenSignature(params map[string]interface{}) (string, error) {
// 对map的key进行排序,包括多层嵌套的情况
data := sortMapRecursively(params)
// 转换为JSON
jsonData, err := json.Marshal(data)
if err != nil {
return "", err
}
sing := utils.HmacSHA256(string(jsonData), config.C.App.SecretKey)
return sing, nil
}
// sortMapRecursively 对map的key进行排序,包括多层嵌套的情况
func sortMapRecursively(data map[string]interface{}) map[string]interface{} {
sortedMap := make(map[string]interface{})
keys := make([]string, 0, len(data))
// 收集所有的key
for key := range data {
keys = append(keys, key)
}
// 对key进行排序
sort.Strings(keys)
// 通过排序后的key插入新map中
for _, key := range keys {
value := data[key]
switch valueTyped := value.(type) {
case map[string]interface{}:
// 如果是嵌套的map,递归调用
sortedMap[key] = sortMapRecursively(valueTyped)
case []interface{}:
// 如果是嵌套的slice,对其中的map进行递归调用
for i, v := range valueTyped {
if vMap, ok := v.(map[string]interface{}); ok {
valueTyped[i] = sortMapRecursively(vMap)
}
}
sortedMap[key] = valueTyped
default:
// 否则直接插入
sortedMap[key] = value
}
}
return sortedMap
}
// HandleImagePrefix 处理app图片前缀
func HandleImagePrefix(u string) (string, error) {
if u == "" {
return "", nil
}
// 去除oss前缀
u = utils.RemoveOssDomain(u)
imgPath := strings.Replace(u, config.C.App.ImagePrefix, "", 1)
if imgPath == "/null" {
return "", nil
}
return imgPath, nil
}
+53
View File
@@ -0,0 +1,53 @@
package app
import (
"encoding/json"
"errors"
"fmt"
)
// PayOrderRequest 获取订单支付请求数据
type PayOrderRequest struct {
OrderId string `json:"orderId" label:"订单编号" validate:"required"` // 订单id
}
// PayOrderDataResponse 获取订单支付返回数据-data
type PayOrderDataResponse struct {
AppId string `json:"appid"` // 公众号id
Total int `json:"total"` // 订单总金额(精确到分)
Description string `json:"description"` // 订单描述
OpenId string `json:"openid"` // 下单用户
OutTradeNo string `json:"out_trade_no"` // 商户订单
Attach string `json:"attach"` // 附加信息
NotifyUrl string `json:"notify_url"` // 异步接收微信支付结果通知的回调地址
GoodName string `json:"goodName"` // 商品名称
}
// VerifySignature 验证签名
func VerifySignature(req PayOrderRequest, requestSign string) error {
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(req)
if err != nil {
return err
}
maps := make(map[string]interface{})
err = json.Unmarshal(jsonData, &maps)
if err != nil {
return err
}
// 生成签名
sign, err := GenSignature(maps)
if err != nil {
return err
}
fmt.Println(sign)
// 对比签名
if sign != requestSign {
return errors.New("签名错误")
}
return nil
}
+243
View File
@@ -0,0 +1,243 @@
package app
import (
"bytes"
"case-api/config"
"case-api/utils"
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"time"
)
// GetUserCaseByAppIdenRequest 根据app唯一标识获取用户病例信息-请求数据
type GetUserCaseByAppIdenRequest struct {
PatientUuid string `json:"patientUuid"` // 患者 uuid
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
// UpdateUserCaseRequest 修改疾病信息-请求数据
type UpdateUserCaseRequest struct {
IsAllergy *int `json:"isAllergy"` // 是否过敏史 0否 1是
AllergyInfo string `json:"allergyInfo"` // 过敏史详情
IsHospital *int `json:"isHospital"` // 是否去医院 0否 1是
IsMedication *int `json:"isMedication"` // 是否服药 0否 1是
MedicationInfo string `json:"medicationInfo"` // 正在服用的药物
LiverStatus string `json:"liverStatus"` // 目前肝脏状态
OtherDisease string `json:"otherDisease"` // 合并其他慢性疾病 (多个英文逗号分隔拼接)
DiseasesList []*DiseasesListRequest `json:"diseasesList"` // 所患疾病列表
PatientUuid string `json:"patientUuid"` // 患者 uuid
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
type DiseasesListRequest struct {
Uuid string `json:"uuid"` // 疾病 uuid
Year *int `json:"year"` // 患病时长
Info string `json:"info"` // 丙肝基因型(仅针对丙肝)
Name string `json:"name"` // 疾病名称
}
// GetUserCaseByAppIdenResponse 根据app唯一标识获取用户病例信息-返回数据
type GetUserCaseByAppIdenResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data *GetUserCaseByAppIdenData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// UpdateUserCaseResponse 修改用户病例-返回数据
type UpdateUserCaseResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// GetUserCaseByAppIdenData 根据app唯一标识获取用户病例信息-data详细数据
type GetUserCaseByAppIdenData struct {
AllergyInfo string `json:"allergyInfo" description:"过敏史详情"`
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
DiseasesList []*DiseasesListData `json:"diseasesList" description:"所患疾病列表"`
MedicationInfo string `json:"medicationInfo" description:"正在服用的药物"`
OtherDisease string `json:"otherDisease" description:"合并其他慢性疾病 (多个英文逗号分隔拼接)"`
IsMedication *int `json:"isMedication" description:"是否服药 0否 1是"`
IsHospital *int `json:"isHospital" description:"是否去医院 0否 1是"`
IsAllergy *int `json:"isAllergy" description:"是否过敏史 0否 1是"`
LiverStatus string `json:"liverStatus" description:"目前肝脏状态"`
}
// DiseasesListData 根据app唯一标识获取用户病例信息-data详细数据-所患疾病数据
type DiseasesListData struct {
UUID string `json:"uuid" description:"疾病 uuid"`
Year *int `json:"year" description:"患病时长"`
Info string `json:"info" description:"丙肝基因型(仅针对丙肝)"`
Name string `json:"name" description:"疾病名称"`
}
// GetUserCaseByAppIden 根据app唯一标识获取用户病例信息
func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err error) {
// 准备要发送的 JSON 数据
requestData := GetUserCaseByAppIdenRequest{
PatientUuid: appIden,
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 + "/patient-api/getDiseaseInfo"
// 创建 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("失败")
}
}
return g, nil
}
// UpdateUserCase 修改用户病例
func UpdateUserCase(reqData UpdateUserCaseRequest) (g *UpdateUserCaseResponse, err error) {
reqData.Platform = config.C.App.Platform
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(reqData)
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 + "/patient-api/upDiseaseInfo"
// 创建 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("失败")
}
}
return g, nil
}
+240
View File
@@ -0,0 +1,240 @@
package app
import (
"bytes"
"case-api/config"
"case-api/utils"
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"time"
)
// GetUserInfoByMobileRequest 根据手机号获取用户信息-请求数据
type GetUserInfoByMobileRequest struct {
Mobile string `json:"mobile"` // 手机号
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
// UpdateUserInfoRequest 修改用户信息-请求数据
type UpdateUserInfoRequest struct {
Birthday string `json:"birthday"` // 出生日期
IsPegnant *int `json:"isPegnant"` // 是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝
Sex *int `json:"sex"` // 性别 0男 1女
Weight *int `json:"weight"` // 体重 KG
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth"` // 预产期
IsHbv *int `json:"isHbv"` // 市区 id
NationUuid string `json:"nationUuid"` // 民族 uuid
PatientUuid string `json:"patientUuid"` // 患者 uuid
Name string `json:"name"` // 姓名
ProvId *int64 `json:"provId"` // 省份 id
CityId *int64 `json:"cityId"` // 城市 id
CountyId *int64 `json:"countyId"` // 市区 id
Height *int `json:"height"` // 身高 cm
Platform string `json:"platform"` // 所属平台
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
}
// GetUserInfoByMobileResponse 根据手机号获取用户信息-返回数据
type GetUserInfoByMobileResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data GetUserInfoByMobileData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// UpdateUserInfoResponse 修改用户信息-返回数据
type UpdateUserInfoResponse struct {
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
Success bool `json:"success"`
Message string `json:"message"`
}
// GetUserInfoByMobileData 根据手机号获取用户信息-data详细数据
type GetUserInfoByMobileData struct {
Birthday string `json:"birthday" description:"出生日期"`
IsPregnant *int `json:"isPregnant" description:"是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝"`
Sex *int `json:"sex" description:"性别 0男 1女"`
Mobile string `json:"mobile" description:"手机号"`
Photo string `json:"photo" description:"头像地址"`
Weight *int `json:"weight" description:"体重 KG"`
CityID *int64 `json:"cityId" description:"城市 id"`
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth" description:"预产期"`
CountyID *int64 `json:"countyId" description:"市区 id"`
IsHBV *int `json:"isHbv" description:"有无 肝硬化或肝癌家族史 0无1有2未知"`
NationUUID string `json:"nationUuid" description:"民族 uuid"`
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
Name string `json:"name" description:"姓名"`
ProvinceID *int64 `json:"provId" description:"省份 id"`
Height *int `json:"height" description:"身高 cm"`
OpenId string `json:"openid" description:"openid"`
UnionId string `json:"unionid" description:"unionid"`
}
// GetUserInfoByMobile 根据手机号获取用户信息
func GetUserInfoByMobile(mobile string) (g *GetUserInfoByMobileResponse, err error) {
// 准备要发送的 JSON 数据
requestData := GetUserInfoByMobileRequest{
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 + "/patient-api/getInfo"
// 创建 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("失败")
}
}
return g, nil
}
// UpdateUserInfo 修改用户信息
func UpdateUserInfo(reqData UpdateUserInfoRequest) (g *UpdateUserInfoResponse, err error) {
reqData.Platform = config.C.App.Platform
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
// 将 JSON 数据编码为字节数组
jsonData, err := json.Marshal(reqData)
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 + "/patient-api/updateInfo"
// 创建 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("失败")
}
}
return g, nil
}