Commit a73f5574 authored by Wzp's avatar Wzp

H5支付

parent a0aa1b11
......@@ -6,10 +6,13 @@ import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradePagePayModel;
import com.alipay.api.domain.AlipayTradeRefundModel;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.hezhi.domain.TbMemberOrder;
import com.ruoyi.hezhi.service.ITbMemberOrderService;
......@@ -25,6 +28,7 @@ import java.util.Map;
/**
* 支付宝支付
*
* @author Wzp
*/
@Component
......@@ -52,12 +56,13 @@ public class AlipayService {
/**
* 支付宝支付生成预付单
*
* @param realPay 支付金额
* @param paySn 支付单号
* @param description 描述
* @return 结果
*/
public String aliPaySubmit(BigDecimal realPay, String paySn, String description,Long examId,Long memberUserId) {
public String aliPaySubmit(BigDecimal realPay, String paySn, String description, Long examId, Long memberUserId) {
try {
// 初始化SDK
AlipayClient alipayClient = getAlipayClient();
......@@ -71,20 +76,59 @@ public class AlipayService {
model.setProductCode("FAST_INSTANT_TRADE_PAY");// 设置产品码
model.setQrPayMode("1");// 设置PC扫码支付的方式
model.setQrcodeWidth(100L);// 设置商户自定义二维码宽度
model.setRequestFromUrl("https://www.chsie.com.cn/payTheFees?examId="+examId+"&memberUserId="+memberUserId);
model.setRequestFromUrl("https://www.chsie.com.cn/payTheFees?examId=" + examId + "&memberUserId=" + memberUserId);
request.setBizModel(model);
request.setNotifyUrl(aliPayConfig.getNotifyUrl()+"/api/pay/aliPayBoilerNotify");
request.setNotifyUrl(aliPayConfig.getNotifyUrl() + "/api/pay/aliPayBoilerNotify");
// request.setReturnUrl("https://www.chsie.com.cn/examDetail?examId="+examId);//支付成功后跳转回哪个页面
AlipayTradePagePayResponse response = alipayClient.pageExecute(request, "POST");
// 如果需要返回GET请求,请使用
if (response.isSuccess()){
if (response.isSuccess()) {
return response.getBody();
}else {
} else {
throw new ServerCloneException("支付宝支付失败");
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("支付宝支付异常");
}
}
/**
* 支付宝支付生成预付单-H5
*
* @param realPay 支付金额
* @param paySn 支付单号
* @param description 描述
* @return 结果
*/
public String aliPayH5Submit(BigDecimal realPay, String paySn, String description, Long examId, Long memberUserId) {
try {
// 初始化SDK
AlipayClient alipayClient = getAlipayClient();
// 构造请求参数以调用接口
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.setOutTradeNo(paySn);// 设置商户订单号
model.setTotalAmount(realPay.toString());// 设置订单总金额
model.setSubject(description);// 设置订单标题
model.setProductCode("QUICK_WAP_WAY");// 设置产品码
model.setQuitUrl("https://h5.chsie.com.cn/#/subPages/examDetailsIndex/examDetailsIndex?examNoticeId="+examId);
request.setBizModel(model);
request.setNotifyUrl(aliPayConfig.getNotifyUrl() + "/api/pay/aliPayBoilerNotify");
request.setReturnUrl("https://h5.chsie.com.cn/#/subPages/examDetailsIndex/examDetailsIndex?examNoticeId="+examId);
AlipayTradeWapPayResponse response = alipayClient.pageExecute(request, "POST");
// 如果需要返回GET请求,请使用
if (response.isSuccess()) {
return response.getBody();
} else {
throw new ServerCloneException("支付宝支付失败");
}
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException("支付宝支付异常");
}
......@@ -92,6 +136,7 @@ public class AlipayService {
/**
* 支付宝退款
*
* @param orderSn 订单号
* @param payment 支付金额
* @return 结果
......@@ -112,14 +157,14 @@ public class AlipayService {
request.setBizModel(refundModel);
AlipayTradeRefundResponse response = alipayClient.certificateExecute(request);
if (response.isSuccess()){
if (response.isSuccess()) {
log.info("支付宝退款调用成功" + response);
return "SUCCESS";
}else{
} else {
log.error("支付宝退款调用失败" + response);
return "FAIL";
}
}catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
log.error("支付宝退款错误!", e.getMessage());
return "FAIL";
......@@ -128,6 +173,7 @@ public class AlipayService {
/**
* 校验回调参数
*
* @param params 参数
* @return
*/
......@@ -141,7 +187,7 @@ public class AlipayService {
}
// 验证商户app_id
String appId = params.get("app_id");
if(! appId.equals(aliPayConfig.getAppId())){
if (!appId.equals(aliPayConfig.getAppId())) {
log.error("app_id 错误");
return "FAIL";
}
......
......@@ -231,6 +231,8 @@ wx:
apiV3Key: yFRJqhZQJ45wrwg2zJwokb40P7Yn2123
# 微信支付回调通知域名
notifyUrl: https://server.chsie.com.cn/api/pay/createNativePayParamNotify
# 微信支付回调通知域名
h5NotifyUrl: https://server.chsie.com.cn/api/pay/createH5PayParamNotify
# 支付宝支付回调通知域名
notifyZfbUrl: https://server.chsie.com.cn/api/pay/aliPayBoilerNotify
# 商品描述
......
......@@ -178,7 +178,7 @@
<version>23.4</version>
<classifier>jdk17</classifier>
<scope>system</scope>
<systemPath>C:/Users/71960/.m2/repository/com/aspose/aspose-words/23.4/aspose-words-23.4-jdk17.jar</systemPath>
<systemPath>F:/Maven/maven-repo/com/aspose/aspose-words/23.4/aspose-words-23.4-jdk17.jar</systemPath>
</dependency>
<dependency>
......
......@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration;
/**
* 微信支付V3相关参数配置
*
* @author Wzp
*/
@Getter
......@@ -25,9 +26,15 @@ public class WeiXinPayConfig {
@Value("${wx.pay.apiV3Key}")
private String apiV3Key;
//微信回调地址
@Value("${wx.pay.notifyUrl}")
private String notifyUrl;
//微信H5回调地址
@Value("${wx.pay.h5NotifyUrl}")
private String h5NotifyUrl;
//支付宝回调地址
@Value("${wx.pay.notifyZfbUrl}")
private String notifyZfbUrl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment