支付宝交易辅助接口实现。

This commit is contained in:
zzs
2017-03-07 20:27:01 +08:00
parent 93586a4530
commit d41fc4cec1
12 changed files with 543 additions and 261 deletions

View File

@@ -2,6 +2,13 @@
package in.egan.pay.demo.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayTradeQueryResponse;
import in.egan.pay.ali.before.bean.AliTransactionType;
import in.egan.pay.common.api.Callback;
import in.egan.pay.common.util.str.StringUtils;
import in.egan.pay.demo.entity.ApyAccount;
import in.egan.pay.demo.entity.PayType;
@@ -14,7 +21,6 @@ import in.egan.pay.common.bean.PayOrder;
import in.egan.pay.common.bean.PayOutMessage;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@@ -149,6 +155,37 @@ public class PayController{
return payResponse.getService().getPayOutMessage("fail","失败").toMessage();
}
/**
* 查询
* @param payId
* @return
*/
@RequestMapping("query")
public Map<String, Object> query(Integer payId) {
PayResponse payResponse = service.getPayResponse(payId);
return payResponse.getService().query("2017012921001004530273937216", "8a2950f959cf08740159ea0666fc04bd");
}
/**
* 查询
* @param payId
* @return
*/
@RequestMapping("query1")
public Map<String, Object> query1(Integer payId) {
PayResponse payResponse = service.getPayResponse(payId);
return payResponse.getService().secondaryInterface("2017012921001004530273937216", "8a2950f959cf08740159ea0666fc04bd", AliTransactionType.QUERY, new Callback<Map<String, Object>>() {
@Override
public Map<String, Object> perform(Map<String, Object> map) {
return map;
}
});
}

View File

