优化获取渠道用户ID逻辑&小新支付接口增加微信和支付宝jsapi支付

This commit is contained in:
dingzhiwei 2021-09-25 22:28:02 +08:00
parent 93b6464a52
commit b86ac87ed3
9 changed files with 217 additions and 11 deletions

View File

@ -154,6 +154,12 @@ jeepay
![Jeepay演示界面](http://jeequan.oss-cn-beijing.aliyuncs.com/jeepay/img/yanshi/022.png "Jeepay演示界面")
## 赞助商:驰骋工作流、表单引擎、驰骋低代码快速开发平台.
- 驰骋工作流、表单、低代码平台100%开源java.net双版本.
- 下载地址: https://ccfast.cc/?Frm=jeepay
- 纯国产工作流支持10多种数据库支持saas,单组织,集团模式。
- 容易集成可配置程度高提高95%的开发效率,完善的视频教程.
## 🥪 关于我们
***
微信扫描下面二维码,关注官方公众号:计全科技,获取更多精彩内容。

View File

@ -23,7 +23,7 @@ spring:
# yml填写url连接串 无需将&符号进行转义
url: jdbc:mysql://127.0.0.1:3306/jeepaydb?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
username: root
password:
password: 123
druid:
# 连接池配置项
initial-size: 5 #初始化时建立物理连接的个数

View File

@ -18,6 +18,7 @@ package com.jeequan.jeepay.pay.channel.alipay;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.params.alipay.AlipayConfig;
import com.jeequan.jeepay.core.model.params.alipay.AlipayIsvParams;
import com.jeequan.jeepay.core.model.params.alipay.AlipayNormalMchParams;
@ -26,6 +27,7 @@ import com.jeequan.jeepay.pay.exception.ChannelException;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
/*
* 支付宝 获取用户ID实现类
@ -52,17 +54,24 @@ public class AlipayChannelUserService implements IChannelUserService {
if(mchAppConfigContext.isIsvsubMch()){
AlipayIsvParams isvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(getIfCode(), AlipayIsvParams.class);
if(isvParams == null) {
throw new BizException("服务商支付宝接口没有配置!");
}
appId = isvParams.getAppId();
}else{
//获取商户配置信息
AlipayNormalMchParams normalMchParams = mchAppConfigContext.getNormalMchParamsByIfCode(getIfCode(), AlipayNormalMchParams.class);
if(normalMchParams == null) {
throw new BizException("商户支付宝接口没有配置!");
}
appId = normalMchParams.getAppId();
if(normalMchParams.getSandbox() != null && normalMchParams.getSandbox() == CS.YES){
oauthUrl = AlipayConfig.SANDBOX_OAUTH_URL;
}
}
return String.format(oauthUrl, appId, callbackUrlEncode);
String alipayUserRedirectUrl = String.format(oauthUrl, appId, callbackUrlEncode);
log.info("alipayUserRedirectUrl={}", alipayUserRedirectUrl);
return alipayUserRedirectUrl;
}
@Override

View File

@ -17,6 +17,7 @@ package com.jeequan.jeepay.pay.channel.wxpay;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayIsvParams;
import com.jeequan.jeepay.core.model.params.wxpay.WxpayNormalMchParams;
import com.jeequan.jeepay.pay.channel.IChannelUserService;
@ -52,11 +53,17 @@ public class WxpayChannelUserService implements IChannelUserService {
String oauth2Url = "";
if(mchAppConfigContext.isIsvsubMch()){
WxpayIsvParams wxpayIsvParams = mchAppConfigContext.getIsvConfigContext().getIsvParamsByIfCode(CS.IF_CODE.WXPAY, WxpayIsvParams.class);
if(wxpayIsvParams == null) {
throw new BizException("服务商微信支付接口没有配置!");
}
appId = wxpayIsvParams.getAppId();
oauth2Url = wxpayIsvParams.getOauth2Url();
}else{
//获取商户配置信息
WxpayNormalMchParams normalMchParams = mchAppConfigContext.getNormalMchParamsByIfCode(CS.IF_CODE.WXPAY, WxpayNormalMchParams.class);
if(normalMchParams == null) {
throw new BizException("商户微信支付接口没有配置!");
}
appId = normalMchParams.getAppId();
oauth2Url = normalMchParams.getOauth2Url();
}
@ -64,8 +71,9 @@ public class WxpayChannelUserService implements IChannelUserService {
if(StringUtils.isBlank(oauth2Url)){
oauth2Url = DEFAULT_OAUTH_URL;
}
return String.format(oauth2Url + "?appid=%s&scope=snsapi_base&state=&redirect_uri=%s&response_type=code#wechat_redirect", appId, callbackUrlEncode);
String wxUserRedirectUrl = String.format(oauth2Url + "?appid=%s&scope=snsapi_base&state=&redirect_uri=%s&response_type=code#wechat_redirect", appId, callbackUrlEncode);
log.info("wxUserRedirectUrl={}", wxUserRedirectUrl);
return wxUserRedirectUrl;
}
@Override

View File

@ -110,6 +110,4 @@ public class XxpayKit {
return payUrl;
}
}

View File

@ -78,10 +78,12 @@ public class XxpayPaymentService extends AbstractPaymentService {
String sign = XxpayKit.getSign(paramMap, params.getKey());
paramMap.put("sign", sign);
// 支付下单地址
String payUrl = XxpayKit.getPaymentUrl(params.getPayUrl());
String payUrl = XxpayKit.getPaymentUrl(params.getPayUrl())+ "?" + JeepayKit.genUrlParams(paramMap);
String resStr = "";
try {
resStr = HttpUtil.createPost(payUrl + "?" + JeepayKit.genUrlParams(paramMap)).timeout(60 * 1000).execute().body();
log.info("请求{}参数:{}", getIfCode(), payUrl);
resStr = HttpUtil.createPost(payUrl).timeout(60 * 1000).execute().body();
log.info("请求{}结果:{}", getIfCode(), resStr);
} catch (Exception e) {
log.error("http error", e);
}
@ -96,7 +98,6 @@ public class XxpayPaymentService extends AbstractPaymentService {
JSONObject resObj = JSONObject.parseObject(resStr);
if(!"0".equals(resObj.getString("retCode"))){
String retMsg = resObj.getString("retMsg");
log.error("请求"+getIfCode()+"返回结果异常, resObj={}", resObj.toJSONString());
channelRetMsg.setChannelState(ChannelRetMsg.ChannelState.CONFIRM_FAIL);
channelRetMsg.setChannelErrCode("");
channelRetMsg.setChannelErrMsg(retMsg);

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jeequan.jeepay.pay.channel.xxpay.payway;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.AlipayTradeCreateModel;
import com.alipay.api.request.AlipayTradeCreateRequest;
import com.alipay.api.response.AlipayTradeCreateResponse;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams;
import com.jeequan.jeepay.core.utils.AmountUtil;
import com.jeequan.jeepay.pay.channel.alipay.AlipayKit;
import com.jeequan.jeepay.pay.channel.xxpay.XxpayPaymentService;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliBarOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliJsapiOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliJsapiOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.WxBarOrderRQ;
import com.jeequan.jeepay.pay.util.ApiResBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.TreeMap;
/*
* 小新支付 支付宝jsapi支付
*
* @author jmdhappy
* @site https://www.jeequan.com
* @date 2021/9/25 16:20
*/
@Service("xxpayPaymentByAliJsapiService") //Service Name需保持全局唯一性
public class AliJsapi extends XxpayPaymentService {
@Override
public String preCheck(UnifiedOrderRQ rq, PayOrder payOrder) {
AliJsapiOrderRQ bizRQ = (AliJsapiOrderRQ) rq;
if(StringUtils.isEmpty(bizRQ.getBuyerUserId())){
throw new BizException("[buyerUserId]不可为空");
}
return null;
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception{
AliJsapiOrderRQ bizRQ = (AliJsapiOrderRQ) rq;
XxpayNormalMchParams params = mchAppConfigContext.getNormalMchParamsByIfCode(getIfCode(), XxpayNormalMchParams.class);
// 构造支付请求参数
Map<String,Object> paramMap = new TreeMap();
paramMap.put("mchId", params.getMchId());
paramMap.put("productId", "8008"); // 支付宝服务端支付
paramMap.put("mchOrderNo", payOrder.getPayOrderId());
paramMap.put("amount", payOrder.getAmount() + "");
paramMap.put("currency", "cny");
paramMap.put("clientIp", payOrder.getClientIp());
paramMap.put("device", "web");
paramMap.put("returnUrl", getReturnUrl());
paramMap.put("notifyUrl", getNotifyUrl(payOrder.getPayOrderId()));
paramMap.put("subject", payOrder.getSubject());
paramMap.put("body", payOrder.getBody());
paramMap.put("channelUserId", bizRQ.getBuyerUserId());
// 构造函数响应数据
AliJsapiOrderRS res = ApiResBuilder.buildSuccess(AliJsapiOrderRS.class);
ChannelRetMsg channelRetMsg = new ChannelRetMsg();
res.setChannelRetMsg(channelRetMsg);
// 发起支付
JSONObject resObj = doPay(payOrder, params, paramMap, channelRetMsg);
if(resObj == null) {
return res;
}
String alipayTradeNo = resObj.getJSONObject("payParams").getString("alipayTradeNo");
res.setAlipayTradeNo(alipayTradeNo);
return res;
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jeequan.jeepay.pay.channel.xxpay.payway;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.params.xxpay.XxpayNormalMchParams;
import com.jeequan.jeepay.pay.channel.xxpay.XxpayPaymentService;
import com.jeequan.jeepay.pay.model.MchAppConfigContext;
import com.jeequan.jeepay.pay.rqrs.AbstractRS;
import com.jeequan.jeepay.pay.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.pay.rqrs.payorder.UnifiedOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliJsapiOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.AliJsapiOrderRS;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.WxJsapiOrderRQ;
import com.jeequan.jeepay.pay.rqrs.payorder.payway.WxJsapiOrderRS;
import com.jeequan.jeepay.pay.util.ApiResBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.TreeMap;
/*
* 小新支付 微信jsapi支付
*
* @author jmdhappy
* @site https://www.jeequan.com
* @date 2021/9/25 16:20
*/
@Service("xxpayPaymentByWxJsapiService") //Service Name需保持全局唯一性
public class WxJsapi extends XxpayPaymentService {
@Override
public String preCheck(UnifiedOrderRQ rq, PayOrder payOrder) {
WxJsapiOrderRQ bizRQ = (WxJsapiOrderRQ) rq;
if(StringUtils.isEmpty(bizRQ.getOpenid())){
throw new BizException("[openId]不可为空");
}
return null;
}
@Override
public AbstractRS pay(UnifiedOrderRQ rq, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) throws Exception{
WxJsapiOrderRQ bizRQ = (WxJsapiOrderRQ) rq;
XxpayNormalMchParams params = mchAppConfigContext.getNormalMchParamsByIfCode(getIfCode(), XxpayNormalMchParams.class);
// 构造支付请求参数
Map<String,Object> paramMap = new TreeMap();
paramMap.put("mchId", params.getMchId());
paramMap.put("productId", "8004"); // 微信公众号支付
paramMap.put("mchOrderNo", payOrder.getPayOrderId());
paramMap.put("amount", payOrder.getAmount() + "");
paramMap.put("currency", "cny");
paramMap.put("clientIp", payOrder.getClientIp());
paramMap.put("device", "web");
paramMap.put("returnUrl", getReturnUrl());
paramMap.put("notifyUrl", getNotifyUrl(payOrder.getPayOrderId()));
paramMap.put("subject", payOrder.getSubject());
paramMap.put("body", payOrder.getBody());
paramMap.put("channelUserId", bizRQ.getOpenid());
// 构造函数响应数据
WxJsapiOrderRS res = ApiResBuilder.buildSuccess(WxJsapiOrderRS.class);
ChannelRetMsg channelRetMsg = new ChannelRetMsg();
res.setChannelRetMsg(channelRetMsg);
// 发起支付
JSONObject resObj = doPay(payOrder, params, paramMap, channelRetMsg);
if(resObj == null) {
return res;
}
res.setPayInfo(resObj.getString("payParams"));
return res;
}
}

View File

@ -1 +0,0 @@
放置打包好的html文件。