TrackingMore Webhooks

Webhook 推送 

Webhook URL
Learn more about   format of inbound webhooks
Version
Callback
If selecting "true", then there must return a "200" response!

什么是 Webhook?

     Webhook 就是用户通过自定义回调函数的方式来改变 Web 应用的一种行为。通过 Webhook ,您可以自定义一些行为通知到指定的 URL 去。 当请求数据完成, Webhook 会通过您设置的 URL 将对应数据响应给您。

 Webhook V2

     当查询状态有更新,且触发了你在设置中的状态更新提醒时,系统会做出一个POST请求发送到你在webhook页面自定义的回调url上。其中,POST主体包含了以下数据的JSON字符串。

     目前,我们支持HTTP和HTTPS链接来确保启用SSL链接时网站的安全性。但是请记住,此时你的终端在互联网上将是完全开放的。

     签名验证:

     为了确保消息的来源身份是 trackingmore, 你可以选择对 POST 数据的来源进行安全认证. ( 不验证, 直接解析 POST 的数据也可以 ).安全认证的方法如下:

     1. 解析出 POST 数据中的 timeStrsignature 这两个参数。

     2. 使用你的trackingmore用户邮箱(密钥)timeStr(明文) 生成签名 signature, 与 POST 数据中的 signature 进行校验 ( 签名算法: PHP:SHA256、JAVA:HmacSHA256)

PHP 示例代码:
function verify($timeStr,$useremail,$signature){
    $hash="sha256";
    $result=hash_hmac($hash,$timeStr,$useremail);
    return strcmp($result,$signature)==0?1:0;
}

     How to use:

       Step 1:你应该先在你的用户后台设置你的webhook url 和需要提醒的状态! my.trackingmore.com/webhook_setting.php

       Step 2:当我们服务器检测到你的单号更新且满足你的设置的时候,我们就会将更新后的数据推送到你设置的webhook url路径上。所以你需要预先在这个webhook url写好你自己的程序,对接收到的webhook数据进行任意操作。当我们推送过来的时候你的程序就会执行一次。

       Step 3:如何获取webhook推送过来的数据,在php中只需要$inputJSON = file_get_contents("php://input"); $inputJSON就是我们推送过来的数据。如下是我们获取数据并写入文件的例子,当然你也可以将它存入数据库。


  •   Example Code  
  • Write response data into file
    
    $handle    = fopen('test.log','a+'); 
    $inputJSON = file_get_contents("php://input");
    if(!empty($inputJSON)){
    	fwrite($handle, date("Y-m-d H:i:s").":  ".$inputJSON . "\r\n");
    	echo 200;
    }else{
    	fwrite($handle, date("Y-m-d H:i:s").": can not get webhook data!\r\n");
    }
    
  • Response  200
  • Headers
    Content-Type: application/json
    Body
    {
    "meta":{
       "code":200,
       "type":"Success",
       "message":"Success"
    },
    "data":{
    	"id":"7eabcb811fa10ab1f77d10418579a7f5",
    	"tracking_number":"LX203960974CN",
    	"carrier_code":"china-ems",
    	"status":"exception",
    	"created_at":"2016-11-09T22:21:43+08:00",
    	"updated_at":"2016-11-16T00:13:34+08:00",
    	"title":"","order_id":null,
    	"customer_name":null,
    	"customer_email":"",
    	"original_country":"China",
    	"destination_country":"Sweden",
    	"itemTimeLength":18,
    	"origin_info":{
    		"weblink":"http:\/\/www.ems.com.cn\/",
    		"phone":null,
    		"carrier_code":"china-ems",
    		"trackinfo":[
    		{
    			"Date":"2016-11-15 08:23",
    			"StatusDescription":"\u672a\u59a5\u6295",
    			"Details":"\u745e\u5178"
    		},{
    			"Date":"2016-11-14 09:34",
    			"StatusDescription":"\u5230\u8fbe\u5904\u7406\u4e2d\u5fc3,\u6765\u81ea\u4e2d\u56fd \u5e7f\u5dde",
    			"Details":"\u745e\u5178"
    		},{
    			"Date":"2016-10-31 22:45",
    			"StatusDescription":"\u6d77\u5173\u653e\u884c",
    			"Details":"\u5e7f\u5dde\u5e02"
    		},{
    			"Date":"2016-10-31 22:35",
    			"StatusDescription":"\u9001\u4ea4\u6d77\u5173",
    			"Details":"\u5e7f\u5dde\u5e02"
    		},{
    			"Date":"2016-10-29 22:04",
    			"StatusDescription":"\u5230\u8fbe\u5e7f\u5dde\u822a\u7ad9\u5904\u7406\u4e2d\u5fc3\uff08\u7ecf\u8f6c\uff09",
    			"Details":"\u5e7f\u5dde\u5e02"
    		},{
    			"Date":"2016-10-29 20:20",
    			"StatusDescription":"\u79bb\u5f00\u4e2d\u5c71\u5e02 \u53d1\u5f80\u5e7f\u5dde\u5e02",
    			"Details":"\u4e2d\u5c71\u5e02"
    		},{
    			"Date":"2016-10-29 16:24",
    			"StatusDescription":"\u4e2d\u5c71\u5e02\u90ae\u653f\u901f\u9012\u7269\u6d41\u516c\u53f8\u6052\u57fa\u901f\u9012\u90e8\u5df2\u6536\u4ef6\uff08\u63fd\u6295\u5458\u59d3\u540d\uff1a\u9ad8\u4f1f\u5065,\u8054\u7cfb\u7535\u8bdd:13631122287\uff09",
    			"Details":"\u4e2d\u5c71\u5e02"
    		}]
    	},
    	"destination_info":{
    		"weblink":"http:\/\/www.posten.se\/",
    		"phone":null,
    		"carrier_code":"sweden-posten",
    		"trackinfo":[{
    			"Date":"2016-11-15 15:04",
    			"StatusDescription":"Posten has not been able to reach the recipient for delivery before 10.00. New delivery attempt to be made no later than 18.00. The item will subsequently be treated as an ordinary letter",
    			"Details":"535031, Sweden"
    		},{
    			"Date":"2016-11-15 14:00",
    			"StatusDescription":"The shipment item could not be delivered because the recipient was not possible to reach. A notice has been given and the shipment item is delivered to a service point.",
    			"Details":"535031, Sweden"
    		},{
    			"Date":"2016-11-15 07:23",
    			"StatusDescription":"The item has arrived at the recipient\u00b4s delivery point. Express to be dispatched to the recipient, other items notified",
    			"Details":"535031, Sweden"
    		},{
    			"Date":"2016-11-14 23:32",
    			"StatusDescription":"The item has been through the post terminal",
    			"Details":"149, Sweden"
    		},{
    			"Date":"2016-11-14 09:34",
    			"StatusDescription":"The item has arrived from abroad to Posten\u00b4s international terminal for sorting",
    			"Details":"Stockholm utr"
    		}]
    	},
    	"lastEvent":"\u672a\u59a5\u6295,\u745e\u5178,2016-11-15 08:23"
    },
    "verifyInfo":{
      "timeStr":1488249109,
      "signature":"4b279021f5c041f6e3344e7a0636cc26201ab24b91adcea6d38331cb89221d45"
    }
    }
    

转变您的
今天的货件追踪

想要自动更新货件或提高交付效率?借助 TrackingMore 强大的 API,您将拥有触手可及的所有工具,以改变客户的售后旅程。