微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何用struts调用支付宝接口

以下为大家介绍如何用struts调用支付宝接口的例子。

一、ACTION类关键代码 没用的包可以干掉

复制代码 代码如下:

package com.hzdracom.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.hzdracom.action.BaseAction;

import com.hzdracom.config.AlipayConfig;

import com.hzdracom.util.AlipaySubmit;

import com.hzdracom.util.HTTPService;

import com.hzdracom.util.UtilDate;

import com.hzlq.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.hzdracom.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 sParaTemp = new HashMap();

            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.hzdracom.alipay.action.AliPayAction

     * @method GetPayPrama

     * @Directions 封装调用支付宝参数

      * @date 2013-4-1下午05:26:11

     * @param totalfee 金额

      * @param out_Trade_no  订单编号

      * @return Map

     */

    public Map getPayPrama(String totalfee, String out_Trade_no) {

        Map sParaTemp = new HashMap();

        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;

    }

}

上一篇:Spring实战之使用TransactionProxyfactorybean实现声明式事务操作示例下一篇:Springboot 项目读取Resources目录下的文件(推荐) 热门搜索

支付宝接口 

支付宝接口、微信接口 

如何改支付宝支付密码 

接口调用 

调用接口 

相关文章

如何用struts调用支付宝接口

2021-10-19阅读(3013)评论(0)推荐()

以下为大家介绍如何用struts调用支付宝接口的例子。

python调用支付宝支付接口流程

2021-10-17阅读(6798)评论(0)推荐()

这篇文章主要介绍了python调用支付宝支付接口流程,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

支付宝开放平台支付接口怎么申请?支付宝支付接口申请教程

2021-09-12阅读(9035)评论(0)推荐()

很多朋友不清楚app、网站、H5中的支付宝支付接口怎么申请?下面小编给大家带来支付宝支付接口申请教程,需要的朋友可以参考下

C#支付宝新版支付请求接口调用

2021-10-06阅读(10306)评论(0)推荐()

这篇文章主要为大家详细介绍了C#支付宝新版支付请求接口调用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

SpringBoot下如何实现支付宝接口的使用

2021-10-19阅读(8962)评论(0)推荐()

这篇文章主要介绍了SpringBoot下如何实现支付宝接口的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考...

Java如何在沙箱环境中测试支付宝支付接口

2021-10-11阅读(9299)评论(0)推荐()

这篇文章主要介绍了Java如何在沙箱环境中测试支付宝支付接口,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小...

Django调用支付宝接口代码实例详解

2021-11-04阅读(6399)评论(0)推荐()

这篇文章主要介绍了Django调用支付宝接口代码实例详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

取消

有人回复邮件通知

提交评论

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