From 6a9f084df10957a904e1ecdd0489ed455c5521a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Thu, 12 Sep 2024 14:34:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0pcpay=20=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 10 ++++++++++ .../system/cashierservice/util/WechatUtil.java | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index b146960..0f03308 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -1897,6 +1897,16 @@ public class PayService { public Result createOrder(String ip,String userId,String payType,String shopId,BigDecimal amount) throws JsonProcessingException { + if(ObjectUtil.isNull(userId)||ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(payType)||ObjectUtil.isNull(payType) + + ||ObjectUtil.isNull(shopId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isNull(shopId)||ObjectUtil.isNull(amount)||ObjectUtil.isEmpty(amount) + ){ + return Result.fail(CodeEnum.PARAM); + } + + if(!"WECHAT".equals(payType)||!"ALIPAY".equals(payType)){ + return Result.fail(CodeEnum.PARAM); + } TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); if(ObjectUtil.isNull(shopInfo)){ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java index 2a389ce..6bb4a48 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/WechatUtil.java @@ -104,7 +104,7 @@ public class WechatUtil { public static JSONObject getSessionKeyOrOpenId(String code, String appId, String secrete) { - String requestUrl = "https://api.weixin.qq.com/sns/jscode2session"; + String requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?"; Map requestUrlParam = new HashMap<>(); // https://mp.weixin.qq.com/wxopen/devprofile?action=get_profile&token=164113089&lang=zh_CN //小程序appId @@ -112,10 +112,11 @@ public class WechatUtil { //小程序secret requestUrlParam.put("secret", secrete); //小程序端返回的code - requestUrlParam.put("js_code", code); + requestUrlParam.put("code", code); //默认参数 requestUrlParam.put("grant_type", "authorization_code"); //发送post请求读取调用微信接口获取openid用户唯一标识 + log.info("请求参数:{}",JSONUtil.toJSONString(requestUrlParam)); JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doPost(requestUrl,requestUrlParam)); return jsonObject; }