微信小程序支付API
This commit is contained in:
parent
20f8f204b2
commit
052a74b038
|
|
@ -9,24 +9,63 @@ import com.ghy.common.core.controller.BaseController;
|
|||
import com.ghy.common.core.domain.AjaxResult;
|
||||
import com.ghy.common.utils.ExceptionUtil;
|
||||
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.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/pay/wx")
|
||||
public class WxPayController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private WxConfig wxConfig;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号支付.
|
||||
|
|
|
|||
Loading…
Reference in New Issue