Java手把手教你完成支付宝H5支付

1,阿里的H5支付相对来微信来说很简单,第一步我们需要获取以下几个参数

    // 商户appid-----h5支付的ID
    public static String        APPID             = "APPID";
    // 私钥 pkcs8格式的
    public static String        RSA_PRIVATE_KEY   =""
    // 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    public static String        notify_url        = "https://此处域名/faint-service/f/ali/alipayRechargeGoldNotify";
    // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问       商户可以自定义同步跳转地址
    public static String        return_url        = "https://此处域名/faint-service/static/h5/app/successh5.html";
    // 请求网关地址
    public static String        URL               = "https://openapi.alipay.com/gateway.do";
    // 编码
    public static String        CHARSET           = "UTF-8";
    // 返回格式
    public static String        FORMAT            = "json";
    // 支付宝公钥
    public static String        ALIPAY_PUBLIC_KEY = ""
    // RSA2
    public static String        SIGNTYPE          = "RSA2";

APPID:怎样申请支付宝支付的整个流程我就不一一细说了,APPID在你申请APP支付的时候就可以得到此数据

RSA_PRIVATE_KEY 和ALIPAY_PUBLIC_KEY   :公钥私钥也是你申请APP支付会设置的数据

notify_url        :支付宝支付成功回调到服务器的地址,获得成功数据

return_url        如果是H5支付的话,需要填写,APP支付不需要,支付成功返回的页面.

URL              :此URL是把数据打包到支付宝  唤醒支付宝支付的地址

CHARSET            FORMAT            SIGNTYPE          :这三个是固定死的,填就完事

2,开始写代码了,前端请求支付,后端处理数据,打包到支付宝服务器

@RequestMapping("aliPayRechargeGold")
    public void CreatPayOrderForH5(HttpServletRequest request, HttpServletResponse response, Integer rechargeNumber, String rechargeId) {
        try {
            //如果是模拟请求则返回null
            boolean bool = rechargeList.contains(rechargeId);
            
                //保存充值记录到数据库
                int aisle = 2; //支付宝充值
                AlipayClient alipayClient = new DefaultAlipayClient(AliPayConfig.URL, AliPayConfig.APPID, AliPayConfig.RSA_PRIVATE_KEY, "json", "UTF-8", AliPayConfig.ALIPAY_PUBLIC_KEY, "RSA2");
                AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
                JSONObject order = new JSONObject();
                Integer money = mdRecharge.getRmb();//获取金额,单位元
                String reaMoney = money.toString() + ".00";
                order.put("out_trade_no", mdRecharge.getNumber()); //订单号
                order.put("subject", ""); //商品标题
                order.put("product_code", "QUICK_WAP_WAY");
                order.put("body", "");//商品名称
                order.put("total_amount", reaMoney); //金额
                alipayRequest.setBizContent(order.toString());
                //在公共参数中设置回跳和通知地址
                alipayRequest.setNotifyUrl(AliPayConfig.notify_url);
                alipayRequest.setReturnUrl(AliPayConfig.return_url);
                String form = alipayClient.pageExecute(alipayRequest).getBody();
                response.setContentType("text/html;charset=utf-8");
                response.getWriter().write(form);
                response.getWriter().flush();

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值