mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
Silenceper release 2.0 (#408)
* feat(miniapp): 增加统一服务消息 * feat(miniapp): 增加获取微信运动数据接口 * refactor(werun): 更改werun的位置 * fix(lint): 更改stuct名称 Co-authored-by: hyperq <hyperq1g@gmail>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/subscribe"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/tcb"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/werun"
|
||||
)
|
||||
|
||||
//MiniProgram 微信小程序相关API
|
||||
@@ -72,3 +73,8 @@ func (miniProgram *MiniProgram) GetSubscribe() *subscribe.Subscribe {
|
||||
func (miniProgram *MiniProgram) GetCustomerMessage() *message.Manager {
|
||||
return message.NewCustomerMessageManager(miniProgram.ctx)
|
||||
}
|
||||
|
||||
// GetWeRun 微信运动接口
|
||||
func (miniProgram *MiniProgram) GetWeRun() *werun.WeRun {
|
||||
return werun.NewWeRun(miniProgram.ctx)
|
||||
}
|
||||
|
||||
40
miniprogram/werun/werun.go
Normal file
40
miniprogram/werun/werun.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package werun
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/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
|
||||
}
|
||||
Reference in New Issue
Block a user