plugins/plugins/union_pay_redpack/internal/util.go

37 lines
955 B
Go

package internal
import (
"fmt"
sdkutils "gitea.cdlsxd.cn/BaseSystem/plugin/utils"
"net/http"
"plugins/union_pay_redpack/internal/po"
"plugins/union_pay_redpack/internal/utils"
"plugins/union_pay_redpack/internal/vo"
"time"
)
func headers(config *Config, req po.Req, bizMethod string) map[string][]string {
h := make(http.Header)
h.Add("Content-type", vo.ContentType)
h.Add("version", vo.Version)
h.Add("appType", vo.AppType)
h.Add("signMethod", vo.SignMethod)
h.Add("appId", config.AppId)
h.Add("bizMethod", bizMethod)
h.Add("reqId", req.GetReId())
now := time.Now()
milliseconds := now.Unix()*1000 + int64(now.Nanosecond())/1e6
h.Add("reqTs", fmt.Sprintf("%d", milliseconds))
rehash := utils.Sha(vo.Version, config.AppId, bizMethod, req.GetReId(), string(req.ToJson()))
signValue, err := utils.Sign(rehash, []byte(sdkutils.NewPrivate().Build(config.Prk)))
if err != nil {
return nil
}
h.Add("sign", signValue)
return h
}