@@ -29,24 +29,25 @@ public class ApyAccountRepository {
ApyAccount apyAccount1 = new ApyAccount();
apyAccount1.setPayId(1);
apyAccount1.setPartner("2088911944978307");
apyAccount1.setAppid("2016052301431829");
apyAccount1.setAppid("2016041301292728");
// TODO 2017/2/9 16:20 author: egan sign_type只有单一key时public_key与private_key相等比如sign_type=MD5的情况
apyAccount1.setPublicKey("48gf0iwuhr***********r9weh9eiut9");
apyAccount1.setPrivateKey("48gf0iwuhr***********r9weh9eiut9");
apyAccount1.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB");
apyAccount1.setPrivateKey("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANJ480HqtM0gcAFfU1Mi9D/U8VCb51nUIQkxAcbCABh1awhVte7cVRU5Qf+iJr9OewPVRSEyFzAbstrSDggv5Igq7qiQr3HeM265FIMdfY5snxe4u+BBrFDmdpewSAa6WpSJRtcKW2uO6Ui5ycD6n61j2B6TvCCKsDijTzFcxOcpAgMBAAECgYEAorOJKL2tQpz+uLDeEviEZAvS+ANtFo3bc+WEgAdcV4v9T5YibCG7TArVMC5DUcPzaIUnSYAVWMUwv+N9oWqUeB9sue04sdfaBpHPAaOSezzb4J/TtEaJoX72HcjWhgrG1AIAKyaw1P1nQ99zr2EbS1wIGXw4FNLWuo92tKDCsZkCQQD19Feh5Xm8N49Mqt8of+Mpez2dbxKVcU3yZLZFTDj47SZVto32q+kRqngRmgM037c2ms6Rnb9qyw6tbvzTUr8rAkEA2xGdPBu5Fmm2/+Jm8/1hxfqzwVATyc/TOAaeVAK7bS2GaWNoe4wJ4Xea/U2XPl+8+qP5Q+RYJ98IUOLC+e5o+wJBAKynEmEWikcipVhHVpHCfH8hARaj4uK+/92Y7w5kPFYZe2CN3sf604hQJysL9xZFuQH+1+UGXFmmIy6CC754hrMCQCmeoBPCZJiofvcAaXTjZ8b4SVxpvUizLjrPrxbg6gDlDEtLcpc+VMY8Nfr32csk3z9zFbFbWZBBpE/RtR9Mty8CQFqhVygF3FIiz5Sc38sz12RqOT7kUQK3R0FiATOtXkKHLzb/QyolOXi/avhLp/gIl7+IqZg51Vx8BvyypnIfKgw=");
apyAccount1.setNotifyUrl("http://pay.egan.in/payBack2.json");
// 无需同步回调可不填
apyAccount1.setReturnUrl("");
apyAccount1.setInputCharset("UTF-8");
apyAccount1.setSignType("MD5");
apyAccount1.setPayType(PayType.wxPay);
apyAccount1.setMsgType(MsgType.xml);
apyAccount1.setSignType("RSA");
apyAccount1.setPayType(PayType.aliPay);
apyAccount1.setMsgType(MsgType.text);
apyAccounts.put(1, apyAccount1);
ApyAccount apyAccount2 = new ApyAccount();
apyAccount2.setPayId(2);
apyAccount2.setPartner("2088****8307");
apyAccount2.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4*****IZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB");
apyAccount2.setPrivateKey("MIICdwIBADANBgkqhkiG9w0BAQ**********g51Vx8BvyypnIfKgw=");
apyAccount2.setPartner("2088911944978307");
apyAccount2.setAppid("2017030105973474");
apyAccount2.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB");
apyAccount2.setPrivateKey("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAI6D7p2Dza+JYQEnLUKTeGTkJ/QSWA7dulJJS/8ETTQDEwb5ODwKXK3ItOLjeJ9yTAemSqJefIMHBTG+MvONrWgZpmz2oK8dAxH/iqyqxb4r9IODsMgzziNb9EjCs3vfHx9zgcmBhTDnqQZE0jnY2MchOXwnUDz45gDdxwhBHZEpAgMBAAECgYBzKU1CX2VwOVT3t46tQ7l/3ZYjdkdODAIpyCzu76zrIKjZc73rVnw5ufvhc+re/V9OtyOMPUnkH2IlJgrKIGxEg2OuBFdl8rDmNYjBdiFSykjMmsyj2s5uLZ73iEfXxtNDVrahh5ISdNYJAaANL6pMLE7mGoTinc/jv0cUKS1aAQJBAMrfLx/vnu5dvDE7+NvJ8xv8xLhR94NTzpGZl9tNYa2FgxsrD9n9j7SBf5AbWOcZzc5eRYMSDFt18DS5jpjx+2ECQQCz1l2AWWbWHwW+JcDgHI3CXUjOv4f1mltOc+tGA2aqKkXV6Euy5r5kla9BXCFr/b1XGGt4dhXDczWWLTfV7nLJAkAfMMkyA8lPpKG2gB32zMnP18D3BcMkMdJkmFS8pt0JrKlHmAtL3KwneHGAWnQEs/bsb5oIWNIFjdBsisrdwPaBAkEAm8ymOpC5Z91+cypv+3ihU3bPodYK6rssST5h4MkHg3qV/+h81GPVJH0NVPmFNvKfuzm7uaPL3QUNsqpACkXHCQJBAIfxCQjvmmj5HrXh0HF+VLYJVsVg6WVcLRNOLAi2xP39Ep1JN/Gsq7D/O7K9RJhs8g+69jKCVW83C4Wss/O7AQM=");
apyAccount2.setNotifyUrl("http://pay.egan.in/payBack3.json");
// 无需同步回调可不填 app填这个就可以
apyAccount2.setReturnUrl("m.alipay.com");

View File

@@ -1,8 +1,8 @@
package in.egan.pay.demo.entity;
import in.egan.pay.ali.api.AliPayConfigStorage;
import in.egan.pay.ali.api.AliPayService;
import in.egan.pay.ali.bean.AliTransactionType;
import in.egan.pay.ali.before.api.AliPayService;
import in.egan.pay.ali.before.bean.AliTransactionType;
import in.egan.pay.common.api.PayService;
import in.egan.pay.common.bean.BasePayType;
import in.egan.pay.common.bean.TransactionType;
@@ -22,11 +22,13 @@ import in.egan.pay.wx.youdian.bean.YoudianTransactionType;
*/
public enum PayType implements BasePayType {
aliPay{
@Override
public PayService getPayService(ApyAccount apyAccount) {
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
aliPayConfigStorage.setPid(apyAccount.getPartner());
aliPayConfigStorage.setAppId(apyAccount.getAppid());
aliPayConfigStorage.setAliPublicKey(apyAccount.getPublicKey());
aliPayConfigStorage.setKeyPrivate(apyAccount.getPrivateKey());
aliPayConfigStorage.setNotifyUrl(apyAccount.getNotifyUrl());

View File

@@ -2,10 +2,10 @@
package in.egan.pay.demo.service;
import in.egan.pay.ali.bean.AliTransactionType;
import in.egan.pay.demo.entity.ApyAccount;
import in.egan.pay.demo.entity.PayType;
import in.egan.pay.demo.service.handler.AliPayMessageHandler;
import in.egan.pay.demo.service.handler.FuiouPayMessageHandler;
import in.egan.pay.demo.service.handler.WxPayMessageHandler;
import in.egan.pay.demo.service.handler.YouDianPayMessageHandler;
import in.egan.pay.demo.service.interceptor.AliPayMessageInterceptor;
@@ -64,20 +64,21 @@ public class PayResponse {
.rule()
.async(false)
.msgType(MsgType.text.name()) //消息类型
.event(PayType.aliPay.name()) //支付账户事件类型
.payType(PayType.aliPay.name()) //支付账户事件类型
.transactionType(AliTransactionType.UNAWARE.name())//交易类型,有关回调的可在这处理
.interceptor(new AliPayMessageInterceptor(payId)) //拦截器
.handler(autowire(new AliPayMessageHandler(payId))) //处理器
.end()
.rule()
.async(false)
.msgType(MsgType.xml.name())
.event(PayType.wxPay.name())
.payType(PayType.wxPay.name())
.handler(autowire(new WxPayMessageHandler(payId)))
.end()
.rule()
.async(false)
.msgType(MsgType.json.name())
.event(PayType.youdianPay.name())
.payType(PayType.youdianPay.name())
.handler(autowire(new YouDianPayMessageHandler(payId)))
.end()

View File

@@ -24,12 +24,8 @@ public class AliPayMessageHandler extends BasePayMessageHandler {
@Override
public PayOutMessage handle(PayMessage payMessage, Map<String, Object> context, PayService payService) throws PayErrorException {
//交易状态
String trade_status = null;
try {
trade_status = new String(payMessage.getPayMessage().get("trade_status").getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String trade_status =payMessage.getPayMessage().get("trade_status");
if(trade_status.equals("TRADE_FINISHED")){
//判断该笔订单是否在商户网站中已经做过处理

View File

@@ -4,7 +4,6 @@ import in.egan.pay.common.api.PayService;
import in.egan.pay.common.bean.PayMessage;
import in.egan.pay.common.bean.PayOutMessage;
import in.egan.pay.common.exception.PayErrorException;
import in.egan.pay.demo.service.handler.BasePayMessageHandler;
import java.util.Map;