2b358cec5bea33852eb05cb10db81df8c9421dfc.svn-base 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.chinacreator.videoalliance.order.util;
  2. import com.chinacreator.common.support.util.SpringContextUtil;
  3. import com.chinacreator.common.util.URLUtil;
  4. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  5. import com.chinacreator.videoalliance.order.bean.VacOrder;
  6. import com.google.gson.Gson;
  7. import com.google.gson.GsonBuilder;
  8. /**
  9. * <p>Description: 调用vac工具类</p>
  10. * <p>Copyright: Copyright (c) 2013</p>
  11. * <p>Company: Chinacreator(长沙科创集成)</p>
  12. * <p>creationTime: 2013-4-12</p>
  13. * @author qiuhai.fan
  14. * @version 1.0
  15. */
  16. public class VacUtil {
  17. /**
  18. * 调用vac接口,vac接口调用地址,由字典表配置
  19. * @param userId 手机号码
  20. * @param spCode sp编码
  21. * @param productId 产品标识
  22. * @param type 1表示包月订购,2表示退订,0:单次订购
  23. * @return
  24. */
  25. public static String vac(String userId,String spCode, String productId,String type) throws Exception{
  26. return vac(userId,spCode,productId,type,null);
  27. }
  28. public static String vac(String userId,String spCode, String productId,String type, String sequence) throws Exception{
  29. DictionaryDao dictionaryDao = SpringContextUtil.getBean(DictionaryDao.class);
  30. String vacUrl = dictionaryDao.getValue("vacUrl");
  31. if(vacUrl.indexOf("?") == -1) {
  32. vacUrl += "?";
  33. } else {
  34. vacUrl += "&";
  35. }
  36. vacUrl += "usermob=" + userId;
  37. vacUrl += "&productid=" + productId;
  38. vacUrl += "&vacid=" + productId;
  39. vacUrl += "&spcode=" + spCode;
  40. vacUrl += "&ordertype=" + type;
  41. vacUrl += "&servicetype=80";
  42. vacUrl += "&sequence=" + sequence;
  43. String resultStr = URLUtil.get(vacUrl);
  44. return resultStr;
  45. }
  46. public static VacOrder query(String userid) throws Exception {
  47. DictionaryDao dictionaryDao = SpringContextUtil.getBean(DictionaryDao.class);
  48. String url = dictionaryDao.getValue("vacQuery");
  49. if(url.indexOf("?") == -1) {
  50. url += "?";
  51. } else {
  52. url += "&";
  53. }
  54. url += "userId=" + userid;
  55. String result = URLUtil.get(url);
  56. Gson gson = new GsonBuilder().serializeNulls().create();
  57. VacOrder vacOrder = gson.fromJson(result, VacOrder.class);
  58. return vacOrder;
  59. }
  60. public static boolean exists(String userid, String productid) throws Exception {
  61. VacOrder vacOrder = query(userid);
  62. return vacOrder.getItem(productid) != null;
  63. }
  64. public static void main(String[] args) throws Exception {
  65. System.out.println(vac("18608011117", "91932", "8000612200", "0","08160935094200100006"));
  66. }
  67. }