VoucherService.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package net.chenlin.dp.common.openapi4j.service;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import java.util.Properties;
  5. import com.mysql.cj.util.StringUtils;
  6. import net.chenlin.dp.common.openapi4j.util.PropUtil;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import com.alibaba.fastjson.JSONObject;
  10. import net.chenlin.dp.common.openapi4j.commons.TokenManager;
  11. import net.chenlin.dp.common.openapi4j.exception.OpenAPIException;
  12. import net.chenlin.dp.common.openapi4j.model.Record;
  13. import net.chenlin.dp.common.openapi4j.platform.TradeService;
  14. import net.chenlin.dp.common.openapi4j.util.HttpUtil;
  15. /**
  16. * Copyright(c) 2015-2015 by yonyouup. All Rights Reserved 凭证
  17. *
  18. * @author yanwuyang
  19. * @version <类版本> , 2015年12月8日
  20. * @see <相关类/方法>
  21. * @since <产品/模块版本>
  22. */
  23. @SuppressWarnings("all")
  24. public class VoucherService extends BaseService {
  25. private static final long serialVersionUID = 9094957269886633171L;
  26. final static Logger logger = LoggerFactory.getLogger(VoucherService.class);
  27. public VoucherService() {
  28. this.access_token = TokenManager.getToKenId();
  29. }
  30. public VoucherService(String token) {
  31. this.access_token = token;
  32. }
  33. public JSONObject add(String jsonBody,String biz_id,String ds) throws OpenAPIException {
  34. JSONObject record;
  35. try {
  36. Properties prop = PropUtil.getProperties("/config.properties");
  37. String to_account = prop.getProperty("to_account");
  38. // String tradeId = TradeService.getTradeId();
  39. Map<String, String> paramMap = new HashMap();
  40. paramMap.put("to_account", to_account);
  41. // paramMap.put("tradeid", tradeId);
  42. paramMap.put("biz_id", biz_id);
  43. if(!StringUtils.isNullOrEmpty(ds)){
  44. paramMap.put("ds_sequence", ds);
  45. }
  46. String url = this.createURL("voucher/add", paramMap);
  47. logger.debug(url);
  48. String resultStr = HttpUtil.post(url, jsonBody);
  49. logger.debug(resultStr);
  50. JSONObject resultRecord = Record.parseObject(resultStr);
  51. Thread.sleep(3000);
  52. record = Record.parseObject(HttpUtil.get(resultRecord.getString("url")));
  53. } catch (Exception e) {
  54. throw new OpenAPIException(e.getMessage(), e);
  55. }
  56. return record;
  57. }
  58. public JSONObject addByBizId(String bizId, String jsonBody, String to_account) throws OpenAPIException {
  59. JSONObject record;
  60. try {
  61. Map<String, String> paramMap = new HashMap();
  62. paramMap.put("to_account", to_account);
  63. paramMap.put("biz_id", bizId);
  64. String url = this.createURL("voucher/add", paramMap);
  65. logger.debug(url);
  66. String resultStr = HttpUtil.post(url, jsonBody);
  67. logger.debug(resultStr);
  68. JSONObject resultRecord = Record.parseObject(resultStr);
  69. Thread.sleep(3000);
  70. record = Record.parseObject(HttpUtil.get(resultRecord.getString("url")));
  71. } catch (Exception e) {
  72. throw new OpenAPIException(e.getMessage(), e);
  73. }
  74. return record;
  75. }
  76. }