fix: Token management update and SMS message type change
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -35,7 +36,7 @@ func (e *eskizSMSService) Request(payload any, path string, isAuth bool, retry b
|
|||||||
req, err := http.NewRequest("POST", e.BaseURL+path, &buf)
|
req, err := http.NewRequest("POST", e.BaseURL+path, &buf)
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
if isAuth {
|
if isAuth {
|
||||||
req.Header.Add("Authorization", "Bearer "+e.GetToken(true))
|
req.Header.Add("Authorization", "Bearer "+e.GetToken(true, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -43,24 +44,32 @@ func (e *eskizSMSService) Request(payload any, path string, isAuth bool, retry b
|
|||||||
}
|
}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if res.StatusCode == http.StatusUnauthorized && retry {
|
if res.StatusCode == http.StatusUnauthorized && retry {
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
pp.Print("Qayta urunish")
|
pp.Print("Qayta urunish")
|
||||||
e.GetToken(false)
|
e.GetToken(false, false)
|
||||||
return e.Request(payload, path, isAuth, false)
|
return e.Request(payload, path, isAuth, false)
|
||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *eskizSMSService) GetToken(cache bool) string {
|
func (e *eskizSMSService) GetToken(cache bool, retry bool) string {
|
||||||
|
email := os.Getenv("ESKIZ_USER")
|
||||||
|
password := os.Getenv("ESKIZ_PASSWORD")
|
||||||
|
|
||||||
|
if email == "" || password == "" {
|
||||||
|
log.Fatal("password or fmail not found")
|
||||||
|
}
|
||||||
|
|
||||||
token, err := redis.RDB.Get(e.Ctx, "eskiz_token").Result()
|
token, err := redis.RDB.Get(e.Ctx, "eskiz_token").Result()
|
||||||
if err == nil && cache {
|
if err == nil && cache {
|
||||||
pp.Print("Eskiz token topildi 😁")
|
pp.Print("Eskiz token topildi 😁")
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
payload := domain.EskizLogin{
|
payload := domain.EskizLogin{
|
||||||
Email: os.Getenv("ESKIZ_USER"),
|
Email: email,
|
||||||
Password: os.Getenv("ESKIZ_PASSWORD"),
|
Password: password,
|
||||||
}
|
}
|
||||||
res, err := e.Request(payload, "/auth/login", false, true)
|
res, err := e.Request(payload, "/auth/login", false, retry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pp.Print(err.Error())
|
pp.Print(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
6
test.py
6
test.py
@@ -25,9 +25,9 @@ r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
|
|||||||
|
|
||||||
# Xabar tayyorlash
|
# Xabar tayyorlash
|
||||||
message = {
|
message = {
|
||||||
'type': 'email',
|
'type': 'sms',
|
||||||
'message': "Subject: test\r\n\r\nclasscom.uz sayti va mobil ilovasiga ro'yxatdan o'tishingiz uchun tasdiqlash kodi: 1234",
|
'message': "Assalomu alaykum %w{1,5} sizni https://classcom.uz o’qituvchining virtual kаbinetida muallif sifatida tasdiqlanganingiz bilan tabriklaymiz!!!",
|
||||||
'to': ["jahongirhakimjonov@gmail.com"]
|
'to': ["+998888112309"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Xabarni JSON formatga o‘tkazib, Redis listga push qilish
|
# Xabarni JSON formatga o‘tkazib, Redis listga push qilish
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
||||||
Reference in New Issue
Block a user