Browse Source

recharge bug

lijilei 3 years ago
parent
commit
e661578157

+ 1 - 1
book-push/src/main/java/com/book/push/cons/UrlCons.java

@@ -13,7 +13,7 @@ public class UrlCons {
     public static final String OAUTH2_REDIRECT_URL_LOGIN = SchemeCons.default_scheme_prefix + "://" + "%s/wx/redirect/login";
     public static final String OAUTH2_REDIRECT_URL_SLIENT = SchemeCons.default_scheme_prefix + "://" + "%s/wx/redirect/slient";
     public static final String FRONT_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%s";
-    public static final String URL_PARAMS = "channelId=%d&userId=%s";
+    public static final String URL_PARAMS = "channelId=%d&userId=%s&openid=%s";
     public static final String MODEL_BOOK = "readDetail";
 
     public static final String BOOK_URL = SchemeCons.default_scheme_prefix + "://" + "%s.%s/%s?channelId=%d&userId=%d&bookId=%s";

+ 4 - 4
book-push/src/main/java/com/book/push/controller/LoginController.java

@@ -94,7 +94,7 @@ public class LoginController {
                 e.printStackTrace();
                 user = userService.createUserByOpenid(oAuth2rRefreshToken.getOpenId(), adminConfig.getAdminId());
             }
-            return buildRedirectUrl(getFontUlr(redisService.get(state),adminConfig,user.getId()));
+            return buildRedirectUrl(getFontUlr(redisService.get(state),adminConfig,user.getId(),oAuth2rRefreshToken.getOpenId()));
         }
 
 
@@ -143,7 +143,7 @@ public class LoginController {
                 e.printStackTrace();
                 user = userService.createUserByOpenid(oAuth2rRefreshToken.getOpenId(), adminConfig.getAdminId());
             }
-            return buildRedirectUrl(getFontUlr(referer,adminConfig,user.getId()));
+            return buildRedirectUrl(getFontUlr(referer,adminConfig,user.getId(),oAuth2rRefreshToken.getOpenId()));
         }
     }
 
@@ -170,7 +170,7 @@ public class LoginController {
         return "redirect:" + fontUlr;
     }
 
