java实现在线支付.docx
文本预览下载声明
java实现在线支付
电子商务系统JAVA实现的基本流程如下: 客户在系统内下订单 - 系统根据订单生成支付宝接口url - 客户通过url使用支付宝(网上银行)付款 - 支付宝将客户的付款完成信息发送给电子商务系统 - 系统收到支付宝信息后确定客户订单已经付款 - 进行发货等后续流程。在开始下面的内容之前,你要先有一个支付宝账户,如果要集成支付宝接口,你还必须申请开通服务(关于如何开通,可以直接到支付宝网站上申请).在服务开通后,支付宝会给你2个字符串编号:1个partnerId(合作伙伴ID),还有1个securityCode(安全码).当你拿到这2个码的时候就可以开始下面的内容了.(1)如何调用支付宝接口?(将客户的订单信息按照既定的规则生成一个url跳转到支付宝网站)
通过下面方法[makeOrderAlipayUrl(HttpServletRequest httpRequest,Order order)]的调用得到支付宝的url,然后进行跳转(response.sendRedirect(url);).
[html] HYPERLINK /harticle/details/7658275 \o view plain view plain HYPERLINK /harticle/details/7658275 \o copy copy HYPERLINK /harticle/details/7658275 \o print print HYPERLINK /harticle/details/7658275 \o ? ?
/**??????
?????*?根据订单生成支付宝接口URL.??????
?????*?@param?httpRequest??????
?????*?@param?order?订单实例??????
?????*?@return??????
?????*?@throws?Exception??????
?????*/???????
????public?static?String?makeOrderAlipayUrl(HttpServletRequest?httpRequest,Order?order)?throws?Exception?{????????
????????HashMap?hm?=?new?HashMap();????????
????????hm.put(_input_charset,httpRequest.getCharacterEncoding());//采用相同的编码方式????????
????????hm.put(body,您在上的订单);//填写在跳到支付宝页面上显示的付款内容信息????????
????????hm.put(discount,-5);//填写折扣信息?-5表示抵扣5元????????
????????hm.put(logistics_fee,10);//物流费用????????
????????hm.put(logistics_payment,BUYER_PAY);//物流费用支付人?BUYER_PAY=买家支付物流费用????????
????????hm.put(logistics_type,EXPRESS);//物流方式????????
????????hm.put(notify_url,/notifyurl.jsp);//客户付款后,支付宝调用的页面????????
????????hm.put(out_trade_no,order.getId());//外部交易号,最好具有唯一性,在获取支付宝发来的付款信息时使用.????????
????????hm.put(partner,partnerId);//partnerId(合作伙伴ID)????????
????????hm.put(agent,partnerId);//partnerId(合作伙伴ID)????????
????????hm.put(payment_type,1);//支付类型?1=商品购买,2=服务购买,...????????
????????hm.put(price,105.30);//订单金额信息????????
????????hm.put(quantity,1);//订单商品数量,一般都是写1,它是按照整个订单包来计算????????
????????hm.put(return_url,/ReturnUrl.jsp);//客户付款成功后,显示给客户的页面????????
????????hm.put(seller_email,alipay@);//你的
显示全部