Action
public class OrderAction extends ActionSupport implements ModelDriven<Order> { //模型驱动要使用的对象 private Order order=new Order(); //注入OrderService private OrderService orderService; //接收支付通道编码 private String pd_FrpId; //接收付款成功后的响应数据 private String r6_Order; private String r3_Amt;
//set public Order getModel() { // TODO Auto-generated method stub return order; } //为订单付款的方法payOrder public String payOrder() throws IOException{ //修改订单 Order currOrder=orderService.findByOid(order.getOid()); currOrder.setAddr(order.getAddr()); currOrder.setName(order.getName()); currOrder.setPhone(order.getPhone()); orderService.update(order); //为订单付款 String p0_Cmd = "Buy"; //业务类型 String p1_MerId = "10001126856"; //商户编号 String p2_Order = order.getOid().toString(); //订单编号 String p3_Amt = "0.01"; //支付金额 String p4_Cur = "CNY"; //交易币种 String p5_Pid =""; //商品名称 String p6_Pcat =""; //商品种类 String p7_Pdesc =""; //商品描述 String p8_Url ="http://localhost:8080/shop/order_callBack.action"; //支付成功后的跳转页面 String p9_SAF =""; //送货地址 String pa_MP = ""; //拓展信息 String pd_FrpId = this.pd_FrpId;//支付通道编码 String pr_NeedResponse = "1"; //应答机制 String keyValue ="69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl"; String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt, p4_Cur, p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP, pd_FrpId, pr_NeedResponse, keyValue); //向易宝出发 StringBuffer stringBuffer=new StringBuffer("https://www.yeepay.com/app-merchant-proxy/node?"); stringBuffer.append("p0_Cmd=").append(p0_Cmd).append("&"); stringBuffer.append("p1_MerId=").append(p1_MerId).append("&"); stringBuffer.append("p2_Order=").append(p2_Order).append("&"); stringBuffer.append("p3_Amt=").append(p3_Amt).append("&"); stringBuffer.append("p4_Cur=").append(p4_Cur).append("&"); stringBuffer.append("p5_Pid=").append(p5_Pid).append("&"); stringBuffer.append("p6_Pcat=").append(p6_Pcat).append("&"); stringBuffer.append("p7_Pdesc=").append(p7_Pdesc).append("&"); stringBuffer.append("p8_Url=").append(p8_Url).append("&"); stringBuffer.append("p9_SAF=").append(p9_SAF).append("&"); stringBuffer.append("pa_MP=").append(pa_MP).append("&"); stringBuffer.append("pd_FrpId=").append(pd_FrpId).append("&"); stringBuffer.append("pr_NeedResponse=").append(pr_NeedResponse).append("&"); stringBuffer.append("keyValue=").append(keyValue).append("&"); stringBuffer.append("hmac=").append(hmac); //重定向到易宝 ServletActionContext.getResponse().sendRedirect(stringBuffer.toString()); return NONE; } //付款成功后的转向 public String callBack(){ //修改订单状态:修改状态为已经付款 Order currOrder=orderService.findByOid(Integer.parseInt(r6_Order)); currOrder.setState(2); orderService.update(currOrder); //在页面显示付款成功信息 this.addActionMessage("订单付款成功:订单编号:"+r6_Order+"付款的金额:"+r3_Amt); return "msg"; } }
JSP
<form id="orderForm" action="${ pageContext.request.contextPath }/order_payOrder.action" method="post"> <input type="hidden" name="oid" value="<s:property value="model.oid"/>"/> <div class="span24"> <p> 收货地址:<input name="order.user.addr" type="text" value="<s:property value="model.user.addr"/>" style="width:350px" /> <br /> 收货人 :<input name="order.user.username" type="text" value="<s:property value="model.user.name"/>" style="width:150px" /> <br /> 联系方式:<input name="order.user.phone" type="text" value="<s:property value="model.user.phone"/>" style="width:150px" />
</p>
</div>
</form>
原文:http://www.cnblogs.com/guoxianda/p/5727485.html