途游notification
This commit is contained in:
parent
324ec44b1f
commit
4a0788729a
@ -6,11 +6,14 @@ import (
|
||||
"crypto/cipher"
|
||||
"crypto/md5"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/gob"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -319,6 +322,11 @@ func Rand6DigitNumber() string {
|
||||
return fmt.Sprintf("%06d", n)
|
||||
}
|
||||
|
||||
func Rand8DigitNumber() string {
|
||||
n := rand.Intn(100000000)
|
||||
return fmt.Sprintf("%08d", n)
|
||||
}
|
||||
|
||||
func UniqueInts(input []int) []int {
|
||||
seen := make(map[int]struct{})
|
||||
result := make([]int, 0, len(input))
|
||||
@ -545,3 +553,71 @@ func GetISOCodeByIP(ip string) (string, error) {
|
||||
func GetVarKey(Uid int) string {
|
||||
return fmt.Sprintf("var_%d", Uid)
|
||||
}
|
||||
|
||||
const (
|
||||
PROJECT_ID = "20659"
|
||||
ACCESS_ID = "a3d8c1f0e5b72a49"
|
||||
NOTIFICATION_SECRET_KEY = "K8pYrR6fXcVzWbAqN3mHsD4gJtL9iUvO1"
|
||||
)
|
||||
|
||||
func NotifyPlayer(uid, pushid int, title, content string) {
|
||||
|
||||
url := "https://tygapi-new.tuyooglobal.com/api/push/ga/push_message/project_trigger"
|
||||
method := "POST"
|
||||
executeId := fmt.Sprintf("%s_%s", PROJECT_ID, Rand8DigitNumber()+Rand8DigitNumber())
|
||||
payload := strings.NewReader(`[
|
||||
{
|
||||
"projectId": "` + PROJECT_ID + `",
|
||||
"platform": "auto",
|
||||
"pushId": "` + PROJECT_ID + `_` + fmt.Sprintf("%08d", pushid) + `",
|
||||
"executeId": "` + executeId + `",
|
||||
"environment": "production",
|
||||
"title": "` + title + `",
|
||||
"body": "` + content + `",
|
||||
"userId": [
|
||||
"` + strconv.Itoa(uid) + `"
|
||||
]
|
||||
}
|
||||
]`)
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(method, url, payload)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
d, _ := time.ParseDuration("30m")
|
||||
timestamp := time.Now().Add(d).Unix()
|
||||
|
||||
var strBuilder strings.Builder
|
||||
strBuilder.WriteString("Access-Id=" + ACCESS_ID + "&Random=a2dS8Iyak03Ma91JC1xR&Secret-Type=forever&Sign-Type=sha256&Timestamp=")
|
||||
strBuilder.WriteString(strconv.Itoa(int(timestamp)))
|
||||
strBuilder.WriteString(":" + NOTIFICATION_SECRET_KEY)
|
||||
|
||||
m := sha256.New()
|
||||
m.Write([]byte(strBuilder.String()))
|
||||
signature := hex.EncodeToString(m.Sum(nil))
|
||||
|
||||
req.Header.Add("Access-Id", ACCESS_ID)
|
||||
req.Header.Add("Secret-Type", "forever")
|
||||
req.Header.Add("Sign-Type", "sha256")
|
||||
req.Header.Add("Random", "a2dS8Iyak03Ma91JC1xR")
|
||||
req.Header.Add("Timestamp", strconv.Itoa(int(timestamp)))
|
||||
req.Header.Add("Signature", signature)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
fmt.Print(req)
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
decorateCfg "server/conf/decorate"
|
||||
"server/db"
|
||||
"server/game"
|
||||
GoUtil "server/game_util"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
"testing"
|
||||
)
|
||||
@ -94,3 +95,7 @@ func TestEndless(t *testing.T) {
|
||||
EndlessMod := p1.GetEndlessMod()
|
||||
EndlessMod.ZeroUpdate(ChargeMod.GetMaxCharge(), BaseMod.GetLevel())
|
||||
}
|
||||
|
||||
func TestNotify(t *testing.T) {
|
||||
GoUtil.NotifyPlayer(3625212, 1, "Test Notification", "This is a test notification from the server.")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user