go get github.com/vtoday/copyright
import (
"github.com/vtoday/copyright"
)
privateKey := "MIIEvAIBADANBgkq......jkl9aD/5k8I/Hag=="
publicKey := "MIIBIjANBgkq......IDAQAB"
opens := []copyright.OptionFunc{}
client, err := copyright.New("1001", privateKey, publicKey, false, opens...)
if err != nil {
return
}
var res map[string]interface{}
if e := client.DoRequestAndVerify("user.info", map[string]interface{}{"phone": "xxxxxx"}, &res); e != nil {
//todo error
}
fmt.Println(res)
req *http.Request := ... //TODO 获取请求request
request, err := copyright.ParseRequest(req)
if err != nil {
return
}
//校验请求
if ok, e := client.VerifyRequestSign(request); !ok {
return
}
//解密请求data
data, e := client.DecryptRequestData(request)
var param map[string]interface{}
if err := json.Unmarshal([]byte(data), ¶m); err != nil {
return
}
// do something ......