37 lines
939 B
Go
37 lines
939 B
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
sdkutils "gitea.cdlsxd.cn/sdk/plugin/utils"
|
|
"net/http"
|
|
"plugins/union_pay_redpack/internal/po"
|
|
"plugins/union_pay_redpack/internal/vo"
|
|
"plugins/utils/union_pay"
|
|
"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 := union_pay.Sha(vo.Version, config.AppId, bizMethod, req.GetReId(), string(req.ToJson()))
|
|
signValue, err := union_pay.Sign(rehash, []byte(sdkutils.NewPrivate().Build(config.Prk)))
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
h.Add("sign", signValue)
|
|
return h
|
|
}
|