|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alipay.api.AlipayApiException; |
|
|
import com.alipay.api.AlipayApiException; |
|
|
import com.alipay.api.AlipayClient; |
|
|
import com.alipay.api.AlipayClient; |
|
|
|
|
|
import com.alipay.api.CertAlipayRequest; |
|
|
import com.alipay.api.DefaultAlipayClient; |
|
|
import com.alipay.api.DefaultAlipayClient; |
|
|
import com.alipay.api.domain.*; |
|
|
import com.alipay.api.domain.*; |
|
|
import com.alipay.api.internal.util.AlipaySignature; |
|
|
import com.alipay.api.internal.util.AlipaySignature; |
|
@ -35,6 +36,7 @@ import com.zscat.mallplus.utils.ValidatorUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
@ -65,10 +67,61 @@ import java.util.Map; |
|
|
@RequestMapping("/api/aliPay") |
|
|
@RequestMapping("/api/aliPay") |
|
|
public class AliPayController extends AbstractAliPayApiController { |
|
|
public class AliPayController extends AbstractAliPayApiController { |
|
|
private static final Logger log = LoggerFactory.getLogger(AliPayController.class); |
|
|
private static final Logger log = LoggerFactory.getLogger(AliPayController.class); |
|
|
|
|
|
|
|
|
|
|
|
@Value("${alipay.domain}") |
|
|
|
|
|
private String DOMAIN; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${alipay.appId}") |
|
|
|
|
|
private String APPID; |
|
|
|
|
|
/** |
|
|
|
|
|
* 支付宝公钥 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.ALIPAY_PUBLIC_KEY}") |
|
|
|
|
|
private String ALIPAY_PUBLIC_KEY; |
|
|
|
|
|
/** |
|
|
|
|
|
* 支付宝网关 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.serverUrl}") |
|
|
|
|
|
private String GATE; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 编码方式 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String CHARSET = "utf-8"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 回调地址 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.notifyUrl}") |
|
|
|
|
|
private String NOTIFY_URL; |
|
|
|
|
|
/** |
|
|
|
|
|
* 支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径) |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.RootCertPath}") |
|
|
|
|
|
private String RootCertPath; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 应用公钥证书路径(app_cert_path 文件绝对路径) |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.CertPath}") |
|
|
|
|
|
private String CertPath; |
|
|
|
|
|
|
|
|
|
|
|
private String SignType = "RSA2"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 应用私钥 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Value("${alipay.privateKey}") |
|
|
|
|
|
private String APP_PRIVATE_KEY; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String domain = ""; |
|
|
String domain = ""; |
|
|
String privateKey = ""; |
|
|
String privateKey = ""; |
|
|
|
|
|
//支付宝公钥
|
|
|
String publicKey = ""; |
|
|
String publicKey = ""; |
|
|
|
|
|
//支付宝支付业务:app_id
|
|
|
String appId = ""; |
|
|
String appId = ""; |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private IOmsOrderService orderService; |
|
|
private IOmsOrderService orderService; |
|
|
@Resource |
|
|
@Resource |
|
@ -91,10 +144,10 @@ public class AliPayController extends AbstractAliPayApiController { |
|
|
aliPayApiConfig = AliPayApiConfig.builder() |
|
|
aliPayApiConfig = AliPayApiConfig.builder() |
|
|
.setAppId(aliPayBean.getAppId()) |
|
|
.setAppId(aliPayBean.getAppId()) |
|
|
.setAliPayPublicKey(aliPayBean.getPublicKey()) |
|
|
.setAliPayPublicKey(aliPayBean.getPublicKey()) |
|
|
.setCharset("UTF-8") |
|
|
.setCharset(CHARSET) |
|
|
.setPrivateKey(aliPayBean.getPrivateKey()) |
|
|
.setPrivateKey(aliPayBean.getPrivateKey()) |
|
|
.setServiceUrl(aliPayBean.getServerUrl()) |
|
|
.setServiceUrl(aliPayBean.getServerUrl()) |
|
|
.setSignType("RSA2") |
|
|
.setSignType(SignType) |
|
|
.build(); |
|
|
.build(); |
|
|
domain = aliPayBean.getDomain(); |
|
|
domain = aliPayBean.getDomain(); |
|
|
privateKey = aliPayBean.getPrivateKey(); |
|
|
privateKey = aliPayBean.getPrivateKey(); |
|
@ -104,29 +157,52 @@ public class AliPayController extends AbstractAliPayApiController { |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
AliPayBean aliPayBean = new AliPayBean(); |
|
|
AliPayBean aliPayBean = new AliPayBean(); |
|
|
aliPayBean.setAppId("2018082761134635"); |
|
|
//APPID 即创建应用后生成,详情见创建应用并获取 APPID
|
|
|
aliPayBean.setDomain("http://www.yyundong.com:8083/api"); |
|
|
aliPayBean.setAppId(APPID); |
|
|
//aliPayBean.setDomain("http://26077a35f5.wicp.vip:43609/api");
|
|
|
//gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
|
|
|
aliPayBean.setServerUrl("https://openapi.alipay.com/gateway.do"); |
|
|
aliPayBean.setServerUrl(GATE); |
|
|
aliPayBean.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlOOOOWg4e2deSDMRG2y5EzG7/udMfTzYkn4u/3PWIOlpcUd2ujCztqKY2HdFhIaWE4q8PCLtT5XtBWCq2IVvpCPE8HRzgSZckh6J36SnO0JG1pZe8HajUgIw+T1NM7/b2Nb4OaI5HKNsQ5ei9NlN9RvlIUSpum/nIyk/9CBvNAg8xUlHUFPaPL0WCMJ9zIwRO+aEn2kwA7JQ8AvjuPy390oil0W4fxfHonJYxuzOo6Lx369Vti5N9UmXczXUcOiVwyCveoH05chNr3r8xu5QqpD1o32cO01Zt4EA9j6aM2H09g08VzoLam2OoU3umKOV0vvX+bMmb1GwrkussSvDpQIDAQAB"); |
|
|
//开发者应用私钥,由开发者自己生成
|
|
|
aliPayBean.setPrivateKey("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCjI8p9Vh3QrBsa2BdTLAa9YrPGdHAo4DeYx79rlrITI4kIwy6/q/JDaXNBQgl80mUYh4Zinc0mDZ68n14zIL0f4At+EzzfxT5RIVYKZb/EEj6ijElldvijblcCAkrcoTl+oWDEKEOyyJW2UFbRIUYUZcszfi+pue1BIdvwlfxHTI77o1H6d2ApkyIHgs6zYeeauDkYYTdAjSCV7PHhTO6H6yS5uyc0rOLxUTdABA+b+ewSnTw2uvuVTTnrC7xIqjfj1fRocsNh/1KfqF4I5iMQmrRaIlujRSTQrO7kLVbYW45D+Qr4mB3TlhTGAFcTL+ovugA+66NASZmUyNsZHcBZAgMBAAECggEAao+eXHA72WoR6l7sHW/Mlzg5pY+5E3oh1rHi3yv39XhoskiL6Lcv78iZeC7ic54aWwNrTE83CXwsC5kttsfTwVZfK2L1iFUWd3gG85OyxygDsblg1932Wwpf2vgUXjkRjR1sT7TdQ5Kx9/xSORg65mf3axMpnvvLdZfgSi4uM4NJ94NzCLwH7zSWuK6CsPfl24RQlQfczRUy4GzG+wtXjDj5XLNNO6GQacQY4BUkcjCfrkUrQ9Lf2joYiXRyVNWUN1HivmfMouG37WQhUzz0CL8tF1EfooCfPhetAF5Aursve3O8l0Lno6K1auziN8g/Jfuo+efKfImzwvyo3m1n4QKBgQDjtfOWqcVP611OSTm1L1RFHCJMZN5wgOLEquO/2VC4VItV7vy0odNrLydd9Eg77VbC0IVcqunQIHjON3fFEVlj0bEVOaEN+X26oP84UNBK12QcLWvxxXQvOyaXg0hqgae5dpG5LvZHIP6b27jF3IuTG3lILZDjZsO9NcZbBr+NGwKBgQC3aD5VAUjCn+xnHIzGd0/avFYIGzqGUw2hZfFfuI3r58gRo/bjlOny7jLTxOFa+2SGggdDVm/izWut2FacNr3/GVTkcZc6ZEIXWq793vFky69PwGj24bCbplLYaCWM79HczM9sIWBl5WKmI7k1O/AIJrPteTa/Du/T+IfcATQDmwKBgQCCNjXI3eP6w3hjn/Pj6+CgdGoYjUW1x73lAGOj/Tzva0kSJstS74baL+ivDVWRDzMhy+O3DfUOEsOCCK3wfu9C6VH99Spnt1dyNUY8idnSMkEI6+BiLKs3pvd2hJgQb3vdzjOeVYB3RCLUNVz/qBIYWQmNgKDtqIId3HZE7yLyKQKBgQCq4Blq00Z55cu4CZZy9ghVL7Er3kp5iXmijLsExoqbZpg1L0E/qacJ6bk7KiwXuy5eT1j6+NZHRcHz9yJCapI70NsR927BPVWCMr/k0Uiv80FDmW1xzrXfXmfDLc0GcQ1inQMHqFUKultdlNziZxRsU7rBHnTOLtls8RmK9SgDzwKBgBnWfQNVF/BSIP/pOkudu966DwqySamzy/HrdOIq92r+OtAWqtLMq8bbIkMW1asC8+MLE81JD9fn7YmKeZTbMwxE2z5Tv1z+UUqy//79Vkj8FmlSfY0kraj9ZXjMp+Hg0kCpavOU4QFXONn2LVvrrh0tACcgJoJGRJJYuJMQeu7c"); |
|
|
aliPayBean.setPrivateKey(APP_PRIVATE_KEY); |
|
|
|
|
|
aliPayBean.setDomain(DOMAIN); |
|
|
|
|
|
aliPayBean.setAlipayPublicKey(ALIPAY_PUBLIC_KEY); |
|
|
|
|
|
aliPayBean.setCertPath(CertPath); |
|
|
|
|
|
aliPayBean.setRootCertPath(RootCertPath); |
|
|
|
|
|
|
|
|
aliPayApiConfig = AliPayApiConfig.builder() |
|
|
aliPayApiConfig = AliPayApiConfig.builder() |
|
|
.setAppId(aliPayBean.getAppId()) |
|
|
.setAppId(aliPayBean.getAppId()) |
|
|
.setAliPayPublicKey(aliPayBean.getPublicKey()) |
|
|
|
|
|
.setCharset("UTF-8") |
|
|
|
|
|
.setPrivateKey(aliPayBean.getPrivateKey()) |
|
|
.setPrivateKey(aliPayBean.getPrivateKey()) |
|
|
|
|
|
.setAliPayPublicKey(aliPayBean.getAlipayPublicKey()) |
|
|
|
|
|
.setCharset(CHARSET) |
|
|
|
|
|
.setSignType(SignType) |
|
|
.setServiceUrl(aliPayBean.getServerUrl()) |
|
|
.setServiceUrl(aliPayBean.getServerUrl()) |
|
|
.setSignType("RSA2") |
|
|
.setAppCertPath(aliPayBean.getCertPath()) |
|
|
|
|
|
.setAliPayPublicKey(aliPayBean.getAlipayPublicKey()) |
|
|
|
|
|
.setAliPayRootCertPath(aliPayBean.getRootCertPath()) |
|
|
.build(); |
|
|
.build(); |
|
|
domain = aliPayBean.getDomain(); |
|
|
domain = aliPayBean.getDomain(); |
|
|
privateKey = aliPayBean.getPrivateKey(); |
|
|
privateKey = aliPayBean.getPrivateKey(); |
|
|
publicKey = aliPayBean.getPublicKey(); |
|
|
publicKey = aliPayBean.getAlipayPublicKey(); |
|
|
appId = aliPayBean.getAppId(); |
|
|
appId = aliPayBean.getAppId(); |
|
|
} |
|
|
} |
|
|
return aliPayApiConfig; |
|
|
return aliPayApiConfig; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public AlipayClient alipayClient() throws AlipayApiException { |
|
|
|
|
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); |
|
|
|
|
|
certAlipayRequest.setServerUrl(GATE); //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
|
|
|
|
|
|
certAlipayRequest.setAppId(APPID); //APPID 即创建应用后生成,详情见创建应用并获取 APPID
|
|
|
|
|
|
certAlipayRequest.setPrivateKey(APP_PRIVATE_KEY); //开发者应用私钥,由开发者自己生成
|
|
|
|
|
|
certAlipayRequest.setFormat("json"); //参数返回格式,只支持 json 格式
|
|
|
|
|
|
certAlipayRequest.setCharset(CHARSET); //请求和签名使用的字符编码格式,支持 GBK和 UTF-8
|
|
|
|
|
|
certAlipayRequest.setSignType(SignType); //商户生成签名字符串所使用的签名算法类型,目前支持 RSA2 和 RSA,推荐商家使用 RSA2。
|
|
|
|
|
|
certAlipayRequest.setCertPath(CertPath); //应用公钥证书路径(app_cert_path 文件绝对路径)
|
|
|
|
|
|
certAlipayRequest.setAlipayPublicCertPath(ALIPAY_PUBLIC_KEY); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径)
|
|
|
|
|
|
certAlipayRequest.setRootCertPath(RootCertPath); //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径)
|
|
|
|
|
|
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest); |
|
|
|
|
|
return alipayClient; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@RequestMapping("") |
|
|
@RequestMapping("") |
|
|
@ResponseBody |
|
|
@ResponseBody |
|
|
public String index() { |
|
|
public String index() { |
|
@ -168,9 +244,10 @@ public class AliPayController extends AbstractAliPayApiController { |
|
|
model.setOutTradeNo(orderInfo.getOrderSn()); |
|
|
model.setOutTradeNo(orderInfo.getOrderSn()); |
|
|
model.setTimeoutExpress("30m"); |
|
|
model.setTimeoutExpress("30m"); |
|
|
model.setTotalAmount(orderInfo.getPayAmount().floatValue() + ""); |
|
|
model.setTotalAmount(orderInfo.getPayAmount().floatValue() + ""); |
|
|
model.setPassbackParams("callback params"); |
|
|
// model.setPassbackParams("callback params");
|
|
|
model.setProductCode("QUICK_MSECURITY_PAY"); |
|
|
model.setProductCode("QUICK_MSECURITY_PAY"); |
|
|
String order = AliPayApi.appPayToResponse(model, domain + "/aliPay/notify_url", this.getApiConfig()).getBody(); |
|
|
// String order = AliPayApi.appPayToResponse1(model, domain + "/aliPay/notify_url", this.getApiConfig()).getBody();
|
|
|
|
|
|
String order = AliPayApi.appPayToResponse1(model, domain + "/aliPay/notify_url", alipayClient()).getBody(); |
|
|
//String order = AliPayApi.appPayToResponse(model, domain, this.getApiConfig()).getBody();
|
|
|
//String order = AliPayApi.appPayToResponse(model, domain, this.getApiConfig()).getBody();
|
|
|
System.out.println(JSONObject.toJSONString(orderInfo)); |
|
|
System.out.println(JSONObject.toJSONString(orderInfo)); |
|
|
return new CommonResult().success(order); |
|
|
return new CommonResult().success(order); |
|
@ -475,7 +552,7 @@ public class AliPayController extends AbstractAliPayApiController { |
|
|
public Object tradeRefund(AlipayTradeRefundModel model) { |
|
|
public Object tradeRefund(AlipayTradeRefundModel model) { |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
// AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
/*model.setOutTradeNo("081014283315023"); |
|
|
/*model.setOutTradeNo("081014283315023"); |
|
|
model.setTradeNo("2017081021001004200200273870"); |
|
|
model.setTradeNo("2017081021001004200200273870"); |
|
|
model.setRefundAmount("86.00"); |
|
|
model.setRefundAmount("86.00"); |
|
|