八月七号(1)

在Controller中写重新支付的controller,在这个controller中用到了两个私有方法为private String alipayRequestWeb(AlipayForm alipayForm) { }和 private String alipayRequestMobile(AlipayForm alipayForm){ }

@RequestMapping(value = "replayOrder", method = RequestMethod.GET)
    public String replayAlipayOrder(Model model, AlipayForm alipayForm, HttpSession session, Device device) {
    	GoodsForm goodsForm=new GoodsForm();
    	List<GoodsForm> commodityType = goodsService.getType();
    	goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId());
    	model.addAttribute("goodsForm", goodsForm);
    	model.addAttribute("commodityType", commodityType);
    	log.info("重新支付");
    	AlipayForm result = cartService.searchAlipayHistory(alipayForm);
    	alipayForm.setOutTradeNo(result.getOutTradeNo());
    	alipayForm.setBody(result.getBody());
    	alipayForm.setPrice(result.getPrice());
    	alipayForm.setReceiveAddress(result.getReceiveAddress());
    	alipayForm.setReceiveMobile(result.getReceiveMobile());
    	alipayForm.setReceiveName(result.getReceiveName());
    	alipayForm.setReceivePhone(result.getReceivePhone());
    	alipayForm.setReceiveZip(result.getReceiveZip());
    	alipayForm.setShowUrl(result.getShowUrl());
    	alipayForm.setSubject(result.getSubject());
    	model.addAttribute("alipayForm", alipayForm);
    	CartForm cartForm = new CartForm();
    	UVO uvo = (UVO)session.getAttribute("UVO");
    	if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) {
    		return "redirect:/initGuestLogin";
    	}
    	cartForm.setGuestId(uvo.getGuestId());
    	model.addAttribute("cartList", cartService.searchCartList(cartForm));
//    	model.addAttribute("orderList", cartService.searchOrderList(cartForm));
    	if (device.isNormal()) {
	        model.addAttribute("sHtmlText", alipayRequestWeb(alipayForm));
		} else {
	        model.addAttribute("sHtmlText", alipayRequestMobile(alipayForm));
		}
		return "manager/charge/alipay";
    }
    
    private String alipayRequestWeb(AlipayForm alipayForm) {
		// 支付类型
	    String payment_type = "1";
	    // 必填,不能修改
	    // 服务器异步通知页面路径
	    String host = env.getProperty("host.web");
	    String notify_url = host + "/initReturn";
	    // 需http://格式的完整路径,不能加?id=123这类自定义参数

	    // 页面跳转同步通知页面路径
	    String return_url = host + "/initPayResult";

	    // 需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/
	    
	    // 商户订单号
	    String out_trade_no = alipayForm.getOutTradeNo();
	    // 订单名称
	    String subject = alipayForm.getSubject();
	    // 付款金额
        String total_fee = alipayForm.getPrice();

        // 订单描述
        String body = alipayForm.getBody();

        // 商品展示地址
        String show_url = alipayForm.getShowUrl();
        // 需以http://开头的完整路径,如:http://www.商户网站.com/myorder.html
        
		//防钓鱼时间戳
		String anti_phishing_key = "";
		//若要使用请调用类文件submit中的query_timestamp函数

		//客户端的IP地址
		String exter_invoke_ip = "";
		//非局域网的外网IP地址,如:221.0.0.1
        
        // 收货人姓名
        String receive_name = alipayForm.getReceiveName();
        // 收货人地址
        String receive_address = alipayForm.getReceiveAddress();
        // 收货人邮编
        String receive_zip = alipayForm.getReceiveZip();
        // 收货人电话号码
        String receive_phone = alipayForm.getReceivePhone();
        // 收货人手机号码
        String receive_mobile = alipayForm.getReceiveMobile();

        body = body + ";" + receive_name + ";" + receive_address + ";" + receive_zip + ";" + receive_phone + ";" + receive_mobile;
        
        Map<String, String> sParaTemp = new HashMap<String, String>();
        sParaTemp.put("service", "create_direct_pay_by_user");
        sParaTemp.put("partner", AlipayConfig.partner);
        sParaTemp.put("seller_email", AlipayConfig.seller_email);
        sParaTemp.put("_input_charset", AlipayConfig.input_charset);
        sParaTemp.put("payment_type", payment_type);
        sParaTemp.put("notify_url", notify_url);
        sParaTemp.put("return_url", return_url);
        sParaTemp.put("out_trade_no", out_trade_no);
        sParaTemp.put("subject", subject);
        sParaTemp.put("total_fee", total_fee);
        sParaTemp.put("body", body);
        sParaTemp.put("show_url", show_url);
        sParaTemp.put("anti_phishing_key", anti_phishing_key);
		sParaTemp.put("exter_invoke_ip", exter_invoke_ip);

        String sHtmlText = AlipaySubmit.buildRequest(sParaTemp, "get", "确认");
        return sHtmlText;
	}
    
    private String alipayRequestMobile(AlipayForm alipayForm) {
		// 支付类型
	    String payment_type = "1";
	    // 必填,不能修改
	    // 服务器异步通知页面路径
	    String host = env.getProperty("host.mobile");
	    String notify_url = host + "/initReturn";
	    // 需http://格式的完整路径,不能加?id=123这类自定义参数

	    // 页面跳转同步通知页面路径
	    String return_url = host + "/initPayResult";

	    // 需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/
	    
	    // 商户订单号
	    String out_trade_no = alipayForm.getOutTradeNo();
	    // 订单名称
	    String subject = alipayForm.getSubject();
	    // 付款金额
        String total_fee = alipayForm.getPrice();

        // 订单描述
        String body = alipayForm.getBody();

        // 商品展示地址
        String show_url = alipayForm.getShowUrl();
        // 需以http://开头的完整路径,如:http://www.商户网站.com/myorder.html
        
		//超时时间
		String it_b_pay = "";
		//选填

		//钱包token
		String extern_token = "";
		//选填
		
        // 收货人姓名
        String receive_name = alipayForm.getReceiveName();
        // 收货人地址
        String receive_address = alipayForm.getReceiveAddress();
        // 收货人邮编
        String receive_zip = alipayForm.getReceiveZip();
        // 收货人电话号码
        String receive_phone = alipayForm.getReceivePhone();
        // 收货人手机号码
        String receive_mobile = alipayForm.getReceiveMobile();

        body = body + ";" + receive_name + ";" + receive_address + ";" + receive_zip + ";" + receive_phone + ";" + receive_mobile;
        
        Map<String, String> sParaTemp = new HashMap<String, String>();
		sParaTemp.put("service", "alipay.wap.create.direct.pay.by.user");
        sParaTemp.put("partner", AlipayConfig.partner);
        sParaTemp.put("seller_id", AlipayConfig.seller_id);
        sParaTemp.put("_input_charset", AlipayConfig.input_charset);
		sParaTemp.put("payment_type", payment_type);
		sParaTemp.put("notify_url", notify_url);
		sParaTemp.put("return_url", return_url);
		sParaTemp.put("out_trade_no", out_trade_no);
		sParaTemp.put("subject", subject);
		sParaTemp.put("total_fee", total_fee);
		sParaTemp.put("show_url", show_url);
		sParaTemp.put("body", body);
		sParaTemp.put("it_b_pay", it_b_pay);
		sParaTemp.put("extern_token", extern_token);

        String sHtmlText = AlipaySubmit.buildRequest(sParaTemp, "get", "确认");
        return sHtmlText;
	}
