-
下载相关的(预)发行release版本(com.one.wxpay.zip)
-
将zip解压到本地maven仓库中
-
添加maven坐标如下
<dependency> <groupId>com.one.wxpay</groupId> <artifactId>wxpay</artifactId> <version>{下载的版本号}</version> </dependency>
-
application.yml配置必要参数
//示例子 spring: wxpay: //微信提供的appId app-id: ****** //微信商户平台ID mch-id: ****** //微信商户平台Key mch-key: ******
-
注入服务
@Autowired private WxpayService wxpayService;
-
调用方法并传入相关参数发起支付
/* * sendPay方法参数介绍 * Map必填参数介绍(其他参数参照官方文档): * body:商品描述 * out_trade_no:商户订单号 * total_fee:价格(单位:分) * spbill_create_ip:发起支付的IP地址 * notify_url trade_type:微信支付回调地址 * trade_type:交易类型(由于一个后台系统可能提供多端app支付使用,故此参数并没加入配置文件中) * openid:当trade_type为JSAPI时为必传 */
// 使用示例 @RestController public class Test() { @Autowired WxpayService wxpayService; @GetMapping("/pay") public Map<String,String> pay{ Map<String,String> params = new HashMap<>(); params.put("body","测试-商品"); params.put("out_trade_no", UUID.randomUUID().toString().replace("-","").toUpperCase()); params.put("total_fee","100"); params.put("spbill_create_ip",request.getRemoteAddr()); params.put("notify_url","你的回调地址 请输入全域名"); params.put("trade_type","NATIVE"); return wxpayService.sendPay(params); } }
lwl9710 / wxpay Goto Github PK
View Code? Open in Web Editor NEWThis is a wxpay starter