实现支付功能 (未完成)
This commit is contained in:
parent
d1b1317d1f
commit
9c9db1c79b
|
|
@ -15,9 +15,6 @@ import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* 通知设置管理
|
|
||||||
*/
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("api/setting/notice")
|
@RequestMapping("api/setting/notice")
|
||||||
@Api(tags = "配置消息通知")
|
@Api(tags = "配置消息通知")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.mdd.admin.controller.setting;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mdd.admin.service.ISettingPaymentService;
|
||||||
|
import com.mdd.admin.validate.setting.SettingPaymentValidate;
|
||||||
|
import com.mdd.common.aop.NotLogin;
|
||||||
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("api/setting/payment")
|
||||||
|
@Api(tags = "配置支付参数")
|
||||||
|
public class SettingPaymentController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ISettingPaymentService iSettingPaymentService;
|
||||||
|
|
||||||
|
public AjaxResult<Object> method() {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotLogin
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation(value="支付渠道列表")
|
||||||
|
public AjaxResult<Object> list() {
|
||||||
|
List<DevPayConfig> list = iSettingPaymentService.list();
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotLogin
|
||||||
|
@PostMapping("/edit")
|
||||||
|
@ApiOperation(value="支付渠道编辑")
|
||||||
|
public AjaxResult<Object> edit(@Validated @RequestBody SettingPaymentValidate paymentValidate) {
|
||||||
|
iSettingPaymentService.edit(paymentValidate);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.mdd.admin.service;
|
||||||
|
|
||||||
|
import com.mdd.admin.validate.setting.SettingPaymentValidate;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付配置服务接口类
|
||||||
|
*/
|
||||||
|
public interface ISettingPaymentService {
|
||||||
|
|
||||||
|
List<DevPayConfig> list();
|
||||||
|
|
||||||
|
void edit(SettingPaymentValidate paymentValidate);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.mdd.admin.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.mdd.admin.service.ISettingPaymentService;
|
||||||
|
import com.mdd.admin.validate.setting.SettingPaymentValidate;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
import com.mdd.common.mapper.setting.DevPayConfigMapper;
|
||||||
|
import com.mdd.common.util.MapUtils;
|
||||||
|
import com.mdd.common.util.UrlUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付配置服务实现类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SettingPaymentServiceImpl implements ISettingPaymentService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DevPayConfigMapper devPayConfigMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DevPayConfig> list() {
|
||||||
|
List<DevPayConfig> devPayConfigs = devPayConfigMapper.selectList(
|
||||||
|
new QueryWrapper<DevPayConfig>()
|
||||||
|
.orderByDesc(Arrays.asList("sort", "id")));
|
||||||
|
|
||||||
|
for (DevPayConfig dev : devPayConfigs) {
|
||||||
|
dev.setParams(MapUtils.jsonToMap(dev.getParams().toString()));
|
||||||
|
dev.setIcon(UrlUtils.toAbsoluteUrl(dev.getIcon()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return devPayConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void edit(SettingPaymentValidate paymentValidate) {
|
||||||
|
DevPayConfig devPayConfig = devPayConfigMapper.selectOne(
|
||||||
|
new QueryWrapper<DevPayConfig>()
|
||||||
|
.eq("id", paymentValidate.getId())
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(devPayConfig, "数据不存在!");
|
||||||
|
|
||||||
|
devPayConfig.setName(paymentValidate.getName());
|
||||||
|
devPayConfig.setIcon(UrlUtils.toRelativeUrl(paymentValidate.getIcon()));
|
||||||
|
devPayConfig.setSort(paymentValidate.getSort());
|
||||||
|
devPayConfig.setRemark(paymentValidate.getRemark());
|
||||||
|
devPayConfig.setParams(JSON.toJSONString(paymentValidate.getParams()));
|
||||||
|
devPayConfigMapper.updateById(devPayConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.mdd.admin.validate.setting;
|
||||||
|
|
||||||
|
import com.mdd.common.validator.annotation.IDMust;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("支付渠道设置参数")
|
||||||
|
public class SettingPaymentValidate {
|
||||||
|
|
||||||
|
@IDMust(message = "id参数必传且需大于0")
|
||||||
|
@ApiModelProperty(value = "ID", required = true)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotNull(message = "name参数缺失")
|
||||||
|
@ApiModelProperty(value = "模版名称", required = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "模版名称")
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "排序编号")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "备注信息")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "配置参数")
|
||||||
|
private Map<String, String> params;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -186,6 +186,12 @@
|
||||||
<artifactId>oshi-core</artifactId>
|
<artifactId>oshi-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Swagger3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 微信小程序 -->
|
<!-- 微信小程序 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.binarywang</groupId>
|
<groupId>com.github.binarywang</groupId>
|
||||||
|
|
@ -198,9 +204,11 @@
|
||||||
<artifactId>weixin-java-mp</artifactId>
|
<artifactId>weixin-java-mp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 微信支付 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>com.github.binarywang</groupId>
|
||||||
<artifactId>springfox-boot-starter</artifactId>
|
<artifactId>weixin-java-pay</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.mdd.common.config.wechat;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||||
|
import com.github.binarywang.wxpay.service.WxPayService;
|
||||||
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
import com.mdd.common.mapper.setting.DevPayConfigMapper;
|
||||||
|
import com.mdd.common.util.ConfigUtils;
|
||||||
|
import com.mdd.common.util.MapUtils;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass(WxPayService.class)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WxPayConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
DevPayConfigMapper devPayConfigMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信小程序支付配置
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return WxPayService
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public WxPayService mnpPayService() {
|
||||||
|
DevPayConfig config = devPayConfigMapper.selectOne(
|
||||||
|
new QueryWrapper<DevPayConfig>()
|
||||||
|
.eq("way", 2)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Map<String, String> params = MapUtils.jsonToMap(config.getParams().toString());
|
||||||
|
String appId = ConfigUtils.get("mp_channel", "appId", "");
|
||||||
|
String mchId = params.get("mch_id");
|
||||||
|
String paySignKey = params.get("pay_sign_key");
|
||||||
|
byte[] privateKey = params.getOrDefault("private_key", "").getBytes();
|
||||||
|
byte[] privateCert = params.getOrDefault("private_cert", "").getBytes();
|
||||||
|
|
||||||
|
WxPayConfig payConfig = new WxPayConfig();
|
||||||
|
payConfig.setAppId(appId);
|
||||||
|
payConfig.setMchId(mchId);
|
||||||
|
payConfig.setApiV3Key(paySignKey);
|
||||||
|
payConfig.setPrivateKeyContent(privateKey);
|
||||||
|
payConfig.setPrivateCertContent(privateCert);
|
||||||
|
payConfig.setUseSandboxEnv(false);
|
||||||
|
WxPayService wxPayService = new WxPayServiceImpl();
|
||||||
|
wxPayService.setConfig(payConfig);
|
||||||
|
return wxPayService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信公众号支付配置
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return WxPayService
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public WxPayService wxOaService() {
|
||||||
|
DevPayConfig config = devPayConfigMapper.selectOne(
|
||||||
|
new QueryWrapper<DevPayConfig>()
|
||||||
|
.eq("way", 2)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Map<String, String> params = MapUtils.jsonToMap(config.getParams().toString());
|
||||||
|
String appId = ConfigUtils.get("oa_channel", "appId", "");
|
||||||
|
String mchId = params.get("mch_id");
|
||||||
|
String paySignKey = params.get("pay_sign_key");
|
||||||
|
byte[] privateKey = params.getOrDefault("private_key", "").getBytes();
|
||||||
|
byte[] privateCert = params.getOrDefault("private_cert", "").getBytes();
|
||||||
|
|
||||||
|
WxPayConfig payConfig = new WxPayConfig();
|
||||||
|
payConfig.setMchId(mchId);
|
||||||
|
payConfig.setAppId(appId);
|
||||||
|
payConfig.setApiV3Key(paySignKey);
|
||||||
|
payConfig.setPrivateKeyContent(privateKey);
|
||||||
|
payConfig.setPrivateCertContent(privateCert);
|
||||||
|
payConfig.setUseSandboxEnv(false);
|
||||||
|
WxPayService wxPayService = new WxPayServiceImpl();
|
||||||
|
wxPayService.setConfig(payConfig);
|
||||||
|
return wxPayService;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.mdd.common.entity.setting;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("支付配置实体")
|
||||||
|
public class DevPayConfig {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value="id", type= IdType.AUTO)
|
||||||
|
@ApiModelProperty("ID")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty("模版名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("渠道图标")
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
@ApiModelProperty("支付方式: [1=余额支付, 2=微信支付, 3=支付宝支付]")
|
||||||
|
private Integer way;
|
||||||
|
|
||||||
|
@ApiModelProperty("排序编号")
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
@ApiModelProperty("备注信息")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@ApiModelProperty("配置参数")
|
||||||
|
private Object params;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.mdd.common.mapper.setting;
|
||||||
|
|
||||||
|
import com.mdd.common.core.basics.IBaseMapper;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付配置Mapper
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface DevPayConfigMapper extends IBaseMapper<DevPayConfig> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.mdd.common.plugin.wechat;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||||
|
import com.github.binarywang.wxpay.service.WxPayService;
|
||||||
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||||
|
import com.mdd.common.entity.setting.DevPayConfig;
|
||||||
|
import com.mdd.common.enums.ClientEnum;
|
||||||
|
import com.mdd.common.mapper.setting.DevPayConfigMapper;
|
||||||
|
import com.mdd.common.util.ConfigUtils;
|
||||||
|
import com.mdd.common.util.MapUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class WxPayDriver {
|
||||||
|
|
||||||
|
private static DevPayConfigMapper devPayConfigMapper;
|
||||||
|
|
||||||
|
private static WxPayService wxPayService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
public void setDevPayConfigMapper(DevPayConfigMapper devPayConfigMapper) {
|
||||||
|
WxPayDriver.devPayConfigMapper = devPayConfigMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
public void setWxPayService(WxPayService wxPayService) {
|
||||||
|
WxPayDriver.wxPayService = wxPayService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象句柄
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return WxPayService
|
||||||
|
*/
|
||||||
|
public static WxPayService handler(String terminal) {
|
||||||
|
if (String.valueOf(ClientEnum.OA.getCode()).equalsIgnoreCase(terminal)) {
|
||||||
|
resetConfig("oa");
|
||||||
|
} else {
|
||||||
|
resetConfig("mnp");
|
||||||
|
}
|
||||||
|
return wxPayService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重设配置
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param type 类型
|
||||||
|
*/
|
||||||
|
private static void resetConfig(String type) {
|
||||||
|
DevPayConfig config = devPayConfigMapper.selectOne(
|
||||||
|
new QueryWrapper<DevPayConfig>()
|
||||||
|
.eq("way", 2)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
String scene = type.equals("oa") ? "oa_channel" : "mp_channel";
|
||||||
|
String appId = ConfigUtils.get(scene, "appId", "");
|
||||||
|
|
||||||
|
Map<String, String> params = MapUtils.jsonToMap(config.getParams().toString());
|
||||||
|
String mchId = params.get("mch_id");
|
||||||
|
String paySignKey = params.get("pay_sign_key");
|
||||||
|
byte[] privateCert = params.getOrDefault("private_cert", "").getBytes();
|
||||||
|
byte[] privateKey = params.getOrDefault("private_key", "").getBytes();
|
||||||
|
|
||||||
|
WxPayConfig payConfig = new WxPayConfig();
|
||||||
|
payConfig.setAppId(appId);
|
||||||
|
payConfig.setMchId(mchId);
|
||||||
|
payConfig.setApiV3Key(paySignKey);
|
||||||
|
payConfig.setPrivateKeyContent(privateKey);
|
||||||
|
payConfig.setPrivateCertContent(privateCert);
|
||||||
|
payConfig.setUseSandboxEnv(false);
|
||||||
|
WxPayService wxPayService = new WxPayServiceImpl();
|
||||||
|
wxPayService.setConfig(payConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
|
import com.mdd.common.aop.NotLogin;
|
||||||
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import com.mdd.front.service.IPayService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/pay")
|
||||||
|
@Api(tags = "支付管理")
|
||||||
|
public class PayController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IPayService iPayService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预支付
|
||||||
|
*
|
||||||
|
* @return AjaxResult<Object>
|
||||||
|
*/
|
||||||
|
@NotLogin
|
||||||
|
@PostMapping("/prepay")
|
||||||
|
public AjaxResult<Object> prepay() throws Exception {
|
||||||
|
iPayService.prepay();
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信支付回调
|
||||||
|
*
|
||||||
|
* @return AjaxResult<Object>
|
||||||
|
*/
|
||||||
|
public AjaxResult<Object> notifyMnp() {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/recharge")
|
||||||
|
@Api(tags = "充值管理")
|
||||||
|
public class RechargeController {
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public AjaxResult<Object> list() {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/placeOrder")
|
||||||
|
public AjaxResult<Object> placeOrder() {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.mdd.front.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付接口服务类
|
||||||
|
*/
|
||||||
|
public interface IPayService {
|
||||||
|
|
||||||
|
void prepay() throws Exception;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.mdd.front.service.impl;
|
||||||
|
|
||||||
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
||||||
|
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
||||||
|
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
||||||
|
import com.github.binarywang.wxpay.service.WxPayService;
|
||||||
|
import com.mdd.common.plugin.wechat.WxPayDriver;
|
||||||
|
import com.mdd.front.service.IPayService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PayServiceImpl implements IPayService {
|
||||||
|
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepay() throws Exception {
|
||||||
|
|
||||||
|
WxPayService wxPayService = WxPayDriver.handler("1");
|
||||||
|
|
||||||
|
String sn = "sn" + System.currentTimeMillis() / 1000;
|
||||||
|
Long expireTime = System.currentTimeMillis() + 60 * 1000;
|
||||||
|
String timeExpire = format.format(expireTime) + "+08:00";
|
||||||
|
|
||||||
|
// 订单信息
|
||||||
|
WxPayUnifiedOrderV3Request wxPayUnifiedOrderV3Request = new WxPayUnifiedOrderV3Request();
|
||||||
|
wxPayUnifiedOrderV3Request.setOutTradeNo(sn);
|
||||||
|
wxPayUnifiedOrderV3Request.setNotifyUrl("https://www.likeadmin.cn");
|
||||||
|
wxPayUnifiedOrderV3Request.setDescription("充值");
|
||||||
|
wxPayUnifiedOrderV3Request.setTimeExpire(timeExpire);
|
||||||
|
|
||||||
|
// 订单金额
|
||||||
|
WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
|
||||||
|
amount.setTotal(1);
|
||||||
|
amount.setCurrency("CNY");
|
||||||
|
wxPayUnifiedOrderV3Request.setAmount(amount);
|
||||||
|
|
||||||
|
// 付款人
|
||||||
|
WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
|
||||||
|
payer.setOpenid("");
|
||||||
|
wxPayUnifiedOrderV3Request.setPayer(payer);
|
||||||
|
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxPayUnifiedOrderV3Request);
|
||||||
|
System.out.println(jsapiResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -222,6 +222,13 @@
|
||||||
<version>${oshi-core.version}</version>
|
<version>${oshi-core.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Swagger3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 微信小程序 -->
|
<!-- 微信小程序 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.binarywang</groupId>
|
<groupId>com.github.binarywang</groupId>
|
||||||
|
|
@ -236,18 +243,19 @@
|
||||||
<version>${weixin.version}</version>
|
<version>${weixin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 微信支付 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.binarywang</groupId>
|
||||||
|
<artifactId>weixin-java-pay</artifactId>
|
||||||
|
<version>${weixin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 全局工具 -->
|
<!-- 全局工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mdd</groupId>
|
<groupId>org.mdd</groupId>
|
||||||
<artifactId>like-common</artifactId>
|
<artifactId>like-common</artifactId>
|
||||||
<version>${like.version}</version>
|
<version>${like.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-boot-starter</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue