|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"video_course/errors"
|
|
|
"video_course/global"
|
|
|
@@ -152,3 +153,47 @@ func (h HeartRateServer) GetDuInfoAndUserInfoByUserMd5(userMd5 string) (inClass
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//上报App心率数据
|
|
|
+func (h HeartRateServer) AddAppHeartRate(userMd5 string, duId int, sn string, hrId int, heartRate int, rcvTime int, calories int, pureCalories int) (inClass int, err error) {
|
|
|
+ api := strings.Join([]string{global.Project.HeartrateUrl, "v1/OutService/AddAppHeartRate"}, "/")
|
|
|
+
|
|
|
+ resp, err := http.PostForm(api, url.Values{
|
|
|
+ "userMd5": {userMd5},
|
|
|
+ "duId": {strconv.Itoa(duId)},
|
|
|
+ "sn": {sn},
|
|
|
+ "hrId": {strconv.Itoa(hrId)},
|
|
|
+ "heartRate": {strconv.Itoa(heartRate)},
|
|
|
+ "rcvTime": {strconv.Itoa(rcvTime)},
|
|
|
+ "calories": {strconv.Itoa(calories)},
|
|
|
+ "pureCalories": {strconv.Itoa(pureCalories)},
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ defer resp.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("response:[%s], err:\n%w", string(body), err)
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var responseBase struct {
|
|
|
+ Code int
|
|
|
+ Memo string
|
|
|
+ InClass int
|
|
|
+ }
|
|
|
+ err = json.Unmarshal(body, &responseBase)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("response:[%s], err:\n%w", string(body), err)
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ rtnCode := responseBase.Code
|
|
|
+ inClass = responseBase.InClass
|
|
|
+ if rtnCode != 0 {
|
|
|
+ err = errors.ErrAddAppHeartRate
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|