一号店网盟API的使用

By | 2017年4月6日

一号店的网盟推广都没怎么关注,近日发现网盟后台开通了在线申请功能,地址:http://union.yhd.com/resourceCenter/apiPopularize.do

申请成功后,显示如下:

如果只是查询商品的佣金信息,那么现在就可以开始了,不需要像京东联盟一样获取Token。

这是接口的详情页面:查询单品接口商品信息接口

当然也提供了SDK下载:http://open.yhd.com/doc2/apiSdkDown.do,这里依然使用的是PHP的SDK文件。

下载后,即可开始使用:

<?php
header("Content-type: application/json");

include "api/YhdClient.php";
include 'api/request/unionAPI/UnionSingleProductGetRequest.php';

define("APPKEY","1022xxxxxxxxxxxxx");
define("APPSECRET","91bcfxxxxxxxxxxx");
define("TRACKERU","1066547923");

$url = @$_GET["url"];

$url = str_replace("http://item.yhd.com/item/","",$url);
$id = explode("?",$url)[0];

$c = new YhdClient;
$c->appkey = APPKEY;
$c->secretKey = APPSECRET;
$c->format = "json";

$req = new UnionSingleProductGetRequest;
$req->setTrackerU(TRACKERU);
$req->setPmInfoId($id);
$resp = $c->execute($req);

if($resp->total_results > 0){
	$productObj = $resp->single_product_info_outer_list->single_product_info_outer[0];
	$result = json_encode($productObj,JSON_UNESCAPED_UNICODE);
	echo $result;
}else{
	echo "";
}

这里使用的是一号店详情页面URL上的ID,对应参数:pmInfoId。

结果会输出JSON,如下:

{"product_id":24381023,"product_name":"Anchor 安佳 超高温灭菌全脂牛奶 250ml*24 新西兰原装进口(整箱装)","product_url_for_phone":"https:\/\/click.yhd.com\/?ut=1066547923&s=NzZiMGI5MGY1MzI3NTdjOGYzMmZlMDFlMzk2NTU5YjdjZTQ1NzgxNmRlMWM4NDhmMTJmNzUwY2RkN2ExNmE0NmMzNDVhNWVkNjc5YWQ3ZTgxMmE0MzYwOGMwMzhjY2VmNjI0OGFkZGMyMjUwZGRmMjkwYzhiM2Y2NTVmMDc2NTQ%3D&cv=1","product_url":"https:\/\/click.yhd.com\/?ut=1066547923&s=ODFiMTQ3M2JjZjAxYjNjOWY5MWFmODYxZDQyOTg5NWVmYjhhZDAxYjRkNTVhODAxMmViZDkwMDQzMGQ1M2MxMjQxNzkwZWRhNWVlZjRlZjc0OWQyOTE5MmQ4NzIxNGMwNTQyZTY0MGZhYjViODExMjdiNDE5NDYzZWY1MzM5YWU%3D&cv=1","site_type":1,"yhd_price":89,"market_price":199,"discount":4.5,"commission_rate":0.045,"commission":4.005,"prod_quality_score":-1,"product_pic_url":"http:\/\/d9.yihaodianimg.com\/N08\/M08\/2C\/77\/ChEi1VgXB3KAb6TXAAPiEn_50lQ73801.jpg","pm_info_id":28629306}

格式化后:

{
  "product_id": 24381023,
  "product_name": "Anchor 安佳 超高温灭菌全脂牛奶 250ml*24 新西兰原装进口(整箱装)",
  "product_url_for_phone": "https://click.yhd.com/?ut=1066547923&s=NzZiMGI5MGY1MzI3NTdjOGYzMmZlMDFlMzk2NTU5YjdjZTQ1NzgxNmRlMWM4NDhmMTJmNzUwY2RkN2ExNmE0NmMzNDVhNWVkNjc5YWQ3ZTgxMmE0MzYwOGMwMzhjY2VmNjI0OGFkZGMyMjUwZGRmMjkwYzhiM2Y2NTVmMDc2NTQ%3D&cv=1",
  "product_url": "https://click.yhd.com/?ut=1066547923&s=ODFiMTQ3M2JjZjAxYjNjOWY5MWFmODYxZDQyOTg5NWVmYjhhZDAxYjRkNTVhODAxMmViZDkwMDQzMGQ1M2MxMjQxNzkwZWRhNWVlZjRlZjc0OWQyOTE5MmQ4NzIxNGMwNTQyZTY0MGZhYjViODExMjdiNDE5NDYzZWY1MzM5YWU%3D&cv=1",
  "site_type": 1,
  "yhd_price": 89,
  "market_price": 199,
  "discount": 4.5,
  "commission_rate": 0.045,
  "commission": 4.005,
  "prod_quality_score": -1,
  "product_pic_url": "http://d9.yihaodianimg.com/N08/M08/2C/77/ChEi1VgXB3KAb6TXAAPiEn_50lQ73801.jpg",
  "pm_info_id": 28629306
}

其中commission就是佣金值,product_url就是推广链接。