Browse Source

Accept Merge Request #17: (develop-wxl -> master)

Merge Request: 修改h5支付接口增加获取支付openid

Created By: @万新亮
Accepted By: @万新亮
URL: https://chuanghaikeji.coding.net/p/smarCampus/d/iHotel_student_houtai/git/merge/17?initial=true
万新亮 1 year ago
parent
commit
adb008716b

+ 5 - 0
src/main/java/com/template/api/HouseOrderAPI.java

@@ -129,5 +129,10 @@ public interface HouseOrderAPI {
     @ApiOperation(value = "小程序-钟点房当天占用状态", notes = "小程序-钟点房当天占用状态", httpMethod = "GET")
     CommonResult appletReserveHour(String houseNumberId, String startTime, int liveTime);
 
+    //微信支付订单号查询订单
+    @PostMapping(value = "/getPayOpenId")
+    @ApiOperation(value = "获取支付人openid", notes = "获取支付人openid", httpMethod = "POST")
+    CommonResult getPayOpenId(@RequestParam String wxcode) throws Exception;
+
 }
 

+ 29 - 13
src/main/java/com/template/controller/HouseOrderController.java

@@ -1733,9 +1733,9 @@ public class HouseOrderController implements HouseOrderAPI {
     @Transactional(rollbackFor = {Exception.class})
     public CommonResult pay(WxPayDto wpd, BindingResult bindingResult, HttpServletRequest request) throws Exception {
         System.out.println(TimeExchange.getTime() + "微信支付参数====:" + JSON.toJSON(wpd));
-        String wxCode = request.getHeader("wxcode");
+        String wxCode = request.getHeader("openId");
         if (wxCode == null || wxCode == "") {
-            return CommonResult.fail("wxcode不能为空");
+            return CommonResult.fail("openId不能为空");
         }
         if (bindingResult.hasErrors()) {
             String st = paramUtils.getParamError(bindingResult);
@@ -1842,18 +1842,19 @@ public class HouseOrderController implements HouseOrderAPI {
 
         // jsapi支付
         //获取openid
-        String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
-        tokenUrl = tokenUrl + "?code=" + wxCode + "&appid=" + wxPayV3Config.getAppId() + "&secret=" + wxPayV3Config.getSecret() + "&grant_type=authorization_code";
-        RestTemplate client = new RestTemplate();
-        String tokenResponse = client.postForObject(tokenUrl, null, String.class);
-        log.info("获取openid结果" + tokenResponse);
-        JSONObject jsonObject1 = JSONObject.parseObject(tokenResponse);
-        String openId = (String) jsonObject1.getString("openid");
-        if (openId == null || openId == "") {
-            return CommonResult.fail("openid查询失败");
-        }
+//        String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
+//        tokenUrl = tokenUrl + "?code=" + wxCode + "&appid=" + wxPayV3Config.getAppId() + "&secret=" + wxPayV3Config.getSecret() + "&grant_type=authorization_code";
+//        RestTemplate client = new RestTemplate();
+//        String tokenResponse = client.postForObject(tokenUrl, null, String.class);
+//        log.info("获取openid结果" + tokenResponse);
+//        JSONObject jsonObject1 = JSONObject.parseObject(tokenResponse);
+//        String openId = (String) jsonObject1.getString("openid");
+//        if (openId == null || openId == "") {
+//            return CommonResult.fail("openid查询失败");
+//        }
 //        String openId = "okdUu5xZ2ICm3RuMUHbpJi4DUyzw";
-//        String openId = wxCode;
+        //改为直接传openId
+        String openId = wxCode;
         PrepayRequest requestpay = new PrepayRequest();
         requestpay.setAppid(wxPayV3Config.getAppId());
         requestpay.setMchid(wxPayV3Config.getMchId());
@@ -3020,6 +3021,21 @@ public class HouseOrderController implements HouseOrderAPI {
         return CommonResult.ok(reserveDayVos);
     }
 
+    @Override
+    public CommonResult getPayOpenId(String wxcode) throws Exception {
+        String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token";
+        tokenUrl = tokenUrl + "?code=" + wxcode + "&appid=" + wxPayV3Config.getAppId() + "&secret=" + wxPayV3Config.getSecret() + "&grant_type=authorization_code";
+        RestTemplate client = new RestTemplate();
+        String tokenResponse = client.postForObject(tokenUrl, null, String.class);
+        log.info("获取openid结果" + tokenResponse);
+        JSONObject jsonObject1 = JSONObject.parseObject(tokenResponse);
+        String openId = (String) jsonObject1.getString("openid");
+        if (openId == null || openId == "") {
+            return CommonResult.fail("openid查询失败:"+tokenResponse);
+        }
+        return CommonResult.ok(openId);
+    }
+
 
     public static void main(String[] args) throws Exception {
 //        获取签名