package com.chinacreator.videoalliance.order.service; import com.alibaba.fastjson.JSONObject; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.videoalliance.common.dao.DictionaryDao; import com.chinacreator.videoalliance.order.bean.SPInfo; import com.chinacreator.videoalliance.order.dao.SPDao; import com.chinacreator.videoalliance.order.util.JsonUtil; import com.chinacreator.videoalliance.order.util.RedisCluster; import com.chinacreator.videoalliance.order.util.URLUtil; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import redis.clients.jedis.JedisCluster; import java.util.HashMap; import java.util.Map; /** * @author czw */ @Component public class CurrencyService { private static Logger logger = Logger.getLogger(CurrencyService.class); @Autowired private DictionaryDao dictionaryDao; /** * 订购 * @param userid * @param cpid * @param spid * @throws BusinessException */ public void order(String userid,String cpid,String spid,String token) throws BusinessException{ String result = ""; try{ Map map = new HashMap<>(); map.put("usermob",userid); map.put("cpid",cpid); map.put("spid",spid); map.put("token",token); map.put("ordermethod","01"); map.put("accesstype","1"); String url = ""; try { url = dictionaryDao.getValue("currencyOrderUrl"); }catch (Exception e){ String hget = RedisCluster.jedis.hget("OUTDB_CONF_COMMON_TB_DICTIONRY_INFO", "currencyOrderUrl"); JSONObject jsonObject = JSONObject.parseObject(hget); url = jsonObject.getString("VALUE"); } logger.info("调用url为:"+url+"参数为:===============================》" + JsonUtil.objectToJson(map)); result = URLUtil.postJson(url, JsonUtil.objectToJson(map)); logger.info("返回值参数为:===============================》" + result); }catch (Exception e) { throw new BusinessException("9170", "调用能力共享平台订购接口异常"); } JSONObject obj = JSONObject.parseObject(result); if(!obj.getString("resultcode").equals("0")){ throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo")); } } public static void main(String[] args) throws BusinessException { Map map = new HashMap<>(); map.put("usermob","18673197465"); map.put("cpid","tencent"); map.put("spid","1292"); map.put("token","8383d76ddd120d928dafef4921929889"); map.put("ordermethod","01"); map.put("accesstype","1"); System.out.println(JsonUtil.objectToJson(map)); String s = "{\"resultcode\":\"8005\",\"errorinfo\":\"ip不合法,\",\"time\":\"\",\"data\":null}"; JSONObject obj = JSONObject.parseObject(s); if(!obj.getString("resultcode").equals("0")){ throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo")); } } /** * 退订 * @param userid * @param cpid * @param spid * @throws BusinessException */ public void cancel(String userid,String cpid,String spid) throws BusinessException{ String result = ""; try{ Map map = new HashMap<>(); map.put("usermob",userid); map.put("cpid",cpid); map.put("spid",spid); String url = ""; try { url = dictionaryDao.getValue("currencyCancelUrl"); }catch (Exception e){ String hget = RedisCluster.jedis.hget("OUTDB_CONF_COMMON_TB_DICTIONRY_INFO", "currencyCancelUrl"); JSONObject jsonObject = JSONObject.parseObject(hget); url = jsonObject.getString("VALUE"); } logger.info("调用url为:"+url+"参数为:===============================》" + JsonUtil.objectToJson(map)); result = URLUtil.postJson(url, JsonUtil.objectToJson(map)); logger.info("返回值参数为:===============================》" + result); }catch (Exception e) { throw new BusinessException("9170", "调用九楼集约平台退订接口异常"); } JSONObject obj = JSONObject.parseObject(result); if(!obj.getString("resultcode").equals("0")){ throw new BusinessException(obj.getString("resultcode"), obj.getString("errorinfo")); } } }