enterprise/common/weixin/qyweixin_approve.go

97 lines
2.2 KiB
Go
Raw Normal View History

2023-08-13 21:24:54 +08:00
package weixin
import (
"encoding/json"
butil "enterprise/base/util"
"fmt"
log "github.com/sirupsen/logrus"
)
type Applyer struct {
Userid string `json:"userid"`
Partyid string `json:"partyid"`
}
type Option struct {
Key string `json:"key"`
Value []struct {
Text string `json:"text"`
Lang string `json:"lang"`
} `json:"value"`
}
type Selector struct {
Type string `json:"type"`
Options []*Option `json:"options"`
}
type ApplyValue struct {
Text string `json:"text"`
Selector *Selector `json:"selector"`
Children []interface{} `json:"children"`
Date struct {
Type string `json:"type"`
Timestamp string `json:"s_timestamp"`
} `json:"date"`
NewMoney string `json:"new_Money"`
Files []struct {
FileId string `json:"file_id"`
} `json:"files"`
}
type ApplyContent struct {
Control string `json:"control"`
Title []struct {
Text string `json:"text"`
Lang string `json:"lang"`
} `json:"title"`
Value *ApplyValue `json:"value"`
}
type ApproveDetail struct {
SpNo string `json:"sp_no"`
SpName string `json:"sp_name"`
SpStatus int `json:"sp_status"`
TemplateID string `json:"template_id"`
ApplyTime int64 `json:"apply_time"`
Applyer *Applyer `json:"applyer"`
ApplyData struct {
Contents []*ApplyContent `json:"contents"`
} `json:"apply_data"`
}
type ApproveDetailRsp struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Info *ApproveDetail `json:"info"`
}
type QyWeixinApprove struct {
QyWeixin
}
func NewQyWeixinApprove(corpId, secret, agent string) *QyWeixinApprove {
return &QyWeixinApprove{
QyWeixin: QyWeixin{
CorpId: corpId,
Secret: secret,
Agent: agent,
},
}
}
func (q *QyWeixinApprove) GetDetail(spNo string) (*ApproveDetail, error) {
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail?access_token=%s", q.GetToken())
reqParam := fmt.Sprintf(`{"sp_no":"%s"}`, spNo)
rspBody, err := butil.HttpPostJson(reqUrl, nil, []byte(reqParam))
if err != nil {
return nil, err
}
var rsp ApproveDetailRsp
if err := json.Unmarshal(rspBody, &rsp); err != nil {
log.Errorf("get body[%s] json error :%s", string(rspBody), err.Error())
return nil, err
}
return rsp.Info, nil
}