| | |
| | | package com.taoke.autopay.utils.order; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.taoke.autopay.dto.DYOrderDto; |
| | | import com.taoke.autopay.dto.DYSkuOrderDto; |
| | | import com.taoke.autopay.dto.DYSubsidyDto; |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.utils.Constant; |
| | | import com.taoke.autopay.utils.HttpUtil; |
| | | import com.taoke.autopay.utils.JsonUtil; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author hxh |
| | |
| | | public class DYOrderApi { |
| | | private static Logger logger = LoggerFactory.getLogger("dyorderApiLogger"); |
| | | |
| | | private static Gson gson=JsonUtil.getSimpleGson(); |
| | | |
| | | private static String requestByOrderNo1(String orderNo) { |
| | | String url = String.format("https://api.youihuo.com/open/order.getFreeOrder?apiKey=sTIFFTyunIFZfp5i4V6g19PN9biudl4v&orderId=%s", orderNo); |
| | | String result = HttpUtil.get(url); |
| | | System.out.println(result); |
| | | return result; |
| | | } |
| | | |
| | | public static DYOrderDto getOrderDetail(String orderNo) throws KeyOrderException { |
| | | private static String requestByOrderNo2(String orderNo) { |
| | | String url = String.format("https://api.bpshe.com/mall/douyinOMS/getSubsidyOrderInfo?appKey=cdaef330f1324961a73e15a85ab67fd2&orderId=%s", orderNo); |
| | | Map<String,String> headers=new HashMap<>(); |
| | | headers.put("Accept","application/json;charset=utf-8"); |
| | | String result = HttpUtil.get(url, headers); |
| | | return result; |
| | | } |
| | | |
| | | private static DYOrderDto getOrderDetail1(String orderNo) throws KeyOrderException { |
| | | String result = requestByOrderNo1(orderNo); |
| | | System.out.println(result); |
| | | JSONObject root = JSONObject.fromObject(result); |
| | | if (root.optInt("code") != 1000) { |
| | | logger.error(String.format("抖音订单查询出错:%s - %s",orderNo, result)); |
| | | throw new KeyOrderException(root.optString("message")); |
| | | try { |
| | | JSONObject root = JSONObject.fromObject(result); |
| | | if (root.optInt("code") != 1000) { |
| | | logger.error(String.format("抖音订单查询出错(超享佣):%s - %s", orderNo, result)); |
| | | throw new KeyOrderException(root.optString("message")); |
| | | } |
| | | JSONObject data = root.optJSONObject("data"); |
| | | DYOrderDto dto = JsonUtil.getSimpleGson().fromJson(data.toString(), DYOrderDto.class); |
| | | dto.setOrderChannel(Constant.ORDER_CHANNEL_CYX); |
| | | return dto; |
| | | }catch(Exception e){ |
| | | throw new KeyOrderException(e.getMessage()); |
| | | } |
| | | JSONObject data = root.optJSONObject("data"); |
| | | return JsonUtil.getSimpleGson().fromJson(data.toString(),DYOrderDto.class); |
| | | } |
| | | |
| | | private static DYOrderDto getOrderDetail2(String orderNo) throws KeyOrderException { |
| | | String result = requestByOrderNo2(orderNo); |
| | | logger.info(String.format("爆品社接口%s:%s", orderNo, result)); |
| | | System.out.println(result); |
| | | JSONObject data = null; |
| | | try { |
| | | JSONObject root = JSONObject.fromObject(result); |
| | | if (root.optInt("errCode") != 0) { |
| | | logger.error(String.format("抖音订单查询出错(爆品社):%s - %s", orderNo, result)); |
| | | throw new KeyOrderException(root.optString("errMsg")); |
| | | } |
| | | data = root.optJSONObject("data"); |
| | | }catch(Exception e){ |
| | | |
| | | } |
| | | if(data==null){ |
| | | logger.error(String.format("抖音订单查询无数据(2):%s - %s",orderNo, result)); |
| | | throw new KeyOrderException("订单查询无数据"); |
| | | } |
| | | if(!data.optBoolean("subsidyFullyCoversOrder")){ |
| | | throw new KeyOrderException("不满足支付条件"); |
| | | } |
| | | |
| | | |
| | | JSONObject orderDetailData = data.optJSONObject("orderDetail"); |
| | | |
| | | if(orderDetailData==null){ |
| | | logger.error(String.format("订单无数据(2):%s - %s",orderNo, result)); |
| | | throw new KeyOrderException("订单无数据"); |
| | | } |
| | | orderDetailData = orderDetailData.optJSONObject("shop_order_detail"); |
| | | DYOrderDto dyOrder = gson.fromJson(orderDetailData.toString(),DYOrderDto.class); |
| | | dyOrder.setOrderChannel(Constant.ORDER_CHANNEL_BPS); |
| | | return dyOrder; |
| | | } |
| | | |
| | | |
| | | public static DYOrderDto getOrderDetail(String orderNo) throws KeyOrderException { |
| | | DYOrderDto dto=null; |
| | | List<KeyOrderException> exceptions=new ArrayList<>(); |
| | | try { |
| | | dto = getOrderDetail1(orderNo); |
| | | }catch(KeyOrderException e){ |
| | | exceptions.add(e); |
| | | } |
| | | if(dto==null){ |
| | | try { |
| | | dto = getOrderDetail2(orderNo); |
| | | }catch(KeyOrderException e){ |
| | | exceptions.add(e); |
| | | } |
| | | } |
| | | |
| | | if(dto!=null){ |
| | | return dto; |
| | | } |
| | | String exception=""; |
| | | for(KeyOrderException e:exceptions){ |
| | | exception+=e.getMessage()+";"; |
| | | } |
| | | throw new KeyOrderException(exception); |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | DYOrderDto dto = (DYOrderApi.getOrderDetail("6931373743528482165")); |
| | | System.out.println("123123"); |
| | | // DYOrderDto dto = (DYOrderApi.getOrderDetail("6932591080266339994")); |
| | | // DYOrderDto result = getOrderDetail("6933551928932504940"); |
| | | // System.out.println(result); |
| | | System.out.println(getOrderDetail("6934328696568616274")); |
| | | } |
| | | |
| | | } |