Fixing .gitignore
This commit is contained in:
@@ -1,80 +1,80 @@
|
||||
package com.peanut.modules.pay.alipay.config;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
|
||||
/**
|
||||
* 支付宝开放平台常量
|
||||
*/
|
||||
public class AliPayConfig {
|
||||
|
||||
/**
|
||||
* 花生appId 沙箱id 2021002161620176
|
||||
*/
|
||||
public static final String HS_APP_ID ="2021003191621137";
|
||||
|
||||
/**
|
||||
* 花生应用私钥
|
||||
*/
|
||||
public static final String HS_MERCHANT_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCa+oIVGBAKp+VjHIeE/IFUFWifnUWQYBPwffWEC5+EKJbqEC/wcVSfZPKXpPAB3T0c6V6yxCOMxguUZEdeRM5W93Wf0jktrtius34Xo79vgnLXsj2TtAN1ku9Qp5ebVVw+WPdpIl1nOFNwCoiaSPmwXOsVIT5MccxUvmGUDNUg8dYVoD9WHYu13O30c4vm+jYGCu7lviRqcjnEFooJ/ORocLqJbHFaTzWMGiiAYnUUSTL1BI5vhDNJDhm3B5wUZ7/j49EWQYZbV0fXlCrZRerfPLrAgXYR95P+62K9Xh8edzThTrPXmLXP9/jTqz2118ijXSoF8EgfhVD2NLCSDid3AgMBAAECggEAR3cPN0TyWMeVer+0Knn59Vkt9rSiWHJFn5el+K8Xbuz8spCmWp0YJax6Rb10Q5fOz5854PubXRYSTupzEqBt+iKApiNd5JgFKYJxudrzsysXZCm4RX00PypzmuC9g464S7Pg2yVSpv+NUlQ5K9RM96vRZ9v9i2jKjaWA/7FvMpI3auOJgrJVoSbPYNx6/QIN1b9imukCMSga9OzF66LhfzACWxJx+DzgAX+7GcfhTF8PbhytPPg9LhlfcGq2gA/TcG6zUorFz5Qy+k//g4rxIvjcPnGfcRgoT+Xgi7I8wnm3O5icIZ6k6+B+wwN3zRTBSmXwbwsgdncGA1RUhe2tAQKBgQDweYu2ij8Io/g7KCvCtVpGHqhzKxgaOZXy0nvPFXY5KFcrrapACriztCaxjvRTXm7t25KJQazICs50OvyTZL5+U3GHp/8GK7KwzZKz5NkHHMtKoKwQADBNau/nHdro4E+PnvL9ucaFX69JF4DZqiw2aDkQkDB/BablHyvuTagJgQKBgQCk++uzero6bXOxFMadLLyWTvlOJP71U1fVSf4Nou+L4ce7k2bMpSDyEDNDOUW3WOO7zz9i8mFGCTUaoX3mhC+B9UQqKZXK2rjFgZtkNDumoCTzvjuPIWTMNN6ABetiLxbq/UD0O1xwThVQNmYwTOzwMHUMkT21ynD23KXE0JL89wKBgGg1Q8YmwooMBFYeYlhOHoCkaHsAAcHbko9Xhy+GLWU3hg73gv+dpcy6FMp9GIPIOGn67NVuEGHfzPexWCLHVYWIw3n14x3ZceYML7alRSc/4xjD58xHSKdD4BJXbbXc/p1OVB5/kvfZLyyNctjgVah+Ibx7v4hL+rbveyoZnOgBAoGAG34je+giqmPc2JB2vHBdCMsmPkBqACWgSFmpLUqOkofQSdC5W7bUs6HBeR1NIc19Pam+jVWIoiwcnlB083nplMVzU3dUj9Y83iTH6T3PBug+4CM+N47ABkt1HG5gGB9yuTv0m/5cXBaW9KPsCXZ4MVpR1wNI/kc65dhFA3QiWmcCgYEA6CfUjOWe201IC332e142WfPGp7hy8p6RHrPtlXS5YnuxVsJVusyuncVdG10kPkvPHakFokqNNUW76Trf++IPnNooMP9ucYj060hYTM7JK9F0mAdx0Mo/+nDC7voXw8rBSsLZHAWfxMh/KjQ5D7L6E2S71wP6ep25hoOuuuLTnrI=";
|
||||
|
||||
/**
|
||||
* 应用公钥
|
||||
*/
|
||||
|
||||
public static final String HS_ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmvqCFRgQCqflYxyHhPyBVBVon51FkGAT8H31hAufhCiW6hAv8HFUn2Tyl6TwAd09HOlessQjjMYLlGRHXkTOVvd1n9I5La7YrrN+F6O/b4Jy17I9k7QDdZLvUKeXm1VcPlj3aSJdZzhTcAqImkj5sFzrFSE+THHMVL5hlAzVIPHWFaA/Vh2Ltdzt9HOL5vo2Bgru5b4kanI5xBaKCfzkaHC6iWxxWk81jBoogGJ1FEky9QSOb4QzSQ4ZtwecFGe/4+PRFkGGW1dH15Qq2UXq3zy6wIF2EfeT/utivV4fHnc04U6z15i1z/f406s9tdfIo10qBfBIH4VQ9jSwkg4ndwIDAQAB";
|
||||
|
||||
/**
|
||||
* 支付宝公钥
|
||||
*/
|
||||
|
||||
public static final String HS_ALI_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiVLUVTnNuq+2C1FRtcIRcG3rCgtVVulkz2QljKbPr7NNWTJJIIfGwyhNuH76s5D1lvNmn2NkuoqM0cMJCSd+W+JW9KpdQ0dgumFHCoRA/OWUoqpLvEOmm2hRMaWpvd+OQq2aPz+p+z6pqZ9SAlgUIolzrUn4idCvgIycqRaGsf1sEJFR5W+rneqtMhNYHdwemqaqnysInwshHR3cHs1AC6y/eL6pcQhaYJ5qVMIRg54/6Lr4CU114Rmph7UM9C28ulmHkFMN/DKPUDbM1+glxjzmqHQChY293Db0dlwZeiDWF3Tli2BVd6pz5KEkQlUsGeLW1O0rT9T9sxzsavxArwIDAQAB";
|
||||
|
||||
/**
|
||||
* 回调地址 因为是内网开发 目前为内网穿透地址
|
||||
*/
|
||||
public static final String NOTIFY_URL = "http://59.110.212.44:9100/pb/pay/aliPay/notify";
|
||||
|
||||
/**
|
||||
* 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数
|
||||
*/
|
||||
public static final String RETURN_URL = "http://外网ip:端口/sccess.html";
|
||||
|
||||
/**
|
||||
* 签名方式
|
||||
*/
|
||||
public static final String SIGN_TYPE = "RSA2";
|
||||
|
||||
/**
|
||||
* 字符编码格式
|
||||
*/
|
||||
public static final String CHARSET = "utf-8";
|
||||
|
||||
/**
|
||||
* 返回格式
|
||||
*/
|
||||
public static String FORMAT = "json";
|
||||
|
||||
/**
|
||||
* 支付宝网关
|
||||
*/
|
||||
public static final String GATEWAYURL = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
private static AlipayClient alipayClient = null;
|
||||
|
||||
public static AlipayClient getAliPayClient() throws AlipayApiException {
|
||||
//实例化客户端
|
||||
if (alipayClient == null) {
|
||||
synchronized (AliPayUtil.class) {
|
||||
if (null == alipayClient) {
|
||||
alipayClient = new DefaultAlipayClient(GATEWAYURL, HS_APP_ID, HS_MERCHANT_PRIVATE_KEY,
|
||||
FORMAT, CHARSET, HS_ALIPAY_PUBLIC_KEY, SIGN_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return alipayClient;
|
||||
}
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.alipay.config;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
|
||||
/**
|
||||
* 支付宝开放平台常量
|
||||
*/
|
||||
public class AliPayConfig {
|
||||
|
||||
/**
|
||||
* 花生appId 沙箱id 2021002161620176
|
||||
*/
|
||||
public static final String HS_APP_ID ="2021003191621137";
|
||||
|
||||
/**
|
||||
* 花生应用私钥
|
||||
*/
|
||||
public static final String HS_MERCHANT_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCa+oIVGBAKp+VjHIeE/IFUFWifnUWQYBPwffWEC5+EKJbqEC/wcVSfZPKXpPAB3T0c6V6yxCOMxguUZEdeRM5W93Wf0jktrtius34Xo79vgnLXsj2TtAN1ku9Qp5ebVVw+WPdpIl1nOFNwCoiaSPmwXOsVIT5MccxUvmGUDNUg8dYVoD9WHYu13O30c4vm+jYGCu7lviRqcjnEFooJ/ORocLqJbHFaTzWMGiiAYnUUSTL1BI5vhDNJDhm3B5wUZ7/j49EWQYZbV0fXlCrZRerfPLrAgXYR95P+62K9Xh8edzThTrPXmLXP9/jTqz2118ijXSoF8EgfhVD2NLCSDid3AgMBAAECggEAR3cPN0TyWMeVer+0Knn59Vkt9rSiWHJFn5el+K8Xbuz8spCmWp0YJax6Rb10Q5fOz5854PubXRYSTupzEqBt+iKApiNd5JgFKYJxudrzsysXZCm4RX00PypzmuC9g464S7Pg2yVSpv+NUlQ5K9RM96vRZ9v9i2jKjaWA/7FvMpI3auOJgrJVoSbPYNx6/QIN1b9imukCMSga9OzF66LhfzACWxJx+DzgAX+7GcfhTF8PbhytPPg9LhlfcGq2gA/TcG6zUorFz5Qy+k//g4rxIvjcPnGfcRgoT+Xgi7I8wnm3O5icIZ6k6+B+wwN3zRTBSmXwbwsgdncGA1RUhe2tAQKBgQDweYu2ij8Io/g7KCvCtVpGHqhzKxgaOZXy0nvPFXY5KFcrrapACriztCaxjvRTXm7t25KJQazICs50OvyTZL5+U3GHp/8GK7KwzZKz5NkHHMtKoKwQADBNau/nHdro4E+PnvL9ucaFX69JF4DZqiw2aDkQkDB/BablHyvuTagJgQKBgQCk++uzero6bXOxFMadLLyWTvlOJP71U1fVSf4Nou+L4ce7k2bMpSDyEDNDOUW3WOO7zz9i8mFGCTUaoX3mhC+B9UQqKZXK2rjFgZtkNDumoCTzvjuPIWTMNN6ABetiLxbq/UD0O1xwThVQNmYwTOzwMHUMkT21ynD23KXE0JL89wKBgGg1Q8YmwooMBFYeYlhOHoCkaHsAAcHbko9Xhy+GLWU3hg73gv+dpcy6FMp9GIPIOGn67NVuEGHfzPexWCLHVYWIw3n14x3ZceYML7alRSc/4xjD58xHSKdD4BJXbbXc/p1OVB5/kvfZLyyNctjgVah+Ibx7v4hL+rbveyoZnOgBAoGAG34je+giqmPc2JB2vHBdCMsmPkBqACWgSFmpLUqOkofQSdC5W7bUs6HBeR1NIc19Pam+jVWIoiwcnlB083nplMVzU3dUj9Y83iTH6T3PBug+4CM+N47ABkt1HG5gGB9yuTv0m/5cXBaW9KPsCXZ4MVpR1wNI/kc65dhFA3QiWmcCgYEA6CfUjOWe201IC332e142WfPGp7hy8p6RHrPtlXS5YnuxVsJVusyuncVdG10kPkvPHakFokqNNUW76Trf++IPnNooMP9ucYj060hYTM7JK9F0mAdx0Mo/+nDC7voXw8rBSsLZHAWfxMh/KjQ5D7L6E2S71wP6ep25hoOuuuLTnrI=";
|
||||
|
||||
/**
|
||||
* 应用公钥
|
||||
*/
|
||||
|
||||
public static final String HS_ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmvqCFRgQCqflYxyHhPyBVBVon51FkGAT8H31hAufhCiW6hAv8HFUn2Tyl6TwAd09HOlessQjjMYLlGRHXkTOVvd1n9I5La7YrrN+F6O/b4Jy17I9k7QDdZLvUKeXm1VcPlj3aSJdZzhTcAqImkj5sFzrFSE+THHMVL5hlAzVIPHWFaA/Vh2Ltdzt9HOL5vo2Bgru5b4kanI5xBaKCfzkaHC6iWxxWk81jBoogGJ1FEky9QSOb4QzSQ4ZtwecFGe/4+PRFkGGW1dH15Qq2UXq3zy6wIF2EfeT/utivV4fHnc04U6z15i1z/f406s9tdfIo10qBfBIH4VQ9jSwkg4ndwIDAQAB";
|
||||
|
||||
/**
|
||||
* 支付宝公钥
|
||||
*/
|
||||
|
||||
public static final String HS_ALI_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiVLUVTnNuq+2C1FRtcIRcG3rCgtVVulkz2QljKbPr7NNWTJJIIfGwyhNuH76s5D1lvNmn2NkuoqM0cMJCSd+W+JW9KpdQ0dgumFHCoRA/OWUoqpLvEOmm2hRMaWpvd+OQq2aPz+p+z6pqZ9SAlgUIolzrUn4idCvgIycqRaGsf1sEJFR5W+rneqtMhNYHdwemqaqnysInwshHR3cHs1AC6y/eL6pcQhaYJ5qVMIRg54/6Lr4CU114Rmph7UM9C28ulmHkFMN/DKPUDbM1+glxjzmqHQChY293Db0dlwZeiDWF3Tli2BVd6pz5KEkQlUsGeLW1O0rT9T9sxzsavxArwIDAQAB";
|
||||
|
||||
/**
|
||||
* 回调地址 因为是内网开发 目前为内网穿透地址
|
||||
*/
|
||||
public static final String NOTIFY_URL = "http://59.110.212.44:9100/pb/pay/aliPay/notify";
|
||||
|
||||
/**
|
||||
* 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数
|
||||
*/
|
||||
public static final String RETURN_URL = "http://外网ip:端口/sccess.html";
|
||||
|
||||
/**
|
||||
* 签名方式
|
||||
*/
|
||||
public static final String SIGN_TYPE = "RSA2";
|
||||
|
||||
/**
|
||||
* 字符编码格式
|
||||
*/
|
||||
public static final String CHARSET = "utf-8";
|
||||
|
||||
/**
|
||||
* 返回格式
|
||||
*/
|
||||
public static String FORMAT = "json";
|
||||
|
||||
/**
|
||||
* 支付宝网关
|
||||
*/
|
||||
public static final String GATEWAYURL = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
private static AlipayClient alipayClient = null;
|
||||
|
||||
public static AlipayClient getAliPayClient() throws AlipayApiException {
|
||||
//实例化客户端
|
||||
if (alipayClient == null) {
|
||||
synchronized (AliPayUtil.class) {
|
||||
if (null == alipayClient) {
|
||||
alipayClient = new DefaultAlipayClient(GATEWAYURL, HS_APP_ID, HS_MERCHANT_PRIVATE_KEY,
|
||||
FORMAT, CHARSET, HS_ALIPAY_PUBLIC_KEY, SIGN_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return alipayClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,167 +1,167 @@
|
||||
package com.peanut.modules.pay.alipay.config;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
||||
import com.alipay.api.domain.AlipayTradeQueryModel;
|
||||
import com.alipay.api.domain.AlipayTradeRefundModel;
|
||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||
import com.alipay.api.request.AlipayTradeQueryRequest;
|
||||
import com.alipay.api.request.AlipayTradeRefundRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import com.alipay.api.response.AlipayTradeRefundResponse;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.dto.ReFundDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AliPayUtil {
|
||||
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 功能描述 下单支付
|
||||
*
|
||||
* @param aliPayDto
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public Map<String, Object> aliPayOrder(AlipayDTO aliPayDto) {
|
||||
log.info(">>>>>>>>>>支付宝下单 订单号 = {}", aliPayDto.getOutTradeNo());
|
||||
Map map = new HashMap();
|
||||
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
||||
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
||||
//(否)对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
|
||||
model.setBody(aliPayDto.getBody());
|
||||
//(是)商品的标题/交易标题/订单标题/订单关键字等
|
||||
model.setSubject(aliPayDto.getSubject());
|
||||
//(是)商户网站唯一订单号
|
||||
model.setOutTradeNo(aliPayDto.getOutTradeNo());
|
||||
//(是)订单总金额,单位为元,精确到小数点后两位
|
||||
model.setTotalAmount(aliPayDto.getTotalAmount());
|
||||
//(否)设置未付款支付宝交易的超时时间,一旦超时,该笔交易就会自动被关闭。
|
||||
model.setTimeoutExpress("30m");
|
||||
//(是)销售产品码,商家和支付宝签约的产品码,为固定值QUICK_MSECURITY_PAY
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(AliPayConfig.NOTIFY_URL);
|
||||
try {
|
||||
//这里和普通的接口调用不同,使用的是sdkExecute
|
||||
AlipayTradeAppPayResponse responseStr = AliPayConfig.getAliPayClient().sdkExecute(request);
|
||||
//可以直接给客户端请求,无需再做处理。
|
||||
map.put("msg", responseStr.getBody());
|
||||
} catch (AlipayApiException e) {
|
||||
log.info(">>>>>>>>>>支付出现异常 exception = {}", e);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* H5请求支付宝支付
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public AlipayTradeWapPayResponse aliPayH5(AlipayDTO h5PayDto) {
|
||||
try {
|
||||
AlipayClient alipayClient = AliPayConfig.getAliPayClient();
|
||||
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||
request.setNotifyUrl(AliPayConfig.NOTIFY_URL);
|
||||
request.setBizContent(getAliPayRequest(h5PayDto).toString());
|
||||
request.setReturnUrl(h5PayDto.getReturnUrl());
|
||||
AlipayTradeWapPayResponse responseStr = alipayClient.pageExecute(request);
|
||||
log.info(responseStr.getBody());
|
||||
return responseStr;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述 退款申请
|
||||
*
|
||||
* @param reFundDTO
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
public AlipayTradeRefundResponse aliPayRefund(ReFundDTO reFundDTO) {
|
||||
log.info(">>>>>>>>>支付宝退款 订单号 = {}", reFundDTO.getOutTrandeNo());
|
||||
Map map = new HashMap();
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
||||
// 退款金额
|
||||
model.setRefundAmount(String.valueOf(reFundDTO.getRefundAmount()));
|
||||
// 支付宝交易号
|
||||
model.setTradeNo(reFundDTO.getTradeNo());
|
||||
// 订单支付时传入的商户订单号
|
||||
model.setOutTradeNo(reFundDTO.getOutTrandeNo());
|
||||
if (StringUtils.isNotBlank(reFundDTO.getRefundReason())) {
|
||||
// 退款原因
|
||||
model.setRefundReason(reFundDTO.getRefundReason());
|
||||
}
|
||||
request.setBizModel(model);
|
||||
AlipayTradeRefundResponse response = null;
|
||||
try {
|
||||
response = AliPayConfig.getAliPayClient().execute(request);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>退款出现异常 exception = {}", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述 查询订单
|
||||
* @param outTradeNo
|
||||
*/
|
||||
public AlipayTradeQueryResponse getAliPayOrder(String outTradeNo) {
|
||||
log.info(">>>>>>>>>查询支付宝订单 订单号 = {}", outTradeNo);
|
||||
Map map = new HashMap();
|
||||
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
||||
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
|
||||
model.setOutTradeNo(outTradeNo);
|
||||
request.setBizModel(model);
|
||||
AlipayTradeQueryResponse response = null;
|
||||
try {
|
||||
response = AliPayConfig.getAliPayClient().execute(request);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>查询订单出现异常 exception = {}", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private ObjectNode getAliPayRequest(AlipayDTO h5PayDto) {
|
||||
ObjectNode obj = mapper.createObjectNode();
|
||||
//obj.put("subject", URLEncoder.encode(payRequest.getBody(), "GBK"));
|
||||
obj.put("subject", h5PayDto.getSubject());
|
||||
obj.put("out_trade_no", h5PayDto.getOutTradeNo());
|
||||
obj.put("timeout_express", 30d);
|
||||
//obj.put("time_expire", DateTimeUtils.getYmdhmFormatDate(System.currentTimeMillis() + DateUtils.DAY_IN_MILLS));
|
||||
obj.put("total_amount", h5PayDto.getTotalAmount());
|
||||
obj.put("quit_url", h5PayDto.getReturnUrl());
|
||||
obj.put("product_code", "QUICK_WAP_PAY");
|
||||
obj.put("body", h5PayDto.getBody());
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.alipay.config;
|
||||
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
||||
import com.alipay.api.domain.AlipayTradeQueryModel;
|
||||
import com.alipay.api.domain.AlipayTradeRefundModel;
|
||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||
import com.alipay.api.request.AlipayTradeQueryRequest;
|
||||
import com.alipay.api.request.AlipayTradeRefundRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import com.alipay.api.response.AlipayTradeRefundResponse;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.dto.ReFundDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AliPayUtil {
|
||||
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 功能描述 下单支付
|
||||
*
|
||||
* @param aliPayDto
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public Map<String, Object> aliPayOrder(AlipayDTO aliPayDto) {
|
||||
log.info(">>>>>>>>>>支付宝下单 订单号 = {}", aliPayDto.getOutTradeNo());
|
||||
Map map = new HashMap();
|
||||
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
||||
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
||||
//(否)对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
|
||||
model.setBody(aliPayDto.getBody());
|
||||
//(是)商品的标题/交易标题/订单标题/订单关键字等
|
||||
model.setSubject(aliPayDto.getSubject());
|
||||
//(是)商户网站唯一订单号
|
||||
model.setOutTradeNo(aliPayDto.getOutTradeNo());
|
||||
//(是)订单总金额,单位为元,精确到小数点后两位
|
||||
model.setTotalAmount(aliPayDto.getTotalAmount());
|
||||
//(否)设置未付款支付宝交易的超时时间,一旦超时,该笔交易就会自动被关闭。
|
||||
model.setTimeoutExpress("30m");
|
||||
//(是)销售产品码,商家和支付宝签约的产品码,为固定值QUICK_MSECURITY_PAY
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(AliPayConfig.NOTIFY_URL);
|
||||
try {
|
||||
//这里和普通的接口调用不同,使用的是sdkExecute
|
||||
AlipayTradeAppPayResponse responseStr = AliPayConfig.getAliPayClient().sdkExecute(request);
|
||||
//可以直接给客户端请求,无需再做处理。
|
||||
map.put("msg", responseStr.getBody());
|
||||
} catch (AlipayApiException e) {
|
||||
log.info(">>>>>>>>>>支付出现异常 exception = {}", e);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* H5请求支付宝支付
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public AlipayTradeWapPayResponse aliPayH5(AlipayDTO h5PayDto) {
|
||||
try {
|
||||
AlipayClient alipayClient = AliPayConfig.getAliPayClient();
|
||||
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||
request.setNotifyUrl(AliPayConfig.NOTIFY_URL);
|
||||
request.setBizContent(getAliPayRequest(h5PayDto).toString());
|
||||
request.setReturnUrl(h5PayDto.getReturnUrl());
|
||||
AlipayTradeWapPayResponse responseStr = alipayClient.pageExecute(request);
|
||||
log.info(responseStr.getBody());
|
||||
return responseStr;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述 退款申请
|
||||
*
|
||||
* @param reFundDTO
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
public AlipayTradeRefundResponse aliPayRefund(ReFundDTO reFundDTO) {
|
||||
log.info(">>>>>>>>>支付宝退款 订单号 = {}", reFundDTO.getOutTrandeNo());
|
||||
Map map = new HashMap();
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
||||
// 退款金额
|
||||
model.setRefundAmount(String.valueOf(reFundDTO.getRefundAmount()));
|
||||
// 支付宝交易号
|
||||
model.setTradeNo(reFundDTO.getTradeNo());
|
||||
// 订单支付时传入的商户订单号
|
||||
model.setOutTradeNo(reFundDTO.getOutTrandeNo());
|
||||
if (StringUtils.isNotBlank(reFundDTO.getRefundReason())) {
|
||||
// 退款原因
|
||||
model.setRefundReason(reFundDTO.getRefundReason());
|
||||
}
|
||||
request.setBizModel(model);
|
||||
AlipayTradeRefundResponse response = null;
|
||||
try {
|
||||
response = AliPayConfig.getAliPayClient().execute(request);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>退款出现异常 exception = {}", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能描述 查询订单
|
||||
* @param outTradeNo
|
||||
*/
|
||||
public AlipayTradeQueryResponse getAliPayOrder(String outTradeNo) {
|
||||
log.info(">>>>>>>>>查询支付宝订单 订单号 = {}", outTradeNo);
|
||||
Map map = new HashMap();
|
||||
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
||||
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
|
||||
model.setOutTradeNo(outTradeNo);
|
||||
request.setBizModel(model);
|
||||
AlipayTradeQueryResponse response = null;
|
||||
try {
|
||||
response = AliPayConfig.getAliPayClient().execute(request);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>查询订单出现异常 exception = {}", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private ObjectNode getAliPayRequest(AlipayDTO h5PayDto) {
|
||||
ObjectNode obj = mapper.createObjectNode();
|
||||
//obj.put("subject", URLEncoder.encode(payRequest.getBody(), "GBK"));
|
||||
obj.put("subject", h5PayDto.getSubject());
|
||||
obj.put("out_trade_no", h5PayDto.getOutTradeNo());
|
||||
obj.put("timeout_express", 30d);
|
||||
//obj.put("time_expire", DateTimeUtils.getYmdhmFormatDate(System.currentTimeMillis() + DateUtils.DAY_IN_MILLS));
|
||||
obj.put("total_amount", h5PayDto.getTotalAmount());
|
||||
obj.put("quit_url", h5PayDto.getReturnUrl());
|
||||
obj.put("product_code", "QUICK_WAP_PAY");
|
||||
obj.put("body", h5PayDto.getBody());
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package com.peanut.modules.pay.alipay.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.service.AliPayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝支付控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/pay/aliPay")
|
||||
@Slf4j
|
||||
public class AliPayController {
|
||||
|
||||
@Autowired
|
||||
private AliPayService aliPayService;
|
||||
|
||||
/**
|
||||
* 请求支付宝接口支付
|
||||
*
|
||||
* @param payDto
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/pay")
|
||||
public R pay(AlipayDTO payDto) {
|
||||
String pay = aliPayService.pay(payDto);
|
||||
return R.ok().put("orderInfo",pay);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping( "/notify")
|
||||
public R notify_url(HttpServletRequest request) {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
String jsonStr = JSONObject.toJSONString(parameterMap);
|
||||
System.out.println("支付宝回调信息=============》"+jsonStr);
|
||||
String aliNotify = aliPayService.aliNotify(request);
|
||||
return R.ok().put("aliNotify",aliNotify);
|
||||
}
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.alipay.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.service.AliPayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝支付控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/pay/aliPay")
|
||||
@Slf4j
|
||||
public class AliPayController {
|
||||
|
||||
@Autowired
|
||||
private AliPayService aliPayService;
|
||||
|
||||
/**
|
||||
* 请求支付宝接口支付
|
||||
*
|
||||
* @param payDto
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/pay")
|
||||
public R pay(AlipayDTO payDto) {
|
||||
String pay = aliPayService.pay(payDto);
|
||||
return R.ok().put("orderInfo",pay);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping( "/notify")
|
||||
public R notify_url(HttpServletRequest request) {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
String jsonStr = JSONObject.toJSONString(parameterMap);
|
||||
System.out.println("支付宝回调信息=============》"+jsonStr);
|
||||
String aliNotify = aliPayService.aliNotify(request);
|
||||
return R.ok().put("aliNotify",aliNotify);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
package com.peanut.modules.pay.alipay.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 支付实体对象
|
||||
*/
|
||||
@Data
|
||||
public class AlipayDTO {
|
||||
/**
|
||||
* 商户订单号,必填
|
||||
*/
|
||||
private String outTradeNo;
|
||||
|
||||
|
||||
/**
|
||||
* 订单名称,必填
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 付款金额,必填
|
||||
*/
|
||||
private String totalAmount;
|
||||
|
||||
/**
|
||||
* 商品描述,可空
|
||||
*/
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* 超时时间参数
|
||||
*/
|
||||
private String timeoutExpress = "10m";
|
||||
|
||||
/**
|
||||
* 销售产品码,与支付宝签约的产品码名称
|
||||
*/
|
||||
private String productCode = "QUICK_MSECURITY_PAY";
|
||||
|
||||
/**
|
||||
* 支付成功后回跳地址,H5支付特有
|
||||
*/
|
||||
private String returnUrl;
|
||||
|
||||
/**
|
||||
* 类型 如果type ==1。是H5支付,如果type == 2是app支付
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 客户编号
|
||||
*/
|
||||
private String customerId;
|
||||
|
||||
private String relevanceoid;
|
||||
package com.peanut.modules.pay.alipay.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 支付实体对象
|
||||
*/
|
||||
@Data
|
||||
public class AlipayDTO {
|
||||
/**
|
||||
* 商户订单号,必填
|
||||
*/
|
||||
private String outTradeNo;
|
||||
|
||||
|
||||
/**
|
||||
* 订单名称,必填
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* 付款金额,必填
|
||||
*/
|
||||
private String totalAmount;
|
||||
|
||||
/**
|
||||
* 商品描述,可空
|
||||
*/
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* 超时时间参数
|
||||
*/
|
||||
private String timeoutExpress = "10m";
|
||||
|
||||
/**
|
||||
* 销售产品码,与支付宝签约的产品码名称
|
||||
*/
|
||||
private String productCode = "QUICK_MSECURITY_PAY";
|
||||
|
||||
/**
|
||||
* 支付成功后回跳地址,H5支付特有
|
||||
*/
|
||||
private String returnUrl;
|
||||
|
||||
/**
|
||||
* 类型 如果type ==1。是H5支付,如果type == 2是app支付
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 客户编号
|
||||
*/
|
||||
private String customerId;
|
||||
|
||||
private String relevanceoid;
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
package com.peanut.modules.pay.alipay.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 退款实体对象
|
||||
*/
|
||||
@Data
|
||||
public class ReFundDTO {
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
public BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 支付时商户订单号
|
||||
*/
|
||||
public String outTrandeNo;
|
||||
|
||||
/**
|
||||
* 支付宝交易编号
|
||||
*/
|
||||
public String tradeNo;
|
||||
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
private String refundReason;
|
||||
|
||||
/**
|
||||
* 客户编号
|
||||
*/
|
||||
private String customerId;
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.alipay.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 退款实体对象
|
||||
*/
|
||||
@Data
|
||||
public class ReFundDTO {
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
public BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 支付时商户订单号
|
||||
*/
|
||||
public String outTrandeNo;
|
||||
|
||||
/**
|
||||
* 支付宝交易编号
|
||||
*/
|
||||
public String tradeNo;
|
||||
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
private String refundReason;
|
||||
|
||||
/**
|
||||
* 客户编号
|
||||
*/
|
||||
private String customerId;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.peanut.modules.pay.alipay.service;
|
||||
|
||||
|
||||
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
public interface AliPayService {
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* @param alipayDTO
|
||||
* @return
|
||||
*/
|
||||
String pay(AlipayDTO alipayDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝异步回调
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
String aliNotify(HttpServletRequest request);
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.peanut.modules.pay.alipay.service;
|
||||
|
||||
|
||||
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
public interface AliPayService {
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* @param alipayDTO
|
||||
* @return
|
||||
*/
|
||||
String pay(AlipayDTO alipayDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝异步回调
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
String aliNotify(HttpServletRequest request);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,230 +1,230 @@
|
||||
package com.peanut.modules.pay.alipay.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.CopyUtils;
|
||||
import com.peanut.common.utils.OrderUtils;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayUtil;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.service.AliPayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付宝支付实现
|
||||
*/
|
||||
@Service("AliPayService")
|
||||
@Slf4j
|
||||
public class AliPayServiceImpl implements AliPayService {
|
||||
|
||||
@Autowired
|
||||
private AliPayUtil aliPayUtil;
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private PayZfbOrderService payZfbOrderService;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private PayPaymentOrderService payPaymentOrderService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
|
||||
@Override
|
||||
public String pay(AlipayDTO payDto) {
|
||||
Integer type = payDto.getType();
|
||||
String orderInfo = "";
|
||||
if (type == 1) {
|
||||
// 走H5请求支付宝支付接口
|
||||
log.info(">>>>>>>>>>H5请求支付宝支付接口");
|
||||
String result = aliPayUtil.aliPayH5(payDto).getBody();
|
||||
log.info(">>>>>>>>>>>支付宝返回的信息是 result = {}", result);
|
||||
orderInfo = result;
|
||||
}
|
||||
if (type == 2) {
|
||||
// 走APP请求支付宝支付接口
|
||||
log.info(">>>>>>>>>>App请求支付宝支付接口");
|
||||
payDto.setOutTradeNo(OrderUtils.getOrderCode(Integer.valueOf(payDto.getCustomerId())));
|
||||
Map<String, Object> map = aliPayUtil.aliPayOrder(payDto);
|
||||
Object obj = map.get("msg");
|
||||
String resJson = obj.toString();
|
||||
|
||||
log.info(">>>>>>>>>>>支付宝返回的信息是 resJson = {}", resJson);
|
||||
PayZfbOrderEntity aliNotifyDto = new PayZfbOrderEntity();
|
||||
aliNotifyDto.setOutTradeNo(payDto.getOutTradeNo());
|
||||
aliNotifyDto.setCustomerid(payDto.getCustomerId());
|
||||
aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid());
|
||||
payZfbOrderService.save(aliNotifyDto);
|
||||
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn",payDto.getRelevanceoid()).eq("del_flag","0"));
|
||||
order.setPaymentDate(new Date());
|
||||
this.buyOrderService.updateById(order);
|
||||
|
||||
orderInfo = resJson;
|
||||
}
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String aliNotify(HttpServletRequest request) {
|
||||
log.info(">>>>>>>>>>支付宝异步回调开始<<<<<<<<<<");
|
||||
Map<String, String> params = new HashMap<>();
|
||||
try {
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
log.info(">>>>>>>>>>支付宝回调 sign = {}, trade_status = {}, out_trade_no = {}, 参数 = {}", params.get("sign"),
|
||||
params.get("trade_status"), params.get("out_trade_no"), params.toString());
|
||||
//调用SDK验证签名,验证是阿里回调,而不是其他恶意回调
|
||||
boolean flag = AlipaySignature.rsaCheckV1(params, AliPayConfig.HS_ALI_PUBLIC_KEY, AliPayConfig.CHARSET, AliPayConfig.SIGN_TYPE);
|
||||
log.info(">>>>>>>>>>验签结果 flag = {}", flag);
|
||||
if (flag) {
|
||||
log.info(">>>>>>>>>>验签通过");
|
||||
//验签通过 获取交易状态
|
||||
String tradeStatus = params.get("trade_status");
|
||||
//只处理支付成功的订单: 修改交易表状态,支付成功
|
||||
//只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,支付宝才会认定为买家付款成功。
|
||||
if (tradeStatus.equals("TRADE_SUCCESS") || tradeStatus.equals("TRADE_FINISHED")) {
|
||||
//TODO 获取支付宝通知完成充值后续业务
|
||||
//交易成功 获取商户订单号
|
||||
/**修改订单信息*/
|
||||
String toJSON = JSONObject.toJSONString(params);
|
||||
PayZfbOrderEntity aliNotifyDto = JSONObject.toJavaObject(JSON.parseObject(toJSON), PayZfbOrderEntity.class);
|
||||
//判断数据库是否存在当前订单
|
||||
PayZfbOrderEntity payZfbOrderEntity = payZfbOrderService.getOne(new QueryWrapper<PayZfbOrderEntity>().eq("trade_no", aliNotifyDto.getTradeNo()));
|
||||
if (payZfbOrderEntity != null) {
|
||||
return "success";
|
||||
}
|
||||
PayZfbOrderEntity oldPayZfbOrderEntity = payZfbOrderService.getOne(new QueryWrapper<PayZfbOrderEntity>().eq("out_trade_no", aliNotifyDto.getOutTradeNo()));
|
||||
CopyUtils.copyProperties(aliNotifyDto,oldPayZfbOrderEntity);
|
||||
|
||||
payZfbOrderService.updateById(oldPayZfbOrderEntity);
|
||||
|
||||
String subject = oldPayZfbOrderEntity.getSubject();
|
||||
|
||||
// 会员开通
|
||||
String body = oldPayZfbOrderEntity.getBody();
|
||||
String customerid = oldPayZfbOrderEntity.getCustomerid();
|
||||
|
||||
if ("vip".equals(subject)) {
|
||||
//获取会员开通 日期
|
||||
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
|
||||
|
||||
// 插入 开通记录
|
||||
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if("point".equals(subject)){
|
||||
// 插入花生币 变动记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
String realMoney = bookBuyConfigEntity.getRealMoney();
|
||||
Integer money = Integer.valueOf(realMoney);
|
||||
userService.rechargeHSPoint(Integer.valueOf(customerid),money);
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(Integer.valueOf(customerid));
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(oldPayZfbOrderEntity.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
// 插入 花生币 充值记录
|
||||
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
|
||||
payPaymentOrderEntity.setUserId(Integer.valueOf(customerid));
|
||||
payPaymentOrderEntity.setOrderId(String.valueOf(oldPayZfbOrderEntity.getId()));
|
||||
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
|
||||
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
|
||||
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
|
||||
payPaymentOrderEntity.setRechargeStatus("success");
|
||||
payPaymentOrderEntity.setSuccessTime(new Date());
|
||||
payPaymentOrderEntity.setUserName(user.getNickname());
|
||||
payPaymentOrderEntity.setTel(user.getTel());
|
||||
payPaymentOrderService.save(payPaymentOrderEntity);
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
}
|
||||
if ("order".equals(subject)) {
|
||||
|
||||
System.out.println("=====到order更新字段==================================================================================================================");
|
||||
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
System.out.println("======orderEntity=========="+orderEntity);
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
System.out.println("======realMoney=========="+realMoney);
|
||||
BigDecimal bigDecimal = new BigDecimal(oldPayZfbOrderEntity.getBuyerPayAmount());
|
||||
System.out.println("======bigDecimal=========="+bigDecimal);
|
||||
//更新 订单 记录
|
||||
if (bigDecimal.compareTo(realMoney) == 0) {
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**余额到账*/
|
||||
//这里就主要是做你们自己的业务需求了,修改一些表什么的..
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
log.info(">>>>>>>>>>验签失败");
|
||||
return "fail";
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>订单回调异常: 订单号 = {}, msg = {}", params.get("out_trade_no"), e.getMessage());
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO 更新订单状态
|
||||
|
||||
|
||||
|
||||
//TODO 更新用户优惠券状态
|
||||
|
||||
|
||||
|
||||
//TODO 推送一路健康优惠券
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
package com.peanut.modules.pay.alipay.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.CopyUtils;
|
||||
import com.peanut.common.utils.OrderUtils;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayConfig;
|
||||
import com.peanut.modules.pay.alipay.config.AliPayUtil;
|
||||
import com.peanut.modules.pay.alipay.dto.AlipayDTO;
|
||||
import com.peanut.modules.pay.alipay.service.AliPayService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付宝支付实现
|
||||
*/
|
||||
@Service("AliPayService")
|
||||
@Slf4j
|
||||
public class AliPayServiceImpl implements AliPayService {
|
||||
|
||||
@Autowired
|
||||
private AliPayUtil aliPayUtil;
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private PayZfbOrderService payZfbOrderService;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private PayPaymentOrderService payPaymentOrderService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
|
||||
@Override
|
||||
public String pay(AlipayDTO payDto) {
|
||||
Integer type = payDto.getType();
|
||||
String orderInfo = "";
|
||||
if (type == 1) {
|
||||
// 走H5请求支付宝支付接口
|
||||
log.info(">>>>>>>>>>H5请求支付宝支付接口");
|
||||
String result = aliPayUtil.aliPayH5(payDto).getBody();
|
||||
log.info(">>>>>>>>>>>支付宝返回的信息是 result = {}", result);
|
||||
orderInfo = result;
|
||||
}
|
||||
if (type == 2) {
|
||||
// 走APP请求支付宝支付接口
|
||||
log.info(">>>>>>>>>>App请求支付宝支付接口");
|
||||
payDto.setOutTradeNo(OrderUtils.getOrderCode(Integer.valueOf(payDto.getCustomerId())));
|
||||
Map<String, Object> map = aliPayUtil.aliPayOrder(payDto);
|
||||
Object obj = map.get("msg");
|
||||
String resJson = obj.toString();
|
||||
|
||||
log.info(">>>>>>>>>>>支付宝返回的信息是 resJson = {}", resJson);
|
||||
PayZfbOrderEntity aliNotifyDto = new PayZfbOrderEntity();
|
||||
aliNotifyDto.setOutTradeNo(payDto.getOutTradeNo());
|
||||
aliNotifyDto.setCustomerid(payDto.getCustomerId());
|
||||
aliNotifyDto.setRelevanceoid(payDto.getRelevanceoid());
|
||||
payZfbOrderService.save(aliNotifyDto);
|
||||
BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn",payDto.getRelevanceoid()).eq("del_flag","0"));
|
||||
order.setPaymentDate(new Date());
|
||||
this.buyOrderService.updateById(order);
|
||||
|
||||
orderInfo = resJson;
|
||||
}
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String aliNotify(HttpServletRequest request) {
|
||||
log.info(">>>>>>>>>>支付宝异步回调开始<<<<<<<<<<");
|
||||
Map<String, String> params = new HashMap<>();
|
||||
try {
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
log.info(">>>>>>>>>>支付宝回调 sign = {}, trade_status = {}, out_trade_no = {}, 参数 = {}", params.get("sign"),
|
||||
params.get("trade_status"), params.get("out_trade_no"), params.toString());
|
||||
//调用SDK验证签名,验证是阿里回调,而不是其他恶意回调
|
||||
boolean flag = AlipaySignature.rsaCheckV1(params, AliPayConfig.HS_ALI_PUBLIC_KEY, AliPayConfig.CHARSET, AliPayConfig.SIGN_TYPE);
|
||||
log.info(">>>>>>>>>>验签结果 flag = {}", flag);
|
||||
if (flag) {
|
||||
log.info(">>>>>>>>>>验签通过");
|
||||
//验签通过 获取交易状态
|
||||
String tradeStatus = params.get("trade_status");
|
||||
//只处理支付成功的订单: 修改交易表状态,支付成功
|
||||
//只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,支付宝才会认定为买家付款成功。
|
||||
if (tradeStatus.equals("TRADE_SUCCESS") || tradeStatus.equals("TRADE_FINISHED")) {
|
||||
//TODO 获取支付宝通知完成充值后续业务
|
||||
//交易成功 获取商户订单号
|
||||
/**修改订单信息*/
|
||||
String toJSON = JSONObject.toJSONString(params);
|
||||
PayZfbOrderEntity aliNotifyDto = JSONObject.toJavaObject(JSON.parseObject(toJSON), PayZfbOrderEntity.class);
|
||||
//判断数据库是否存在当前订单
|
||||
PayZfbOrderEntity payZfbOrderEntity = payZfbOrderService.getOne(new QueryWrapper<PayZfbOrderEntity>().eq("trade_no", aliNotifyDto.getTradeNo()));
|
||||
if (payZfbOrderEntity != null) {
|
||||
return "success";
|
||||
}
|
||||
PayZfbOrderEntity oldPayZfbOrderEntity = payZfbOrderService.getOne(new QueryWrapper<PayZfbOrderEntity>().eq("out_trade_no", aliNotifyDto.getOutTradeNo()));
|
||||
CopyUtils.copyProperties(aliNotifyDto,oldPayZfbOrderEntity);
|
||||
|
||||
payZfbOrderService.updateById(oldPayZfbOrderEntity);
|
||||
|
||||
String subject = oldPayZfbOrderEntity.getSubject();
|
||||
|
||||
// 会员开通
|
||||
String body = oldPayZfbOrderEntity.getBody();
|
||||
String customerid = oldPayZfbOrderEntity.getCustomerid();
|
||||
|
||||
if ("vip".equals(subject)) {
|
||||
//获取会员开通 日期
|
||||
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
|
||||
|
||||
// 插入 开通记录
|
||||
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if("point".equals(subject)){
|
||||
// 插入花生币 变动记录
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
|
||||
String realMoney = bookBuyConfigEntity.getRealMoney();
|
||||
Integer money = Integer.valueOf(realMoney);
|
||||
userService.rechargeHSPoint(Integer.valueOf(customerid),money);
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(Integer.valueOf(customerid));
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(oldPayZfbOrderEntity.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
// 插入 花生币 充值记录
|
||||
PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
|
||||
payPaymentOrderEntity.setUserId(Integer.valueOf(customerid));
|
||||
payPaymentOrderEntity.setOrderId(String.valueOf(oldPayZfbOrderEntity.getId()));
|
||||
payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
|
||||
payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
|
||||
payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
|
||||
payPaymentOrderEntity.setRechargeStatus("success");
|
||||
payPaymentOrderEntity.setSuccessTime(new Date());
|
||||
payPaymentOrderEntity.setUserName(user.getNickname());
|
||||
payPaymentOrderEntity.setTel(user.getTel());
|
||||
payPaymentOrderService.save(payPaymentOrderEntity);
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
|
||||
}
|
||||
if ("order".equals(subject)) {
|
||||
|
||||
System.out.println("=====到order更新字段==================================================================================================================");
|
||||
BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderEntity>().eq("order_sn", oldPayZfbOrderEntity.getRelevanceoid()));
|
||||
System.out.println("======orderEntity=========="+orderEntity);
|
||||
BigDecimal realMoney = orderEntity.getRealMoney();
|
||||
System.out.println("======realMoney=========="+realMoney);
|
||||
BigDecimal bigDecimal = new BigDecimal(oldPayZfbOrderEntity.getBuyerPayAmount());
|
||||
System.out.println("======bigDecimal=========="+bigDecimal);
|
||||
//更新 订单 记录
|
||||
if (bigDecimal.compareTo(realMoney) == 0) {
|
||||
buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**余额到账*/
|
||||
//这里就主要是做你们自己的业务需求了,修改一些表什么的..
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
log.info(">>>>>>>>>>验签失败");
|
||||
return "fail";
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(">>>>>>>>>>订单回调异常: 订单号 = {}, msg = {}", params.get("out_trade_no"), e.getMessage());
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO 更新订单状态
|
||||
|
||||
|
||||
|
||||
//TODO 更新用户优惠券状态
|
||||
|
||||
|
||||
|
||||
//TODO 推送一路健康优惠券
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user