lijilei 3 éve
szülő
commit
aea9e4386d

+ 1 - 1
book-server/src/main/java/com/book/server/config/Const.java

@@ -4,7 +4,7 @@ public class Const {
     public static final String CacheSplit = "_";
     public static final String EDIT_BOOK_PRE = "edit_book";
 
-    public static  final  String URL_PAY_CENTER = "http://{host}/pay?userId={userId}&payOpenid={openid}";
+    public static  final  String URL_PAY_CENTER = "http://%s/pay?userId=%s&channelId=%s&redirectUrl=%s&redirectId=%s&payOpenid=%s";
 
     public static final Long bookIdMin = 110_0001L;
     public static final Long bookInMax = 110_9999L;

+ 8 - 5
book-server/src/main/java/com/book/server/controller/WxPayController.java

@@ -74,13 +74,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 code, @RequestParam(required = false) String state
+            ,@RequestParam(required = false) String channelId ,@RequestParam(required = false) String redirectUrl
+            ,@RequestParam(required = false) String redirectId ) {
 
-        String domain = request.getServerName();
-        if (userId == null) {
+       /* if (userId == null) {
             userId = state;
-        }
-        return wxPayService.chargePage(userId, code, domain);
+        }*/
+
+
+        return wxPayService.chargePage(userId, channelId, redirectUrl,redirectId,state,code);
     }
 
     /**

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

@@ -23,8 +23,8 @@ public interface WxPayService {
     String PayNotify(HttpServletRequest request);
 
 
-    String chargePage(String userId, String code,String page);
 
     OrderVo queryOrder(String orderId);
 
+    String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code);
 }

+ 12 - 10
book-server/src/main/java/com/book/server/service/impl/WxPayServiceImpl.java

@@ -234,21 +234,26 @@ public class WxPayServiceImpl implements WxPayService {
         return "success";
     }
 
+
+
     @Override
-    public String chargePage(String userId, String code, String domain) {
-        User userByUserId = userService.getUserByUserId(Long.parseLong(userId));
-        Integer channelId = userByUserId.getChannelId();
-        AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(channelId);
+    public String chargePage(String userId, String channelId, String redirectUrl, String redirectId, String state, String code) {
+
+
+        AdminConfig adminConfig = adminConfigMapper.selectByPrimaryKey(Integer.valueOf(channelId));
         Integer wxpayId = adminConfig.getWxpayId();
         Wxpay wxpay = wxpayMapper.selectByPrimaryKey(wxpayId);
         String appid = wxpay.getAppid();
         String secret = wxpay.getSecret();
         String host = wxpay.getPayHost();
         if (StringUtils.isEmpty(code)) {
-            String redirectUrl = "http://" + host + "/api/wxpay/login?userId=" + userId;
+            String params = "userId=%s&channelId=%s&redirectUrl=%s&redirectId=%s";
+            params = String.format(params,userId,channelId,redirectUrl,redirectId);
+
+            String oau2thRedirectUrl = "http://" + host + "/api/wxpay/login?" +params;
             String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect";
             try {
-                url = String.format(url, appid, java.net.URLEncoder.encode(redirectUrl, "UTF-8"), userId);
+                url = String.format(url, appid, java.net.URLEncoder.encode(oau2thRedirectUrl, "UTF-8"), userId);
             } catch (UnsupportedEncodingException e) {
                 e.printStackTrace();
             }
@@ -262,10 +267,7 @@ public class WxPayServiceImpl implements WxPayService {
             String s = HttpUtils.sendGet(format);
             SnsapiBase object = JsonUtils.getObject(s, SnsapiBase.class);
             String openid = object.getOpenid();
-            String url = Const.URL_PAY_CENTER
-                    .replace("{host}", wxpay.getPayHost())
-                    .replace("userId", userId)
-                    .replace("{openid}", openid);
+            String url =String.format( Const.URL_PAY_CENTER,wxpay.getPayHost(),userId,channelId,redirectUrl,redirectId,openid);
             return "redirect:" + url;
         }