关闭

支付宝支付-PC电脑网站支付

标签: 支付宝支付宝电脑网站支付支付宝PC支付支付宝Web支付支付宝支付
1910人阅读 评论(0) 收藏 举报
分类:

支付产品全面升级(更新时间:2017/05/05 ),若您使用的是老接口,请移步老版本即时到账文档

支持沙盒环境的测试

此项目已开源欢迎Start、PR、发起Issues一起讨论交流共同进步
https://github.com/Javen205/IJPay
http://git.oschina.net/javen205/IJPay

1、有图有真相

使用手机扫码进行支付

i统一收单下单并支付页面接口alipay.trade.page.pay

手机扫码进行支付

PC 端登录账号进行支付

登录账号进行支付

进去支付宝收银台

输入交易密码进行支付

付款完成

正在跳转到商户页面

商户页面、这里只是将签名验证的结果显示在页面上

PC支付两次扣款记录

2、如何申请PC电脑网站支付

费率、申请条件、签约、使用场景 传送门接入指引

签约流程

3、如何快速接入PC电脑网站支付

如果你是使用新版本接入就比较方便了,因为官方提供了开放平台服务端SDK

3.1 接口调用流程图

主要涉及到的接口有:

3.2 支付接口alipay.trade.page.pay封装

初始化接口

