lijilei 3 年之前
父节点
当前提交
0ef554613b

+ 1 - 5
book-dao/pom.xml

@@ -82,10 +82,6 @@
             <artifactId>jackson-annotations</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>18.0</version>
-        </dependency>
+
     </dependencies>
 </project>

+ 6 - 7
book-push/src/main/java/com/book/push/controller/BookIndexController.java

@@ -53,6 +53,7 @@ public class BookIndexController {
 //    @GetMapping("/{state}")
 //    public String BookMain(HttpServletRequest request, @PathVariable String state) {
 
+
     @GetMapping()
     public String BookMain(HttpServletRequest request) {
 
@@ -67,14 +68,12 @@ public class BookIndexController {
             appid = "wxe1271417b2ff5b1c";
         }else {
 
-
-
         }
-        String state ="center";
-        if (appid == null || !appid.startsWith("wx")) {
+        String state ="home";
+//        if (appid == null || !appid.startsWith("wx")) {
             String referer = request.getHeader("referer");
             if (referer==null){
-                referer = "http://book.api.esalary.com.cn/";
+                referer = "http://wxe1271417b2ff5b1c.esalary.com.cn/";
             }
              state = Md5Util.md5(referer);
 
@@ -90,7 +89,7 @@ public class BookIndexController {
                 return "登录失败";
             }
 
-        }
+//        }
         AdminConfig adminConfig = adminConfigService.selectByAppid(appid);
         String redirect_url = String.format(UrlCons.OAUTH2_REDIRECT_URL_LOGIN, contextUrl);
 
@@ -98,7 +97,7 @@ public class BookIndexController {
         Integer platformId = adminConfig.getPlatformId();
         WxOpenService wxOpenService = thirdPartService.getWxOpenServiceByPlatFormId(platformId);
         String auto2Url = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appid).getOAuth2Service()
-                .buildAuthorizationUrl(redirect_url, WxConsts.OAuth2Scope.SNSAPI_BASE, state + "_" + adminConfig.getAdminId());
+                .buildAuthorizationUrl(redirect_url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, state + "_" + adminConfig.getAdminId());
         // 静默授权
 
         log.info("跳转:"+auto2Url);

+ 9 - 3
book-push/src/main/java/com/book/push/controller/WxEventController.java

@@ -1,7 +1,9 @@
 package com.book.push.controller;
 
+import com.book.dao.cps.pojo.AdminConfig;
 import com.book.dao.cps.pojo.Platform;
 import com.book.dao.utils.DateUtils;
+import com.book.push.service.dao.AdminConfigService;
 import com.book.push.service.dao.PlatformService;
 import com.book.push.service.dao.UserService;
 import com.book.push.service.wx.WxThirdPartService;
@@ -34,6 +36,8 @@ public class WxEventController {
     private PlatformService platformService;
     @Autowired
     private UserService userService;
+    @Autowired
+    private AdminConfigService adminConfigService;
 
     @RequestMapping("/mpapi/appid/{appId}")
     public Object callback(@RequestBody(required = false) String requestBody,
@@ -50,9 +54,11 @@ public class WxEventController {
                 appId, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
 
 
-        Platform platform = platformService.selectByAppid(appId);
+//        Platform platform = platformService.selectByAppid(appId);
+        AdminConfig adminConfig = adminConfigService.selectByAppid(appId);
+        Integer platformId = adminConfig.getPlatformId();
 
-        WxOpenService wxOpenService = thirdPartService.getWxOpenServiceByPlatFormId(platform.getId());
+        WxOpenService wxOpenService = thirdPartService.getWxOpenServiceByPlatFormId(platformId);
 
         if (!StringUtils.equalsIgnoreCase("aes", encType)
                 || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) {
@@ -72,7 +78,7 @@ public class WxEventController {
                 logger.error("测试报错:", e);
             }
         } else {
-            WxMpXmlOutMessage outMessage = thirdPartService.getWxThirdPartMessageRouter().route(inMessage, platform.getId(), appId);
+            WxMpXmlOutMessage outMessage = thirdPartService.getWxThirdPartMessageRouter().route(inMessage, platformId, appId);
             //todo update user operate time
             userService.updateOperateTimeByOpenid(inMessage.getFromUser(), DateUtils.getNow());
             if (outMessage != null) {

+ 7 - 6
book-push/src/main/java/com/book/push/controller/WxRedirectController.java

@@ -17,6 +17,7 @@ import com.book.push.utils.JsonUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
 import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
@@ -37,7 +38,6 @@ import org.springframework.web.bind.annotation.RequestParam;
  *
  * @author win7
  */
-@AllArgsConstructor
 @Controller
 @Slf4j
 @RequestMapping("/wx/redirect")
@@ -68,6 +68,7 @@ public class WxRedirectController {
      * @return
      */
     @RequestMapping("/login")
+
     public String login(@RequestParam String appid, @RequestParam String code, @RequestParam String state, ModelMap map) {
 
         String[] s = state.split("_");
@@ -104,11 +105,11 @@ public class WxRedirectController {
 
                 //todo 获取基本信息,save
                 WxOpenMpService wxMpServiceByAppid = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appid);
-                WxMpUser wxMpUser = wxMpServiceByAppid.getUserService()
-                        .userInfo(openId, null);
-
-                user = userService.createUserByWxUser(wxMpUser, channelId);
-                user = userService.selectByOpenId(wxMpUser.getOpenId());
+             /*   WxMpUser wxMpUser = wxMpServiceByAppid.getUserService()
+                        .userInfo(openId, null);*/
+                WxOAuth2UserInfo userInfo = wxMpServiceByAppid.getOAuth2Service().getUserInfo(accessToken, "");
+                user = userService.createUserByWxOAuth2UserInfo(userInfo, channelId);
+                user = userService.selectByOpenId(userInfo.getOpenid());
 
             }
             boolean twoLogin = false;

+ 3 - 0
book-push/src/main/java/com/book/push/service/dao/UserService.java

@@ -3,6 +3,7 @@ package com.book.push.service.dao;
 
 import com.book.dao.cps.pojo.AdminConfig;
 import com.book.dao.cps.pojo.User;
+import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
 
 import java.util.List;
@@ -30,4 +31,6 @@ public interface UserService {
 
     void updateOperateTimeByOpenid(String openid, Integer operateTime);
     int insertKandian(Long userId, String type, int kandian, int freeKandian);
+
+    User createUserByWxOAuth2UserInfo(WxOAuth2UserInfo userInfo, Integer channelId);
 }

+ 30 - 0
book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java

@@ -9,6 +9,7 @@ import com.book.dao.cps.pojo.example.RechargeExample;
 import com.book.dao.utils.DateUtils;
 import com.book.push.service.dao.AdminConfigService;
 import com.book.push.service.dao.UserService;
+import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -66,6 +67,8 @@ public class UserServiceImpl implements UserService {
         user.setProvince(wxMpUser.getProvince());
         user.setCreatetime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
         user.setChannelId(channel_id);
+        user.setKandian(0);
+        user.setFreeKandian(0);
 
         userMapper.insert(user);
         return user;
@@ -118,6 +121,33 @@ public class UserServiceImpl implements UserService {
         return i;
     }
 
+    @Override
+    public User createUserByWxOAuth2UserInfo(WxOAuth2UserInfo wxMpUser, Integer channelId) {
+
+        User user = new User();
+        user.setOpenid(wxMpUser.getOpenid());
+        user.setArea(wxMpUser.getCity());
+        user.setCity(wxMpUser.getCity());
+        user.setCountry(wxMpUser.getCountry());
+        user.setUnionid(wxMpUser.getUnionId());
+        user.setNickname(wxMpUser.getNickname());
+        user.setSex(wxMpUser.getSex());
+//        user.setMobile(wxMpUser.getmobile);
+        user.setAvatar(wxMpUser.getHeadImgUrl());
+        user.setSubscribeTime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
+        user.setOperateTime(user.getSubscribeTime());
+//        user.setRegisterIp(wxMpUser.geti);
+        user.setSubscriptionExtend("0");
+        user.setProvince(wxMpUser.getProvince());
+        user.setCreatetime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
+        user.setChannelId(channelId);
+        user.setKandian(0);
+        user.setFreeKandian(0);
+        user.setState("1");
+        userMapper.insert(user);
+        return user;
+    }
+
     public List<Recharge> getFreeCharges(Long userId) {
         RechargeExample example = RechargeExample.newAndCreateCriteria()
                 .andUserIdEqualTo(userId)

+ 1 - 1
book-push/src/main/resources/application-pro.yml

@@ -2,7 +2,7 @@ server:
   port: 18089
 
 book:
-  debug: true
+  debug: false
   redis:
     host: r-bp1fhw9pqpgtfnu638.redis.rds.aliyuncs.com
     port: 6379

+ 5 - 1
book-server/pom.xml

@@ -115,7 +115,11 @@
             <version>1.0</version>
             <scope>compile</scope>
         </dependency>
-
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>18.0</version>
+        </dependency>
         <!--redis-->
         <dependency>
             <groupId>org.springframework.boot</groupId>