本文主要是介绍企业支付宝账号开发接口教程SpringMVC+JSP),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
[java]代码库
String payment_type = "1" ; |
String notify_url = "http://localhost:8080/alipay/async" ; |
String return_url = "http://192.168.0.222:8080/alipay/return_url" ; |
String subject = new String( "测试商品" .getBytes( "ISO-8859-1" ), "UTF-8" ); |
String total_fee = "0.01" ; |
Map<String, String> sParaTemp = new HashMap<String, String>(); |
sParaTemp.put( "service" , "create_direct_pay_by_user" ); |
sParaTemp.put( "partner" , AlipayConfig.partner); |
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( "seller_email" , Constants.SELLER_EMAIL); |
sParaTemp.put( "out_trade_no" , date.getTime()+payment_type); |
sParaTemp.put( "subject" , subject); |
sParaTemp.put( "total_fee" , total_fee); |
String sHtmlText = AlipaySubmit.buildRequest(sParaTemp, "get" , "立即付款" ); |
request.setAttribute( "sHtmlText" , sHtmlText); |
Map<String , String> params = new HashMap<String, String>(); |
Map requestParams = request.getParameterMap(); |
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) { |
String name = (String) iter.next(); |
String[] values = (String[]) requestParams.get(name); |
for ( int i = 0 ; i < values.length; i++) { |
valueStr = (i == values.length - 1 )? valueStr + values[i]:valueStr+values[i]+ "," ; |
params.put(name, valueStr); |
String tradeNo = request.getParameter( "out_trade_no" ); |
String tradeStatus = request.getParameter( "trade_status" ); |
if (AlipayNotify.verify(params)){ |
if (tradeStatus.equals( "TRADE_FINISHED" ) || tradeStatus.equals( "TRADE_SUCCESS" )){ |
System.out.println( "ok!>>>>>>>>" + tradeNo); |
* @修改日期 2014-9-25下午1:29:53 |
@RequestMapping (value= "/aliapi" ) |
public class AlipayApiController { |
private static Log log = LogFactory.getLog(AlipayApiController. class ); |
@RequestMapping (value= "/index" ) |
public String index(HttpServletRequest request, |
HttpServletResponse response){ |
@RequestMapping (value = "/deposit" , method = RequestMethod.POST,produces = "application/json" ) |
public String deposit(HttpServletRequest request,HttpServletResponse response,Model model) throws Exception { |
String payment_type = "1" ; |
String notify_url = "http://192.168.0.222:8080/live/aliapi/async" ; |
String return_url = "http://192.168.0.222:8080/live/aliapi/return_url" ; |
String anti_phishing_key = "" ; |
String exter_invoke_ip = "" ; |
String total_fee = ServletRequestUtils.getStringParameter(request, "amount" , "" ); |
String body = ServletRequestUtils.getStringParameter(request, "body" , "test" ); |
String show_url = ServletRequestUtils.getStringParameter(request, "show_url" , "http://www.elve.cn" ); |
Map<String, String> sParaTemp = new HashMap<String, String>(); |
sParaTemp.put( "service" , "create_direct_pay_by_user" ); |
sParaTemp.put( "partner" , AlipayConfig.partner); |
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( "seller_email" , Constants.SELLER_EMAIL); |
sParaTemp.put( "out_trade_no" , date.getTime()+payment_type); |
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, "post" , "确认" ); |
Gson gson = new GsonBuilder().setDateFormat( "yyyy-MM-dd HH:mm:ss" ).create(); |
String s = gson.toJson(sHtmlText); |
model.addAttribute( "sHtmlText" , s); |
request.setAttribute( "sHtmlText" , s); |
result = "{\"success\":true,\"msg\":\"跳转成功\"}" ; |
StringUtil.writeToWeb(sHtmlText, "html" , response); |
if (log.isErrorEnabled()){ |
log.error( "ddddddddddddddddddddd" ); |
result = "{\"success\":false,\"msg\":\"跳转失败,请稍候再试!\"}" ; |
StringUtil.writeToWeb(result, "html" , response); |
@RequestMapping (value= "/return_url" ) |
public String Return_url(HttpServletRequest request,HttpServletResponse response){ |
return "web/pay/success" ; |
@SuppressWarnings ( "rawtypes" ) |
@RequestMapping (value= "/async" ,method = RequestMethod.GET) |
public String async(HttpServletRequest request, |
HttpServletResponse response){ |
Map<String,String> params = new HashMap<String,String>(); |
Map requestParams = request.getParameterMap(); |
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) { |
String name = (String) iter.next(); |
String[] values = (String[]) requestParams.get(name); |
for ( int i = 0 ; i < values.length; i++) { |
valueStr = (i == values.length - 1 ) ? valueStr + values[i]: valueStr + values[i] + "," ; |
params.put(name, valueStr); |
String tradeNo = request.getParameter( "out_trade_no" ); |
String tradeStatus = request.getParameter( "trade_status" ); |
if (AlipayNotify.verify(params)){ |
if (tradeStatus.equals( "TRADE_FINISHED" ) || tradeStatus.equals( "TRADE_SUCCESS" )) { |
System.out.println( ">>>>>充值成功" + tradeNo); |
return "web/pay/success" ; |
<%@ page contentType= "text/html;charset=UTF-8" %> |
<html xmlns= "http://www.w3.org/1999/xhtml" > |
<meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> |
<%@ include file= "/common/webMeta.jsp" %> |
<title>www.elve.cn</title> |
<meta content= "www.elve.cn" name= "keywords" /> |
<meta content= "www.elve.cn" name= "description" /> |
<script type= "text/javascript" > |
$( "#doSubmit" ).click(function(){ |
<form id= "form1" action= "${ctx }/aliapi/deposit" method= "post" target= "_blank" > |
<td class = "balance" id= "userBalance" ></td> |
<td><i class = "zfb" ></i></td> |
<td style= "padding-bottom: 0px;" >亲爱的<span |
class = "suppliment_user" id= "suppliment_user" ></span>,您可以使用支付宝充值积善分,请填写以下信息 |