??
1.<p> 
2.一、ACTION类关键代码 没用的包可以干掉</p>


[java] view plaincopyprint?
package com.test.alipay.action;  import it.sauronsoftware.base64.Base64;  import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;  import javax.servlet.http.HttpServletResponse;  import org.apache.struts2.ServletActionContext;
import org.dom4j.Document;
import org.springframework.stereotype.Controller;  import com.alibaba.fastjson.JSON;
import com.test.action.BaseAction;
import com.test.config.AlipayConfig;
import com.test.util.AlipaySubmit;
import com.test.util.HTTPService;
import com.test.util.UtilDate;
import com.hztest.source.security.DESUtil;
/* * 支付宝付款接口 * @author ZhuangZi * @Directions  * @version $Id: AliPayAction.java,v 0.1 2013-3-27 下午04:49:57 ZhuangZi Exp $ */
@Controller
public class AliPayAction extends BaseAction {  private String              phoneCode;  private String              totalfee;  /** * 调用支付宝接口 * @author ZhuangZi * @class com.test.alipay.action.AliPayAction * @method AliPay * @Directions 调用支付宝接口 * @date 2013-3-27下午04:53:35 void */  public void pay() {  try {  /*1****生成支付宝交易号,根据时间到毫秒级别*/  String out_trade_no = UtilDate.getOrderNum() ;  /*2*****↓↓↓↓↓↓↓↓↓↓把请求参数打包成数组↓↓↓↓↓↓↓↓↓↓*/  Map<String, String> sParaTemp = new HashMap<String, String>();  sParaTemp = getPayPrama(totalfee, out_trade_no);  /*3*****↓↓↓↓↓↓↓↓↓↓请求支付宝接口↓↓↓↓↓↓↓↓↓↓*/  String json = AlipaySubmit.buildRequest(sParaTemp, "get", "确认");  HttpServletResponse response = ServletActionContext.getResponse();  response.setContentType("text/html");  response.setCharacterEncoding("utf-8");  PrintWriter out;  out = response.getWriter();  json = JSON.toJSONString(json);  out.write(json);  out.flush();  out.close();  } catch (IOException e) {  }  }  /** *  * @author ZhuangZi * @class com.test.alipay.action.AliPayAction * @method GetPayPrama * @Directions 封装调用支付宝参数 * @date 2013-4-1下午05:26:11 * @param totalfee 金额 * @param out_trade_no  订单编号 * @return Map<String,String> */  public Map<String, String> getPayPrama(String totalfee, String out_trade_no) {  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", AlipayConfig.payment_type);  /*服务器异步通知页面路径//需http://格式的完整路径,不能加?id=123这类自定义参数*/  sParaTemp.put("notify_url", AlipayConfig.notify_url);  /*页面跳转同步通知页面路径 //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/*/  sParaTemp.put("return_url", AlipayConfig.return_url);  /*卖家支付宝帐户*/  sParaTemp.put("seller_email", AlipayConfig.seller_email);  /*商户订单号*/  sParaTemp.put("out_trade_no", out_trade_no);  /*订单名称*/  sParaTemp.put("subject", AlipayConfig.subject);  /*付款金额*/  sParaTemp.put("total_fee", totalfee);  /*订单描述*/  sParaTemp.put("body", AlipayConfig.body);  /*需以http://开头的完整路径,例如:http://www.xxx.com/myorder.html*/  sParaTemp.put("show_url", AlipayConfig.show_url);  //防钓鱼时间戳  sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);  /*客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1*/  sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);  return sParaTemp;  }  public String getPhoneCode() {  return phoneCode;  }  public void setPhoneCode(String phoneCode) {  this.phoneCode = phoneCode;  }  public String getTotalfee() {  return totalfee;  }  public void setTotalfee(String totalfee) {  this.totalfee = totalfee;  }  }
package com.test.alipay.action;import it.sauronsoftware.base64.Base64;import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;
import org.dom4j.Document;
import org.springframework.stereotype.Controller;import com.alibaba.fastjson.JSON;
import com.test.action.BaseAction;
import com.test.config.AlipayConfig;
import com.test.util.AlipaySubmit;
import com.test.util.HTTPService;
import com.test.util.UtilDate;
import com.hztest.source.security.DESUtil;
/** 支付宝付款接口* @author ZhuangZi* @Directions * @version $Id: AliPayAction.java,v 0.1 2013-3-27 下午04:49:57 ZhuangZi Exp $*/
@Controller
public class AliPayAction extends BaseAction {private String              phoneCode;private String              totalfee;/*** 调用支付宝接口* @author ZhuangZi* @class com.test.alipay.action.AliPayAction* @method AliPay* @Directions 调用支付宝接口* @date 2013-3-27下午04:53:35 void*/public void pay() {try {/*1****生成支付宝交易号,根据时间到毫秒级别*/String out_trade_no = UtilDate.getOrderNum() ;/*2*****↓↓↓↓↓↓↓↓↓↓把请求参数打包成数组↓↓↓↓↓↓↓↓↓↓*/Map<String, String> sParaTemp = new HashMap<String, String>();sParaTemp = getPayPrama(totalfee, out_trade_no);/*3*****↓↓↓↓↓↓↓↓↓↓请求支付宝接口↓↓↓↓↓↓↓↓↓↓*/String json = AlipaySubmit.buildRequest(sParaTemp, "get", "确认");HttpServletResponse response = ServletActionContext.getResponse();response.setContentType("text/html");response.setCharacterEncoding("utf-8");PrintWriter out;out = response.getWriter();json = JSON.toJSONString(json);out.write(json);out.flush();out.close();} catch (IOException e) {}}/*** * @author ZhuangZi* @class com.test.alipay.action.AliPayAction* @method GetPayPrama* @Directions 封装调用支付宝参数* @date 2013-4-1下午05:26:11* @param totalfee 金额* @param out_trade_no  订单编号* @return Map<String,String>*/public Map<String, String> getPayPrama(String totalfee, String out_trade_no) {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", AlipayConfig.payment_type);/*服务器异步通知页面路径//需http://格式的完整路径,不能加?id=123这类自定义参数*/sParaTemp.put("notify_url", AlipayConfig.notify_url);/*页面跳转同步通知页面路径 //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/*/sParaTemp.put("return_url", AlipayConfig.return_url);/*卖家支付宝帐户*/sParaTemp.put("seller_email", AlipayConfig.seller_email);/*商户订单号*/sParaTemp.put("out_trade_no", out_trade_no);/*订单名称*/sParaTemp.put("subject", AlipayConfig.subject);/*付款金额*/sParaTemp.put("total_fee", totalfee);/*订单描述*/sParaTemp.put("body", AlipayConfig.body);/*需以http://开头的完整路径,例如:http://www.xxx.com/myorder.html*/sParaTemp.put("show_url", AlipayConfig.show_url);//防钓鱼时间戳sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);/*客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1*/sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);return sParaTemp;}public String getPhoneCode() {return phoneCode;}public void setPhoneCode(String phoneCode) {this.phoneCode = phoneCode;}public String getTotalfee() {return totalfee;}public void setTotalfee(String totalfee) {this.totalfee = totalfee;}}
</pre><pre class="html" name="code"> 二、AlipayConfig 类是封装支付宝接口参数<p>
package com.test.config;  import com.test.util.UtilDate;  /* * *类名:AlipayConfig *功能:基础配置类 *详细:设置帐户有关信息及返回路径 *版本:3.3 *日期:2012-08-10 *说明: *以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 *该代码仅供学习和研究支付宝接口使用,只是提供一个参考。 *提示:如何获取安全校验码和合作身份者ID *1.用您的签约支付宝账号登录支付宝网站(<a target=_blank href="http://www.alipay.com/" target="_blank">www.alipay.com</a>)*2.点击“商家服务”(<a target=_blank href="https://b.alipay.com/order/myOrder.htm" target="_blank">https://b.alipay.com/order/myOrder.htm</a>)*3.点击“查询合作者身份(PID)”、“查询安全校验码(Key)” *安全校验码查看时,输入支付密码后,页面呈灰色的现象,怎么办? *解决方法: *1、检查浏览器配置,不让浏览器做弹框屏蔽设置 *2、更换浏览器或电脑,重新登录查询。 */  public class AlipayConfig {  //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓  // 合作身份者ID,以2088开头由16位纯数字组成的字符串  public static String partner = "2088001466494907";  // 商户的私钥  public static String key = "abcdrfg";  //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑  // 调试用,创建TXT日志文件夹路径  public static String log_path = "D:\\";  // 字符编码格式 目前支持 gbk 或 utf-8  public static String input_charset = "utf-8";  // 签名方式 不需修改  public static String sign_type = "MD5";  public static String payment_type = "1";  //必填,不能修改  //服务器异步通知页面路径  public static  String notify_url = "notify_url.jsp";  //需http://格式的完整路径,不能加?id=123这类自定义参数  //页面跳转同步通知页面路径  public static  String return_url = "return_url.jsp";  //需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成<a target=_blank href="http://localhost/" target="_blank">http://localhost/</a> //卖家支付宝帐户  public static   String seller_email = "<a target=_blank href="mailto:test@163.com" target="_blank">test@163.com</a>"; //必填  //商户订单号  public static  String out_trade_no =UtilDate.getOrderNum();  //商户网站订单系统中唯一订单号,必填  //订单名称  public static String subject = "**充值";  //必填  //订单描述  public static  String body = "**充值";  //商品展示地址  public static String show_url ="";  //防钓鱼时间戳  public static String anti_phishing_key="";  /*客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1*/  public static String exter_invoke_ip="";
}
package com.test.config;</p><p>import com.test.util.UtilDate;</p><p>/* **类名:AlipayConfig*功能:基础配置类*详细:设置帐户有关信息及返回路径*版本:3.3*日期:2012-08-10*说明:*以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。*该代码仅供学习和研究支付宝接口使用,只是提供一个参考。*提示:如何获取安全校验码和合作身份者ID*1.用您的签约支付宝账号登录支付宝网站(<a target=_blank href="http://www.alipay.com/" target="_blank">www.alipay.com</a>)*2.点击“商家服务”(<a target=_blank href="https://b.alipay.com/order/myOrder.htm" target="_blank">https://b.alipay.com/order/myOrder.htm</a>)*3.点击“查询合作者身份(PID)”、“查询安全校验码(Key)”</p><p> *安全校验码查看时,输入支付密码后,页面呈灰色的现象,怎么办?*解决方法:*1、检查浏览器配置,不让浏览器做弹框屏蔽设置*2、更换浏览器或电脑,重新登录查询。*/</p><p>public class AlipayConfig {//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓// 合作身份者ID,以2088开头由16位纯数字组成的字符串public static String partner = "2088001466494907";// 商户的私钥public static String key = "fb30213vjc4k4oabt7z4q9e07sfmlmzr";</p><p> //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑// 调试用,创建TXT日志文件夹路径public static String log_path = "D:\\";</p><p> // 字符编码格式 目前支持 gbk 或 utf-8public static String input_charset = "utf-8";// 签名方式 不需修改public static String sign_type = "MD5";public static String payment_type = "1";//必填,不能修改//服务器异步通知页面路径public static  String notify_url = "notify_url.jsp";//需http://格式的完整路径,不能加?id=123这类自定义参数//页面跳转同步通知页面路径public static  String return_url = "return_url.jsp";//需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成<a target=_blank href="http://localhost/" target="_blank">http://localhost/</a></p><p>    //卖家支付宝帐户public static   String seller_email = "<a target=_blank href="mailto:jjj@test.com" target="_blank">jjj@test.com</a>";//必填</p><p>    //商户订单号public static  String out_trade_no =UtilDate.getOrderNum();//商户网站订单系统中唯一订单号,必填</p><p>    //订单名称public static String subject = "隐号充值";//必填</p><p>    //订单描述public static  String body = "隐号充值";//商品展示地址public static String show_url ="";//防钓鱼时间戳public static String anti_phishing_key="";/*客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1*/public static String exter_invoke_ip="";
}
</p>

三、strut配置文件

<action name="pay" method="pay" class="com.test.alipay.action.AliPayAction">
   </action>

以上属于关键代码部分,需要注意的事项有 :

1.需要把支付宝提供的接口的几个类引入到你的项目中,包括架包

2.notify_url.jsp和return_url.jsp地址要做好些成外网地址的全路径

3.你自己的业务处理写notify_url.jsp这个里面,也可以直接写个接口给支付宝接口调用??



sturts调用支付宝接口。相关推荐

