新增:余额支付接口
This commit is contained in:
@@ -36,23 +36,49 @@ public class RequestUtil {
|
||||
ACCESS_TOKEN = token;
|
||||
}
|
||||
|
||||
// 微信支付通知
|
||||
public void pushWxPayNotify(Transaction transaction){
|
||||
System.out.println("transaction = " + transaction);
|
||||
// 预付请求付款(余额支付)
|
||||
public Object balancePay(Order order){
|
||||
// 设置租户ID
|
||||
// setTenantId(payment.getTenantId().toString());
|
||||
// 推送支付通知地址
|
||||
// String path = payment.getNotifyUrl();
|
||||
setTenantId(order.getTenantId().toString());
|
||||
// 设置token
|
||||
setAccessToken(order.getAccessToken());
|
||||
// 余额支付接口
|
||||
String path = "/system/payment/balancePay";
|
||||
try {
|
||||
// 链式构建请求
|
||||
String result = HttpRequest.post("http://pxf4av.natappfree.cc/api/shop/wx-pay/nbg/paySuccess")
|
||||
.header("Tenantid", "10158")
|
||||
.body(JSONUtil.toJSONString(transaction))//表单内容
|
||||
final String body = HttpRequest.post(host.concat(path))
|
||||
.header("Tenantid", TENANT_ID)
|
||||
.header("Authorization", ACCESS_TOKEN)
|
||||
.body(JSONUtil.toJSONString(order))//表单内容
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute().body();
|
||||
|
||||
return JSONUtil.parseObject(body, ApiResult.class).getData();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 微信支付通知
|
||||
public String pushWxPayNotify(Transaction transaction, Payment payment){
|
||||
// 设置租户ID
|
||||
setTenantId(payment.getTenantId().toString());
|
||||
// 推送支付通知地址
|
||||
String path = payment.getNotifyUrl();
|
||||
try {
|
||||
// 链式构建请求
|
||||
return HttpRequest.post(path)
|
||||
.header("Tenantid", TENANT_ID)
|
||||
.body(JSONUtil.toJSONString(transaction))//表单内容
|
||||
.timeout(20000)//超时,毫秒
|
||||
.execute().body();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "支付失败";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -102,32 +102,48 @@ public class CartController extends BaseController {
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
|
||||
// 查询参数
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(cart.getType());
|
||||
|
||||
// 购物车是否已存在
|
||||
final Cart item = cartService.getOne(new LambdaQueryWrapper<Cart>()
|
||||
.eq(Cart::getUserId, loginUser.getUserId())
|
||||
.eq(Cart::getGoodsId, cart.getGoodsId())
|
||||
.eq(Cart::getType,cart.getType())
|
||||
.last("limit 1"));
|
||||
|
||||
// 附加用户ID
|
||||
cart.setUserId(loginUser.getUserId());
|
||||
|
||||
// 字段验证
|
||||
if (cart.getCartNum() == null) {
|
||||
return fail("购买数量不能为空");
|
||||
}
|
||||
|
||||
System.out.println("cart = " + cart);
|
||||
// 立即购买按钮
|
||||
if(cart.getIsNew() != null && cart.getIsNew()){
|
||||
cartService.save(cart);
|
||||
return success(cart);
|
||||
}
|
||||
|
||||
// 修改购物车
|
||||
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
if (cart.getIsNew() != null) {
|
||||
queryWrapper.eq(Cart::getIsNew,cart.getIsNew());
|
||||
}
|
||||
|
||||
// 购物车是否已存在
|
||||
queryWrapper.eq(Cart::getUserId, loginUser.getUserId())
|
||||
.eq(Cart::getGoodsId, cart.getGoodsId())
|
||||
.eq(Cart::getType, cart.getType())
|
||||
.last("limit 1");
|
||||
|
||||
Cart item = cartService.getOne(queryWrapper);
|
||||
|
||||
// 查询购物车的参数
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(cart.getType());
|
||||
if (cart.getIsNew() != null) {
|
||||
param.setIsNew(cart.getIsNew());
|
||||
}
|
||||
|
||||
// 重复商品叠加数量
|
||||
if(item != null){
|
||||
System.out.println("item = " + item);
|
||||
item.setCartNum(item.getCartNum() + cart.getCartNum());
|
||||
cartService.updateById(item);
|
||||
|
||||
return success("添加成功",computeCart(param));
|
||||
if (cartService.updateById(item)) {
|
||||
return success("更新成功", computeCart(param));
|
||||
}
|
||||
}
|
||||
|
||||
// 新添加商品
|
||||
@@ -220,8 +236,6 @@ public class CartController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// @ApiOperation("按店铺ID更新选择状态")
|
||||
// @PutMapping("/updateCartByMerchantId/{id}")
|
||||
// public ApiResult<?> updateCartByMerchantId(@PathVariable("id") Long id) {
|
||||
|
||||
@@ -314,7 +314,7 @@ public class OrderController extends BaseController {
|
||||
// TODO 余额支付
|
||||
if (order.getPayType().equals(0)) {
|
||||
order.setAccessToken(order.getAccessToken());
|
||||
return success("下单成功", orderService.payByBalance(order));
|
||||
return success("下单成功", requestUtil.balancePay(order));
|
||||
}
|
||||
|
||||
// TODO 微信统一下单接口
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Api(tags = "微信支付结果通知")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/wx-pay/nbg")
|
||||
@RequestMapping("/api/shop/wx-pay/notify/nbg")
|
||||
public class WxPayNotifyNbgController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@@ -52,7 +52,7 @@ public class WxPayNotifyNbgController extends BaseController {
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@ApiModelProperty("微信支付通知")
|
||||
@PostMapping("/notify")
|
||||
@PostMapping()
|
||||
public String demo(@RequestBody Transaction transaction){
|
||||
|
||||
System.out.println("支付通知 >>>>> ");
|
||||
|
||||
@@ -66,6 +66,9 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
|
||||
if(param.getType() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getType,param.getType());
|
||||
}
|
||||
if(param.getIsNew() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getIsNew,param.getIsNew());
|
||||
}
|
||||
|
||||
return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper);
|
||||
}
|
||||
|
||||
@@ -123,6 +123,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
.select(GoodsSpec::getSpecValue)
|
||||
.select(GoodsSpec::getSpecName)
|
||||
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
||||
.gt(Goods::getStock,0)
|
||||
.eq(Goods::getType,0);
|
||||
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
||||
}
|
||||
@@ -135,6 +136,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
||||
.select(GoodsSpec::getSpecValue)
|
||||
.select(GoodsSpec::getSpecName)
|
||||
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
|
||||
.gt(Goods::getStock,0)
|
||||
.eq(Goods::getType,1);
|
||||
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.gxwebsoft.shop.param.OrderParam;
|
||||
import com.gxwebsoft.shop.service.*;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAConfig;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
|
||||
Reference in New Issue
Block a user