微信小程序支付API

This commit is contained in:
HH 2022-05-09 23:11:42 +08:00
parent 20f8f204b2
commit 052a74b038
1 changed files with 43 additions and 4 deletions

View File

@ -9,24 +9,63 @@ import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.ExceptionUtil; import com.ghy.common.utils.ExceptionUtil;
import com.ghy.common.utils.WxUtils; import com.ghy.common.utils.WxUtils;
import org.springframework.beans.factory.annotation.Autowired; import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderMasterService;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
@RequestMapping("/pay/wx") @RequestMapping("/pay/wx")
public class WxPayController extends BaseController { public class WxPayController extends BaseController {
@Autowired @Resource
private WxConfig wxConfig; private WxConfig wxConfig;
@Resource
@Autowired
private AdapayService adapayService; private AdapayService adapayService;
@Resource
private OrderMasterService orderMasterService;
@PostMapping("lite")
public AjaxResult litePay(HttpServletRequest request) {
String code = request.getParameter("code");
String orderMasterCode = request.getParameter("orderMasterCode");
List<OrderMaster> orderMasters = orderMasterService.selectOrderMasterList(new OrderMaster(orderMasterCode));
if (orderMasters.isEmpty()) {
return AjaxResult.error("订单不存在");
}
OrderMaster orderMaster = orderMasters.get(0);
JSONObject wxUser;
try {
wxUser = WxUtils.getOpenid(code, wxConfig.getAppId(), wxConfig.getSecret());
} catch (IOException e) {
logger.error("获取微信用户信息失败", e);
return AjaxResult.error();
}
String openId = wxUser.getString("openid");
//调用adapay微信公众号支付.
WxLiteExpend expend = new WxLiteExpend();
expend.setOpen_id(openId);
Map<String, Object> map;
try {
// TODO 订单里需要补充支付金额tittle简要描述分账信息description
map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, orderMaster.getCode(), "orderMaster.get支付金额",
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
} catch (BaseAdaPayException e) {
logger.error("获取微信用户信息失败", e);
return AjaxResult.error();
}
return AjaxResult.success(map);
}
/** /**
* 微信公众号支付. * 微信公众号支付.