package com.yeshi.fanli.util.vipshop;
|
|
import com.google.gson.Gson;
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.fanli.dto.vip.VIPConvertResultDTO;
|
import com.yeshi.fanli.dto.vipshop.VipShopOrderQueryModel;
|
import com.yeshi.fanli.dto.vipshop.VipShopQueryOrderResultDTO;
|
import com.yeshi.fanli.entity.vipshop.VipShopOrder;
|
import com.yeshi.fanli.service.inter.order.OrderProcessService;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.yeshi.utils.HttpUtil;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.StringUtil;
|
|
import java.lang.reflect.Type;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.UUID;
|
|
/**
|
* 订单侠
|
*/
|
public class DingDanXiaApiUtil {
|
private final static String API_KEY = "1VCQjf4ymNbNAhvhDZA7WDFgSv6mnDxN";
|
|
public static VIPConvertResultDTO convertLink(String goodsId, String tag) {
|
|
String url = "http://api.tbk.dingdanxia.com/vip/id_privilege?apikey=" + API_KEY;
|
|
url += "&id=" + goodsId;
|
if (tag != null) {
|
url += "&chanTag=" + tag;
|
}
|
String result = HttpUtil.get(url);
|
System.out.println(result);
|
JSONObject data = JSONObject.fromObject(result);
|
if (data.optInt("code") != 200) {
|
return null;
|
}
|
data = data.optJSONObject("data");
|
Gson gson = JsonUtil.getSimpleGson();
|
return gson.fromJson(data.toString(), VIPConvertResultDTO.class);
|
}
|
|
public static VIPConvertResultDTO convertLinkByUrl(String url, String tag) {
|
|
String baseUrl = "http://api.tbk.dingdanxia.com/vip/url_privilege?apikey=" + API_KEY;
|
|
baseUrl += "&url=" + URLEncoder.encode(url);
|
if (tag != null) {
|
baseUrl += "&chanTag=" + tag;
|
}
|
String result = HttpUtil.get(baseUrl);
|
System.out.println(result);
|
JSONObject data = JSONObject.fromObject(result);
|
if (data.optInt("code") != 200) {
|
return null;
|
}
|
data = data.optJSONObject("data");
|
Gson gson = JsonUtil.getSimpleGson();
|
return gson.fromJson(data.toString(), VIPConvertResultDTO.class);
|
}
|
|
public static VipShopQueryOrderResultDTO getOrderList(VipShopOrderQueryModel query) {
|
String url = "http://api.tbk.dingdanxia.com/vip/order_details2?apikey=" + API_KEY;
|
url += "&page=" + query.getPage();
|
if (query.getPageSize() != null) {
|
url += "&pageSize=" + query.getPageSize();
|
}
|
|
if (query.getOrderTimeStart() != null) {
|
url += "&orderTimeStart=" + query.getOrderTimeStart();
|
}
|
|
if (query.getOrderTimeEnd() != null) {
|
url += "&orderTimeEnd=" + query.getOrderTimeEnd();
|
}
|
|
if (query.getStatus() != null) {
|
url += "&status=" + query.getStatus();
|
}
|
|
if (query.getUpdateTimeStart() != null) {
|
url += "&updateTimeStart=" + query.getUpdateTimeStart();
|
}
|
|
if (query.getUpdateTimeEnd() != null) {
|
url += "&updateTimeEnd=" + query.getUpdateTimeEnd();
|
}
|
String result = HttpUtil.get(url);
|
System.out.println(result);
|
JSONObject data = JSONObject.fromObject(result);
|
if (data.optInt("code") != 200) {
|
return null;
|
}
|
|
int total = data.optInt("total_results");
|
JSONArray array = JSONArray.fromObject(data.optJSONArray("data"));
|
if (array == null)
|
return null;
|
Type type = new TypeToken<ArrayList<VipShopOrder>>() {
|
}.getType();
|
List<VipShopOrder> orderList = new Gson().fromJson(array.toString(), type);
|
return new VipShopQueryOrderResultDTO(orderList, total);
|
}
|
|
|
public static VipShopOrder getOrderDetail(String orderSn) {
|
VipShopOrder vipShopOrder = getOrderDetail(orderSn, null);
|
if (vipShopOrder == null) {
|
//临时使用
|
return getOrderDetail(orderSn, "B8DCE961C5DBD2F52AAEECB6F307546608445FE3");
|
}
|
return vipShopOrder;
|
}
|
|
public static VipShopOrder getOrderDetail(String orderSn, String accessToken) {
|
|
String url = "http://api.tbk.dingdanxia.com/vip/order_details?apikey=" + API_KEY;
|
url += "&orderSn=" + orderSn;
|
if (!StringUtil.isNullOrEmpty(accessToken)) {
|
url += "&access_token=" + accessToken;
|
}
|
|
String result = HttpUtil.get(url);
|
System.out.println(result);
|
JSONObject data = JSONObject.fromObject(result);
|
if (data.optInt("code") != 200) {
|
return null;
|
}
|
if (data.optJSONObject("data") != null) {
|
VipShopOrder vipShopOrder = new Gson().fromJson(data.optJSONObject("data").toString(), VipShopOrder.class);
|
return vipShopOrder;
|
}
|
return null;
|
}
|
|
|
//获取accesstoken的信息
|
public static String getAcessTokenInfo(String code, String state) {
|
String url = "http://api.tbk.dingdanxia.com/user/get_vip_access?apikey=" + API_KEY;
|
url += "&code=" + code;
|
url += "&state=" + state;
|
String result = HttpUtil.get(url);
|
return result;
|
}
|
|
public static void main(String[] args) {
|
// convertLinkByUrl("6918302458239328477", "123");
|
// convertLinkByUrl("https://t.vip.com/T7RyKKCJLj9", "437032");
|
|
//
|
// VipShopOrderQueryModel queryModel = new VipShopOrderQueryModel();
|
// queryModel.setPage(1);
|
// queryModel.setPageSize(20);
|
// queryModel.setOrderTimeEnd(System.currentTimeMillis());
|
// queryModel.setOrderTimeStart(System.currentTimeMillis() - 1000 * 60 * 60 * 48L);
|
// VipShopQueryOrderResultDTO resultDTO = getOrderList(queryModel);
|
// System.out.println(resultDTO);
|
|
// String result = getAcessTokenInfo("576a51ae7b9b4db1bbfc921cf381ac0c", "1234");
|
// System.out.println(result);
|
VipShopOrder order = getOrderDetail("23022226147872");
|
System.out.println(order);
|
}
|
|
}
|