-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhoneVerification_test.go
67 lines (58 loc) · 2.15 KB
/
PhoneVerification_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package example
import (
"encoding/json"
"github.com/TencentCloud/faceid-api-crypto-golang/faceid"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
tencentcloudsdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/faceid/v20180301"
"log"
"testing"
)
func TestPhoneVerification(t *testing.T) {
var (
Algorithm = faceid.AES256CBC // 该接口仅支持 Algorithm.AES256CBC 加密算法
SecretId = "" // TODO 腾讯云密钥
SecretKey = "" // TODO 腾讯云密钥
)
// Step 1. 组装加密参数并对敏感数据加密
m := make(map[string]string)
m["Phone"] = "13800000000a"
m["Name"] = "张三"
m["IdCard"] = "340103202308176095"
reqJson, err := faceid.Encrypt(Algorithm, "", m)
if err != nil {
log.Fatalln(err)
}
log.Printf("req json:%s \n", reqJson)
// Step 2. 使用Tencent Cloud API SDK组装请求体,填充参数
credential := common.NewCredential(SecretId, SecretKey)
client, _ := tencentcloudsdk.NewClient(credential, regions.Guangzhou, profile.NewClientProfile())
request := tencentcloudsdk.NewPhoneVerificationRequest()
encryption := T{}
_ = json.Unmarshal([]byte(reqJson), &request)
_ = json.Unmarshal([]byte(reqJson), &encryption)
request.CiphertextBlob = encryption.Encryption.CiphertextBlob
request.EncryptList = encryption.Encryption.EncryptList
request.Iv = encryption.Encryption.Iv
// Step 3. 调用接口
response, err := client.PhoneVerification(request)
if err != nil {
if _, ok := err.(*errors.TencentCloudSDKError); ok {
log.Printf("An API error has returned: %s", err)
return
}
log.Fatalln(err)
}
log.Printf("%s \n", response.ToJsonString())
}
type T struct {
Encryption struct {
EncryptList []*string `json:"EncryptList"`
CiphertextBlob *string `json:"CiphertextBlob"`
Iv *string `json:"Iv"`
Algorithm *string `json:"Algorithm"`
TagList []*string `json:"TagList"`
} `json:"Encryption"`
}