zoukankan      html  css  js  c++  java
  • 支付宝h5支付从支付到退款

    先说明,支付是之前写好的,调用的是支付宝旧的即时到账接口,所也没有去集成应用,退款调用的是无密即时到账退款接口!!!

    https://doc.open.alipay.com/支付宝文档资料,蚂蚁金服开发平台。首先从开放平台找到即时到账接口资料,上面有demo可以下载,下载demo,修改里面的配置参数即可接通wep支付宝支付(公钥查看支付宝和私钥生成支付宝有生成工具提供)(ps:私钥生成后需要在支付宝上面配置,放到一个地方去才生效)。具体代码修改根据公司需要,支付回掉签名错误问题,demo上面的valueStr不需要进行转码,直接注释掉这一行就行。

    下一步生成二维码(我用的是zxing.jar包生成),通过支付宝扫码进行h5跳转到demo里面的掉起支付页面,完成支付,回掉处理根据业务需求写。如果在参数上面加入

    sParaTemp.put("app_pay", "Y");//启用该参数启用APP钱包支付。(!!!)

    这样在浏览器上面wap支付的时候就能直接打开支付宝app。

    下面说退款,退款不要做什么h5页面跳转,只需要后台httpclient去请求支付宝无密退款接口即可,接口地址:https://mapi.alipay.com/gateway.do。

    /**
         * 处理支付宝退款功能
         * @param money                    退款金额
         * @param alipaycode            支付宝交易流水号
         * @return
         * @throws DocumentException
         */
        public boolean oldAlipayRefund(String money,String alipaycode) throws DocumentException{
            boolean bl=false;
            Map resultMap=null;
            try {
                resultMap = AssemblyParameter(money, alipaycode);
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();return bl;
            }
            String result = HttpClientUtil.post(AlipayConfig.old_refund_url, null, resultMap);
            Document document = DocumentHelper.parseText(result);
            Element root =document.getRootElement();
            List<Element> list =root.elements();
            for(Element l:list){
                if(l.getName().toLowerCase().equals("is_success")){
                    if(l.getText().equals("T")){
                        bl=true;
                    }
                }
            }
            return bl;
        }
        
        /**
         * 拼装支付宝支付接口所需参数,
         * @param money            退款金额
         * @param alipaycode    支付宝支付完成返回流水号
         * @return
         * @throws UnsupportedEncodingException 
         */
        public static Map AssemblyParameter(String money,String alipaycode) throws UnsupportedEncodingException{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Map<String, String> sParaTemp = new HashMap<String, String>();
            sParaTemp.put("service", AlipayConfig.oldrefundservice);
            sParaTemp.put("partner", AlipayConfig.partner);
            sParaTemp.put("_input_charset", AlipayConfig.input_charset);
            sParaTemp.put("sign_type", AlipayConfig.sign_type);
            //sParaTemp.put("notify_url", "");
            sParaTemp.put("seller_email", AlipayConfig.seller_email);
            sParaTemp.put("seller_user_id", AlipayConfig.partner);
            sParaTemp.put("refund_date",DateUtil.normalDateTimeFormat());//退款时间
            sParaTemp.put("batch_no", sdf.format(new Date())+System.currentTimeMillis()/1000);//退款号
            sParaTemp.put("batch_num", "1");//退款笔数
            sParaTemp.put("detail_data",new String((alipaycode+"^"+money+"^正常退款").getBytes("ISO-8859-1"), "utf-8"));//退款描述//alipaycode+"^"+money+"^"+"aaa"
            sParaTemp=AlipaySubmit.buildRequestPara(sParaTemp);
            sdf=null;
            //建立请求
            //String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"get","确认");
            return sParaTemp;
        }

    这个地方有一点需要注意,detail_data,需要转码,不然一直是签名错误。退款流水号是支付宝返回的一个流水号,支付完成的时候是需要保存数据库的,退款需要用到这个流水号!!!

  • 相关阅读:
    异步CTP(Async CTP)为什么那样工作?
    Async Console Programs 异步控制台程序
    Async and Await 异步和等待
    OpenJudge计算概论-自整除数
    OpenJudge计算概论-整数的个数
    OpenJudge计算概论-找和为K的两个元素
    OpenJudge计算概论-找出第k大的数
    OpenJudge计算概论-异常细胞检测
    OpenJudge计算概论-数组逆序重放
    OpenJudge计算概论-数字求和
  • 原文地址:https://www.cnblogs.com/ghsy/p/7193435.html
Copyright © 2011-2022 走看看