mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-06-02 05:50:29 +08:00
Payoneer 支付
This commit is contained in:
@@ -1,6 +1,25 @@
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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;
|
||||
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.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.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -12,8 +31,60 @@ import com.egzosn.pay.payoneer.bean.PayoneerRequestBean;
|
||||
*/
|
||||
public class PayTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
// URI uri = URI.create("https://api.sandbox.payoneer.com/v2/programs/100086190/payees/registration-link");
|
||||
// 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(uri.getHost(), uri.getPort()),
|
||||
new UsernamePasswordCredentials("Huodull6190", "12BkDT8152Zj"));
|
||||
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
try {
|
||||
|
||||
// Create AuthCache instance
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
// Generate BASIC scheme object and add it to the local
|
||||
// auth cache
|
||||
BasicScheme basicAuth = new BasicScheme();
|
||||
authCache.put(target, basicAuth);
|
||||
|
||||
// Add AuthCache to the execution context
|
||||
HttpClientContext localContext = HttpClientContext.create();
|
||||
// localContext.setCredentialsProvider(credsProvider);
|
||||
localContext.setAuthCache(authCache);
|
||||
|
||||
// BasicHttpContext localContext = new BasicHttpContext();
|
||||
// localContext.setAttribute(ClientContext.AUTH_CACHE,authCache);
|
||||
|
||||
// PayoneerRequestBean bean = new PayoneerRequestBean("666");
|
||||
PayoneerRequestBean bean = new PayoneerRequestBean("asdfg11213","1.01", UUID.randomUUID().toString().replace("-", ""), CurType.USD,"huodull order");
|
||||
// PayoneerRequestBean bean = JSON.parseObject("{\"amount\":\"1.00\",\"client_reference_id\":\""+ System.nanoTime()+"\",\"currency\":\"USD\",\"description\":\"aaabb\",\"payee_id\":\"asdfg13\"}", PayoneerRequestBean.class);
|
||||
System.out.println(JSON.toJSONString(bean));
|
||||
StringEntity entity = new StringEntity(JSON.toJSONString(bean), ContentType.APPLICATION_JSON);
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
|
||||
System.out.println("Executing request " + httpPost.getRequestLine() + " to target " + target);
|
||||
for (int i = 0; i < 1; i++) {
|
||||
CloseableHttpResponse response = httpclient.execute(target, httpPost, localContext);
|
||||
try {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
System.out.println(EntityUtils.toString(response.getEntity()));
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
89
pay-java-payoneer/test/java/PayoneerRequestBean.java
Normal file
89
pay-java-payoneer/test/java/PayoneerRequestBean.java
Normal file
@@ -0,0 +1,89 @@
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
|
||||
/**
|
||||
* @author Fuzx
|
||||
* @create 2018 2018/1/22 0022
|
||||
*/
|
||||
public class PayoneerRequestBean {
|
||||
public PayoneerRequestBean() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
if (null == currency){
|
||||
currency = CurType.USD;
|
||||
}
|
||||
this.currency = currency;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收款id
|
||||
*/
|
||||
@JSONField(name="payee_id")
|
||||
private String payeeId;
|
||||
/**
|
||||
* 收款金额
|
||||
*/
|
||||
private String 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 String getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(String 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user