Authored by chenchao

add miniapp pay

package com.yohoufo.order.common;
public enum Payment {
MINIAPP(3, "miniapp", "微信小程序"),
ALIPAY(2, "alipay", "支付宝"),
WECHAT(1, "wechat", "微信");
... ...
... ... @@ -70,6 +70,12 @@ public class WeixinPayConfig {
public static final String PARTNER_KEY_UFO_REAL_APP = "5f47f0050f5550f16d9262c65a165e0f";
public static final String WECHAT_PAY_UFOREAL_APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ufo_real_app.p12";
public interface Miniapp{
String APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_wx_miniapp.p12";
String KEY = "5f47f0050f5550f16d9262c65a165e0f";
String APPID = "wxc677c88385762287";
String MALL_ID = "1516774631";
}
public static final String APP_ID_BLK_PC = "wxd370556ef064789e";
public static final String APP_SECRET_BLK_PC = "xxxxxxxxxxxxxxxxxxxx";
... ...
... ... @@ -70,9 +70,11 @@ public class PaymentController {
@RequestMapping(params = "method=ufo.order.pay")
public ApiResponse pay(@RequestParam(name = "uid") int uid,
@RequestParam(name = "orderCode") long orderCode,
@RequestParam(name = "payment") int payment){
@RequestParam(name = "payment") int payment,
@RequestParam(name = "openid", required = false)String openid){
PaymentRequest request = PaymentRequest.builder().uid(uid).orderCode(orderCode).payment(payment).build();
PaymentRequest request = PaymentRequest.builder().uid(uid).orderCode(orderCode).payment(payment)
.openid(openid).build();
logger.info("method com.yohoufo.order.controller.PaymentController.pay in, request is {}", request);
... ...
... ... @@ -24,4 +24,5 @@ public class PaymentRequest {
*/
private double refundAmount;
private String openid;
}
... ...
... ... @@ -31,6 +31,7 @@ import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.SellerOrderPaymentService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -89,7 +90,7 @@ public class PaymentServiceImpl implements IPaymentService {
OrdersPayTransferMapper ordersPayTransferMapper;
@Autowired
ManualTransferMapper manualTransferMapper;
WeixinMiniappPayService weixinMiniappPayService;
@Autowired
BuyerOrderMapper buyerOrderMapper;
... ... @@ -120,9 +121,8 @@ public class PaymentServiceImpl implements IPaymentService {
if (codeMeta.getType() == OrderCodeType.BUYER_TYPE.getType()){
paymentService = this.buyerOrderPaymentService;
}else{
}else if(codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()){
paymentService = this.sellerOrderPaymentService;
}
return paymentService;
... ... @@ -131,7 +131,7 @@ public class PaymentServiceImpl implements IPaymentService {
/**
* 获取支付的主场service
* @param payment
* @param paymentCode
* @return
*/
private AbstractPayService getPayService(int paymentCode){
... ... @@ -146,8 +146,10 @@ public class PaymentServiceImpl implements IPaymentService {
if (payment == Payment.WECHAT){
payService = weixinPayAppService;
}else {
}else if(payment == Payment.ALIPAY){
payService = alipayService;
}else if(payment == Payment.MINIAPP){
payService = weixinMiniappPayService;
}
return payService;
... ... @@ -966,7 +968,8 @@ public class PaymentServiceImpl implements IPaymentService {
// check 订单是否存在
OrderInfo orderInfo = paymentService.getOrderInfo(request.getOrderCode(), request.getUid());
//将openID 附属在 orderinfo上,用于拼接支付URL
orderInfo.setOpenid(request.getOpenid());
// 卖家or买家订单,支付方式更新,返回实付金额
BigDecimal amount = paymentService.checkUpdOrderCodePayment(orderInfo, request);
... ...
... ... @@ -513,7 +513,9 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
parameters.put(WeixinPayConfig.ApiConstants.NOTIFY_URL, notifyURL);
//parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, "APP");
parameters.put(WeixinPayConfig.ApiConstants.TRADE_TYPE, getTradeType());
if(WeixinPayConfig.TRADE_TYPE_JSAPI.equals(getTradeType())) {
parameters.put(WeixinPayConfig.ApiConstants.OPEN_ID, orderInfo.getOpenid());
}
// parameters.put(WeixinPayConfig.ApiConstants.TIME_EXPIRE, orderInfo.getPayExpireTimeStr(Payment.WECHAT));
//md5签名
String sign = WXUtils.signMd5(parameters, getMchKey());
... ...
package com.yohoufo.order.service.pay.weixin;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.WxMiniappHttpSslClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chao.chen on 2018/11/9.
*/
@Service
public class WeixinMiniappPayService extends AbstractWeixinPayService {
@Autowired
private WxMiniappHttpSslClient wxMiniappHttpSslClient;
@Override
protected String getMchId() {
return WeixinPayConfig.Miniapp.MALL_ID;
}
@Override
protected String getMchKey() {
return WeixinPayConfig.Miniapp.KEY;
}
@Override
protected String getAppId() {
return WeixinPayConfig.Miniapp.APPID;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.Miniapp.APP_PARTNER_CERT;
}
@Override
protected String getTradeType() {
return WeixinPayConfig.TRADE_TYPE_JSAPI;
}
@Override
protected HttpClient getSslHttpClient() {
return wxMiniappHttpSslClient;
}
}
... ...
package com.yohoufo.order.service.pay.weixin.ssl;
import com.yohoufo.order.config.WeixinPayConfig;
import org.springframework.stereotype.Component;
/**
* Created by chao.chen on 2018/11/9.
*/
@Component
public class WxMiniappHttpSslClient extends HttpSslClientAbstract {
@Override
protected String getMchCertPath() {
return WeixinPayConfig.Miniapp.APP_PARTNER_CERT;
}
@Override
protected String getMchCertPassword() {
return WeixinPayConfig.Miniapp.KEY;
}
}
... ...