使用JoinChat电商机器人的商户,可以实现自己的商品和订单查询接口,并和JoinChat的电商模板三个功能卡片集成,随后即可让用户以便捷的方式查询商品和订单信息。
JoinChat会为每一个机器人生成独一无二的私钥。JoinChat调取API时,先用此密钥对整个请求参数进行sha256、base64加密,并将签名加在请求Header的x-joinchat-signature
字段里。商户需要验证此字段来证明此请求确实来自JoinChat,并注意不要泄露自己的私钥。 商户可以随时在后台设置--API管理页面
更改自己的私钥
<?php
// API管理中秘钥
const API_SECRET = 'xxxxx';
// 伪代码, 从请求头获取签名
$src_sign = $request->header('x-joinchat-signature');
// 伪代码, 获取请求参数, 字符串格式
$input = $request->getContentRaw();
// 对请求参数进行加密生成签名并对比header里的签名
$result_sign = base64_encode(hash_hmac('sha256', $input, API_SECRET, true));
$result = hash_equals($src_sign, $result_sign);
var_dump($result);
{
"method":"products",
"params":{
"title":"T_shirt",
"product_type":"clothes",
"vendor":"JACK & JONES",
"order_type":"title,desc"
},
"pagination":{
"page":1,
"limit":3
}
}
{
"success":true,
"total" : 1, //搜索结果的数量
"data":[
{
"title":"商品name",
"image_url":"商品pic",
"product_type":"商品类型",
"vendor":"商品品牌",
"desc":"商品描述", // 可选
"detail_url":"商品详情连接", // 可选
"buy_url":"商品购买链接",
"price":"商品price",
}
]
}
{
"success": false,
"errors": "Unknow errors".
}
当商店想给顾客更多查询选择,但是考虑到顾客不知道输入什么,JoinChat将向商户的webhook发送请求参数进行查询,获取商家的商品分类和品牌,展示给客户,让客户有明确的选择。
{
"method" : "property",
"params" : {
"search_type" : "product_type|vendor", //product_type: 商品类型 vendor: 商品品牌
}
}
{
"success": true,
"data" :[
"Nike","LiNing","xxx"
]
}
{
"success": true,
"data" :[
"clothes","T_shirt","xxx"
]
}
{
"success": false,
"errors": "Unknow errors".
}
{
"method":"orders",
"params":{
"order_number":"12345678902", //订单号
"user_account":"bob.norman@hostmail.com", //邮箱或者手机号
//user_account与order_number只能发送一个
"filter":"open" // 当根据用户账户进行查询时, 可以查询未完成和已完成的订单
},
"pagination":{
"page":1,
"limit":3
}
}
"success": true,
"total" : 2,
"data" : [
{
"template_type":"receipt", // 必须为receipt
"recipient_name":"Stephane Crozatier",
"order_number":"12345678902",
"currency":"USD",
"payment_method":"Visa 2345",
"order_url":"http://petersapparel.parseapp.com/order?order_id=123456",
"timestamp":"1428444852",
"address":{
"street_1":"1 Hacker Way",
"street_2":"",
"city":"Menlo Park",
"postal_code":"94025",
"state":"CA",
"country":"US"
},
"summary":{
"subtotal":75.00,
"shipping_cost":4.95,
"total_tax":6.19,
"total_cost":56.14
},
"adjustments":[
{
"name":"New Customer Discount",
"amount":20
},
{
"name":"$10 Off Coupon",
"amount":10
}
],
"elements":[
{
"title":"Classic White T-Shirt",
"subtitle":"100% Soft and Luxurious Cotton",
"quantity":2,
"price":50,
"currency":"USD",
"image_url":"http://petersapparel.parseapp.com/img/whiteshirt.png"
},
{
"title":"Classic Gray T-Shirt",
"subtitle":"100% Soft and Luxurious Cotton",
"quantity":1,
"price":25,
"currency":"USD",
"image_url":"http://petersapparel.parseapp.com/img/grayshirt.png"
}
]
},
{
"template_type":"receipt", //必须为receipt
"recipient_name":"Stephane Crozatier",
"order_number":"12345678902",
"currency":"USD",
"payment_method":"Visa 2345",
"order_url":"http://petersapparel.parseapp.com/order?order_id=123456",
"timestamp":"1428444852",
"address":{
"street_1":"1 Hacker Way",
"street_2":"",
"city":"Menlo Park",
"postal_code":"94025",
"state":"CA",
"country":"US"
},
"summary":{
"subtotal":75.00,
"shipping_cost":4.95,
"total_tax":6.19,
"total_cost":56.14
},
"adjustments":[
{
"name":"New Customer Discount",
"amount":20
},
{
"name":"$10 Off Coupon",
"amount":10
}
],
"elements":[
{
"title":"Classic White T-Shirt",
"subtitle":"100% Soft and Luxurious Cotton",
"quantity":2,
"price":50,
"currency":"USD",
"image_url":"http://petersapparel.parseapp.com/img/whiteshirt.png"
},
{
"title":"Classic Gray T-Shirt",
"subtitle":"100% Soft and Luxurious Cotton",
"quantity":1,
"price":25,
"currency":"USD",
"image_url":"http://petersapparel.parseapp.com/img/grayshirt.png"
}
]
}]
}
{
"success": false,
"errors": "Unknow errors".
}