-    private String getFontUlr(String referer, AdminConfig adminConfig, Long userId) {
+    private String getFontUlr(String referer, AdminConfig adminConfig, Long userId,String openid) {
         if (referer == null) {
             return "登录失败啦,请在网站里面进行登录";
         }
@@ -178,7 +178,7 @@ public class LoginController {
         Ophost ophost = opHostService.selectById(ophostId);
 //        String s = redisService.get(referer);
         String url = UrlUtil.replaceDomain(referer, adminConfig.getAppid() + "." + ophost.getHost());
-        return UrlUtil.addParams(url, String.format(UrlCons.URL_PARAMS, adminConfig.getAdminId(), userId));
+        return UrlUtil.addParams(url, String.format(UrlCons.URL_PARAMS, adminConfig.getAdminId(), userId,openid));
     }
 
 

+ 4 - 3
book-server/src/main/java/com/book/server/controller/WxPayController.java

@@ -75,15 +75,16 @@ public class WxPayController extends BaseController {
     @GetMapping("/login")
     public String chargePage(HttpServletRequest request, @RequestParam(required = false) String userId,
                              @RequestParam(required = false) String code, @RequestParam(required = false) String state
-            ,@RequestParam(required = false) String channelId ,@RequestParam(required = false) String redirectUrl
+            ,@RequestParam(required = false) String channelId ,@RequestParam(required = false) String redirectUrl,@RequestParam(required = false) String openid
             ,@RequestParam(required = false) String redirectId ) {
 
        /* if (userId == null) {
             userId = state;
         }*/
+        String s = wxPayService.chargePage(userId, channelId, redirectUrl, redirectId, state, code,openid);
+        log.info("跳转:"+ s);
 
-
-        return wxPayService.chargePage(userId, channelId, redirectUrl,redirectId,state,code);
+        return s;
     }
 
     /**

+ 1 - 1
book-server/src/main/java/com/book/server/service/WxPayService.java

@@ -26,5 +26,5 @@ public interface WxPayService {
 
     OrderVo queryOrder(String orderId);
 
-    String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code);
+    String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code,String openid);
 }

+ 26 - 8
book-server/src/main/java/com/book/server/service/impl/WxPayServiceImpl.java

@@ -77,6 +77,7 @@ public class WxPayServiceImpl implements WxPayService {
         Integer wxpayId = adminConfig.getWxpayId();
         Wxpay wxpay = wxpayMapper.selectByPrimaryKey(wxpayId);
         String appid = wxpay.getAppid();
+        appid = adminConfig.getAppid();
         String secret = wxpay.getSecret();
         String host = wxpay.getPayHost();
         String palmpayAppid = wxpay.getQuartetAppId();
@@ -137,7 +138,7 @@ public class WxPayServiceImpl implements WxPayService {
         map.put("notifyUrl", url + "/api/wxpay/notify");
         map.put("ip", wxPayRequest.getIp());
 
-        map.put("api", "1");
+
 
 
         String str = palmpayAppid + "WECHAT_SUB" + amount + mchOrderid + palmpayAppkey;
@@ -152,9 +153,9 @@ public class WxPayServiceImpl implements WxPayService {
         wxPayInfo.setUserId(userByUserId.getId() + "");
         wxPayInfo.setOrderId(String.valueOf(order.getId()));
         if ( StringUtils.isNotEmpty(wxPayRequest.getOpenid())) {
-            map.put("subAppid", wxpay.getAppid()==null?"":wxpay.getAppid());
+            map.put("subAppid", appid==null?"":appid);
             map.put("openid", wxPayRequest.getOpenid());
-
+            map.put("api", "1");
             String result = HTTPSUtil.sendGetByHttps(PALMPAY_URL, map);
             System.out.println("响应:" + result);
             PalmpayResponse object = JsonUtils.getObject(result, PalmpayResponse.class);
@@ -169,11 +170,17 @@ public class WxPayServiceImpl implements WxPayService {
             updateOrder.setId(order.getId());
             updateOrder.setPdorderid(r.getPdorderid());
             String pay_info = r.getPay_info();
+
+
             updateOrder.setPayJson(pay_info);
+            if(pay_info.startsWith("http")){
+                wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
+            }else {
+                Map<String, Object> map1 = JsonUtils.getMap(pay_info);
+                wxPayInfo.setPayInfo(map1);
+                wxPayInfo.setUrl("");
+            }
 
-            Map<String, Object> map1 = JsonUtils.getMap(pay_info);
-            wxPayInfo.setPayInfo(map1);
-            wxPayInfo.setUrl("");
 
         } else {
             wxPayInfo.setUrl(PALMPAY_URL + "?" + form);
@@ -240,12 +247,23 @@ public class WxPayServiceImpl implements WxPayService {
 
 
     @Override
-    public String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code) {
+    public String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code,String openid) {
 
 
         AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(Integer.valueOf(channelId));
         Integer wxpayId = adminConfig.getWxpayId();
         Wxpay wxpay = wxpayMapper.selectByPrimaryKey(wxpayId);
+        boolean newpay = true;
+        if (newpay){
+            if (StringUtils.isEmpty(openid)){
+                User userByUserId = userService.getUserByUserId(Long.parseLong(userId));
+                openid = userByUserId.getOpenid();
+            }
+            String url =String.format( Const.URL_PAY_CENTER,wxpay.getPayHost(),userId,channelId,redirectUrl,redirectId,openid);
+            return "redirect:" + url;
+        }
+
+
         String appid = wxpay.getAppid();
         String secret = wxpay.getSecret();
         String host = wxpay.getPayHost();
@@ -269,7 +287,7 @@ public class WxPayServiceImpl implements WxPayService {
             String format = String.format(openidUrl, appid, secret, code);
             String s = HttpUtils.sendGet(format);
             SnsapiBase object = JsonUtils.getObject(s, SnsapiBase.class);
-            String openid = object.getOpenid();
+             openid = object.getOpenid();
             String url =String.format( Const.URL_PAY_CENTER,wxpay.getPayHost(),userId,channelId,redirectUrl,redirectId,openid);
             return "redirect:" + url;
         }