Ver código fonte

优化微信手机号登录

java110 5 anos atrás
pai
commit
76135256f3

+ 30 - 0
java110-core/src/main/java/com/java110/core/factory/WechatFactory.java

@@ -8,7 +8,11 @@ import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.client.RestTemplate;
+import sun.misc.BASE64Decoder;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
 import java.util.Date;
 
 /**
@@ -99,4 +103,30 @@ public class WechatFactory {
         return AuthenticationFactory.decrypt(password, wId);
     }
 
+
+    public static String getPhoneNumberBeanS5(String decryptData, String key, String iv) {
+        /*
+         *这里你没必要非按照我的方式写,下面打代码主要是在一个自己的类中 放上decrypts5这个解密工具,工具在下方有代码
+         */
+        String resultMessage = decryptS5(decryptData, "UTF-8", key, iv);
+        return resultMessage;
+    }
+
+    public static String decryptS5(String sSrc, String encodingFormat, String sKey, String ivParameter) {
+        try {
+            BASE64Decoder decoder = new BASE64Decoder();
+            byte[] raw = decoder.decodeBuffer(sKey);
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            IvParameterSpec iv = new IvParameterSpec(decoder.decodeBuffer(ivParameter));
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
+            byte[] myendicod = decoder.decodeBuffer(sSrc);
+            byte[] original = cipher.doFinal(myendicod);
+            String originalString = new String(original, encodingFormat);
+            return originalString;
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+
 }

+ 1 - 1
java110-utils/src/main/java/com/java110/utils/constant/ServiceCodeConstant.java

@@ -471,7 +471,7 @@ public class ServiceCodeConstant {
     // App 用户绑定业主接口
     public static final String SERVICE_CODE_APP_USER_BINDING_OWNER = "owner.appUserBindingOwner";
     // App 业主注册接口
-    public static final String SERVICE_CODE_OWNER_REGISTER = "owner.ownerRegister";
+    public static final String SERVICE_CODE_OWNER_REGISTER = "owner.ownerRegisterWxPhoto";
 
 
     /**

+ 9 - 5
service-api/src/main/java/com/java110/api/bmo/owner/impl/OwnerBMOImpl.java

@@ -4,17 +4,17 @@ import com.alibaba.fastjson.JSONObject;
 import com.java110.api.bmo.ApiBaseBMO;
 import com.java110.api.bmo.owner.IOwnerBMO;
 import com.java110.core.context.DataFlowContext;
-import com.java110.intf.community.ICommunityInnerServiceSMO;
-import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
-import com.java110.intf.common.IFileRelInnerServiceSMO;
-import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
-import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.dto.CommunityMemberDto;
 import com.java110.dto.community.CommunityDto;
 import com.java110.dto.fee.FeeConfigDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.owner.OwnerAppUserDto;
 import com.java110.dto.owner.OwnerDto;
+import com.java110.intf.common.IFileRelInnerServiceSMO;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.fee.IFeeConfigInnerServiceSMO;
+import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
 import com.java110.po.community.CommunityMemberPo;
 import com.java110.po.fee.PayFeePo;
 import com.java110.po.file.FileRelPo;
@@ -160,6 +160,10 @@ public class OwnerBMOImpl extends ApiBaseBMO implements IOwnerBMO {
         JSONObject businessOwner = new JSONObject();
         businessOwner.putAll(BeanConvertUtil.beanCovertMap(ownerDtos.get(0)));
         businessOwner.putAll(paramInJson);
+
+        if (paramInJson.containsKey("wxPhoto")) {
+            businessOwner.put("link", paramInJson.getString("wxPhoto"));
+        }
         businessOwner.put("state", ownerDtos.get(0).getState());
         OwnerPo ownerPo = BeanConvertUtil.covertBean(businessOwner, OwnerPo.class);
         super.delete(dataFlowContext, ownerPo, BusinessTypeConstant.BUSINESS_TYPE_UPDATE_OWNER_INFO);

+ 213 - 0
service-api/src/main/java/com/java110/api/listener/owner/OwnerRegisterWxPhotoListener.java

@@ -0,0 +1,213 @@
+package com.java110.api.listener.owner;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.bmo.owner.IOwnerBMO;
+import com.java110.api.bmo.user.IUserBMO;
+import com.java110.api.listener.AbstractServiceApiPlusListener;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.event.service.api.ServiceDataFlowEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.community.CommunityDto;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.owner.OwnerDto;
+import com.java110.intf.common.IFileInnerServiceSMO;
+import com.java110.intf.common.ISmsInnerServiceSMO;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
+import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+
+import java.util.List;
+
+/**
+ * @ClassName AppUserBindingOwnerListener
+ * @Description 业主注册小程序
+ * @Author wuxw
+ * @Date 2019/4/26 14:51
+ * @Version 1.0
+ * add by wuxw 2019/4/26
+ **/
+
+@Java110Listener("ownerRegisterWxPhotoListener")
+public class OwnerRegisterWxPhotoListener extends AbstractServiceApiPlusListener {
+
+
+    private static final int DEFAULT_SEQ_COMMUNITY_MEMBER = 2;
+
+    @Autowired
+    private IOwnerBMO ownerBMOImpl;
+
+    @Autowired
+    private IUserBMO userBMOImpl;
+
+    @Autowired
+    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
+
+    @Autowired
+    private ISmsInnerServiceSMO smsInnerServiceSMOImpl;
+
+    @Autowired
+    private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
+    @Autowired
+    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMOImpl;
+
+    private static Logger logger = LoggerFactory.getLogger(OwnerRegisterWxPhotoListener.class);
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_OWNER_REGISTER;
+    }
+
+    @Override
+    public HttpMethod getHttpMethod() {
+        return HttpMethod.POST;
+    }
+
+    @Override
+    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+        Assert.hasKeyAndValue(reqJson, "communityName", "未包含小区名称");
+        Assert.hasKeyAndValue(reqJson, "areaCode", "未包含小区地区");
+        Assert.hasKeyAndValue(reqJson, "appUserName", "未包含用户名称");
+        Assert.hasKeyAndValue(reqJson, "idCard", "未包含身份证号");
+        Assert.hasKeyAndValue(reqJson, "link", "未包含联系电话");
+        Assert.hasKeyAndValue(reqJson, "sessionKey", "未包含微信回话");
+        Assert.hasKeyAndValue(reqJson, "password", "未包含密码");
+        String photo = CommonCache.getValue(reqJson.getString("sessionKey"));
+
+        if (!reqJson.getString("link").equals(photo)) {
+            throw new IllegalArgumentException("该手机号不是微信返回手机号");
+        }
+    }
+
+    @Override
+    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
+
+        logger.debug("ServiceDataFlowEvent : {}", event);
+
+        try {
+            OwnerAppUserDto ownerAppUserDto = BeanConvertUtil.covertBean(reqJson, OwnerAppUserDto.class);
+            ownerAppUserDto.setStates(new String[]{"10000", "12000"});
+
+            List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+
+            //Assert.listOnlyOne(ownerAppUserDtos, "已经申请过入驻小区");
+            if (ownerAppUserDtos != null && ownerAppUserDtos.size() > 0) {
+                throw new IllegalArgumentException("已经申请过绑定业主");
+            }
+
+            //查询小区是否存在
+            CommunityDto communityDto = new CommunityDto();
+            communityDto.setCityCode(reqJson.getString("areaCode"));
+            communityDto.setName(reqJson.getString("communityName"));
+            communityDto.setState("1100");
+            List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
+
+            Assert.listOnlyOne(communityDtos, "填写小区信息错误");
+
+            CommunityDto tmpCommunityDto = communityDtos.get(0);
+
+            OwnerDto ownerDto = new OwnerDto();
+            ownerDto.setCommunityId(tmpCommunityDto.getCommunityId());
+            ownerDto.setIdCard(reqJson.getString("idCard"));
+            ownerDto.setName(reqJson.getString("appUserName"));
+            List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
+
+            Assert.listOnlyOne(ownerDtos, "填写业主信息错误");
+
+            OwnerDto tmpOwnerDto = ownerDtos.get(0);
+
+            DataFlowContext dataFlowContext = event.getDataFlowContext();
+
+            String paramIn = dataFlowContext.getReqData();
+            JSONObject paramObj = JSONObject.parseObject(paramIn);
+            String appId = context.getAppId();
+
+            paramObj.put("appType", OwnerAppUserDto.APP_TYPE_APP);
+            paramObj.put("userId", GenerateCodeFactory.getUserId());
+            if (reqJson.containsKey("openId")) {
+                paramObj.put("openId", reqJson.getString("openId"));
+            } else {
+                paramObj.put("openId", "-1");
+            }
+            //添加小区楼
+            ownerBMOImpl.addOwnerAppUser(paramObj, tmpCommunityDto, tmpOwnerDto, dataFlowContext);
+            paramObj.put("name", paramObj.getString("appUserName"));
+            paramObj.put("tel", paramObj.getString("link"));
+            userBMOImpl.registerUser(paramObj, dataFlowContext);
+            JSONObject ownerObj = new JSONObject();
+            ownerObj.put("memberId",tmpOwnerDto.getMemberId());
+            ownerObj.put("wxPhoto",reqJson.getString("link"));
+            ownerBMOImpl.editOwner(ownerObj,dataFlowContext);
+
+        } catch (Exception e) {
+            context.setServiceBusiness(null);
+            context.setResponseEntity(ResultVo.createResponseEntity(ResultVo.CODE_UNAUTHORIZED, e.getMessage()));
+        }
+    }
+
+
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+
+
+    public IFileInnerServiceSMO getFileInnerServiceSMOImpl() {
+        return fileInnerServiceSMOImpl;
+    }
+
+    public void setFileInnerServiceSMOImpl(IFileInnerServiceSMO fileInnerServiceSMOImpl) {
+        this.fileInnerServiceSMOImpl = fileInnerServiceSMOImpl;
+    }
+
+
+    public ICommunityInnerServiceSMO getCommunityInnerServiceSMOImpl() {
+        return communityInnerServiceSMOImpl;
+    }
+
+    public void setCommunityInnerServiceSMOImpl(ICommunityInnerServiceSMO communityInnerServiceSMOImpl) {
+        this.communityInnerServiceSMOImpl = communityInnerServiceSMOImpl;
+    }
+
+
+    public IOwnerInnerServiceSMO getOwnerInnerServiceSMOImpl() {
+        return ownerInnerServiceSMOImpl;
+    }
+
+    public void setOwnerInnerServiceSMOImpl(IOwnerInnerServiceSMO ownerInnerServiceSMOImpl) {
+        this.ownerInnerServiceSMOImpl = ownerInnerServiceSMOImpl;
+    }
+
+    public IOwnerAppUserInnerServiceSMO getOwnerAppUserInnerServiceSMOImpl() {
+        return ownerAppUserInnerServiceSMOImpl;
+    }
+
+    public void setOwnerAppUserInnerServiceSMOImpl(IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl) {
+        this.ownerAppUserInnerServiceSMOImpl = ownerAppUserInnerServiceSMOImpl;
+    }
+
+    public IUserInnerServiceSMO getUserInnerServiceSMOImpl() {
+        return userInnerServiceSMOImpl;
+    }
+
+    public void setUserInnerServiceSMOImpl(IUserInnerServiceSMO userInnerServiceSMOImpl) {
+        this.userInnerServiceSMOImpl = userInnerServiceSMOImpl;
+    }
+}

