@ApiModelProperty(value = “逻辑删除 1(true)已删除, 0(false)未删除”)
private Boolean isDeleted;
@ApiModelProperty(value = “创建时间”)
@TableField(fill = FieldFill.INSERT)
private Date gmtCreate;
@ApiModelProperty(value = “更新时间”)
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gmtModified;
}
1.3 导入依赖
在订单模块service_order
导入微信支付需要的依赖:
com.github.wxpay
wxpay-sdk
0.0.3
com.alibaba
fastjson
1.4 配置文件
在配置文件application.properties
配置相关的信息:
服务端口
server.port=8007
服务名
spring.application.name=service-order
mysql数据库连接
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
#返回json的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/atguigu/eduorder/mapper/xml/*.xml
#mybatis日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
#开启熔断机制
#feign.hystrix.enabled=true
设置hystrix超时时间,默认1000ms
#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000
#关联的公众号appid
wx.pay.app_id=wx74862e0dfc69954
#商户号
wx.pay.partner=155895011
#商户key
wx.pay.partnerkey=T6m9iK73b0kn9g5v426MKHQH7X8rKwb
#回调地址
wx.pay.notifyurl=http://guli.shop/api/order/weixinPay/weixinNotify
#微信提供的固定地址
wx.pay.wxurl=https://api.mch.weixin.qq.com/pay/unifiedorder
#微信查询状态地址
wx.pay.queryUrl=https://api.mch.weixin.qq.com/pay/orderquery
1.5 创建读取微信支付相关信息的工具类
创建一个读取微信支付需要的信息的工具类ConstantWxPayUtils
:
@Controller
public class ConstantWxPayUtils implements InitializingBean {
@Value(“${wx.pay.app_id}”)
private String appID;
@Value(“${wx.pay.partner}”)
private String partner;
@Value(“${wx.pay.partnerkey}”)
private String partnerKey;
@Value(“${wx.pay.notifyurl}”)
private String notifyUrl;
@Value(“${wx.pay.wxurl}”)
private String wxUrl;
@Value(“${wx.pay.queryUrl}”)
private String queryUrl;
//定义公共静态常量
public static String WX_PAY_APP_ID;
public static String WX_PAY_PARTNER;
public static String WX_PAY_PARTNER_KEY;
public static String WX_PAY_NOTIFY_URL;
public static String WX_PAY_WX_URL;
public static String WX_PAY_QUERY_URL;
@Override
public void afterPropertiesSet() throws Exception {
WX_PAY_APP_ID = appID;
WX_PAY_PARTNER = partner;
WX_PAY_PARTNER_KEY = partnerKey;
WX_PAY_NOTIFY_URL = notifyUrl;
WX_PAY_WX_URL = wxUrl;
WX_PAY_QUERY_URL=queryUrl;
}
}
1.6 其他工具类
用于随机生成订单号的工具类OrderNoUtil
:
public class OrderNoUtil {
/**
-
获取订单号
-
@return
*/
public static String getOrderNo() {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyyMMddHHmmss”);
String newDate = sdf.format(new Date());
String result = “”;
Random random = new Random();
for (int i = 0; i < 3; i++) {
result += random.nextInt(10);
}
return newDate + result;
}
}
HttpClient
工具类:
/**
-
http请求客户端
-
@author xppll
*/
public class HttpClient {
private String url;
private