1.需求:本公司作为C方,需要把A平台的数据通过定时任务脚本导入到B平台;
2.需求分析:
(1)怎么获取A平台的数据?
(2)怎么把从A平台的数据导入到B平台?
3.需求实施:
(1)通过postman采用get方式调试A平台的开放接口,可以成功返回数据;
(2)在php脚本,通过下载Snoopy.class.php拓展类并引入,以get方式请求接口,可以成功返回数据。
4.具体运用:
require_once "Snoopy.class.php";//引用类
$snoopy_class = new Snoopy;//实例化
$url = "https://***.com/supplier/v1/orders/toBeSent //请求的链接
$snoopy_class->rawheaders["Authorization"] = "Bearer lzGYlRUF9PrJcKKZA%2BwAvN%2F00M";//设置token
$snoopy_class->fetch($url); //获取链接的返回内容
$dingdanStr = $snoopy_class->results;//显示结果,结果是字符串
$dingdanArr = json_decode($dingdanStr, true, 512, JSON_BIGINT_AS_STRING);//格式化返回结果
至此