在Controller中寫從新支付的controller,在這個controller中用到了兩個私有方法爲private String alipayRequestWeb(AlipayForm alipayForm) { }和 private String alipayRequestMobile(AlipayForm alipayForm){ }javascript
@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中html
public AlipayForm searchAlipayHistory(AlipayForm frm) {java
AlipayForm result = queryDao.executeForObject("Cart.selectAlipayHistory", frm, AlipayForm.class);web
return result;服務器
}session
SQL文app
<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:onclick="${#strings.concat('openLink(''').concat(order.outTradeNo).concat(''')')}" class="button" th:value="登陸支付寶從新付款" />