-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
264 lines (218 loc) · 5.95 KB
/
main.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package main
import (
"context"
"errors"
"log"
"os"
"path/filepath"
"strings"
"time"
"github.com/chromedp/chromedp"
"github.com/go-vgo/robotgo"
"github.com/pdcgo/common_conf/pdc_common"
"github.com/pdcgo/tokopedia_lib"
)
var baseKtp = "./ktp"
func createBaseKtp(nik string) (string, string, error) {
nikfoto := filepath.Join(baseKtp, nik+".jpg")
nikfoto, _ = filepath.Abs(nikfoto)
selfiefoto := filepath.Join(baseKtp, nik+"_2.jpg")
selfiefoto, _ = filepath.Abs(selfiefoto)
if _, err := os.Stat(nikfoto); errors.Is(err, os.ErrNotExist) {
return "", "", errors.New(nikfoto + " tidak ada")
}
if _, err := os.Stat(selfiefoto); errors.Is(err, os.ErrNotExist) {
return "", "", errors.New(selfiefoto + " selfie tidak ada")
}
return nikfoto, selfiefoto, nil
}
var ErrSessionInvalid = errors.New("session invalid")
func runVerification(akun *tokopedia_lib.Account, force bool) error {
driver, _ := tokopedia_lib.NewDriverAccount(akun.Username, akun.Pass, akun.Secret)
if force {
driver.Session.DeleteSession()
}
nikfoto, selfiefoto, err := createBaseKtp(akun.Ktp)
if err != nil {
akun.Status = err.Error()
return nil
}
done := make(chan int, 1)
errChan := make(chan error)
errNowaitChan := make(chan error)
defer close(errChan)
defer close(errNowaitChan)
return driver.Run(false, func(dctx *tokopedia_lib.DriverContext) error {
driver.SellerLogin(dctx)
submitCtx, cancel := context.WithCancel(dctx.Ctx)
defer cancel()
button1 := `//*/label[@for="pic1"]`
finish := `//*/button/div/span[contains(text(), "Upload")]`
finishTitle := `//*/div[contains(text(), "Fotomu sedang kami proses")]`
toast := `//*/div[@data-unify="Toaster"]`
toastTitle := `//*/p[@data-unify="Typography"]`
titleSeller := `//*/div[@data-testid="btnSellerAccount"]`
connectionNotEstablished := `//*/div[contains(text(), "Koneksi internet nggak stabil")]`
go func() {
driver.RLock()
defer driver.RUnlock()
Parent:
for {
select {
case <-dctx.Ctx.Done():
break Parent
default:
var pesan string
chromedp.Run(dctx.Ctx,
chromedp.WaitReady(toast, chromedp.BySearch),
chromedp.Text(toastTitle, &pesan, chromedp.BySearch),
)
if pesan != "" {
log.Println("error", pesan)
pesan = strings.ReplaceAll(pesan, "\n", "")
pesan = strings.ReplaceAll(pesan, "OK", "")
pesan = strings.ReplaceAll(pesan, "\t", "")
pesan = strings.ReplaceAll(pesan, "'", "")
// cancel()
errChan <- errors.New(pesan)
time.Sleep(time.Second * 3)
}
}
}
}()
go func() {
driver.RLock()
defer driver.RUnlock()
for {
select {
case <-submitCtx.Done():
return
default:
chromedp.Run(dctx.Ctx,
chromedp.WaitReady(finish, chromedp.BySearch),
chromedp.Click(finish, chromedp.BySearch),
)
}
}
}()
go chromedp.Run(dctx.Ctx,
chromedp.WaitReady(finishTitle, chromedp.BySearch),
chromedp.ActionFunc(func(ctx context.Context) error {
done <- 1
return nil
}),
)
go chromedp.Run(dctx.Ctx,
chromedp.WaitReady(finishTitle, chromedp.BySearch),
chromedp.ActionFunc(func(ctx context.Context) error {
done <- 1
return nil
}),
)
go chromedp.Run(dctx.Ctx,
chromedp.WaitReady(connectionNotEstablished, chromedp.BySearch),
chromedp.ActionFunc(func(ctx context.Context) error {
errNowaitChan <- ErrSessionInvalid
return nil
}),
)
isiktp := func() {
driver.RLock()
defer driver.RUnlock()
chromedp.Run(dctx.Ctx,
chromedp.WaitVisible(titleSeller, chromedp.BySearch),
chromedp.Navigate("https://mitra.tokopedia.com/kyc"),
chromedp.WaitReady(button1, chromedp.BySearch),
)
title := `//*/div[contains(text(), "Foto Bagian Depan KTP")]`
chromedp.Run(submitCtx,
chromedp.WaitReady(button1, chromedp.BySearch),
chromedp.Sleep(time.Second*4),
chromedp.Click(button1, chromedp.BySearch),
chromedp.Sleep(time.Second*2),
chromedp.ActionFunc(func(ctx context.Context) error {
robotgo.TypeStr(nikfoto)
robotgo.KeyTap("enter")
return nil
}),
chromedp.WaitReady(title, chromedp.BySearch),
chromedp.WaitReady(button1, chromedp.BySearch),
chromedp.Sleep(time.Second*4),
chromedp.Click(button1, chromedp.BySearch),
chromedp.Sleep(time.Second*2),
chromedp.ActionFunc(func(ctx context.Context) error {
robotgo.TypeStr(selfiefoto)
robotgo.KeyTap("enter")
return nil
}),
)
}
go isiktp()
// jika ktp gagal
go func() {
driver.RLock()
defer driver.RUnlock()
tick := time.NewTicker(time.Second * 2)
defer tick.Stop()
titlerr := `//*/h5[@data-unify="Typography"]`
cek := "Foto KTP gagal diproses"
retry := 5
for {
select {
case <-submitCtx.Done():
return
case <-tick.C:
title := ""
chromedp.Run(submitCtx,
chromedp.WaitVisible(titlerr, chromedp.BySearch),
chromedp.Text(titlerr, &title, chromedp.BySearch),
)
log.Println(title)
if strings.Contains(title, cek) {
go isiktp()
retry -= 1
}
if retry <= 0 {
return
}
}
}
}()
timeout := time.After(time.Minute)
select {
case <-done:
log.Println(driver.Username, "Submit Done")
akun.Status = "done"
case err := <-errNowaitChan:
log.Println(driver.Username, "error", err.Error())
akun.Status = err.Error()
if errors.Is(err, ErrSessionInvalid) {
return ErrSessionInvalid
}
case err := <-errChan:
log.Println(driver.Username, "error", err.Error())
pdc_common.ReportError(err)
akun.Status = err.Error()
time.Sleep(time.Minute)
case <-timeout:
akun.Status = "timeout 60 second"
}
return nil
})
}
func main() {
akuns, save, err := tokopedia_lib.GetVerificationAkun("akun_verification.txt")
if err != nil {
pdc_common.ReportError(err)
time.Sleep(time.Minute)
return
}
for _, akun := range akuns {
err := runVerification(akun, false)
if errors.Is(err, ErrSessionInvalid) {
runVerification(akun, true)
}
save()
}
save()
}