临时提交

This commit is contained in:
Fuzx
2018-01-22 16:52:34 +08:00
parent 5c02c55248
commit 8b833cf591
12 changed files with 204 additions and 105 deletions

View File

@@ -1,6 +1,9 @@
package com.egzosn.pay.common.api;
import com.egzosn.pay.common.bean.AuthPageType;
import com.egzosn.pay.common.bean.PayOrder;
import java.util.Map;
/**
* 高级支付接口
@@ -19,4 +22,11 @@ public interface AdvancedPayService extends PayService{
*/
String getAuthorizationPage(String payeeId,AuthPageType authPageType);
/**
* 发起授权
* @param payeeId 收款id
* @param payOrder 订单信息
* @return 返回请求结果
*/
Map<String ,Object> charge(String payeeId,PayOrder payOrder);
}

View File

@@ -4,16 +4,11 @@ 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;
@@ -171,9 +166,6 @@ 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);
@@ -243,27 +235,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){
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 请求执行
@@ -278,29 +249,4 @@ 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;
}
}

View File

@@ -21,17 +21,22 @@
<dependencies>
<!--支付-->
<dependency>
<groupId>com.egzosn</groupId>
<artifactId>pay-java-payoneer</artifactId>
<version>${pay.version}</version>
</dependency>
<dependency>
<groupId>com.egzosn</groupId>
<artifactId>pay-java-wx</artifactId>
<version>${pay.version}</version>
</dependency>
<dependency>
<groupId>com.egzosn</groupId>
<artifactId>pay-java-ali</artifactId>
<version>${pay.version}</version>
</dependency>
<dependency>
<groupId>com.egzosn</groupId>
<artifactId>pay-java-wx-youdian</artifactId>

View File

@@ -13,6 +13,7 @@ import com.egzosn.pay.demo.entity.PayType;
import com.egzosn.pay.demo.request.QueryOrder;
import com.egzosn.pay.demo.service.ApyAccountService;
import com.egzosn.pay.demo.service.PayResponse;
import com.egzosn.pay.payoneer.api.PayoneerPayService;
import com.egzosn.pay.wx.bean.WxTransactionType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -26,6 +27,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
@@ -50,6 +52,38 @@ public class PayController {
return new ModelAndView("/index.html");
}
/**
* 获取授权页面
* @param payId
* @param payeeId
* @param authPageType
* @return
*/
@RequestMapping("getAuthorizationPage.json")
public Map<String ,Object> getAuthorizationPage(Integer payId,String payeeId,AuthPageType authPageType ){
PayResponse payResponse = service.getPayResponse(payId);
PayoneerPayService payoneerPayService = (PayoneerPayService) payResponse.getService();
Map<String, Object> data = new LinkedHashMap<>();
data.put("code", 0);
data.put("url", payoneerPayService.getAuthorizationPage(payeeId,authPageType));
return data;
}
/**
* 发起收款申请
* @param payId 账户id
* @param payeeId 授权id(收款id)
* @param payOrder 订单信息
* @return 收款请求结果
*/
@RequestMapping("charge")
public Map<String ,Object> charge(Integer payId,String payeeId,PayOrder payOrder){
PayResponse payResponse = service.getPayResponse(payId);
PayoneerPayService service = (PayoneerPayService) payResponse.getService();
return service.charge(payeeId,payOrder);
}
/**
* 这里模拟账户信息增加
*

View File

@@ -99,6 +99,15 @@ public class ApyAccountRepository {
apyAccount4.setTest(true);
apyAccounts.put(apyAccount4.getPayId(), apyAccount4);
ApyAccount apyAccount5 = new ApyAccount();
apyAccount5.setPayId(5);
apyAccount5.setPartner("100086190");//Program ID
apyAccount5.setSeller("Huodull6190");//Username
apyAccount5.setStorePassword("12BkDT8152Zj");//API password
apyAccount5.setInputCharset("UTF-8");
apyAccount5.setPayType(PayType.payoneer);
apyAccount5.setMsgType(MsgType.json);
apyAccounts.put(apyAccount5.getPayId(), apyAccount5);
}
//_____________________________________________________________

View File

@@ -6,6 +6,7 @@ import com.egzosn.pay.ali.bean.AliTransactionType;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.BasePayType;
import com.egzosn.pay.common.bean.TransactionType;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.fuiou.api.FuiouPayConfigStorage;
import com.egzosn.pay.fuiou.api.FuiouPayService;
import com.egzosn.pay.fuiou.bean.FuiouTransactionType;
@@ -178,8 +179,6 @@ public enum PayType implements BasePayType {
public PayService getPayService(ApyAccount apyAccount) {
PayoneerConfigStorage payoneerConfigStorage = new PayoneerConfigStorage();
payoneerConfigStorage.setProgramId(apyAccount.getPartner());
payoneerConfigStorage.setApiUserName(apyAccount.getSeller());
payoneerConfigStorage.setApiPassword(apyAccount.getStorePassword());
payoneerConfigStorage.setKeyPublic(apyAccount.getPublicKey());
payoneerConfigStorage.setKeyPrivate(apyAccount.getPrivateKey());
payoneerConfigStorage.setNotifyUrl(apyAccount.getNotifyUrl());
@@ -189,7 +188,12 @@ public enum PayType implements BasePayType {
payoneerConfigStorage.setMsgType(apyAccount.getMsgType());
payoneerConfigStorage.setInputCharset(apyAccount.getInputCharset());
payoneerConfigStorage.setTest(apyAccount.isTest());
return new PayoneerPayService(payoneerConfigStorage);
//Basic Auth
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
httpConfigStorage.setHttpProxyUsername(apyAccount.getSeller());
httpConfigStorage.setHttpProxyPassword(apyAccount.getStorePassword());
return new PayoneerPayService(payoneerConfigStorage,httpConfigStorage);
}
@Override

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>pay-java-parent</artifactId>
<groupId>com.egzosn</groupId>
<version>2.0.6-SNAPSHOT</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pay-java-payoneer</artifactId>

View File

@@ -12,16 +12,6 @@ public class PayoneerConfigStorage extends BasePayConfigStorage {
* 商户Id
*/
public String programId;
/**
* Api用户名
*/
public String apiUserName;
/**
* api密码
*/
public String apiPassword;
/**
* 应用id
@@ -55,19 +45,4 @@ public class PayoneerConfigStorage extends BasePayConfigStorage {
this.programId = programId;
}
public String getApiUserName() {
return apiUserName;
}
public void setApiUserName(String apiUserName) {
this.apiUserName = apiUserName;
}
public String getApiPassword() {
return apiPassword;
}
public void setApiPassword(String apiPassword) {
this.apiPassword = apiPassword;
}
}

View File

@@ -6,9 +6,11 @@ import com.egzosn.pay.common.api.BasePayService;
import com.egzosn.pay.common.api.Callback;
import com.egzosn.pay.common.api.PayConfigStorage;
import com.egzosn.pay.common.bean.*;
import com.egzosn.pay.common.bean.outbuilder.PayTextOutMessage;
import com.egzosn.pay.common.bean.result.PayException;
import com.egzosn.pay.common.exception.PayErrorException;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.payoneer.bean.PayoneerRequestBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -17,7 +19,6 @@ import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
/**
* @descrption payoneer业务逻辑
@@ -44,31 +45,31 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
* 授权登录url
* https://api.sandbox.payoneer.com/v2/programs/{Program_Id}/payees/login-link
*/
public String URL_LOGIN_LINK = payConfigStorage.getPid()+"/payees/login-link";
public String urlLoginLink = payConfigStorage.getPid()+"/payees/login-link";
/**
* 授权注册url
* https://api.sandbox.payoneer.com/v2/programs/{Program_Id}/payees/registration-link
*/
public String URL_REGISTRATION_LINK = payConfigStorage.getPid()+"/payees/registration-link";
public String urlRegistrationLink = payConfigStorage.getPid()+"/payees/registration-link";
/**
* 收款url
* https://api.sandbox.payoneer.com/v2/programs/{Program_Id}/charges
*/
public String URL_CHARGES_LINK = payConfigStorage.getPid()+"/charges";
public String urlChargesLink = payConfigStorage.getPid()+"/charges";
/**
* 取消收款url
* https://api.sandbox.payoneer.com/v2/programs/{Program_Id}/charges/{client_reference_id}/cancel
*/
public String URL_CANCEL_CHARGES_LINK = payConfigStorage.getPid()+"/charges/%s/cancel";
public String urlCancelChargesLink = payConfigStorage.getPid()+"/charges/%s/cancel";
/**
* 查看收款状态
* https://api.sandbox.payoneer.com/v2/programs/{Program_Id}/charges/{client_reference_id}/status
*/
public String URL_STATUS_LINK = payConfigStorage.getPid()+"/charges/%s/status";
public String urlStatusLink = payConfigStorage.getPid()+"/charges/%s/status";
public PayoneerPayService(PayConfigStorage payConfigStorage) {
@@ -88,14 +89,30 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
*/
@Override
public String getAuthorizationPage(String payeeId, AuthPageType authPageType) {
Map<String ,Object> params = new TreeMap<>();
params.put("payee_id", payeeId);
JSONObject response = getHttpRequestTemplate().postForObject("login".equals(authPageType.name())?URL_LOGIN_LINK:URL_REGISTRATION_LINK,params,JSONObject.class);
if("0".equals(response.getString("code"))){
PayoneerRequestBean params = new PayoneerRequestBean();
params.setPayeeId(payeeId);
JSONObject response = getHttpRequestTemplate().postForObject("login".equals(authPageType.name())?getUrlLoginLink():getUrlRegistrationLink(),params,JSONObject.class);
if(response != null && "0".equals(response.getString("code"))){
return response.getString(authPageType.name()+"_link");
}
throw new PayErrorException(new PayException("failure", "Payoneer获取授权页面失败,原因:"+response.getString("hint"), response.toJSONString()));
throw new PayErrorException(new PayException("fail", "Payoneer获取授权页面失败,原因:"+response.getString("hint"), response.toJSONString()));
}
/**
* 发起授权
* @param payeeId 授权id(收款id)
* @param payOrder 订单信息
* @return 返回请求结果
*/
@Override
public Map<String ,Object> charge(String payeeId,PayOrder payOrder){
PayoneerRequestBean params = new PayoneerRequestBean(payeeId,payOrder.getPrice(),payOrder.getOutTradeNo(),payOrder.getCurType(),payOrder.getBody());
JSONObject response = getHttpRequestTemplate().postForObject(getUrlChargesLink(),params,JSONObject.class);
if(response != null && "0".equals(response.getString("code"))){
return response;
}
throw new PayErrorException(new PayException("fail", "Payoneer申请收款失败,原因:"+response.getString("hint"), response.toJSONString()));
}
/**
@@ -142,9 +159,6 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
*/
@Override
public Map<String, Object> orderInfo(PayOrder order) {
//todo 发起收款
return null;
}
@@ -194,7 +208,7 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
*/
@Override
public PayOutMessage getPayOutMessage(String code, String message) {
return null;
return PayTextOutMessage.TEXT().content(code.toLowerCase()).build();
}
/**
@@ -206,7 +220,7 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
*/
@Override
public PayOutMessage successPayOutMessage(PayMessage payMessage) {
return null;
return getPayOutMessage("ok", null);
}
/**
@@ -413,4 +427,24 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer
public <T> T secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType, Callback<T> callback) {
return null;
}
public String getUrlLoginLink() {
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlLoginLink:RELEASE_DOMAIN+urlLoginLink;
}
public String getUrlRegistrationLink() {
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlRegistrationLink:RELEASE_DOMAIN+urlRegistrationLink;
}
public String getUrlChargesLink() {
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlChargesLink:RELEASE_DOMAIN+urlChargesLink;
}
public String getUrlCancelChargesLink() {
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlCancelChargesLink:RELEASE_DOMAIN+urlCancelChargesLink;
}
public String getUrlStatusLink() {
return payConfigStorage.isTest()?SANDBOX_DOMAIN+urlStatusLink:RELEASE_DOMAIN+urlStatusLink;
}
}

View File

@@ -1,8 +1,87 @@
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
*/
public class RequestBean {
public class PayoneerRequestBean {
public PayoneerRequestBean() {
}
public PayoneerRequestBean(String payeeId, BigDecimal amount, String clientReferenceId, CurType currency, String description) {
this.payeeId = payeeId;
this.amount = amount;
this.clientReferenceId = clientReferenceId;
this.currency = currency;
this.description = description;
}
/**
* 收款id
*/
@JSONField(name="payee_id")
private String payeeId;
/**
* 收款金额
*/
private BigDecimal amount;
/**
* 订单id
*/
@JSONField(name="client_reference_id")
private String clientReferenceId;
/**
* 币种
*/
private CurType currency;
/**
* 订单详情 (选填)
*/
private String description;
public String getPayeeId() {
return payeeId;
}
public void setPayeeId(String payeeId) {
this.payeeId = payeeId;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getClientReferenceId() {
return clientReferenceId;
}
public void setClientReferenceId(String clientReferenceId) {
this.clientReferenceId = clientReferenceId;
}
public CurType getCurrency() {
return currency;
}
public void setCurrency(CurType currency) {
this.currency = currency;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@@ -1,3 +1,7 @@
import com.alibaba.fastjson.JSON;
import com.egzosn.pay.common.bean.CurType;
import com.egzosn.pay.payoneer.bean.PayoneerRequestBean;
/**
*
*
@@ -8,10 +12,8 @@
*/
public class PayTest {
public static void main(String[] args) {
public static void main(String[] args) {
}
}

View File

@@ -45,11 +45,12 @@
<module>pay-java-fuiou</module>
<module>pay-java-union</module>
<module>pay-java-demo</module>
<module>pay-java-payoneer</module>
</modules>
<properties>
<pay.version>2.0.6-SNAPSHOT</pay.version>
<pay.version>2.0.7-SNAPSHOT</pay.version>
<httpmime.version>4.5.4</httpmime.version>
<log4j.version>1.2.17</log4j.version>
<fastjson.version>1.2.41</fastjson.version>