package net.chenlin.dp.common.openapi4j.service; import java.util.HashMap; import java.util.Map; import java.util.Properties; import com.mysql.cj.util.StringUtils; import net.chenlin.dp.common.openapi4j.util.PropUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.fastjson.JSONObject; import net.chenlin.dp.common.openapi4j.commons.TokenManager; import net.chenlin.dp.common.openapi4j.exception.OpenAPIException; import net.chenlin.dp.common.openapi4j.model.Record; import net.chenlin.dp.common.openapi4j.platform.TradeService; import net.chenlin.dp.common.openapi4j.util.HttpUtil; /** * Copyright(c) 2015-2015 by yonyouup. All Rights Reserved 凭证 * * @author yanwuyang * @version <类版本> , 2015年12月8日 * @see <相关类/方法> * @since <产品/模块版本> */ @SuppressWarnings("all") public class VoucherService extends BaseService { private static final long serialVersionUID = 9094957269886633171L; final static Logger logger = LoggerFactory.getLogger(VoucherService.class); public VoucherService() { this.access_token = TokenManager.getToKenId(); } public VoucherService(String token) { this.access_token = token; } public JSONObject add(String jsonBody,String biz_id,String ds) throws OpenAPIException { JSONObject record; try { Properties prop = PropUtil.getProperties("/config.properties"); String to_account = prop.getProperty("to_account"); // String tradeId = TradeService.getTradeId(); Map paramMap = new HashMap(); paramMap.put("to_account", to_account); // paramMap.put("tradeid", tradeId); paramMap.put("biz_id", biz_id); if(!StringUtils.isNullOrEmpty(ds)){ paramMap.put("ds_sequence", ds); } String url = this.createURL("voucher/add", paramMap); logger.debug(url); String resultStr = HttpUtil.post(url, jsonBody); logger.debug(resultStr); JSONObject resultRecord = Record.parseObject(resultStr); Thread.sleep(3000); record = Record.parseObject(HttpUtil.get(resultRecord.getString("url"))); } catch (Exception e) { throw new OpenAPIException(e.getMessage(), e); } return record; } public JSONObject addByBizId(String bizId, String jsonBody, String to_account) throws OpenAPIException { JSONObject record; try { Map paramMap = new HashMap(); paramMap.put("to_account", to_account); paramMap.put("biz_id", bizId); String url = this.createURL("voucher/add", paramMap); logger.debug(url); String resultStr = HttpUtil.post(url, jsonBody); logger.debug(resultStr); JSONObject resultRecord = Record.parseObject(resultStr); Thread.sleep(3000); record = Record.parseObject(HttpUtil.get(resultRecord.getString("url"))); } catch (Exception e) { throw new OpenAPIException(e.getMessage(), e); } return record; } }