forked from silenceper/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
werun.go
40 lines (34 loc) · 845 Bytes
/
werun.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package werun
import (
"encoding/json"
"github.com/amazing-gao/wechat/v2/miniprogram/context"
"github.com/amazing-gao/wechat/v2/miniprogram/encryptor"
)
// WeRun 微信运动
type WeRun struct {
*context.Context
}
// Data 微信运动数据
type Data struct {
StepInfoList []struct {
Timestamp int `json:"timestamp"`
Step int `json:"step"`
} `json:"stepInfoList"`
}
// NewWeRun 实例化
func NewWeRun(ctx *context.Context) *WeRun {
return &WeRun{Context: ctx}
}
// GetWeRunData 解密数据
func (werun *WeRun) GetWeRunData(sessionKey, encryptedData, iv string) (*Data, error) {
cipherText, err := encryptor.GetCipherText(sessionKey, encryptedData, iv)
if err != nil {
return nil, err
}
var weRunData Data
err = json.Unmarshal(cipherText, &weRunData)
if err != nil {
return nil, err
}
return &weRunData, nil
}