最近接到一个小程序微信支付的需求,需要我写后台支持,本着能不自己写就不自己写的cv原则,在网上找到了些第三方程序,经过尝试后,最后决定了这不要脸作者的这款
https://github.com/Pay-Group/best-pay-sdk
不要脸的作者,自称最好用的sdk,demo地址:
https://github.com/Pay-Group/best-pay-demo
/**
* 发起支付
*/
@GetMapping(value = "/pay")
@ResponseBody
public PayResponse pay(@RequestParam("openid") String openid,
@RequestParam("amount") Double amount,
Map<String, Object> map) {
PayRequest request = new PayRequest();
Random random = new Random();
//支付请求参数
request.setPayTypeEnum(BestPayTypeEnum.WXPAY_H5);
request.setOrderId(String.valueOf(random.nextInt(1000000000)));
request.setOrderAmount(amount);
request.setOrderName("xxx费");
request.setOpenid(openid);
log.info("【发起支付】request={}", JsonUtil.toJson(request));
PayResponse payResponse = bestPayService.pay(request);
log.info("【发起支付】response={}", JsonUtil.toJson(payResponse));
return payResponse;
}