12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package com.chinacreator.videoalliance.order.action;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.pipe.DataOutPipe;
- import com.chinacreator.videoalliance.common.annotation.DataOut;
- import com.chinacreator.videoalliance.common.util.ConfigUtil;
- import com.chinacreator.videoalliance.order.bean.TransferBean;
- import com.chinacreator.videoalliance.order.service.TransferService;
- import com.chinacreator.videoalliance.order.util.JsonUtil;
- import com.chinacreator.videoalliance.order.util.URLUtil;
- import org.apache.commons.lang.StringUtils;
- import org.frameworkset.util.annotations.ResponseBody;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.InputStream;
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * Create by IntelliJ IDEA.
- * User: EricJin
- * Date: 4/25/2018 10:28 AM
- */
- @Controller
- public class TransferAction {
- @Autowired
- private TransferService transferService;
- @RequestMapping("/transfer.do")
- @DataOut(callback = "transfer")
- public DataOutPipe transfer(HttpServletRequest request, HttpServletResponse response) throws Exception{
- DataOutPipe pipe = new DataOutPipe();
- String queryStr = request.getQueryString();
- //请求转换为Map
- Map<String, String> map= URLUtil.urlParamsToMap(queryStr);
- //得到spid cpid userid进行解码
- String fromSpid = map.get("spid");
- String fromCpid = map.get("cpid");
- String fromUserid = map.get("userid");
- String phone = "";
- try {
- //解码得到手机号
- phone = ConfigUtil.decrypt(URLDecoder.decode(fromUserid,"UTF-8"),fromCpid);
- }catch (Exception e){
- e.printStackTrace();
- throw new BusinessException("9037", "渠道产品id验证失败");
- }
- //通过数据库查询到与之匹配的spid 和cpid
- TransferBean bean = transferService.matchTransferInfo(fromCpid,fromSpid);
- if (bean == null){
- throw new BusinessException("9037", "渠道产品id验证失败");
- }
- String toSpid = bean.getToSpid();
- String toCpid = bean.getToCpid();
- String server = bean.getServerurl();
- //重新编码phone成为往供应商的 userid
- String toUserid = URLEncoder.encode(ConfigUtil.encrypt(phone,toCpid),"UTF-8");
- //替换新的spid cpid userid
- map.put("spid",toSpid);
- map.put("cpid",toCpid);
- map.put("userid",toUserid);
- //把map中内容转换为往供应商发的url 地址
- String url = URLUtil.mapToUrl(server, map);
- String res = URLUtil.get(url);
- Map<?,?> resMap = JsonUtil.jsonToMap(res);
- //把返回数据封装到DataOutPipe
- for(Map.Entry<?,?> entry: resMap.entrySet()){
- Object key = entry.getKey();
- Object val = entry.getValue();
- if (key.toString().equals("errorinfo")) {
- pipe.setErrorInfo(val.toString());
- } else if (key.toString().equals("resultcode")) {
- pipe.setResultCode(val.toString());
- } else {
- pipe.add(key.toString(), val);
- }
- }
- return pipe;
- }
- }
|