Procházet zdrojové kódy

Merge branch 'master' of http://git.zthymaoyi.com/wangchao/businessCard

achao před 2 roky
rodič
revize
b90c69cd28

+ 33 - 0
unimall-app-api/src/main/java/com/iotechn/unimall/app/api/commonUser/CommonUserService.java

@@ -0,0 +1,33 @@
+package com.iotechn.unimall.app.api.commonUser;
+
+import com.iotechn.unimall.core.Const;
+import com.iotechn.unimall.core.annotation.HttpMethod;
+import com.iotechn.unimall.core.annotation.HttpOpenApi;
+import com.iotechn.unimall.core.annotation.HttpParam;
+import com.iotechn.unimall.core.annotation.HttpParamType;
+import com.iotechn.unimall.core.annotation.param.NotNull;
+import com.iotechn.unimall.core.annotation.param.TextFormat;
+import com.iotechn.unimall.core.exception.ServiceException;
+import com.iotechn.unimall.data.dto.UserDTO;
+import com.iotechn.unimall.data.domain.unimall.CommonUserInfo;
+
+import java.io.IOException;
+
+/**
+ * Created by rize on 2019/6/30.
+ */
+@HttpOpenApi(group = "commonUserApp", description = "用户服务")
+public interface CommonUserService {
+
+    @HttpMethod(description = "小程序登录")
+    public CommonUserInfo commonUserLogin(
+            @NotNull @HttpParam(name = "ip", type = HttpParamType.IP, description = "用户Ip") String ip,
+            @NotNull @HttpParam(name = "raw", type = HttpParamType.COMMON, description = "第三方平台返回的数据") String raw) throws ServiceException, IOException;
+
+
+    @HttpMethod(description = "同步信息")
+    public CommonUserInfo edit(
+            @NotNull @HttpParam(name = "commonUserInfo", type = HttpParamType.COMMON, description = "同步信息") CommonUserInfo commonUserInfo) ;
+
+
+}

+ 111 - 0
unimall-app-api/src/main/java/com/iotechn/unimall/app/api/commonUser/CommonUserServiceImpl.java

@@ -0,0 +1,111 @@
+package com.iotechn.unimall.app.api.commonUser;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.iotechn.unimall.biz.service.user.UserBizService;
+import com.iotechn.unimall.core.Const;
+import com.iotechn.unimall.core.exception.AppServiceException;
+import com.iotechn.unimall.core.exception.ExceptionDefinition;
+import com.iotechn.unimall.core.exception.ServiceException;
+import com.iotechn.unimall.core.exception.ThirdPartServiceException;
+import com.iotechn.unimall.core.notify.SMSClient;
+import com.iotechn.unimall.core.notify.SMSResult;
+import com.iotechn.unimall.core.util.GeneratorUtil;
+import com.iotechn.unimall.core.util.SHA1Util;
+import com.iotechn.unimall.data.component.CacheComponent;
+import com.iotechn.unimall.data.domain.UserDO;
+import com.iotechn.unimall.data.domain.unimall.CommonUserInfo;
+import com.iotechn.unimall.data.dto.UserDTO;
+import com.iotechn.unimall.data.enums.UserLoginType;
+import com.iotechn.unimall.data.mapper.UserMapper;
+import com.iotechn.unimall.data.util.SessionUtil;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import org.apache.commons.codec.digest.Md5Crypt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import com.iotechn.unimall.data.mapper.unimall.CommonUserInfoMapper;
+/**
+ * Created by rize on 2019/6/30.
+ */
+@Service
+public class CommonUserServiceImpl implements CommonUserService {
+
+    private static final String VERIFY_CODE_PREFIX = "VERIFY_CODE_";
+
+    private static final Logger logger = LoggerFactory.getLogger(CommonUserServiceImpl.class);
+
+    @Autowired
+    private CommonUserInfoMapper commonUserInfoMapper;
+
+
+    @Autowired
+    private StringRedisTemplate userRedisTemplate;
+
+    private OkHttpClient okHttpClient = new OkHttpClient();
+
+    @Value("${com.iotechn.unimall.wx.mini.app-id}")
+    private String wxMiNiAppid;
+
+    @Value("${com.iotechn.unimall.wx.mini.app-secret}")
+    private String wxMiNiSecret;
+
+    @Override
+    public CommonUserInfo commonUserLogin(String ip, String raw) throws ServiceException, IOException {
+        JSONObject thirdPartJsonObject = JSONObject.parseObject(raw);
+        String code = thirdPartJsonObject.getString("code");
+        String body = okHttpClient.newCall(new Request.Builder()
+                .url("https://api.weixin.qq.com/sns/jscode2session?appid=" + wxMiNiAppid +
+                        "&secret=" + wxMiNiSecret +
+                        "&grant_type=authorization_code&js_code=" + code).get().build()).execute().body().string();
+        JSONObject jsonObject = JSONObject.parseObject(body);
+        Integer errcode = jsonObject.getInteger("errcode");
+        if (errcode == null || errcode == 0) {
+            String miniOpenId = jsonObject.getString("openid");
+            List<CommonUserInfo> list = commonUserInfoMapper.selectList(new EntityWrapper<CommonUserInfo>().eq("open_id", miniOpenId));
+            CommonUserInfo newUserDO;
+            if (CollectionUtils.isEmpty(list)) {
+                //若用户为空,则注册此用户
+                Date now = new Date();
+                newUserDO = new CommonUserInfo();
+                newUserDO.setOpenId(miniOpenId);
+                newUserDO.setGmtUpdate(now);
+                newUserDO.setGmtCreate(now);
+                commonUserInfoMapper.insert(newUserDO);
+            } else {
+                newUserDO = list.get(0);
+            }
+            //检查帐号是否已经冻结
+            if (newUserDO.getStatus() == 0) {
+                throw new AppServiceException(ExceptionDefinition.USER_CAN_NOT_ACTICE);
+            }
+            String accessToken = GeneratorUtil.genSessionId();
+            userRedisTemplate.opsForValue().set(Const.USER_REDIS_PREFIX + accessToken, JSONObject.toJSONString(newUserDO));
+            newUserDO.setAccessToken(accessToken);
+            newUserDO.setSessionKey(jsonObject.getString("session_key"));
+            return newUserDO;
+        } else {
+            throw new AppServiceException(ExceptionDefinition.USER_THIRD_UNEXPECT_RESPONSE);
+        }
+    }
+
+    @Override
+    public CommonUserInfo edit(CommonUserInfo commonUserInfo) {
+        commonUserInfoMapper.updateById(commonUserInfo);
+        return commonUserInfo;
+    }
+}

+ 2 - 1
unimall-app-api/src/main/java/com/iotechn/unimall/app/api/user/UserServiceImpl.java

@@ -418,8 +418,9 @@ public class UserServiceImpl implements UserService {
         updateUserDO.setAvatarUrl(avatarUrl);
         updateUserDO.setGender(gender);
         updateUserDO.setGmtUpdate(new Date());
-        if (birthday != null)
+        if (birthday != null) {
             updateUserDO.setBirthday(new Date(birthday));
+        }
         if (userMapper.updateById(updateUserDO) > 0) {
             //更新SESSION缓存
             UserDTO user = SessionUtil.getUser();

+ 16 - 1
unimall-data/src/main/java/com/iotechn/unimall/data/domain/CommonUserInfo.java

@@ -43,10 +43,19 @@ public class CommonUserInfo extends SuperDO {
     @TableField("phone")
     private String phone;
 
+    /** 微信id */
+    @Excel(name = "微信id")
+    @TableField("open_id")
+    private String openId;
+
     /** 真实姓名 */
     @Excel(name = "真实姓名")
     @TableField("realname")
     private String realname;
+    /** 真实姓名 */
+    @Excel(name = "头像")
+    @TableField("head")
+    private String head;
 
     /** 允许他人分享名片(1允许) */
     @Excel(name = "允许他人分享名片(1允许)")
@@ -83,7 +92,13 @@ public class CommonUserInfo extends SuperDO {
     @TableField("delete_flag")
     private Long deleteFlag;
 
-
+    @TableField(exist = false)
+    private String sessionKey;
+    /**
+     * 登录成功,包装此参数
+     */
+    @TableField(exist = false)
+    private String accessToken;
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 4 - 4
unimall-launcher/src/main/resources/application.properties

@@ -86,14 +86,14 @@ oss.aliyun.oss.basekUrl=https://taohaoliang.oss-cn-beijing.aliyuncs.com/
 ########################################################
 ### 微信 小程序、APP、H5信息
 ########################################################
-com.iotechn.unimall.wx.mini.app-id=wxe3c17ca92931512d
-com.iotechn.unimall.wx.mini.app-secret=049151cd78f6671a27704be472832ff1
+com.iotechn.unimall.wx.mini.app-id=wxa03b5fb231b72b08
+com.iotechn.unimall.wx.mini.app-secret=c6c220553a737cc4d626ebd4ff245c5e
 
 com.iotechn.unimall.wx.app.app-id=wxe3c17ca92931512d
 com.iotechn.unimall.wx.app.app-secret=049151cd78f6671a27704be472832ff1
 
-com.iotechn.unimall.wx.h5.app-id=wxe3c17ca92931512d
-com.iotechn.unimall.wx.h5.app-secret=049151cd78f6671a27704be472832ff1
+com.iotechn.unimall.wx.h5.app-id=wxa03b5fb231b72b08
+com.iotechn.unimall.wx.h5.app-secret=c6c220553a737cc4d626ebd4ff245c5e
 
 ########################################################
 ### 微信商户信息