72bbc7895ded853366f0c6d098d49f88e98de4b4.svn-base 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.chinacreator.videoalliance.order.action;
  2. import com.chinacreator.common.exception.BusinessException;
  3. import com.chinacreator.common.pipe.DataOutPipe;
  4. import com.chinacreator.videoalliance.common.annotation.DataOut;
  5. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  6. import com.chinacreator.videoalliance.order.bean.TransferBean;
  7. import com.chinacreator.videoalliance.order.service.TransferService;
  8. import com.chinacreator.videoalliance.order.util.JsonUtil;
  9. import com.chinacreator.videoalliance.order.util.URLUtil;
  10. import org.apache.commons.lang.StringUtils;
  11. import org.frameworkset.util.annotations.ResponseBody;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17. import java.io.InputStream;
  18. import java.net.URLDecoder;
  19. import java.net.URLEncoder;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * Create by IntelliJ IDEA.
  24. * User: EricJin
  25. * Date: 4/25/2018 10:28 AM
  26. */
  27. @Controller
  28. public class TransferAction {
  29. @Autowired
  30. private TransferService transferService;
  31. @RequestMapping("/transfer.do")
  32. @DataOut(callback = "transfer")
  33. public DataOutPipe transfer(HttpServletRequest request, HttpServletResponse response) throws Exception{
  34. DataOutPipe pipe = new DataOutPipe();
  35. String queryStr = request.getQueryString();
  36. //请求转换为Map
  37. Map<String, String> map= URLUtil.urlParamsToMap(queryStr);
  38. //得到spid cpid userid进行解码
  39. String fromSpid = map.get("spid");
  40. String fromCpid = map.get("cpid");
  41. String fromUserid = map.get("userid");
  42. String phone = "";
  43. try {
  44. //解码得到手机号
  45. phone = ConfigUtil.decrypt(URLDecoder.decode(fromUserid,"UTF-8"),fromCpid);
  46. }catch (Exception e){
  47. e.printStackTrace();
  48. throw new BusinessException("9037", "渠道产品id验证失败");
  49. }
  50. //通过数据库查询到与之匹配的spid 和cpid
  51. TransferBean bean = transferService.matchTransferInfo(fromCpid,fromSpid);
  52. if (bean == null){
  53. throw new BusinessException("9037", "渠道产品id验证失败");
  54. }
  55. String toSpid = bean.getToSpid();
  56. String toCpid = bean.getToCpid();
  57. String server = bean.getServerurl();
  58. //重新编码phone成为往供应商的 userid
  59. String toUserid = URLEncoder.encode(ConfigUtil.encrypt(phone,toCpid),"UTF-8");
  60. //替换新的spid cpid userid
  61. map.put("spid",toSpid);
  62. map.put("cpid",toCpid);
  63. map.put("userid",toUserid);
  64. //把map中内容转换为往供应商发的url 地址
  65. String url = URLUtil.mapToUrl(server, map);
  66. String res = URLUtil.get(url);
  67. Map<?,?> resMap = JsonUtil.jsonToMap(res);
  68. //把返回数据封装到DataOutPipe
  69. for(Map.Entry<?,?> entry: resMap.entrySet()){
  70. Object key = entry.getKey();
  71. Object val = entry.getValue();
  72. if (key.toString().equals("errorinfo")) {
  73. pipe.setErrorInfo(val.toString());
  74. } else if (key.toString().equals("resultcode")) {
  75. pipe.setResultCode(val.toString());
  76. } else {
  77. pipe.add(key.toString(), val);
  78. }
  79. }
  80. return pipe;
  81. }
  82. }