package com.chinacreator.videoalliance.order.util; import com.chinacreator.common.support.util.SpringContextUtil; import com.chinacreator.common.util.URLUtil; import com.chinacreator.videoalliance.common.dao.DictionaryDao; import com.chinacreator.videoalliance.order.bean.VacOrder; import com.google.gson.Gson; import com.google.gson.GsonBuilder; /** *
Description: 调用vac工具类
*Copyright: Copyright (c) 2013
*Company: Chinacreator(长沙科创集成)
*creationTime: 2013-4-12
* @author qiuhai.fan * @version 1.0 */ public class VacUtil { /** * 调用vac接口,vac接口调用地址,由字典表配置 * @param userId 手机号码 * @param spCode sp编码 * @param productId 产品标识 * @param type 1表示包月订购,2表示退订,0:单次订购 * @return */ public static String vac(String userId,String spCode, String productId,String type) throws Exception{ return vac(userId,spCode,productId,type,null); } public static String vac(String userId,String spCode, String productId,String type, String sequence) throws Exception{ DictionaryDao dictionaryDao = SpringContextUtil.getBean(DictionaryDao.class); String vacUrl = dictionaryDao.getValue("vacUrl"); if(vacUrl.indexOf("?") == -1) { vacUrl += "?"; } else { vacUrl += "&"; } vacUrl += "usermob=" + userId; vacUrl += "&productid=" + productId; vacUrl += "&vacid=" + productId; vacUrl += "&spcode=" + spCode; vacUrl += "&ordertype=" + type; vacUrl += "&servicetype=80"; vacUrl += "&sequence=" + sequence; String resultStr = URLUtil.get(vacUrl); return resultStr; } public static VacOrder query(String userid) throws Exception { DictionaryDao dictionaryDao = SpringContextUtil.getBean(DictionaryDao.class); String url = dictionaryDao.getValue("vacQuery"); if(url.indexOf("?") == -1) { url += "?"; } else { url += "&"; } url += "userId=" + userid; String result = URLUtil.get(url); Gson gson = new GsonBuilder().serializeNulls().create(); VacOrder vacOrder = gson.fromJson(result, VacOrder.class); return vacOrder; } public static boolean exists(String userid, String productid) throws Exception { VacOrder vacOrder = query(userid); return vacOrder.getItem(productid) != null; } public static void main(String[] args) throws Exception { System.out.println(vac("18608011117", "91932", "8000612200", "0","08160935094200100006")); } }