API for push Message
public description
If you need to send personalized push, please bind the UUID with the user ID. After binding, you can send personalized push to this user ID. How to obtain the UUID.
Parameters are encrypted using: AES CBC PKCS5Padding method
Encryption key: app_secret in merchant backend
Encryption sample code(golang)
package test
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"fmt"
"math/big"
"testing"
)
func Test_mod(t *testing.T) {
jsonStr := `
{
"title":"here is the title",
"body":"Here is the message body",
"icon":"https://icon.com/icon.png"
"time":1703482072,
"app_id":"app_id123456",
"channel_id":["channel_id-1","channel_id-2"],
"url":"https://jump.com",
"uuids":["awe123wq","sad45124"]
}
`
secret_str := AesCBCEncrypt([]byte(jsonStr), "ses5jKwnIhOLYGMuON0FhTKWCmh7doIk")
fmt.Println(s)
//secret_str This result will be used as the ciphertext passed in when calling the push API
}
func AesCBCEncrypt(text []byte, key string) string {
block, _ := aes.NewCipher([]byte(key))
blockSize := block.BlockSize()
originData := pKCS5Padding(text, blockSize)
iv := generateIV()
blockMode := cipher.NewCBCEncrypter(block, iv)
crypted := make([]byte, len(originData))
blockMode.CryptBlocks(crypted, originData)
temp := [][]byte{iv, crypted}
crypted = bytes.Join(temp, []byte{})
dst := make([]byte, base64.RawURLEncoding.EncodedLen(len(crypted)))
base64.RawURLEncoding.Encode(dst, crypted)
return string(dst)
}
func pKCS5Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
}
func generateIV() []byte {
s := []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}:|<>?")
iv := make([]byte, 16)
for i := 0; i < 16; i++ {
r, _ := rand.Int(rand.Reader, big.NewInt(12800))
iv[i] = s[int(r.Int64())%len(s)]
}
return iv
}
ReturnCode
code: 1 //Parameter error
code: 0 //Successful operation
code: -1 //business failure
1.Message push request API
https://api.w2.app/api/v1/pushMsg
Request method
POST
parameter name | Required | type | Example |
---|
timestemp | yes | int | Request timestamp |
content-Type | yes | string | application/json |
Request parameters
parameter name | Required | type | directions |
---|
app_key | yes | string | The appkey obtained from the merchant backend |
secret_str | yes | string | Ciphertext encrypted with necessary parameters |
Necessary parameter description
parameter name | Required | type | directions |
---|
title | yes | string | Message title, length range 2~50 |
body | yes | string | Message body, length range 2~1000 |
icon | no | string | The icon displayed when pushing is not transmitted to display the icon configured in the app (must https) |
time | yes | int | Push time, when it is 0, it means push immediately. If you specify a scheduled push, you can send a timestamp greater than the current time (in seconds). |
app_id | yes | string | Which app to push message to? |
channel_id | no | []string | Specify those channels to push messages to. By default, push messages to all channels (if uuids are not specified) |
url | no | string | The landing URL for push jump, which is configured in the app by default (must be https) |
uuids | no | []string | Specify user uuid push (when uuid is specified, channel conditions do not take effect) (if not passed, it means full push (channel_id is default),Supports up to 500 uuid at one time) |
Required parameter json example
{
"title":"here is the title",
"body":"Here is the message body",
"icon":"https://icon.com/icon.png",
"time":1703482072,
"app_id":"app_id123456",
"channel_id":["channel_id-1","channel_id-2"],
"url":"https://jump.com",
"uuids":["awe123wq","sad45124"]
}
return
{
"code": 0,
"msg":"success",
"data":{
"pushId":"pushTask-1552154345565"
}
}
return directions
return | type | Required | directions |
---|
code | int | yes | 0.Successful operation 1.Parameter error -1.business failure |
msg | string | yes | return message |
data | object | yes | return data |
data.pushId | string | yes | Task id, the message execution status can be asynchronously queried based on the task id |
2.Get message push result request API (asynchronous)
https://api.w2.app/api/v1/pushMsgResult
Request method
GET
parameter name | Required | type | Example |
---|
timestemp | yes | int | Request timestamp |
content-Type | yes | string | application/json |
Request parameters
parameter name | Required | type | Example |
---|
app_key | yes | string | The appkey obtained from the merchant backend |
secret_str | yes | string | Ciphertext encrypted with necessary parameters |
Necessary parameter description
parameter name | Required | type | Example |
---|
push_task_id | yes | string | Message task id |
return
{
"code": 0,
"msg":"success",
"data":{
"push_task_id":"pushTask-1552154345565",
"push_stat":2 ,
"push_err_msg":"" ,
"fail_push_num":0
}
}
return directions
return | type | Required | directions |
---|
code | int | yes | 0.Successful operation 1.Parameter error -1.business failure |
msg | string | yes | return message |
data | object | yes | return data |
data.push_task_id | string | yes | push_id |
push_stat | int | yes | 1 To be pushed 2 Pushing 3 Pushed successfully. 4 Push failed 100 unknown error |
push_err_msg | string | no | err msg |
fail_push_num | int | yes | fail push num |