  1. Android之应用程序如何调用支付宝接口

    http://blog.csdn.net/lilidejing/article/details/19483717 最近在做一个关于购物商城的项目,项目里面付款这块我选的是调用支付宝的接口,因为用的人比 ...

  2. JavaWeb开发调用支付宝接口实现在线支付(整个支付过程从头到尾)

    项目中需要用到在线支付,实现了调用支付宝接口的在线支付,记录下来以便以后使用. 一.进入蚂蚁金服开放平台登录 网址:https://openhome.alipay.com/developmentDoc ...

  3. 调用支付宝接口android最新,Android 外接sdk之支付宝

    支付宝开放平台 最新sdk可以访问开放平台进行下载. 以下为流程和注意事项. 1.名词简介 请求    手机客户端以字符串形式把需要传输的数据发送给接收方的过程. 返回     支付宝以字符串形式直接 ...

  4. java调用支付宝接口代码介绍

    App支付产品介绍 更新时间:2018-05-08 场景介绍 适用于商家在App应用中集成支付宝支付功能. 商家APP调用支付宝提供的SDK,SDK再调用支付宝APP内的支付模块.如果用户已安装支付宝 ...

  5. 调用支付宝接口生成小程序二维码的坑(PHP)

    引言:最近在开发支付宝小程序生成二维码的时候碰到了一点问题,记录一下 1.需求 正在开发的这个项目是一个电商类小程序,需求是给每个产品生成一个独立的小程序二维码 2.实现 了解了需求之后,开始查官方文 ...

