mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-02 02:34:34 +00:00
feat 手机收银台支持
This commit is contained in:
@@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* 结算台演示
|
||||
@@ -44,4 +45,23 @@ public class CashierController {
|
||||
public ResResult<String> getPayEnv(@RequestHeader("User-Agent") String ua){
|
||||
return Res.ok(cashierService.getPayEnv(ua));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取手机收银台链接")
|
||||
@GetMapping("/getUniCashierUrl")
|
||||
public ResResult<String> getUniCashierUrl(){
|
||||
return Res.ok(cashierService.getUniCashierUrl());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取微信授权链接")
|
||||
@GetMapping("getWxAuthUrl")
|
||||
public ResResult<String> getWxAuthUrl(){
|
||||
return Res.ok(cashierService.getWxAuthUrl());
|
||||
}
|
||||
|
||||
@Operation(summary = "微信授权回调页面")
|
||||
@GetMapping("/wxAuthCallback")
|
||||
public ModelAndView wxAuthCallback(@RequestParam("code") String code){
|
||||
return new ModelAndView("redirect:" + cashierService.wxAuthCallback(code));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.demo.result;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -21,6 +22,7 @@ public class WxJsapiSignResult {
|
||||
@Schema(description = "随机串")
|
||||
private String nonceStr;
|
||||
@Alias("package")
|
||||
@JsonProperty("package")
|
||||
@Schema(description = "预支付ID, 已经是 prepay_id=xxx 格式")
|
||||
private String prePayId;
|
||||
@Schema(description = "签名类型")
|
||||
|
@@ -91,7 +91,7 @@ public class AggregateService {
|
||||
}
|
||||
else if (ua.contains(AggregatePayEnum.UA_WECHAT_PAY.getCode())) {
|
||||
// 微信重定向到中间页, 因为微信需要授权后才能发起支付
|
||||
return this.wxJsapiAuth(code);
|
||||
return this.wxJsapiAuthPage(code);
|
||||
}
|
||||
else {
|
||||
// 跳转到异常页
|
||||
@@ -102,7 +102,7 @@ public class AggregateService {
|
||||
/**
|
||||
* 微信jsapi支付 - 跳转到授权页面
|
||||
*/
|
||||
private String wxJsapiAuth(String code) {
|
||||
private String wxJsapiAuthPage(String code) {
|
||||
// 回调地址为 结算台微信jsapi支付的回调地址
|
||||
WxAuthUrlParam wxAuthUrlParam = new WxAuthUrlParam();
|
||||
wxAuthUrlParam.setState(code);
|
||||
|
@@ -9,9 +9,13 @@ import cn.bootx.platform.daxpay.sdk.code.AggregatePayEnum;
|
||||
import cn.bootx.platform.daxpay.sdk.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.sdk.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.sdk.code.PayWayEnum;
|
||||
import cn.bootx.platform.daxpay.sdk.model.assist.WxAccessTokenModel;
|
||||
import cn.bootx.platform.daxpay.sdk.model.assist.WxAuthUrlModel;
|
||||
import cn.bootx.platform.daxpay.sdk.model.pay.PayOrderModel;
|
||||
import cn.bootx.platform.daxpay.sdk.model.pay.QueryPayOrderModel;
|
||||
import cn.bootx.platform.daxpay.sdk.net.DaxPayKit;
|
||||
import cn.bootx.platform.daxpay.sdk.param.assist.WxAccessTokenParam;
|
||||
import cn.bootx.platform.daxpay.sdk.param.assist.WxAuthUrlParam;
|
||||
import cn.bootx.platform.daxpay.sdk.param.channel.AliPayParam;
|
||||
import cn.bootx.platform.daxpay.sdk.param.channel.WeChatPayParam;
|
||||
import cn.bootx.platform.daxpay.sdk.param.pay.QueryPayOrderParam;
|
||||
@@ -147,10 +151,49 @@ public class CashierService {
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 手机收银台演示
|
||||
// */
|
||||
// public PayOrderResult h5SimplePay(){
|
||||
//
|
||||
// }
|
||||
/**
|
||||
* 获取手机收银台链接
|
||||
*/
|
||||
public String getUniCashierUrl() {
|
||||
return StrUtil.format("{}/cashier/uniCashier", daxPayDemoProperties.getFrontUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信jsapi支付 - 跳转到授权页面
|
||||
*/
|
||||
public String getWxAuthUrl() {
|
||||
// 回调地址为 结算台微信jsapi支付的回调地址
|
||||
WxAuthUrlParam wxAuthUrlParam = new WxAuthUrlParam();
|
||||
String url = StrUtil.format("{}/demo/cashier/wxAuthCallback", daxPayDemoProperties.getServerUrl());
|
||||
wxAuthUrlParam.setUrl(url);
|
||||
DaxPayResult<WxAuthUrlModel> execute = DaxPayKit.execute(wxAuthUrlParam);
|
||||
if (execute.getCode() != 0){
|
||||
throw new BizException(execute.getMsg());
|
||||
}
|
||||
// 微信授权页面链接
|
||||
return execute.getData().getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信授权回调页面, 然后重定向到统一收银台中, 携带openid
|
||||
*/
|
||||
public String wxAuthCallback(String code) {
|
||||
return StrUtil.format("{}/cashier/uniCashier?source=redirect&openId={}", daxPayDemoProperties.getFrontUrl(), this.getOpenId(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信OpenId
|
||||
*/
|
||||
private String getOpenId(String authCode) {
|
||||
// 获取OpenId
|
||||
WxAccessTokenParam param = new WxAccessTokenParam();
|
||||
param.setCode(authCode);
|
||||
|
||||
DaxPayResult<WxAccessTokenModel> result = DaxPayKit.execute(param);
|
||||
// 判断是否支付成功
|
||||
if (result.getCode() != 0){
|
||||
throw new BizException(result.getMsg());
|
||||
}
|
||||
return result.getData().getOpenId();
|
||||
}
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package cn.bootx.platform.daxpay.param.assist;
|
||||
|
||||
import cn.bootx.platform.daxpay.param.PaymentCommonParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 预付订单再次签名参数
|
||||
* @author xxm
|
||||
* @since 2024/2/10
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "预付订单再次签名")
|
||||
public class WxJsapiPrePayParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "预付订单ID")
|
||||
private String prepayId;
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user