+ 2 - 0
service-front/src/main/java/com/java110/front/configuration/ServiceConfiguration.java

@@ -25,6 +25,7 @@ public class ServiceConfiguration {
         exclusions.append("/callComponent/download/getFile/fileByObjId,");//放开 下载图片也不需要登录
         exclusions.append("/app/payment/notify,");//微信支付通知
         exclusions.append("/app/loginWx,");// 登录跳过
+        exclusions.append("/app/getWxPhoto,");// 登录跳过
         exclusions.append("/app/loginProperty,");// 物业APP登录跳过
         exclusions.append("/app/loginOwner,");// 业主APP登录跳过
         exclusions.append("/app/loginOwnerByKey,");// 根据key登录业主
@@ -32,6 +33,7 @@ public class ServiceConfiguration {
         exclusions.append("/app/community.listCommunitys,");// 加载小区
         exclusions.append("/app/user.userSendSms,");// 发送短信验证码
         exclusions.append("/app/owner.ownerRegister,");// 业主注册
+        exclusions.append("/app/owner.ownerRegisterWxPhoto,");// 业主注册
         exclusions.append("/app/activities.listActivitiess,");//小区广告
         exclusions.append("/app/advert.listAdvertPhoto,");//小区广告图片
         exclusions.append("/app/junkRequirement.listJunkRequirements,");//市场

+ 19 - 3
service-front/src/main/java/com/java110/front/controller/mina/WxLoginController.java

@@ -1,11 +1,14 @@
 package com.java110.front.controller.mina;
 
 import com.alibaba.fastjson.JSONObject;
-import com.java110.front.smo.wxLogin.IWxLoginSMO;
 import com.java110.core.base.controller.BaseController;
 import com.java110.core.context.IPageData;
 import com.java110.core.context.PageData;
+import com.java110.core.factory.WechatFactory;
+import com.java110.front.smo.wxLogin.IWxLoginSMO;
+import com.java110.utils.cache.CommonCache;
 import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,14 +53,27 @@ public class WxLoginController extends BaseController {
 
         /*IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);*/
         String appId = request.getHeader("APP_ID");
-        if(StringUtil.isEmpty(appId)){
+        if (StringUtil.isEmpty(appId)) {
             appId = request.getHeader("APP-ID");
         }
-        IPageData pd = PageData.newInstance().builder("", "","", postInfo,
+        IPageData pd = PageData.newInstance().builder("", "", "", postInfo,
                 "", "", "", "",
                 appId);
 
         return wxLoginSMOImpl.doLogin(pd);
     }
 
+
+    @RequestMapping(path = "/getWxPhoto", method = RequestMethod.POST)
+    public ResponseEntity<String> getWxPhoto(@RequestBody String postInfo) {
+        JSONObject postObj = JSONObject.parseObject(postInfo);
+
+
+        String photoInfo = WechatFactory.getPhoneNumberBeanS5(postObj.getString("decryptData"),
+                postObj.getString("key"), postObj.getString("iv"));
+        JSONObject photoObj = JSONObject.parseObject(photoInfo);
+        CommonCache.setValue(postObj.getString("key"), photoObj.toJSONString(), CommonCache.defaultExpireTime);
+        return ResultVo.createResponseEntity(photoObj);
+
+    }
 }

+ 1 - 0
service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java

@@ -111,6 +111,7 @@ public class WxLoginSMOImpl extends AppAbstractComponentSMO implements IWxLoginS
         if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
             //将openId放到redis 缓存,给前段下发临时票据
             paramOut.put("openId", openId);
+            paramOut.put("sessionKey", sessionKey);
             paramOut.put("msg", "还没有注册请先注册");
             responseEntity = new ResponseEntity<String>(paramOut.toJSONString(), HttpStatus.UNAUTHORIZED);