• 大小: 10KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: Java
  • 标签: 支付宝  

资源简介

整合支付宝 登陆、支付、获取用户信息等功能的一个工具类,将参数放在properties配置文件中,所有功能统一调用。货真价实,绝对好用~~

资源截图

代码片段和文件信息

package com.xhlc.pay.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConstants;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayOpenAuthTokenAppRequest;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest;
import com.alipay.api.response.AlipayOpenAuthTokenAppResponse;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.smy.framework.core.config.Property;
import com.xhlc.pay.dto.AliRefundRequestDto;
import com.xhlc.pay.dto.AliSignOrderRequestDto;

/**
 * https://openauth.alipay.com/oauth2/appToAppAuth.htm?app_id=2017121300692655&
 * redirect_uri=http://oliver.vicp.io:12886/alipayTest/return_url.jsp 支付宝 集成工具
 * 
 * @since 2017-12-20
 * @author oliver
 * 
 */
public class AlipayUtils {

private static String appId;

private static String privateKey;

public static String publicKey;

private static String redirectIp;

static {
appId = Property.getProperty(“alipay.appId“ ““);
privateKey = Property.getProperty(“alipay.privateKey“ ““);
publicKey = Property.getProperty(“alipay.publicKey“ ““);
redirectIp = Property.getProperty(“alipay.redirectIp“ ““);
}

private static Logger LOG = LoggerFactory.getLogger(AlipayUtils.class);
// 统一收单交易创建接口
private static AlipayClient alipayClient = null;

public static AlipayClient getAlipayClient() {
if (alipayClient == null) {
synchronized (AlipayUtils.class) {
if (null == alipayClient) {
alipayClient = new DefaultAlipayClient(“https://openapi.alipay.com/gateway.do“ appId privateKey
AlipayConstants.FORMAT_JSON AlipayConstants.CHARSET_UTF8 publicKey “RSA2“);
}
}
}
return alipayClient;
}

/**
 * 用户同意授权,获取authCode
 * 
 * @param url
 *            回调地址
 * @return
 */
public static String visitUrl(String url) {
String encodeUrl = ““;
try {
encodeUrl = URLEncoder.encode(url “UTF-8“);
} catch (UnsupportedEncodingException e) {
return null;
}
String scope = “auth_userauth_base“;
String visitUrl = “https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=“ + appId + “&s

评论

共有 条评论