# payment-spring-boot **Repository Path**: ville/payment-spring-boot ## Basic Information - **Project Name**: payment-spring-boot - **Description**: 微信支付V3支付,支持微信优惠券,代金券、商家券、公众号支付、微信小程序支付、分账、支付分、商家券、合单支付、先享卡、电商收付通等全部微信支付功能API,同时满足服务商、商户开发需求。一键集成,上手快,欢迎star。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: release - **Homepage**: https://felord.gitee.io/payment-spring-boot - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 348 - **Created**: 2025-11-02 - **Last Updated**: 2025-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
如果你感觉这个项目不错,请点击右上角的Star以鼓励作者,谢谢。
## 简介 Java微信支付V3支付Spring Boot Starter,支持微信优惠券,代金券、商家券、智慧商圈、商家转账到零钱、公众号支付、微信小程序支付、分账、支付分、商家券、合单支付、先享卡、电商收付通等全部微信支付功能API,同时满足多个服务商、多个商户开发需求。一键集成,屏蔽了复杂度,API友好,上手快,欢迎star。 ## Maven 最新中央仓库坐标 ```xml
* 此处建议在商品订单生成之后调用
*
* @param orderId 商品订单id
* @return the object node
*/
@PostMapping("/js")
public ObjectNode js(@RequestParam String orderId) {
//TODO
// 查询该orderId下是否生成了支付订单
// 如果没有
// 新增支付订单存入数据库 并标明支付状态为【待支付】
// 根据新生成的支付订单信息向微信支付发起支付 并根据返回结果进行处理
// 如果有状态为待支付
// 根据待支付订单信息向微信支付发起支付 并根据返回结果进行处理
// 如果有状态为待支付之外的状态
// 根据产品的业务设计自行实现
// 支付状态更新逻辑在【回调接口 /wxpay/callbacks/transaction】中处理 需要幂等处理
// 开发时需要指定使用的商户租户配置 这里为 mobile 请参考 application-wechat.yml
PayParams payParams = new PayParams();
payParams.setDescription("felord.cn");
//
// 商户侧唯一订单号 建议为商户侧支付订单号 订单表主键 或者唯一标识字段
payParams.setOutTradeNo("X135423420201521613448");
// 需要定义回调通知
payParams.setNotifyUrl("/wxpay/callbacks/transaction");
Amount amount = new Amount();
amount.setTotal(100);
payParams.setAmount(amount);
// 此类支付 Payer 必传 且openid需要同appid有绑定关系 具体去看文档
Payer payer = new Payer();
payer.setOpenid("ooadI5kQYrrCqpgbisvC8bEw_oUc");
payParams.setPayer(payer);
return wechatApiProvider.directPayApi(TENANT_ID)
.jsPay(payParams)
.getBody();
}
/**
* 下载对账单 如果要解析内容的话自行实现
*
* @return the response entity
*/
@GetMapping("/tradebill")
public ResponseEntity
* 务必保证回调接口的幂等性
*
* 微信回调控制器,当支付成功、代金券核销成功后,微信支付服务器会通过回调进行通知商户侧。
* 商户侧可以根据微信的回调通知进行支付的后续处理,例如支付状态的变更等等。
* 需要注意的是回调接口需要白名单放行。
*
* 开发者只需要编写对结果的{@link java.util.function.Consumer}即可。
*
* 请注意:返回的格格式必须是{@link WechatPayCallback} 给出的格式,不能被包装和更改,切记!
* @author felord.cn
* @since 1.0.0.RELEASE
*/
@Profile({"wechat", "dev"})
@RestController
@RequestMapping("/wxpay/callbacks")
public class CallbackController {
private static final String TENANT_ID = "mobile";
@Autowired
private WechatApiProvider wechatApiProvider;
/**
* 代金券核销通知.
*
* 需要手动调用{@link WechatMarketingFavorApi#setMarketingFavorCallback(String)} 设置,一次性操作!
*
* @param wechatpaySerial the wechatpay serial
* @param wechatpaySignature the wechatpay signature
* @param wechatpayTimestamp the wechatpay timestamp
* @param wechatpayNonce the wechatpay nonce
* @param request the request
* @return the map
*/
@SneakyThrows
@PostMapping("/coupon")
public Map
* 无需开发者判断,只有扣款成功微信才会回调此接口
*
* @param wechatpaySerial the wechatpay serial
* @param wechatpaySignature the wechatpay signature
* @param wechatpayTimestamp the wechatpay timestamp
* @param wechatpayNonce the wechatpay nonce
* @param request the request
* @return the map
*/
@SneakyThrows
@PostMapping("/transaction")
public Map
* 无需开发者判断,只有扣款成功微信才会回调此接口
*
* @param wechatpaySerial the wechatpay serial
* @param wechatpaySignature the wechatpay signature
* @param wechatpayTimestamp the wechatpay timestamp
* @param wechatpayNonce the wechatpay nonce
* @param request the request
* @return the map
*/
@SneakyThrows
@PostMapping("/combine_transaction")
public Map