-
Notifications
You must be signed in to change notification settings - Fork 0
/
onboarding-tecnico.go
135 lines (113 loc) · 2.72 KB
/
onboarding-tecnico.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
)
func cript(msg string) string {
sh := sha1.New()
sh.Write([]byte(msg))
sha1 := hex.EncodeToString(sh.Sum(nil))
return sha1
}
type User struct {
Cpf string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Gender string `json:"gender"`
Birthday string `json:"birthday"`
Location string `json:"location"`
Phone string `json:"phone"`
}
type UserParams struct {
ApiKey string `json:"platform_api_key"`
Signature string `json:"sha1_signature"`
Name string `json:"network_name"`
Encoding string `json:"encoding"`
IdType string `json:"id_type"`
User string `json:"user_data"`
}
type Event struct {
Action string `json:"action"`
}
type EventParams struct {
ApiKey string `json:"platform_api_key"`
Signature string `json:"sha1_signature"`
Name string `json:"network_name"`
Encoding string `json:"encoding"`
IdType string `json:"id_type"`
Event string `json:"event"`
}
func create_user(sha1, id string) {
url_user := "https://login.plataformasocial.com.br/users/portal/" + id + "/signup"
user := User{
Name: "teste-onboarding",
Email: "teste-onboarding@dito.com.br",
Gender: "female",
Birthday: "1995-01-18",
Location: "Manaus",
}
userJson, _ := json.Marshal(user)
params := UserParams{
ApiKey: os.Getenv("API_KEY"),
Signature: sha1,
Name: "pt",
Encoding: "base64",
IdType: "id",
User: string(userJson),
}
req, err := json.Marshal(params)
if err != nil {
fmt.Println("deu erro")
}
resp_event, err := http.Post(url_user, "application/json", bytes.NewBuffer(req))
if err != nil {
fmt.Println(err)
} else {
respp, _ := ioutil.ReadAll(resp_event.Body)
str := string(respp[:])
fmt.Println(str)
}
}
func create_event(sha1, id string) {
url_event := "http://events.plataformasocial.com.br/users/" + id
event := Event{Action: "evento-1"}
eventJson, _ := json.Marshal(event)
params := EventParams{
ApiKey: os.Getenv("API_KEY"),
Signature: sha1,
Name: "pt",
Encoding: "base64",
IdType: "id",
Event: string(eventJson),
}
req, err := json.Marshal(params)
if err != nil {
fmt.Println("deu erro")
}
resp_event, err := http.Post(url_event, "application/json", bytes.NewBuffer(req))
if err != nil {
fmt.Println(err)
} else {
respp, _ := ioutil.ReadAll(resp_event.Body)
str := string(respp[:])
fmt.Println(str)
}
}
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
sha1 := cript(os.Getenv("API_SECRET"))
id := "92256834212"
create_user(sha1, id)
create_event(sha1, id)
}