mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-07 19:46:15 +08:00
APP接口实现
This commit is contained in:
@@ -125,7 +125,6 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
* @param characterEncoding 字符编码
|
||||
* @return 签名
|
||||
*/
|
||||
@Override
|
||||
public String createSign(Map<String, Object> content, String characterEncoding) {
|
||||
return SignUtils.valueOf(payConfigStorage.getSignType()).sign(content, payConfigStorage.getKeyPrivate(), characterEncoding);
|
||||
}
|
||||
@@ -141,6 +140,16 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
Map orderInfo = orderInfo(order);
|
||||
return buildRequest(orderInfo, MethodType.POST);
|
||||
}
|
||||
/**
|
||||
* app支付
|
||||
* @param order 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @return 对应app所需参数信息
|
||||
*/
|
||||
@Override
|
||||
public <O extends PayOrder> Map<String, Object> app(O order) {
|
||||
return orderInfo(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码支付
|
||||
|
||||
@@ -98,6 +98,13 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
* @return 对应页面重定向信息
|
||||
*/
|
||||
<O extends PayOrder>String toPay(O order);
|
||||
/**
|
||||
* app支付
|
||||
* @param order 订单信息
|
||||
* @param <O> 预订单类型
|
||||
* @return 对应app所需参数信息
|
||||
*/
|
||||
<O extends PayOrder>Map<String, Object> app(O order);
|
||||
|
||||
/**
|
||||
* 创建签名
|
||||
@@ -108,14 +115,7 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
*/
|
||||
String createSign(String content, String characterEncoding);
|
||||
|
||||
/**
|
||||
* 创建签名
|
||||
*
|
||||
* @param content 需要签名的内容
|
||||
* @param characterEncoding 字符编码
|
||||
* @return 签名
|
||||
*/
|
||||
String createSign(Map<String, Object> content, String characterEncoding);
|
||||
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AliPayController {
|
||||
PayOrder order = new PayOrder("订单title", "摘要", new BigDecimal(0.01), UUID.randomUUID().toString().replace("-", ""));
|
||||
//App支付
|
||||
order.setTransactionType(AliTransactionType.APP);
|
||||
data.put("orderInfo", UriVariables.getMapToParameters(service.orderInfo(order)));
|
||||
data.put("orderInfo", UriVariables.getMapToParameters(service.app(order)));
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ public class WxPayController {
|
||||
PayOrder order = new PayOrder("订单title", "摘要", new BigDecimal(0.01), UUID.randomUUID().toString().replace("-", ""));
|
||||
//App支付
|
||||
order.setTransactionType(WxTransactionType.APP);
|
||||
data.put("orderInfo", service.orderInfo(order));
|
||||
data.put("orderInfo", service.app(order));
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
@@ -359,21 +362,35 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
|
||||
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) builder.build(pkixParams);
|
||||
/*PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult)*/ builder.build(pkixParams);
|
||||
return cert;
|
||||
} catch (java.security.cert.CertPathBuilderException e) {
|
||||
LOG.error("verify certificate chain fail.", e);
|
||||
} catch (CertificateExpiredException e) {
|
||||
LOG.error(e);
|
||||
} catch (CertificateNotYetValidException e) {
|
||||
LOG.error(e);
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送订单
|
||||
*
|
||||
* @param order 发起支付的订单信息
|
||||
* @return 返回支付结果
|
||||
*/
|
||||
|
||||
public JSONObject postOrder(PayOrder order) {
|
||||
Map<String, Object> params = orderInfo(order);
|
||||
String responseStr = getHttpRequestTemplate().postForObject(this.getBackTransUrl(), params, String.class);
|
||||
JSONObject response = UriVariables.getParametersToMap(responseStr);
|
||||
if (response.isEmpty()) {
|
||||
throw new PayErrorException(new PayException("failure", "响应内容有误!", responseStr));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPay(PayOrder order) {
|
||||
|
||||
@@ -395,20 +412,15 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
@Override
|
||||
public String getQrPay(PayOrder order) {
|
||||
order.setTransactionType(UnionTransactionType.APPLY_QR_CODE);
|
||||
Map<String, Object> params = orderInfo(order);
|
||||
String responseStr = getHttpRequestTemplate().postForObject(this.getBackTransUrl(), params, String.class);
|
||||
Map<String, Object> response = UriVariables.getParametersToMap(responseStr);
|
||||
if (response.isEmpty()) {
|
||||
throw new PayErrorException(new PayException("failure", "响应内容有误!", responseStr));
|
||||
}
|
||||
JSONObject response = postOrder(order);
|
||||
if (this.verify(response)) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
//成功
|
||||
return (String) response.get(SDKConstants.param_qrCode);
|
||||
}
|
||||
throw new PayErrorException(new PayException((String) response.get(SDKConstants.param_respCode), (String) response.get(SDKConstants.param_respMsg), responseStr));
|
||||
throw new PayErrorException(new PayException((String) response.get(SDKConstants.param_respCode), (String) response.get(SDKConstants.param_respMsg), response.toJSONString()));
|
||||
}
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", responseStr));
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,9 +432,8 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
@Override
|
||||
public Map<String, Object> microPay(PayOrder order) {
|
||||
order.setTransactionType(UnionTransactionType.CONSUME);
|
||||
Map<String, Object> params = orderInfo(order);
|
||||
String responseStr = getHttpRequestTemplate().postForObject(this.getBackTransUrl(), params, String.class);
|
||||
return UriVariables.getParametersToMap(responseStr);
|
||||
JSONObject response = postOrder(order);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -499,17 +510,14 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
|
||||
/**
|
||||
* 功能:将订单信息进行签名并提交请求
|
||||
* 业务范围:手机控件支付产品(WAP),
|
||||
* 业务范围:手机支付控件(含安卓Pay)
|
||||
* @param order 订单信息
|
||||
* @return 成功:返回支付结果 失败:返回
|
||||
*/
|
||||
public Map<String ,Object> sendHttpRequest(PayOrder order){
|
||||
Map<String, Object> params = orderInfo(order);
|
||||
String responseStr = getHttpRequestTemplate().postForObject(this.getBackTransUrl(), params, String.class);
|
||||
Map<String, Object> response = UriVariables.getParametersToMap(responseStr);
|
||||
if (response.isEmpty()) {
|
||||
throw new PayErrorException(new PayException("failure", "响应内容有误!", responseStr));
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> app(PayOrder order){
|
||||
order.setTransactionType(UnionTransactionType.APP);
|
||||
JSONObject response = postOrder(order);
|
||||
if (this.verify(response)) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
// //成功,获取tn号
|
||||
@@ -517,9 +525,9 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
// //TODO
|
||||
return response;
|
||||
}
|
||||
throw new PayErrorException(new PayException((String) response.get(SDKConstants.param_respCode), (String) response.get(SDKConstants.param_respMsg), responseStr));
|
||||
throw new PayErrorException(new PayException((String) response.get(SDKConstants.param_respCode), (String) response.get(SDKConstants.param_respMsg), response.toJSONString()));
|
||||
}
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", responseStr));
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user