mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-06-02 22:12:43 +08:00
1.Payoneer 接口初步完成
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-ali</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -28,5 +28,5 @@ public interface AdvancedPayService extends PayService{
|
||||
* @param payOrder 订单信息
|
||||
* @return 返回请求结果
|
||||
*/
|
||||
Map<String ,Object> charge(String payeeId,PayOrder payOrder);
|
||||
Map<String ,Object> charges(String payeeId,PayOrder payOrder);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,26 @@
|
||||
package com.egzosn.pay.common.http;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
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.methods.HttpPost;
|
||||
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.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
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 org.apache.http.util.EntityUtils;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -115,9 +108,9 @@ public class HttpRequestTemplate {
|
||||
|
||||
if (StringUtils.isNotBlank(configStorage.getHttpProxyHost())) {
|
||||
|
||||
URI uri = URI.create(configStorage.getHttpProxyHost());
|
||||
// URI uri = URI.create(configStorage.getHttpProxyHost());
|
||||
//http代理地址设置
|
||||
httpProxy = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());;
|
||||
httpProxy = new HttpHost(configStorage.getHttpProxyHost(),configStorage.httpProxyPort);;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +121,7 @@ public class HttpRequestTemplate {
|
||||
// 需要用户认证的代理服务器
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(httpProxy.getHostName(), httpProxy.getPort()),
|
||||
AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword()));
|
||||
|
||||
|
||||
@@ -178,14 +171,15 @@ 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);
|
||||
}
|
||||
|
||||
public <T> T postForObject(String uri, Object request, List<Header> headeres, Class<T> responseType, Object... uriVariables){
|
||||
return doExecute(URI.create(UriVariables.getUri(uri, uriVariables)), request,headeres, responseType, MethodType.POST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -239,11 +233,28 @@ public class HttpRequestTemplate {
|
||||
*/
|
||||
public <T>T doExecute(URI uri, Object request, Class<T> responseType, MethodType method){
|
||||
ClientHttpRequest<T> httpRequest = new ClientHttpRequest(uri ,method, request);
|
||||
httpRequest.setProxy(httpProxy).setResponseType(responseType);
|
||||
|
||||
httpRequest.setResponseType(responseType);
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
|
||||
return httpRequest.handleResponse(response);
|
||||
}catch ( IOException e){
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
httpRequest.releaseConnection();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T>T doExecute(URI uri, Object request, List<Header> headers, Class<T> responseType, MethodType method){
|
||||
ClientHttpRequest<T> httpRequest = new ClientHttpRequest(uri ,method, request);
|
||||
httpRequest.setResponseType(responseType);
|
||||
if(headers != null){
|
||||
for(Header header : headers){
|
||||
httpRequest.addHeader(header);
|
||||
}
|
||||
}
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
|
||||
return httpRequest.handleResponse(response);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
httpRequest.releaseConnection();
|
||||
@@ -251,51 +262,6 @@ 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){
|
||||
//todo 研究研究
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(uri.getHost(), uri.getPort()),
|
||||
new UsernamePasswordCredentials("Huodull6190", "12BkDT8152Zj"));
|
||||
|
||||
CloseableHttpClient hc = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build();
|
||||
|
||||
// ClientHttpRequest<T> httpRequest = new ClientHttpRequest(uri ,method, request);
|
||||
// httpRequest.setProxy(httpProxy).setResponseType(responseType);
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
BasicScheme basicAuth = new BasicScheme();
|
||||
HttpHost host = new HttpHost(uri.getHost(),uri.getPort(),uri.getScheme());
|
||||
authCache.put(host, basicAuth);
|
||||
|
||||
HttpClientContext context = HttpClientContext.create();
|
||||
// context.setCredentialsProvider(credsProvider);
|
||||
context.setAuthCache(authCache);
|
||||
|
||||
HttpPost httpPost = new HttpPost(uri.toString());
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(request), ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
try (CloseableHttpResponse response = hc.execute(host,httpPost,context)) {
|
||||
|
||||
return (T)JSON.parseObject(EntityUtils.toString(response.getEntity()));
|
||||
}catch ( IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* http 请求执行
|
||||
* @param uri 地址
|
||||
@@ -308,30 +274,4 @@ public class HttpRequestTemplate {
|
||||
public <T>T doExecute(String uri, Object request, Class<T> responseType, MethodType method){
|
||||
return doExecute(URI.create(uri), request, responseType, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Basic Auth
|
||||
* @param uri
|
||||
// * @param username
|
||||
// * @param password
|
||||
* @return
|
||||
*/
|
||||
private HttpClientContext createBasicAuthContext(URI uri) {
|
||||
// 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(),uri.getScheme());
|
||||
authCache.put(host, basicAuth);
|
||||
|
||||
HttpClientContext context = HttpClientContext.create();
|
||||
// context.setCredentialsProvider(credsProvider);
|
||||
context.setAuthCache(authCache);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>war</packaging>
|
||||
|
||||
@@ -76,11 +76,11 @@ public class PayController {
|
||||
* @param payOrder 订单信息
|
||||
* @return 收款请求结果
|
||||
*/
|
||||
@RequestMapping("charge")
|
||||
public Map<String ,Object> charge(Integer payId,String payeeId,PayOrder payOrder){
|
||||
@RequestMapping("charges")
|
||||
public Map<String ,Object> charges(Integer payId,String payeeId,PayOrder payOrder){
|
||||
PayResponse payResponse = service.getPayResponse(payId);
|
||||
PayoneerPayService service = (PayoneerPayService) payResponse.getService();
|
||||
return service.charge(payeeId,payOrder);
|
||||
return service.charges(payeeId,payOrder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public class ApyAccountRepository {
|
||||
apyAccount5.setInputCharset("UTF-8");
|
||||
apyAccount5.setPayType(PayType.payoneer);
|
||||
apyAccount5.setMsgType(MsgType.json);
|
||||
apyAccount5.setTest(true);
|
||||
apyAccounts.put(apyAccount5.getPayId(), apyAccount5);
|
||||
}
|
||||
//_____________________________________________________________
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-fuiou</artifactId>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.egzosn.pay.common.http;
|
||||
package com.egzosn.pay.payoneer;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.http.HttpEntity;
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
import com.egzosn.pay.payoneer.bean.PayoneerRequestBean;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
@@ -32,14 +33,19 @@ import java.net.URI;
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
URI uri = URI.create("https://api.sandbox.payoneer.com/v2/programs/100086190/payees/login-link");
|
||||
// URI uri = URI.create("https://api.sandbox.payoneer.com/v2/programs/100086190/payees/registration-link");
|
||||
URI uri = URI.create("https://api.sandbox.payoneer.com/v2/programs/100086190/charges");
|
||||
HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
|
||||
HttpPost httpPost = new HttpPost(uri.toString());
|
||||
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(target.getHostName(), target.getPort()),
|
||||
new AuthScope(uri.getHost(), uri.getPort()),
|
||||
new UsernamePasswordCredentials("Huodull6190", "12BkDT8152Zj"));
|
||||
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build();
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
try {
|
||||
|
||||
// Create AuthCache instance
|
||||
@@ -51,14 +57,20 @@ public class Test {
|
||||
|
||||
// Add AuthCache to the execution context
|
||||
HttpClientContext localContext = HttpClientContext.create();
|
||||
// localContext.setCredentialsProvider(credsProvider);
|
||||
localContext.setAuthCache(authCache);
|
||||
|
||||
HttpPost httpPost = new HttpPost("https://api.sandbox.payoneer.com/v2/programs/100086190/payees/login-link");
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(Pay), ContentType.APPLICATION_JSON);
|
||||
// BasicHttpContext localContext = new BasicHttpContext();
|
||||
// localContext.setAttribute(ClientContext.AUTH_CACHE,authCache);
|
||||
|
||||
// PayoneerRequestBean bean = new PayoneerRequestBean("666");
|
||||
PayoneerRequestBean bean = new PayoneerRequestBean("6666","1","566002", CurType.USD,"66");
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(bean), ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
|
||||
httpPost.setEntity();
|
||||
System.out.println("Executing request " + httpPost.getRequestLine() + " to target " + target);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
CloseableHttpResponse response = httpclient.execute(target, httpPost, localContext);
|
||||
try {
|
||||
System.out.println("----------------------------------------");
|
||||
|
||||
@@ -106,8 +106,8 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
|
||||
* @return 返回请求结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String ,Object> charge(String payeeId,PayOrder payOrder){
|
||||
PayoneerRequestBean params = new PayoneerRequestBean(payeeId,payOrder.getPrice(),payOrder.getOutTradeNo(),payOrder.getCurType(),payOrder.getBody());
|
||||
public Map<String ,Object> charges(String payeeId,PayOrder payOrder){
|
||||
PayoneerRequestBean params = new PayoneerRequestBean(payeeId,payOrder.getPrice().toString(),payOrder.getOutTradeNo(),payOrder.getCurType(),payOrder.getBody());
|
||||
JSONObject response = getHttpRequestTemplate().postForObject(getUrlChargesLink(),params,JSONObject.class);
|
||||
if(response != null && "0".equals(response.getString("code"))){
|
||||
return response;
|
||||
@@ -429,22 +429,22 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
|
||||
}
|
||||
|
||||
public String getUrlLoginLink() {
|
||||
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlLoginLink:RELEASE_DOMAIN+urlLoginLink;
|
||||
return (payConfigStorage.isTest()?SANDBOX_DOMAIN:RELEASE_DOMAIN)+urlLoginLink;
|
||||
}
|
||||
|
||||
public String getUrlRegistrationLink() {
|
||||
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlRegistrationLink:RELEASE_DOMAIN+urlRegistrationLink;
|
||||
return (payConfigStorage.isTest()?SANDBOX_DOMAIN:RELEASE_DOMAIN)+urlRegistrationLink;
|
||||
}
|
||||
|
||||
public String getUrlChargesLink() {
|
||||
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlChargesLink:RELEASE_DOMAIN+urlChargesLink;
|
||||
return (payConfigStorage.isTest()?SANDBOX_DOMAIN:RELEASE_DOMAIN)+urlChargesLink;
|
||||
}
|
||||
|
||||
public String getUrlCancelChargesLink() {
|
||||
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlCancelChargesLink:RELEASE_DOMAIN+urlCancelChargesLink;
|
||||
return (payConfigStorage.isTest()?SANDBOX_DOMAIN:RELEASE_DOMAIN)+urlCancelChargesLink;
|
||||
}
|
||||
|
||||
public String getUrlStatusLink() {
|
||||
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlStatusLink:RELEASE_DOMAIN+urlStatusLink;
|
||||
return (payConfigStorage.isTest()?SANDBOX_DOMAIN:RELEASE_DOMAIN)+urlStatusLink;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.egzosn.pay.payoneer.bean;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Fuzx
|
||||
* @create 2018 2018/1/22 0022
|
||||
@@ -14,7 +12,10 @@ public class PayoneerRequestBean {
|
||||
|
||||
}
|
||||
|
||||
public PayoneerRequestBean(String payeeId, BigDecimal amount, String clientReferenceId, CurType currency, String description) {
|
||||
public PayoneerRequestBean(String payeeId) {
|
||||
this.payeeId = payeeId;
|
||||
}
|
||||
public PayoneerRequestBean(String payeeId, String amount, String clientReferenceId, CurType currency, String description) {
|
||||
this.payeeId = payeeId;
|
||||
this.amount = amount;
|
||||
this.clientReferenceId = clientReferenceId;
|
||||
@@ -30,7 +31,7 @@ public class PayoneerRequestBean {
|
||||
/**
|
||||
* 收款金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
private String amount;
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
@@ -53,11 +54,11 @@ public class PayoneerRequestBean {
|
||||
this.payeeId = payeeId;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
public String getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
public void setAmount(String amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx-youdian</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>pay-java-parent</artifactId>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<version>2.0.6</version>
|
||||
<version>2.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>pay-java-wx</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user