cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cn.ksource.web.controller.wxpay;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.DateUtil;
import cn.ksource.core.util.HttpCharset;
import cn.ksource.core.util.HttpUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.web.controller.wxpay.paybean.OrderBean;
import cn.ksource.web.controller.wxpay.paybean.RequestData;
import cn.ksource.web.controller.wxpay.util.CommonUtil;
 
@Controller
@RequestMapping("/wxpay")
public class WxPayController {
 
    @RequestMapping("payIndex.html")
    public ModelAndView payIndex(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/wxpay/payIndex");
        return modelAndView;
    }
    
    
    @RequestMapping("payform.html")
    public ModelAndView payform(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/wxpay/payform");
        String body = request.getParameter("body");
        String detail = request.getParameter("detail");
        String attach = request.getParameter("attach");
        String total_fee = request.getParameter("total_fee");
        
        OrderBean orderBean = new OrderBean();
        orderBean.setBody(body);
        orderBean.setAttach(attach);
        orderBean.setDetail(detail);
        orderBean.setFee_type("CNY");
        orderBean.setGoods_tag("");
        orderBean.setLimit_pay("");
        orderBean.setOpenid("");
        orderBean.setOut_trade_no(StringUtil.getUUID());
        orderBean.setProduct_id(StringUtil.getUUID());
        orderBean.setTime_start(DateUtil.getCurrentDate14().toString());
        orderBean.setTime_expire("");
        orderBean.setTotal_fee(ConvertUtil.obj2Int(CommonUtil.getMoney(total_fee)));
        
        
        RequestData requestData = new RequestData(orderBean);
        //将要提交给API的数据对象转换成XML格式数据Post给API
        String postDataXML = CommonUtil.toXML(requestData);
        System.out.println(postDataXML);
        /*String code_url = new GetWxOrderno().getCodeUrl(WxNativeConfig.ewmInterfaceUrl, postDataXML);
        System.out.println("code_url----------------"+code_url);*/
        String result = HttpUtil.doPost(WxNativeConfig.ewmInterfaceUrl, postDataXML, HttpCharset.UTF8);
        System.out.println(result);
        
        String codeUrl = CommonUtil.codeUrl(result);
        
        
        modelAndView.addObject("codeUrl", codeUrl);
        return modelAndView;
    }
    
}