|
@@ -9,15 +9,12 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.llisoft.pay.common.Constant;
|
|
|
import com.llisoft.pay.config.MtaException;
|
|
|
-import com.llisoft.pay.dao.ItemDao;
|
|
|
-import com.llisoft.pay.dao.OrderDao;
|
|
|
-import com.llisoft.pay.entity.App;
|
|
|
-import com.llisoft.pay.entity.Item;
|
|
|
-import com.llisoft.pay.entity.Order;
|
|
|
+import com.llisoft.pay.dao.PayDao;
|
|
|
+import com.llisoft.pay.entity.Pay;
|
|
|
import com.llisoft.pay.util.CodeUtil;
|
|
|
-import com.llisoft.pay.vo.ApiAddResponseVo;
|
|
|
-import com.llisoft.pay.vo.ApiPayWxAppResponseVo;
|
|
|
+import com.llisoft.pay.util.JsonUtil;
|
|
|
import com.llisoft.pay.vo.ApiInfoResponseVo;
|
|
|
+import com.llisoft.pay.vo.ApiPayWxAppResponseVo;
|
|
|
|
|
|
@Service
|
|
|
public class ApiService {
|
|
@@ -26,96 +23,63 @@ public class ApiService {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- private ItemDao payDao;
|
|
|
- @Autowired
|
|
|
- private OrderDao orderDao;
|
|
|
- @Autowired
|
|
|
- private PayAliService payAliService;
|
|
|
+ private PayDao payDao;
|
|
|
@Autowired
|
|
|
private PayWxV3Service payWxV3Service;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 下单
|
|
|
- * @param money 金额(分)
|
|
|
- * @param title 订单描述
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ApiAddResponseVo add(int money, String title) {
|
|
|
- Order order = new Order();
|
|
|
- order.setOrderNum(CodeUtil.time()); // 当前时间+5位随机数
|
|
|
- order.setOrderMoney(money); // 订单金额(分)
|
|
|
- order.setOrderTitle(title); // 订单描述
|
|
|
- order.setOrderStatus(Constant.STATUS_WAIT);
|
|
|
- orderDao.insert(order);
|
|
|
- logger.debug("添加订单成功: {}", order.getOrderNum());
|
|
|
- ApiAddResponseVo responseVo = new ApiAddResponseVo();
|
|
|
- responseVo.setId(order.getOrderNum());
|
|
|
- responseVo.setMoney(money);
|
|
|
- return responseVo;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 查询
|
|
|
- * @param id orderNum
|
|
|
* @return
|
|
|
*/
|
|
|
- public ApiInfoResponseVo info(String id) {
|
|
|
- Order order = orderDao.selectByOrderNum(id);
|
|
|
- if(Objects.isNull(order)) {
|
|
|
- throw MtaException.build("订单不存在:" + id);
|
|
|
+ public ApiInfoResponseVo info(String pid) {
|
|
|
+ Pay pay = payDao.selectByPid(pid);
|
|
|
+ if(Objects.isNull(pay)) {
|
|
|
+ throw MtaException.build("支付记录不存在:" + pid);
|
|
|
}
|
|
|
ApiInfoResponseVo responseVo = new ApiInfoResponseVo();
|
|
|
- responseVo.setPid(order.getOrderNum());
|
|
|
- responseVo.setPayed(order.getOrderStatus() == Constant.STATUS_PAYED);
|
|
|
+ responseVo.setPid(pay.getPid());
|
|
|
+ responseVo.setPayed(pay.getStatus() == Constant.STATUS_PAYED);
|
|
|
return responseVo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付 栋科
|
|
|
- * @param id orderNum
|
|
|
- * @param type 支付方式(1支付宝,2微信)
|
|
|
* @return
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
- public ApiPayWxAppResponseVo payDongke(String appid, String id, byte type) {
|
|
|
- Order order = orderDao.selectByOrderNum(id);
|
|
|
- if(Objects.isNull(order)) {
|
|
|
- throw MtaException.build("订单不存在:" + id);
|
|
|
- }
|
|
|
- if(order.getOrderStatus() == Constant.STATUS_PAYED){
|
|
|
- throw MtaException.build("订单已支付:" + id);
|
|
|
- }
|
|
|
- // 添加支付记录
|
|
|
- Item item = new Item();
|
|
|
- item.setPayNum(CodeUtil.uuid());
|
|
|
- item.setPayType(type);
|
|
|
- item.setOrderId(order.getOrderId());
|
|
|
- item.setPayMoney(order.getOrderMoney());
|
|
|
- item.setPayStatus(Constant.STATUS_WAIT);
|
|
|
- payDao.insert(item);
|
|
|
- // 发起支付
|
|
|
- if (item.getPayType() == Constant.TYPE_ALI) { // 支付宝
|
|
|
-
|
|
|
- }else if (item.getPayType() == Constant.TYPE_WX) { // 微信
|
|
|
- payWxV3Service.appDongke(appid, item.getPayNum(), item.getPayMoney(), order.getOrderTitle());
|
|
|
- return wxPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- String payNum = payService.add(payType, order.getOrderMoney(), order.getOrderId());
|
|
|
- return payService.pay(payNum, isMobile);
|
|
|
+ public ApiPayWxAppResponseVo wxAppDongke(String appid, int money, String title) throws Exception {
|
|
|
+ Pay pay = this.pay(appid, money, title);
|
|
|
+ logger.debug("添加支付记录:{}", JsonUtil.toJson(pay));
|
|
|
+ return payWxV3Service.appDongke(appid, pay.getPid(), money, title);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 支付 青谷
|
|
|
- * @param id orderNum
|
|
|
- * @param type 支付方式(1支付宝,2微信)
|
|
|
* @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public ApiPayWxAppResponseVo wxAppQinggu(String appid, int money, String title) throws Exception {
|
|
|
+ Pay pay = this.pay(appid, money, title);
|
|
|
+ return payWxV3Service.appQinggu(appid, pay.getPid(), money, title);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加支付记录
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
- public ApiPayWxAppResponseVo payQinggu(String appid, String id, byte type) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- return null;
|
|
|
+ private Pay pay(String appid, int money, String title) throws Exception {
|
|
|
+ Pay pay = new Pay();
|
|
|
+ pay.setMoney(money);
|
|
|
+ pay.setTitle(title);
|
|
|
+ pay.setPid(CodeUtil.time());
|
|
|
+ pay.setType(Constant.TYPE_WX);
|
|
|
+ pay.setStatus(Constant.STATUS_WAIT);
|
|
|
+ payDao.insert(pay);
|
|
|
+ logger.debug("添加支付记录:{}", JsonUtil.toJson(pay));
|
|
|
+ return pay;
|
|
|
}
|
|
|
|
|
|
}
|