package com.taoke.autopay.utils.order;
|
|
import com.taoke.autopay.entity.OrderChannelEnum;
|
import com.taoke.autopay.utils.HttpUtil;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.io.UnsupportedEncodingException;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.net.URLEncoder;
|
import java.nio.charset.StandardCharsets;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Map;
|
import java.util.Set;
|
|
/**
|
* @author hxh
|
* @title: OrderChannelApiUtil
|
* @description:
|
* @date 2024/9/14 17:07
|
*/
|
public class OrderChannelApiUtil {
|
|
private static Logger logger = LoggerFactory.getLogger("dyorderApiLogger");
|
|
/**
|
* @return boolean
|
* @author hxh
|
* @description 获取渠道商家是否可以付款
|
* @date 17:10 2024/9/14
|
* @param: channel
|
* @param: orderChannelName
|
**/
|
public static boolean isMerchantCanPay(OrderChannelEnum channel, String merchant, BigDecimal payMoney) throws UnsupportedEncodingException {
|
if (channel == OrderChannelEnum.cyx) {
|
String url = String.format("https://api.youihuo.com/open/free.checkKsCompanyName?bsName=%s&apiKey=%s", URLEncoder.encode(merchant, "UTF-8"), OrderChannelUtil.CYX_API_KEY);
|
String result = HttpUtil.get(url);
|
logger.info(String.format("超佣享商家付款判断:%s-%s-%s", merchant, result, payMoney!=null?payMoney.setScale(2,RoundingMode.HALF_UP).toString():null));
|
JSONObject root = JSONObject.fromObject(result);
|
System.out.println(result);
|
if (root.optInt("code") == 1000) {
|
return true;
|
}
|
} else if (channel == OrderChannelEnum.bps) {
|
String url = String.format("https://api.bpshe.com/mall/douyinOMS/getSubsidyOrderInfo?appKey=cdaef330f1324961a73e15a85ab67fd2&payAccount=%s", URLEncoder.encode(merchant, StandardCharsets.UTF_8.displayName()));
|
Map<String, String> headers = new HashMap<>();
|
headers.put("Accept", "application/json;charset=utf-8");
|
String result = HttpUtil.get(url, headers);
|
logger.info(String.format("爆品社商家付款判断:%s-%s-%s", merchant, result, payMoney!=null?payMoney.setScale(2,RoundingMode.HALF_UP).toString():null));
|
JSONObject root = JSONObject.fromObject(result);
|
if (root.optInt("errCode") == 0) {
|
JSONArray array = root.optJSONObject("data").optJSONArray("payAmounts");
|
if (array != null) {
|
if (payMoney == null) {
|
return true;
|
}
|
Set<String> moneys = new HashSet<>();
|
for (int i = 0; i < array.size(); i++) {
|
moneys.add(array.optString(i));
|
}
|
return moneys.contains(payMoney.setScale(2, RoundingMode.HALF_UP).toString());
|
}
|
}
|
}
|
return false;
|
}
|
|
public static void main(String[] args) throws UnsupportedEncodingException {
|
|
|
}
|
|
|
}
|