941c17a17dd560326264548aaae96503b1488eda.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.chinacreator.videoalliance.order.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.chinacreator.common.exception.BusinessException;
  4. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  5. import com.chinacreator.videoalliance.order.bean.SPInfo;
  6. import com.chinacreator.videoalliance.order.dao.SPDao;
  7. import com.chinacreator.videoalliance.order.util.JsonUtil;
  8. import com.chinacreator.videoalliance.order.util.RedisCluster;
  9. import com.chinacreator.videoalliance.order.util.URLUtil;
  10. import org.apache.log4j.Logger;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Component;
  13. import redis.clients.jedis.JedisCluster;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16. /**
  17. * @author czw
  18. */
  19. @Component
  20. public class CurrencyService {
  21. private static Logger logger = Logger.getLogger(CurrencyService.class);
  22. @Autowired
  23. private DictionaryDao dictionaryDao;
  24. /**
  25. * 订购
  26. * @param userid
  27. * @param cpid
  28. * @param spid
  29. * @throws BusinessException
  30. */
  31. public void order(String userid,String cpid,String spid,String token) throws BusinessException{
  32. String result = "";
  33. try{
  34. Map<String,String> map = new HashMap<>();
  35. map.put("usermob",userid);
  36. map.put("cpid",cpid);
  37. map.put("spid",spid);
  38. map.put("token",token);
  39. map.put("ordermethod","01");
  40. map.put("accesstype","1");
  41. String url = "";
  42. try {
  43. url = dictionaryDao.getValue("currencyOrderUrl");
  44. }catch (Exception e){
  45. String hget = RedisCluster.jedis.hget("OUTDB_CONF_COMMON_TB_DICTIONRY_INFO", "currencyOrderUrl");
  46. JSONObject jsonObject = JSONObject.parseObject(hget);
  47. url = jsonObject.getString("VALUE");
  48. }
  49. logger.info("调用url为:"+url+"参数为:===============================》" + JsonUtil.objectToJson(map));
  50. result = URLUtil.postJson(url, JsonUtil.objectToJson(map));
  51. logger.info("返回值参数为:===============================》" + result);
  52. }catch (Exception e) {
  53. throw new BusinessException("9170", "调用能力共享平台订购接口异常");
  54. }
  55. JSONObject obj = JSONObject.parseObject(result);
  56. if(!obj.getString("resultcode").equals("0")){
  57. throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo"));
  58. }
  59. }
  60. public static void main(String[] args) throws BusinessException {
  61. Map<String,String> map = new HashMap<>();
  62. map.put("usermob","18673197465");
  63. map.put("cpid","tencent");
  64. map.put("spid","1292");
  65. map.put("token","8383d76ddd120d928dafef4921929889");
  66. map.put("ordermethod","01");
  67. map.put("accesstype","1");
  68. System.out.println(JsonUtil.objectToJson(map));
  69. String s = "{\"resultcode\":\"8005\",\"errorinfo\":\"ip不合法,\",\"time\":\"\",\"data\":null}";
  70. JSONObject obj = JSONObject.parseObject(s);
  71. if(!obj.getString("resultcode").equals("0")){
  72. throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo"));
  73. }
  74. }
  75. /**
  76. * 退订
  77. * @param userid
  78. * @param cpid
  79. * @param spid
  80. * @throws BusinessException
  81. */
  82. public void cancel(String userid,String cpid,String spid) throws BusinessException{
  83. String result = "";
  84. try{
  85. Map<String,String> map = new HashMap<>();
  86. map.put("usermob",userid);
  87. map.put("cpid",cpid);
  88. map.put("spid",spid);
  89. String url = "";
  90. try {
  91. url = dictionaryDao.getValue("currencyCancelUrl");
  92. }catch (Exception e){
  93. String hget = RedisCluster.jedis.hget("OUTDB_CONF_COMMON_TB_DICTIONRY_INFO", "currencyCancelUrl");
  94. JSONObject jsonObject = JSONObject.parseObject(hget);
  95. url = jsonObject.getString("VALUE");
  96. }
  97. logger.info("调用url为:"+url+"参数为:===============================》" + JsonUtil.objectToJson(map));
  98. result = URLUtil.postJson(url, JsonUtil.objectToJson(map));
  99. logger.info("返回值参数为:===============================》" + result);
  100. }catch (Exception e) {
  101. throw new BusinessException("9170", "调用九楼集约平台退订接口异常");
  102. }
  103. JSONObject obj = JSONObject.parseObject(result);
  104. if(!obj.getString("resultcode").equals("0")){
  105. throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo"));
  106. }
  107. }
  108. }