新增加app支付、邀请码等

This commit is contained in:
hupeng
2020-03-28 17:28:10 +08:00
parent ee423b83b5
commit e8e618c459
21 changed files with 412 additions and 129 deletions

View File

@ -56,7 +56,7 @@ public class WxPayConfiguration {
}
/**
* 获取WxAppPayService
* 获取小程序WxAppPayService
* @return
*/
public static WxPayService getWxAppPayService() {
@ -79,6 +79,30 @@ public class WxPayConfiguration {
return wxPayService;
}
/**
* 获取APPPayService
* @return
*/
public static WxPayService getAppPayService() {
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE);
if(wxPayService == null || RedisUtil.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE) == null) {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(RedisUtil.get("wx_native_app_appId"));
payConfig.setMchId(RedisUtil.get("wxpay_mchId"));
payConfig.setMchKey(RedisUtil.get("wxpay_mchKey"));
payConfig.setKeyPath(RedisUtil.get("wxpay_keyPath"));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
payServices.put(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE, wxPayService);
//增加标识
RedisUtil.set(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE,"yshop");
}
return wxPayService;
}
/**
* 移除WxPayService
*/
@ -86,6 +110,7 @@ public class WxPayConfiguration {
RedisUtil.del(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_MINI_PAY_SERVICE);
payServices.remove(ShopConstants.YSHOP_WEIXIN_APP_PAY_SERVICE);
}

View File

@ -6,6 +6,7 @@ import co.yixiang.exception.ErrorRequestException;
import co.yixiang.mp.config.WxPayConfiguration;
import co.yixiang.mp.handler.RedisHandler;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
@ -97,6 +98,38 @@ public class YxPayService {
}
/**
* 微信app支付
*
* @param orderId
* @param body
* @param totalFee
* @return
* @throws WxPayException
*/
public WxPayAppOrderResult appPay(String orderId, String body,
Integer totalFee, String attach) throws WxPayException {
String apiUrl = redisHandler.getVal("api_url");
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getAppPayService();
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setTradeType("APP");
orderRequest.setBody(body);
orderRequest.setOutTradeNo(orderId);
orderRequest.setTotalFee(totalFee);
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify");
orderRequest.setAttach(attach);
WxPayAppOrderResult appOrderResult = wxPayService.createOrder(orderRequest);
return appOrderResult;
}
/**
* 退款