order_client.go
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package socialwork_sdk
import (
"encoding/json"
"gitlab.workai.com.cn/chenang/socialwork-sdk/common"
"log"
)
type OrderClient struct {
Key string `json:"key"`
IV string `json:"iv"`
PublicKey string `json:"public_key"`
CustomerPrivateKey string `json:"customer_private_key"`
}
func NewOrderClient(key, iv, customerPrivateKey, publicKey string) *OrderClient {
return &OrderClient{
Key: key,
IV: iv,
PublicKey: publicKey,
CustomerPrivateKey: customerPrivateKey,
}
}
func (o *OrderClient) EncryptAndSign(res interface{}) (string, string, error) {
bs, _ := json.Marshal(res)
cipherText, err := common.Aes_CBC_Encrypt(bs, []byte(o.Key), []byte(o.IV))
if err != nil {
log.Printf("Aes_CBC_Encrypt.failed.err=%v\n", err)
return "", "", err
}
sign, err := common.RsaSignWithMd5Hex(cipherText, o.CustomerPrivateKey)
if err != nil {
log.Printf("RsaSignWithMd5Hex.failed.err=%v\n", err)
return "", "", err
}
return cipherText, sign, nil
}
func (o *OrderClient) PrintVersion() string {
return "1.0"
}