@RequestMapping(value = "initPayResult", method = RequestMethod.GET)
	public String initPayResult(Model model, HttpSession session, ReturnForm returnForm, Device device) {
		log.info("支付宝处理完毕后返回商户网站");
		UVO uvo = (UVO)session.getAttribute("UVO");
		CartForm cartForm = new CartForm();
		if (uvo != null) {
			cartForm.setGuestId(uvo.getGuestId());
		} else {
			uvo = new UVO();
			session.setAttribute("UVO", uvo);
		}
    	
    	model.addAttribute("cartList", cartService.searchCartList(cartForm));
		if (device.isNormal()) {
			model.addAttribute("returnForm", returnForm);
			return "shop/cart/cart-3";
		} else {
			return "mobile/alipay/payResult";
		}
	}

在Service中

public AlipayForm searchAlipayHistory(AlipayForm frm) {

AlipayForm result = queryDao.executeForObject("Cart.selectAlipayHistory", frm, AlipayForm.class);

return result;

}

SQL文

<select id="selectAlipayHistory" parameterClass="cn.agriculture.web.form.AlipayForm"

resultClass="cn.agriculture.web.form.AlipayForm">

SELECT out_trade_no as outTradeNo,

subject as subject,

price as price,

body as body,

show_url as showUrl,

receive_name as receiveName,

receive_address as receiveAddress,

receive_zip as receiveZip,

receive_phone as receivePhone,

receive_mobile as receiveMobile,

guest_id as guestId,

update_time as updateTime,

update_user as updateUser

FROM alipay_history

WHERE out_trade_no = #outTradeNo#

</select>

在order页面里

<script type="text/javascript">

function openLink(outTradeNo){

alipayForm.target = "newWindow";

var win = window.open("replayOrder?outTradeNo=" + outTradeNo, "newWindow");

win.focus();

window.location.href="initGoods";

}

</script>

<input type="button" th:οnclick="${#strings.concat('openLink(''').concat(order.outTradeNo).concat(''')')}" class="button" th:value="登录支付宝重新付款" />



转载于:https://my.oschina.net/u/2411785/blog/488969

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值