支付相关

This commit is contained in:
13405411873 2024-09-23 22:51:44 +08:00
parent 2ef8c3ac63
commit 1097aba239
5 changed files with 90 additions and 6 deletions

View File

@ -112,4 +112,6 @@ public interface RepairOrderInfoService extends IService<RepairOrderInfo> {
* @return
*/
Map<String,Object> payTransactions(String orderId);
}

View File

@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@ -196,7 +197,7 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
params.put("notify_url", wechatPayConfig.getRepairNotifyUrl());
Map<String, Object> amountMap = new HashMap<>(4);
// 金额单位为分
amountMap.put("total", orderInfo.getPayMoney());
amountMap.put("total", orderInfo.getPayMoney().multiply(BigDecimal.valueOf(100L)).intValue());
//人民币
amountMap.put("currency", "CNY");
params.put("amount", amountMap);

View File

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.app.apy;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.order.entity.RepairOrderInfo;
import cn.iocoder.yudao.module.order.service.RepairOrderInfoService;
import cn.iocoder.yudao.module.order.vo.RepairOrderInfoRespVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "用户端 - 维修模块 订单模块")
@RestController
@RequestMapping("/userClient/order")
@Validated
public class ClientOrderApi {
@Resource
private RepairOrderInfoService repairOrderInfoService;
@GetMapping("/page")
@Operation(summary = "订单分页查询")
@TenantIgnore
public CommonResult<?> getOrderPage(RepairOrderInfoRespVO respVO,
@RequestParam(value = "pageNo", defaultValue = "1")Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
// 当前登录用户的id
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
respVO.setUserId(loginUserId);
Page<RepairOrderInfo> page = new Page<>(pageNo, pageSize);
return success(repairOrderInfoService.getOrderPageByStatus(respVO, page));
}
}

View File

@ -1,15 +1,21 @@
package cn.iocoder.yudao.module.app.apy;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.order.service.RepairOrderInfoService;
import cn.iocoder.yudao.util.WechatPayConfig;
import com.alibaba.fastjson.JSONObject;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -20,16 +26,50 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class RepairPayApi {
@Resource
private RepairOrderInfoService repairOrderInfoService;
@Resource
private WechatPayConfig wechatPayConfig;
/**
* 支付吊起接口
* @param orderId 订单主键
* @return
*/
@GetMapping("/toPay")
@TenantIgnore
public CommonResult<Map<String, Object>> payTransactions(String orderId){
Map<String, Object> res = repairOrderInfoService.payTransactions(orderId);
return success(res);
}
private final ReentrantLock lock = new ReentrantLock();
@PostMapping("/payNotify")
public Map<String, String> payNotify(@RequestBody JSONObject jsonObject) {
try {
String key = wechatPayConfig.getApiV3Key();
String json = jsonObject.toString();
String associated_data = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.associated_data");
String ciphertext = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.ciphertext");
String nonce = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.nonce");
String decryptData = new AesUtil(key.getBytes(StandardCharsets.UTF_8)).decryptToString(associated_data.getBytes(StandardCharsets.UTF_8), nonce.getBytes(StandardCharsets.UTF_8), ciphertext);
//验签成功
JSONObject decryptDataObj = JSONObject.parseObject(decryptData, JSONObject.class);
if(lock.tryLock()) {
try {
String orderNo = decryptDataObj.get("out_trade_no").toString();
repairOrderInfoService.rechargeCallback(orderNo);
} catch (Exception ignored){
} finally{
//要主动释放锁
lock.unlock();
}
}
}catch (Exception ignored){
}
Map<String, String> res = new HashMap<>();
res.put("code", "SUCCESS");
res.put("message", "成功");
return res;
}
}