  6. 调用支付宝接口,完成付款功能

     支付宝接口调用,完成付款 先到支付宝下载sdk,下载SDK,看看demo,可以看看支付宝开发文档,Demo中,Base64.java.Result.java.Rsa.java这3个类不需要动,直接放 ...

  7. 关于Android调用支付宝接口”有的手机无法调起网页支付”遇到的问题

    今天测试给了一个BUG给我,说是调用支付宝支付时,直接显示结果"已取消''. 根据现象,可以看到支付宝已经返回了结果,而在代码中 String resultStatus = payResul ...

  8. java调用支付接口实例_Java 调用支付宝接口

    1.注册开发者中心应用   登录点击沙箱服务 https://open.alipay.com/platform/developerIndex.htm 2.创建沙箱应用获取APPID和支付宝网关地址(创 ...

  9. 调用支付宝接口开发遇到的错误

    转载于:http://nassir.iteye.com/blog/1853150 用openssl 生成的密钥老是报以下错误: Java代码   java.security.spec.InvalidK ...

最新文章

  1. 【面试题】如何设计一个高并发的系统?
  2. 曾大战LeCun的谷歌女性科学家,刚刚被Jeff Dean开除了!
  3. 使用ASV2011研究Molehill API
  4. Xshell 命令后台执行
  5. maven上传源码脚本
  6. (九)python3 只需3小时带你轻松入门——函数自定义
  7. tornado学习笔记day02-进阶与提升
  8. xss漏洞php注射实战,利用XSS渗透DISCUZ 6.1.0实战
  9. 《ArcGIS Runtime SDK for Android开发笔记》——离在线一体化技术:概述
  10. 1月22日发布!疑似渠道商泄露荣耀V40价格:3999元起?
  11. Android 制定安装重写迁移至SD卡 APP2SD
  12. 射频放大电路的优化及ADS仿真
  13. 网络共享中心的计算机名,网络和共享中心在哪?教你打开Windows电脑系统网络和共享中心5大方法...
  14. html仿360首页动画效果图,仿360影视网站模板html源码
  15. vue实现PS效果,鼠标拖拽指令、十字辅助线、鼠标选点、打印页面指定内容、生成随机id、颜色选择器、div上输入文字(类似QQ截图输入文字)、vue图片上传转base64...
  16. linux32 浏览器,谷歌停止支持32位linux系统的Chrome浏览器
  17. Java聊天室——实现多人聊天、私聊、群聊
  18. 虾皮电商选品时必须注意哪些是违禁品
  19. R语言使用sd函数计算向量数据的标准差
  20. linux文件中提取某些字节,linux – 如何转储二进制文件的一部分

热门文章

  1. java取石子_HDU 1527 取石子游戏
  2. 开发板Linux手指滑动方向,移动应用滑动屏幕方向判断解决方案,JS判断手势方向...
  3. C++String fing函数
  4. MySQL数据库迁移详细步骤
  5. JAVA stream流对集合进行替换修改
  6. comp9334辅导 proj2
  7. MindSpore报错ValueError:For xx,the x shape:xx must be equal to xxx
  8. html ide iOS,用于ios开发的ide是 ios开发的ide有哪些
  9. Field baseMapper in com.xxx required a single bean,but 100 were found --------Mybatis-Plus
  10. Linux电脑安全管家