Package com.lgx8.common.payment.service

Source Code of com.lgx8.common.payment.service.AlipayMerchantService

package com.lgx8.common.payment.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import com.lgx8.common.payment.config.AlipayMerchantConfig;
import com.lgx8.common.payment.util.AlipayMerchantSubmit;

public class AlipayMerchantService {
  
    /**
     * 支付宝提供给商户的服务接入网关URL(新)
     */
    private static final String ALIPAY_GATEWAY_NEW = "https://mapi.alipay.com/gateway.do?";

    /**
     * 构造标准双接口
     * @param sParaTemp 请求参数集合
     * @return 表单提交HTML信息
     */
    public static String trade_create_by_buyer(Map<String, String> sParaTemp) {

      //增加基本配置
        sParaTemp.put("service", "trade_create_by_buyer");
        sParaTemp.put("partner", AlipayMerchantConfig.partner);
        sParaTemp.put("return_url", AlipayMerchantConfig.return_url);
        sParaTemp.put("notify_url", AlipayMerchantConfig.notify_url);
        sParaTemp.put("seller_email", AlipayMerchantConfig.seller_email);
        sParaTemp.put("_input_charset", AlipayMerchantConfig.input_charset);

        String strButtonName = "确认";

        return AlipayMerchantSubmit.buildForm(sParaTemp, ALIPAY_GATEWAY_NEW, "post", strButtonName);
    }

    /**
     * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
     * 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
     * @return 时间戳字符串
     * @throws IOException
     * @throws DocumentException
     * @throws MalformedURLException
     */
    public static String query_timestamp() throws MalformedURLException,
                                                        DocumentException, IOException {

        //构造访问query_timestamp接口的URL串
        String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayMerchantConfig.partner;
        StringBuffer result = new StringBuffer();

        SAXReader reader = new SAXReader();
        Document doc = reader.read(new URL(strUrl).openStream());

        List<Node> nodeList = doc.selectNodes("//alipay/*");

        for (Node node : nodeList) {
            // 截取部分不需要解析的信息
            if (node.getName().equals("is_success") && node.getText().equals("T")) {
                // 判断是否有成功标示
                List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
                for (Node node1 : nodeList1) {
                    result.append(node1.getText());
                }
            }
        }

        return result.toString();
    }
}
TOP

Related Classes of com.lgx8.common.payment.service.AlipayMerchantService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.