web2app

Interface documentation

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

Request header

parameter nameRequiredtypeExample
timestempyesintRequest timestamp
content-Typeyesstringapplication/json

Request parameters

parameter nameRequiredtypedirections
app_keyyesstringThe appkey obtained from the merchant backend
secret_stryesstringCiphertext encrypted with necessary parameters

Necessary parameter description

parameter nameRequiredtypedirections
titleyesstringMessage title, length range 2~50
bodyyesstringMessage body, length range 2~1000
iconnostringThe icon displayed when pushing is not transmitted to display the icon configured in the app (must https)
timeyesintPush 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_idyesstringWhich app to push message to?
channel_idno[]stringSpecify those channels to push messages to. By default, push messages to all channels (if uuids are not specified)
urlnostringThe landing URL for push jump, which is configured in the app by default (must be https)
uuidsno[]stringSpecify 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

returntypeRequireddirections
codeintyes0.Successful operation 1.Parameter error -1.business failure
msgstringyesreturn message
dataobjectyesreturn data
data.pushIdstringyesTask 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

Request header

parameter nameRequiredtypeExample
timestempyesintRequest timestamp
content-Typeyesstringapplication/json

Request parameters

parameter nameRequiredtypeExample
app_keyyesstringThe appkey obtained from the merchant backend
secret_stryesstringCiphertext encrypted with necessary parameters

Necessary parameter description

parameter nameRequiredtypeExample
push_task_idyesstringMessage 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

returntypeRequireddirections
codeintyes0.Successful operation 1.Parameter error -1.business failure
msgstringyesreturn message
dataobjectyesreturn data
data.push_task_idstringyespush_id
push_statintyes1 To be pushed 2 Pushing 3 Pushed successfully. 4 Push failed 100 unknown error
push_err_msgstringnoerr msg
fail_push_numintyesfail push num
Previous
Privacy Policy