| | |
| | | |
| | | import com.taoke.autopay.entity.OrderChannelEnum; |
| | | import com.taoke.autopay.utils.HttpUtil; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | 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 |
| | |
| | | * @param: channel |
| | | * @param: orderChannelName |
| | | **/ |
| | | public static boolean isMerchantCanPay(OrderChannelEnum channel, String merchant) 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", merchant, result)); |
| | | JSONObject root = JSONObject.fromObject(result); |
| | | System.out.println(result); |
| | | if(root.optInt("code") == 1000){ |
| | | return true; |
| | | } |
| | | } |
| | | public static boolean isMerchantCanPay(OrderChannelEnum channel, String merchant, BigDecimal payMoney) throws UnsupportedEncodingException { |
| | | try { |
| | | 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 payMoneyStr = payMoney != null ? payMoney.setScale(2, RoundingMode.HALF_UP).toString() :""; |
| | | String url = String.format("https://api.bpshe.com/mall/douyinOMS/getSubsidyOrderInfo?appKey=cdaef330f1324961a73e15a85ab67fd2&payAccount=%s&amount=%s", URLEncoder.encode(merchant, StandardCharsets.UTF_8.displayName()), URLEncoder.encode(payMoneyStr, 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, payMoneyStr)); |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | }catch(Exception e){ |
| | | logger.error("商家验证错误:", e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static void main(String[] args) throws UnsupportedEncodingException { |
| | | |
| | | System.out.print( isMerchantCanPay(OrderChannelEnum.cyx,"广州市天河区长兴街安尔雅服饰商行1")); |
| | | |
| | | } |
| | | |
| | | |