mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-24 21:29:24 +08:00
临时提交 更新主分支
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.egzosn.pay.common.api;
|
||||
|
||||
import com.egzosn.pay.common.bean.AuthPageType;
|
||||
|
||||
/**
|
||||
* 高级支付接口
|
||||
* @author Actinia
|
||||
* @email hayesfu@qq.com
|
||||
* @date 2018/1/18
|
||||
*
|
||||
*/
|
||||
|
||||
public interface AdvancedPayService extends PayService{
|
||||
/**
|
||||
* 获取授权页面
|
||||
* @param payeeId 收款id
|
||||
* @param authPageType 授权类型
|
||||
* @return 返回请求结果
|
||||
*/
|
||||
String getAuthorizationPage(String payeeId,AuthPageType authPageType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.egzosn.pay.common.bean;
|
||||
|
||||
/**
|
||||
* 授权页面的授权类型
|
||||
* @author Actinia
|
||||
* @email hayesfu@qq.com
|
||||
* @date 2018/1/18
|
||||
*/
|
||||
public enum AuthPageType {
|
||||
//注册,登录
|
||||
registration,login;
|
||||
}
|
||||
@@ -1,16 +1,39 @@
|
||||
package com.egzosn.pay.common.bean;/**
|
||||
* Created by Fuzx on 2017/1/24 0024.
|
||||
*/
|
||||
package com.egzosn.pay.common.bean;
|
||||
|
||||
/**
|
||||
* @author Fuzx 货币类型
|
||||
* create 2017 2017/1/24 0024
|
||||
* 货币类型
|
||||
* @author Actinia
|
||||
* @email hayesfu@qq.com
|
||||
* <pre>
|
||||
* create 2017 2017/1/16
|
||||
* </pre>
|
||||
*/
|
||||
public interface CurType {
|
||||
public enum CurType {
|
||||
|
||||
CNY("人民币"),
|
||||
USD("美元"),
|
||||
HKD("港币"),
|
||||
MOP("澳门元"),
|
||||
EUR("欧元"),
|
||||
TWD("新台币"),
|
||||
KRW("韩元"),
|
||||
JPY("日元"),
|
||||
SGD("新加坡元"),
|
||||
AUD("澳大利亚元");
|
||||
/**
|
||||
* 货币类型
|
||||
* @return 货币类型
|
||||
* 币种名称
|
||||
*/
|
||||
String getCurType();
|
||||
private String name;
|
||||
//索引
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param name
|
||||
*/
|
||||
CurType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,19 +4,26 @@ import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.impl.client.BasicAuthCache;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.security.*;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -108,7 +115,7 @@ public class HttpRequestTemplate {
|
||||
//http代理地址设置
|
||||
httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
|
||||
|
||||
if (StringUtils.isNotBlank(configStorage.getHttpProxyHost())) {
|
||||
if (StringUtils.isBlank(configStorage.getHttpProxyUsername())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -164,6 +171,9 @@ public class HttpRequestTemplate {
|
||||
public <T> T postForObject(String uri, Object request, Class<T> responseType, Map<String, Object> uriVariables) {
|
||||
return doExecute(URI.create(UriVariables.getUri(uri, uriVariables)), request, responseType, MethodType.POST);
|
||||
}
|
||||
public <T> T postForObjectAndBasicAuth(String uri, Object request, Class<T> responseType, Object... uriVariables) {
|
||||
return doExecuteAndBasicAuth(URI.create(UriVariables.getUri(uri, uriVariables)), request, responseType, MethodType.POST);
|
||||
}
|
||||
|
||||
public <T> T postForObject(URI uri, Object request, Class<T> responseType){
|
||||
return doExecute(uri, request, responseType, MethodType.POST);
|
||||
@@ -233,6 +243,28 @@ public class HttpRequestTemplate {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* http 请求执行
|
||||
* @param uri 地址
|
||||
* @param request 请求数据
|
||||
* @param responseType 响应类型
|
||||
* @param method 请求方法
|
||||
* @param <T> 响应类型
|
||||
* @return 类型对象
|
||||
*/
|
||||
public <T>T doExecuteAndBasicAuth(URI uri, Object request, Class<T> responseType, MethodType method){
|
||||
ClientHttpRequest<T> httpRequest = new ClientHttpRequest(uri ,method, request);
|
||||
httpRequest.setProxy(httpProxy).setResponseType(responseType);
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpRequest,createBasicAuthContext(uri,"Huodull6190","12BkDT8152Zj"))) {
|
||||
return httpRequest.handleResponse(response);
|
||||
}catch ( IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
httpRequest.releaseConnection();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* http 请求执行
|
||||
* @param uri 地址
|
||||
@@ -246,6 +278,28 @@ public class HttpRequestTemplate {
|
||||
return doExecute(URI.create(uri), request, responseType, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Basic Auth
|
||||
* @param uri
|
||||
* @param username
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
private HttpClientContext createBasicAuthContext(URI uri,String username, String password) {
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
Credentials defaultCreds = new UsernamePasswordCredentials(username, password);
|
||||
credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), defaultCreds);
|
||||
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
BasicScheme basicAuth = new BasicScheme();
|
||||
HttpHost host = new HttpHost(uri.getHost(),uri.getPort(),"https");
|
||||
authCache.put(host, basicAuth);
|
||||
|
||||
HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
context.setAuthCache(authCache);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user