...
|
...
|
@@ -5,14 +5,22 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.yohobuy.ufo.model.order.bo.OrderInfo;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.RSAUtils;
|
|
|
import com.yohoufo.common.utils.XMLUtil;
|
|
|
import com.yohoufo.order.config.AlipayConfig;
|
|
|
import com.yohoufo.order.constants.RefundContant;
|
|
|
import com.yohoufo.order.model.PayQueryBo;
|
|
|
import com.yohoufo.order.model.PayRefundBo;
|
|
|
import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryResponse;
|
|
|
import com.yohoufo.order.service.pay.alipay.bean.AlipayRefundResponse;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.client.utils.DateUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
...
|
...
|
@@ -51,7 +59,6 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract { |
|
|
return "zfbgj@yoho.cn";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* OpenApi退款
|
|
|
* @param refundBo
|
...
|
...
|
@@ -60,13 +67,30 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract { |
|
|
public PayRefundBo refundOpenApi(PayRefundBo refundBo) {
|
|
|
logger.info("enter AliPayRefunder to refund tradeNo {}, amount {}", refundBo.getRefundOrderCode(), refundBo.getAmount());
|
|
|
Map<String, String> refundParams = buildOpenApiRefundParams(refundBo.getPayOrderCode(), refundBo.getRefundOrderCode(), refundBo.getAmount());
|
|
|
String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, AlipayConfig.OPENAPI_URL);
|
|
|
String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, AlipayConfig.CROSS_BORDER_OPENAPI_URL);
|
|
|
|
|
|
PayRefundBo bo = refundOpenApiConvert(respTxt, refundBo);
|
|
|
logger.info("exit AliPayRefunder refund, refundStatus: {}, refundMsg", bo.getRefundStatus(), bo.getRefundMsg());
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
|
|
|
public PayRefundBo refundOpenApiConvert(String respText, PayRefundBo bo) {
|
|
|
AlipayRefundResponse refundResponse = (AlipayRefundResponse)XMLUtil.convertXmlStrToObject(AlipayRefundResponse.class, respText);
|
|
|
|
|
|
if ("T".equalsIgnoreCase(refundResponse.getIs_success())){
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS);
|
|
|
bo.setRefundMsg("退款申请成功");
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
bo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_FAIL);
|
|
|
bo.setRefundMsg(refundResponse.getError());
|
|
|
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* openapi退款参数
|
|
|
* @param tradeNo
|
...
|
...
|
@@ -86,21 +110,8 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract { |
|
|
params.put("out_trade_no", tradeNo);
|
|
|
params.put("return_rmb_amount", String.valueOf(amount));
|
|
|
params.put("currency", "HKD");
|
|
|
|
|
|
|
|
|
|
|
|
params.put("app_id", getAppId());
|
|
|
params.put("method", "alipay.trade.refund");
|
|
|
params.put("charset", AlipayConfig.input_charset);
|
|
|
params.put("sign_type", "RSA");
|
|
|
params.put("timestamp", DateUtil.getCurrentTime());
|
|
|
params.put("version", "1.0");
|
|
|
|
|
|
JSONObject bizJson = new JSONObject();
|
|
|
bizJson.put("out_trade_no", tradeNo);
|
|
|
bizJson.put("refund_amount", amount);
|
|
|
bizJson.put("out_request_no", refundNo);
|
|
|
params.put("biz_content", bizJson.toJSONString());
|
|
|
params.put("gmt_return", DateUtil.formatDate(DateUtil.getCurrentTimeSecond(), DateUtil.yyyyMMddHHmmss));
|
|
|
params.put("product_code", "NEW_WAP_OVERSEAS_SELLER");
|
|
|
|
|
|
String preSignStr = getOpenApiSignString(params, true);
|
|
|
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
|
...
|
...
|
@@ -115,37 +126,22 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract { |
|
|
* @return
|
|
|
*/
|
|
|
public PayQueryBo payQuery(String tradeNo, int orderCreateTime) {
|
|
|
// TODO 临时吃掉异常,否则无法取消
|
|
|
try{
|
|
|
Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo);
|
|
|
String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.CROSS_BORDER_OPENAPI_URL);
|
|
|
QueryBo queryBo = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respTxt).getJSONObject("alipay_trade_query_response")), QueryBo.class);
|
|
|
|
|
|
// 查询结果转换成 共通的对象
|
|
|
PayQueryBo payQueryBo = new PayQueryBo();
|
|
|
|
|
|
if ("10000".equals(queryBo.getCode())){
|
|
|
// 订单支付时的商户号
|
|
|
payQueryBo.setPayOrderCode(queryBo.getOut_trade_no());
|
|
|
payQueryBo.setTradeNo(queryBo.getTrade_no());
|
|
|
|
|
|
if ("TRADE_SUCCESS".equals(queryBo.getTrade_status())) {
|
|
|
payQueryBo.setPayStatus(true);
|
|
|
|
|
|
}else if("TRADE_CLOSED".equals(queryBo.getTrade_status())){
|
|
|
payQueryBo.setRefundStatus(true);
|
|
|
}
|
|
|
|
|
|
payQueryBo.setAmount(Double.parseDouble(queryBo.getTotal_amount()));
|
|
|
payQueryBo.setBuyerId(queryBo.getBuyer_user_id());
|
|
|
}
|
|
|
|
|
|
return payQueryBo;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo);
|
|
|
String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.CROSS_BORDER_OPENAPI_URL);
|
|
|
|
|
|
AlipayQueryResponse alipayQueryResponse = (AlipayQueryResponse) XMLUtil.convertXmlStrToObject(AlipayQueryResponse.class, respTxt);
|
|
|
|
|
|
PayQueryBo payQueryBo = new PayQueryBo();
|
|
|
if ("T".equalsIgnoreCase(alipayQueryResponse.getIs_success())){
|
|
|
AlipayQueryResponse.Trade trade =alipayQueryResponse.getResponse().getTrade();
|
|
|
payQueryBo.setPayOrderCode(trade.getOut_trade_no());
|
|
|
payQueryBo.setTradeNo(trade.getTrade_no());
|
|
|
payQueryBo.setPayStatus(true);
|
|
|
payQueryBo.setAmount(Double.parseDouble(trade.getTotal_fee()));
|
|
|
payQueryBo.setBuyerId(trade.getBuyer_id());
|
|
|
}
|
|
|
|
|
|
return new PayQueryBo();
|
|
|
return payQueryBo;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|