static {
        alipayClient = new DefaultAlipayClient(SERVICE_URL, APP_ID, PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
    }

封装支付接口并将SDK生成的表单响应给页面

/**
     * 电脑网站支付(PC支付)
     * @param model
     * @param notifyUrl
     * @param returnUrl
     * @return
     * @throws AlipayApiException
     * @throws IOException 
     */
    public static void tradePage(HttpServletResponse httpResponse, AlipayTradePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException{
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setBizModel(model);
        request.setNotifyUrl(notifyUrl);
        request.setReturnUrl(returnUrl);
        String form  = alipayClient.pageExecute(request).getBody();//调用SDK生成表单
        httpResponse.setContentType("text/html;charset=" + CHARSET);
        httpResponse.getWriter().write(form);//直接将完整的表单html输出到页面
        httpResponse.getWriter().flush();
        httpResponse.getWriter().close();
    }
3.3 其他支付接口封装

可以参考 支付宝支付-常用支付API详解(查询、退款、提现等)

3.4 封装测试
/**
     * PC支付
     */
    public void pcPay(){
        try {
            String totalAmount = "88.88"; 
            String outTradeNo =StringUtils.getOutTradeNo();
            log.info("pc outTradeNo>"+outTradeNo);

            String returnUrl = AliPayApi.NOTIFY_DOMAIN + "/alipay/return_url";
            String notifyUrl = AliPayApi.NOTIFY_DOMAIN + "/alipay/notify_url";
            AlipayTradePayModel model = new AlipayTradePayModel();

            model.setOutTradeNo(outTradeNo);
            model.setProductCode("FAST_INSTANT_TRADE_PAY");
            model.setTotalAmount(totalAmount);
            model.setSubject("Javen PC支付测试");
            model.setBody("Javen IJPay PC支付测试");

            AliPayApi.tradePage(getResponse(),model , notifyUrl, returnUrl);
        } catch (Exception e) {
            e.printStackTrace();

        }

    }

异步通知处理

public void notify_url() {
        try {
            // 获取支付宝POST过来反馈信息
            Map<String, String> params = AliPayApi.toMap(getRequest());

            for (Map.Entry<String, String> entry : params.entrySet()) {
                System.out.println(entry.getKey() + " = " + entry.getValue());
            }

            boolean verify_result = AlipaySignature.rsaCheckV1(params, AliPayApi.ALIPAY_PUBLIC_KEY, AliPayApi.CHARSET,
                    AliPayApi.SIGN_TYPE);

            if (verify_result) {// 验证成功
                // TODO 请在这里加上商户的业务逻辑程序代码 异步通知可能出现订单重复通知 需要做去重处理
                System.out.println("notify_url 验证成功succcess");
                renderText("success");
                return;
            } else {
                System.out.println("notify_url 验证失败");
                // TODO
                renderText("failure");
                return;
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
            renderText("failure");
        }
    }

同步商户页面验签,这里只是返回验签的状态

public void return_url() {
        try {
            // 获取支付宝GET过来反馈信息
            Map<String, String> map = AliPayApi.toMap(getRequest());
            for (Map.Entry<String, String> entry : map.entrySet()) {
                System.out.println(entry.getKey() + " = " + entry.getValue());
            }

            boolean verify_result = AlipaySignature.rsaCheckV1(map, AliPayApi.ALIPAY_PUBLIC_KEY, AliPayApi.CHARSET,
                    AliPayApi.SIGN_TYPE);

            if (verify_result) {// 验证成功
                // TODO 请在这里加上商户的业务逻辑程序代码 
                System.out.println("return_url 验证成功");
                renderText("success");
                return;
            } else {
                System.out.println("return_url 验证失败");
                // TODO
                renderText("failure");
                return;
            }
        } catch (AlipayApiException e) {
            e.printStackTrace();
            renderText("failure");
        }
    }

将参数转化为Map,为验签做准备

/**
     * 
     * @param request
     * @return
     */
    public static Map<String, String> toMap(HttpServletRequest request) {
        System.out.println(">>>>" + request.getQueryString());
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String[]> requestParams = request.getParameterMap();
        for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            // 乱码解决,这段代码在出现乱码时使用。
            // valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
            params.put(name, valueStr);
        }
        return params;
    }

4、测试数据

异步通知的参数

gmt_create = 2017-05-14 13:26:58
charset = UTF-8
notify_time = 2017-05-14 13:28:04
gmt_payment = 2017-05-14 13:28:03
subject = Javen PC支付测试
sign = ZYQO+lzxAMDj8Al25KoJzSXegrx1rriBMGLOAEyiNHEac0OMe5e49ZW6m0waDSmTBDX8bwEHUjAk8rdCXTXPzNQSVP0p+46V+8k9AHiEiom6OzV3ZTLzGXGw8A8lnrGPYeCDmKSa3pogJKP0Ob7PyBRgz4HWydWC4P+G1yYEjvVX8kK2XbM6bMauW23a0AklvZbve6WUwUpkioMNLCOHAQzPBDW/LaoDUGx6GN6f3sFDsomBJ03w9rJgqZCs1zw29HHIW4kNFrLcQFleaC+2NnNPLhVanH1iXcK8800dsOXagRPuoy9Gr2EYGV+hSOiVE+XszBKIWTlAbZpE5QgJ6g==
buyer_id = 2088102169474200
body = Javen IJPay PC支付测试
invoice_amount = 88.88
version = 1.0
notify_id = 43749ffb4d02c02f4bfc5ee4fe5761ehjm
fund_bill_list = [{"amount":"88.88","fundChannel":"ALIPAYACCOUNT"}]
notify_type = trade_status_sync
out_trade_no = 051413260514947
total_amount = 88.88
trade_status = TRADE_SUCCESS
trade_no = 2017051421001004200200241311
auth_app_id = 2016102000727659
receipt_amount = 88.88
point_amount = 0.00
sign_type = RSA2
buyer_pay_amount = 88.88
app_id = 2016102000727659
seller_id = 2088102180432465
notify_url 验证成功succcess

商户页面同步的参数

>>>>total_amount=88.88&timestamp=2017-05-14+13%3A28%3A11&sign=KRn%2FEi%2B8lOpPdmSBg8ZsB9dUsV8la2bMWaFGFs5R2hhQOP283m%2BolOwFamfC%2B1thxfIsEi92w99lH24K044yj6aLAN8mJq3umQTRI6j2SvZgn1Ufgpd5KdjfmpEAR5omFOJJP%2FDXIb2zEFs6VvA60RmpwYT5mHbujSWDUvj7X0LX1SGd5l90DbyUDtfMe%2FRSqBFd0iIDLloa78a3dPqHcId3mUKP4RrzZBGWNbAYxrZiEslmZiU%2BnT9K0zL9t%2BVm%2B24pHWsgVOR7hb4UicT%2FfHk6VnDPTnOlfVfJD3vOE2FP6N0jgj0QEKNIynOp6t74zmE8Xkca3pGQnkYyrUEQyg%3D%3D&trade_no=2017051421001004200200241311&sign_type=RSA2&auth_app_id=2016102000727659&charset=UTF-8&seller_id=2088102180432465&method=alipay.trade.page.pay.return&app_id=2016102000727659&out_trade_no=051413260514947&version=1.0
charset = UTF-8
out_trade_no = 051413260514947
method = alipay.trade.page.pay.return
total_amount = 88.88
sign = KRn/Ei+8lOpPdmSBg8ZsB9dUsV8la2bMWaFGFs5R2hhQOP283m+olOwFamfC+1thxfIsEi92w99lH24K044yj6aLAN8mJq3umQTRI6j2SvZgn1Ufgpd5KdjfmpEAR5omFOJJP/DXIb2zEFs6VvA60RmpwYT5mHbujSWDUvj7X0LX1SGd5l90DbyUDtfMe/RSqBFd0iIDLloa78a3dPqHcId3mUKP4RrzZBGWNbAYxrZiEslmZiU+nT9K0zL9t+Vm+24pHWsgVOR7hb4UicT/fHk6VnDPTnOlfVfJD3vOE2FP6N0jgj0QEKNIynOp6t74zmE8Xkca3pGQnkYyrUEQyg==
trade_no = 2017051421001004200200241311
auth_app_id = 2016102000727659
version = 1.0
sign_type = RSA2
app_id = 2016102000727659
seller_id = 2088102180432465
timestamp = 2017-05-14 13:28:11
return_url 验证成功

推荐阅读:
微信、支付宝App支付-JPay0.0.2发布
支付宝支付-提现到个人支付宝
支付宝支付-刷卡支付(条码支付)
支付宝支付-扫码支付一张二维码集成微信、支付宝支付
支付宝Wap支付你了解多少?
Android版-支付宝APP支付
支付宝支付-常用支付API详解(查询、退款、提现等)

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48771次
    • 积分:1038
    • 等级:
    • 排名:千里之外
    • 原创:52篇
    • 转载:3篇
    • 译文:0篇
    • 评论:27条
    一起讨论学习,共同进步
    博客专栏
    文章分类
    最新评论