Webhook 通道对接

创建入口

1.进入智能运营平台

2.点击顶导航中的 产品配置

3.点击侧边导航的 webhook 配置

4.点击 新建 webhook 通道

HTTP 请求

Request 验证

一些场景下,客户需要验证 Webhook 请求是来自GIO而不是第三方伪造,可为 Webhook 配置一个 Secret Key,该 Secret Key 在GIO运营服务端和客户的服务器上共享。

对于配置了Secret Key的可以生成消息签名来验证消息的合法性和完整性,未配置的默认用空字符串作为Secret Key。

/**
 * java生成签名示例
 */
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.codec.digest.HmacUtils;

String sign(Map<String, String> payload, String secret) {
  ObjectMapper mapper = new ObjectMapper();
  String str = mapper.writeValueAsString(payload);
  return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secret).hmacHex(str);
}

生成的签名放置在http响应头 X-gio-signature 中,例如:

X-gio-signature:1e089260ba1bfde37f88eca8e665d8b1fb690ae763979d25dd10a831dedd52a8

可参考秘钥计算的代码:https://github.com/growingio/growing-webhook-demo

Request Body

类型

Key 配置处

值配置

值获取方式

说明

用户属性

产品配置页面

侧边栏:Webhook配置

不需要配置

从对应的用户属性中获取

自定义参数

产品配置页面

侧边栏:Webhook配置

运营活动名称

从 触点返回值中获取

Response Code

GIO 会遵循HTTP状态码,如果目标地址返回 200 代表post成功,其余的都是错误信息。

Request Header

Content-Type:application/json
X-gio-signature:xxx

Request Body

正式发送的 webhook 请求

发送速率为每秒 1000 个用户的信息

在 growingio 的页面上能配置若干模板参数,

例如:

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29"
  },
  "userAttr": [ //每个用户的属性值查出结果后和填充完的文本一起发送
    {
      "name": "user1",
      "age": "12",
      "content": "user1,12,hello"
    },
    {
      "name": "user2",
      "age": "10",
      "content": "user2,10,hello"
    }
  ],
  "timestamp": "15xxxx" //时间戳
}

如果不查询用户属性,userAttr字段为空数组:

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29",
    "content": “hello,world”
  },
  "userAttr":[]
  "timestamp": "15xxxx" //时间戳
}

测试 webhook 配置

Request Body

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29"
  },
  "userAttr": [ //每个用户的属性值查出结果后和填充完的文本一起发送
    {
      "name": "user1",
      "age": "12",
      "content": "user1,12,hello"
    }
  ],
  "timestamp": "15xxxx" //时间戳
}

如果不查询用户属性:

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29",
    “content”: "hello, world"
  },
  "userAttr":[]
  "timestamp": "15xxxx" //时间戳
}

测试 Webhook

Request Body

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29"
  },
  "userAttr": [ //每个用户的属性值查出结果后和填充完的文本一起发送
    {
      "name": "user1",
      "age": "12",
      "content": "user1,12,hello" // 测试webhook配置的场景中不填写用户属性,只填写简单文本内容
    }
  ],
  "timestamp": "15xxxx" //时间戳
}

如果不查询用户属性:

{
  "name": "webhook名称",
  "templateParam": { // 运营同学填写的模板参数值
    "campaignType": "双十一",
    "campaignDate": "2020-04-29",
    "content": "hello,world"
  },
  "userAttr":[]
  "timestamp": "15xxxx" //时间戳
}

目前webhook只支持http请求。

Last updated