Showing
9 changed files
with
92 additions
and
11 deletions
@@ -69,7 +69,13 @@ public class WeixinPayConfig { | @@ -69,7 +69,13 @@ public class WeixinPayConfig { | ||
69 | public static final String PARTNER_UFO_REAL_APP = "1516774631"; | 69 | public static final String PARTNER_UFO_REAL_APP = "1516774631"; |
70 | public static final String PARTNER_KEY_UFO_REAL_APP = "5f47f0050f5550f16d9262c65a165e0f"; | 70 | public static final String PARTNER_KEY_UFO_REAL_APP = "5f47f0050f5550f16d9262c65a165e0f"; |
71 | public static final String WECHAT_PAY_UFOREAL_APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ufo_real_app.p12"; | 71 | public static final String WECHAT_PAY_UFOREAL_APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ufo_real_app.p12"; |
72 | - | 72 | + |
73 | + public interface Miniapp{ | ||
74 | + String APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_wx_miniapp.p12"; | ||
75 | + String KEY = "5f47f0050f5550f16d9262c65a165e0f"; | ||
76 | + String APPID = "wxc677c88385762287"; | ||
77 | + String MALL_ID = "1516774631"; | ||
78 | + } | ||
73 | 79 | ||
74 | public static final String APP_ID_BLK_PC = "wxd370556ef064789e"; | 80 | public static final String APP_ID_BLK_PC = "wxd370556ef064789e"; |
75 | public static final String APP_SECRET_BLK_PC = "xxxxxxxxxxxxxxxxxxxx"; | 81 | public static final String APP_SECRET_BLK_PC = "xxxxxxxxxxxxxxxxxxxx"; |
@@ -70,9 +70,11 @@ public class PaymentController { | @@ -70,9 +70,11 @@ public class PaymentController { | ||
70 | @RequestMapping(params = "method=ufo.order.pay") | 70 | @RequestMapping(params = "method=ufo.order.pay") |
71 | public ApiResponse pay(@RequestParam(name = "uid") int uid, | 71 | public ApiResponse pay(@RequestParam(name = "uid") int uid, |
72 | @RequestParam(name = "orderCode") long orderCode, | 72 | @RequestParam(name = "orderCode") long orderCode, |
73 | - @RequestParam(name = "payment") int payment){ | 73 | + @RequestParam(name = "payment") int payment, |
74 | + @RequestParam(name = "openid", required = false)String openid){ | ||
74 | 75 | ||
75 | - PaymentRequest request = PaymentRequest.builder().uid(uid).orderCode(orderCode).payment(payment).build(); | 76 | + PaymentRequest request = PaymentRequest.builder().uid(uid).orderCode(orderCode).payment(payment) |
77 | + .openid(openid).build(); | ||
76 | 78 | ||
77 | logger.info("method com.yohoufo.order.controller.PaymentController.pay in, request is {}", request); | 79 | logger.info("method com.yohoufo.order.controller.PaymentController.pay in, request is {}", request); |
78 | 80 |
@@ -31,6 +31,7 @@ import com.yohoufo.order.service.IPaymentService; | @@ -31,6 +31,7 @@ import com.yohoufo.order.service.IPaymentService; | ||
31 | import com.yohoufo.order.service.SellerOrderPaymentService; | 31 | import com.yohoufo.order.service.SellerOrderPaymentService; |
32 | import com.yohoufo.order.service.pay.AbstractPayService; | 32 | import com.yohoufo.order.service.pay.AbstractPayService; |
33 | import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; | 33 | import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; |
34 | +import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; | ||
34 | import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService; | 35 | import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService; |
35 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | 36 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; |
36 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; | 37 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; |
@@ -89,7 +90,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -89,7 +90,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
89 | OrdersPayTransferMapper ordersPayTransferMapper; | 90 | OrdersPayTransferMapper ordersPayTransferMapper; |
90 | 91 | ||
91 | @Autowired | 92 | @Autowired |
92 | - ManualTransferMapper manualTransferMapper; | 93 | + WeixinMiniappPayService weixinMiniappPayService; |
93 | 94 | ||
94 | @Autowired | 95 | @Autowired |
95 | BuyerOrderMapper buyerOrderMapper; | 96 | BuyerOrderMapper buyerOrderMapper; |
@@ -120,9 +121,8 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -120,9 +121,8 @@ public class PaymentServiceImpl implements IPaymentService { | ||
120 | if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()){ | 121 | if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()){ |
121 | paymentService = this.buyerOrderPaymentService; | 122 | paymentService = this.buyerOrderPaymentService; |
122 | 123 | ||
123 | - }else{ | 124 | + }else if(codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()){ |
124 | paymentService = this.sellerOrderPaymentService; | 125 | paymentService = this.sellerOrderPaymentService; |
125 | - | ||
126 | } | 126 | } |
127 | 127 | ||
128 | return paymentService; | 128 | return paymentService; |
@@ -131,7 +131,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -131,7 +131,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
131 | 131 | ||
132 | /** | 132 | /** |
133 | * 获取支付的主场service | 133 | * 获取支付的主场service |
134 | - * @param payment | 134 | + * @param paymentCode |
135 | * @return | 135 | * @return |
136 | */ | 136 | */ |
137 | private AbstractPayService getPayService(int paymentCode){ | 137 | private AbstractPayService getPayService(int paymentCode){ |
@@ -146,8 +146,10 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -146,8 +146,10 @@ public class PaymentServiceImpl implements IPaymentService { | ||
146 | 146 | ||
147 | if (payment == Payment.WECHAT){ | 147 | if (payment == Payment.WECHAT){ |
148 | payService = weixinPayAppService; | 148 | payService = weixinPayAppService; |
149 | - }else { | 149 | + }else if(payment == Payment.ALIPAY){ |
150 | payService = alipayService; | 150 | payService = alipayService; |
151 | + }else if(payment == Payment.MINIAPP){ | ||
152 | + payService = weixinMiniappPayService; | ||
151 | } | 153 | } |
152 | 154 | ||
153 | return payService; | 155 | return payService; |
@@ -966,7 +968,8 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -966,7 +968,8 @@ public class PaymentServiceImpl implements IPaymentService { | ||
966 | 968 | ||
967 | // check 订单是否存在 | 969 | // check 订单是否存在 |
968 | OrderInfo orderInfo = paymentService.getOrderInfo(request.getOrderCode(), request.getUid()); | 970 | OrderInfo orderInfo = paymentService.getOrderInfo(request.getOrderCode(), request.getUid()); |
969 | - | 971 | + //将openID 附属在 orderinfo上,用于拼接支付URL |
972 | + orderInfo.setOpenid(request.getOpenid()); | ||
970 | // 卖家or买家订单,支付方式更新,返回实付金额 | 973 | // 卖家or买家订单,支付方式更新,返回实付金额 |
971 | BigDecimal amount = paymentService.checkUpdOrderCodePayment(orderInfo, request); | 974 | BigDecimal amount = paymentService.checkUpdOrderCodePayment(orderInfo, request); |
972 | 975 |
@@ -513,7 +513,9 @@ public abstract class AbstractWeixinPayService extends AbstractPayService { | @@ -513,7 +513,9 @@ public abstract class AbstractWeixinPayService extends AbstractPayService { | ||
513 | parameters.put(WeixinPayConfig.ApiConstants.NOTIFY_URL, notifyURL); | 513 | parameters.put(WeixinPayConfig.ApiConstants.NOTIFY_URL, notifyURL); |
514 | //parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, "APP"); | 514 | //parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, "APP"); |
515 | parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, getTradeType()); | 515 | parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, getTradeType()); |
516 | - | 516 | + if(WeixinPayConfig.TRADE_TYPE_JSAPI.equals(getTradeType())) { |
517 | + parameters.put(WeixinPayConfig.ApiConstants.OPEN_ID, orderInfo.getOpenid()); | ||
518 | + } | ||
517 | // parameters.put(WeixinPayConfig.ApiConstants.TIME_EXPIRE, orderInfo.getPayExpireTimeStr(Payment.WECHAT)); | 519 | // parameters.put(WeixinPayConfig.ApiConstants.TIME_EXPIRE, orderInfo.getPayExpireTimeStr(Payment.WECHAT)); |
518 | //md5签名 | 520 | //md5签名 |
519 | String sign = WXUtils.signMd5(parameters, getMchKey()); | 521 | String sign = WXUtils.signMd5(parameters, getMchKey()); |
1 | +package com.yohoufo.order.service.pay.weixin; | ||
2 | + | ||
3 | +import com.yohoufo.common.utils.HttpClient; | ||
4 | +import com.yohoufo.order.config.WeixinPayConfig; | ||
5 | +import com.yohoufo.order.service.pay.weixin.ssl.WxMiniappHttpSslClient; | ||
6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | +import org.springframework.stereotype.Service; | ||
8 | + | ||
9 | +/** | ||
10 | + * Created by chao.chen on 2018/11/9. | ||
11 | + */ | ||
12 | +@Service | ||
13 | +public class WeixinMiniappPayService extends AbstractWeixinPayService { | ||
14 | + | ||
15 | + @Autowired | ||
16 | + private WxMiniappHttpSslClient wxMiniappHttpSslClient; | ||
17 | + | ||
18 | + @Override | ||
19 | + protected String getMchId() { | ||
20 | + return WeixinPayConfig.Miniapp.MALL_ID; | ||
21 | + } | ||
22 | + | ||
23 | + @Override | ||
24 | + protected String getMchKey() { | ||
25 | + return WeixinPayConfig.Miniapp.KEY; | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + protected String getAppId() { | ||
30 | + return WeixinPayConfig.Miniapp.APPID; | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + protected String getMchCertPath() { | ||
35 | + return WeixinPayConfig.Miniapp.APP_PARTNER_CERT; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + protected String getTradeType() { | ||
40 | + return WeixinPayConfig.TRADE_TYPE_JSAPI; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + protected HttpClient getSslHttpClient() { | ||
45 | + return wxMiniappHttpSslClient; | ||
46 | + } | ||
47 | +} |
1 | +package com.yohoufo.order.service.pay.weixin.ssl; | ||
2 | + | ||
3 | +import com.yohoufo.order.config.WeixinPayConfig; | ||
4 | +import org.springframework.stereotype.Component; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by chao.chen on 2018/11/9. | ||
8 | + */ | ||
9 | +@Component | ||
10 | +public class WxMiniappHttpSslClient extends HttpSslClientAbstract { | ||
11 | + @Override | ||
12 | + protected String getMchCertPath() { | ||
13 | + return WeixinPayConfig.Miniapp.APP_PARTNER_CERT; | ||
14 | + } | ||
15 | + | ||
16 | + @Override | ||
17 | + protected String getMchCertPassword() { | ||
18 | + return WeixinPayConfig.Miniapp.KEY; | ||
19 | + } | ||
20 | +} |
No preview for this file type
-
Please register or login to post a comment