Sfoglia il codice sorgente

新增微信小程序登陆

赵冬冬 4 anni fa
parent
commit
b1a3c6eac3

+ 10 - 7
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/controller/web/WechatAppController.java

@@ -77,20 +77,23 @@ public class WechatAppController extends BaseController {
             // 解密用户信息
             WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(session.getSessionKey(),
                     request.getEncryptedData(), request.getIv());
+            //解密手机号
+            WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(session.getSessionKey(), request.getEncryptedData(), request.getIv());
             if (null == wxUserInfo) {
                 throw new RuntimeException("wxUser not exist");
             }
-
             MyWxMpUser myWxMpUser = new MyWxMpUser();
             //TODO 可以增加自己的逻辑,关联业务相关数据
             myWxMpUser.setOpenId(session.getOpenid());
             myWxMpUser.setUnionId(session.getUnionid());
             myWxMpUser.setNickname(wxUserInfo.getNickName());
             myWxMpUser.setHeadImgUrl(wxUserInfo.getAvatarUrl());
+            myWxMpUser.setSex(Integer.parseInt(wxUserInfo.getGender()));
+            myWxMpUser.setPhone(phoneNoInfo.getPhoneNumber());
             //后台新增用户成功
             Map<String, String> tokenMap = customerInfoService.wxlogin(myWxMpUser);
             //登录系统获取本地
-            return responseSuccess(new ResultVO(ResultEnum.SUCCESS, tokenMap));
+            return resultVOSuccess(tokenMap);
         } catch (WxErrorException e) {
             this.logger.error(e.getMessage(), e);
             return responseSuccess(new ResultVO(1, "登录错误!"));
@@ -103,10 +106,10 @@ public class WechatAppController extends BaseController {
     @PostMapping("/login/test")
     @ResponseBody
     public ResponseBase login(@RequestBody MyWxMpUser myWxMpUser) {
-            //后台新增用户成功
-            Map<String, String> tokenMap = customerInfoService.wxlogin(myWxMpUser);
-            //登录系统获取本地
-            return resultVOSuccess(tokenMap);
+        //后台新增用户成功
+        Map<String, String> tokenMap = customerInfoService.wxlogin(myWxMpUser);
+        //登录系统获取本地
+        return resultVOSuccess(tokenMap);
     }
 
     private Map<String, Object> getStringObjectMap(String customerId) {
@@ -153,7 +156,7 @@ public class WechatAppController extends BaseController {
     }
 
 
-    @Value("${wx.auth.wxpayAppcallbackurl}")
+    @Value("${wx.pay.wxpayAppcallbackurl}")
     private String wxpayCallbackUrl;
 
     @Autowired

+ 1 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/controller/web/WechatAppPayController.java

@@ -47,7 +47,7 @@ public class WechatAppPayController extends BaseController {
     private OrderInfoService orderInfoService;
 
 
-    @Value("${wx.auth.wxpaycallbackurl}")
+    @Value("${wx.pay.wxpayAppcallbackurl}")
     private String wxpayCallbackUrl;
 
     @ApiOperation(value = "微信支付接口(二次支付)", notes = "微信支付接口请勿随意调用(二次支付)")

+ 21 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CustomerInfoServiceImpl.java

@@ -3,6 +3,7 @@ package com.hcloud.microserver.h5.service.impl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.hcloud.microserver.commoncore.exception.Asserts;
+import com.hcloud.microserver.commoncore.util.TracedCodeUtils;
 import com.hcloud.microserver.h5.bo.CustomerDetails;
 import com.hcloud.microserver.h5.bo.CustomerInfoBO;
 import com.hcloud.microserver.h5.dao.*;
@@ -349,7 +350,8 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
         if (null == customerInfo) {
             customerInfo = new CustomerInfo();
             //设置唯一标识
-            customerInfo.setGuid(GetUUID.getUUID());
+            String uuid = GetUUID.getUUID();
+            customerInfo.setGuid(uuid);
             customerInfo.setUnionId(unionId);
             customerInfo.setWxId(openId);
             customerInfo.setSex(sex);
@@ -357,10 +359,24 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
                 customerInfo.setPhone(phone);
             }
             customerInfo.setNickName(nickname);
+            //默认设置为自己的昵称
+            customerInfo.setCustomerName(nickname);
             customerInfo.setHeadImage(headImgUrl);
             customerInfo.setIsCompany(0);
             //状态设置为可用
             customerInfo.setIsEnable(1);
+            customerInfo.setCreateTime(new Date());
+            customerInfo.setCreateUser(uuid);
+            //设置为自然人
+            customerInfo.setCustomerType(1);
+            //0 为未认证
+            customerInfo.setIsValidate(0);
+            //默认密码
+            String s = Md5Util.toMD5("000000");
+            customerInfo.setPasswd(s);
+            //设置登陆账号
+            String commonRandomCode = TracedCodeUtils.getCommonRandomCode();
+            customerInfo.setAccount(commonRandomCode);
             customerInfoMapper.insertSelective(customerInfo);
         } else {
             customerInfo.setUnionId(unionId);
@@ -371,12 +387,16 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
             }
             customerInfo.setNickName(nickname);
             customerInfo.setHeadImage(headImgUrl);
+            customerInfo.setModifiedUser(customerInfo.getGuid());
+            customerInfo.setModifiedTime(new Date());
             customerInfoMapper.updateByPrimaryKeySelective(customerInfo);
         }
         return customerInfo.getGuid();
     }
 
 
+
+
     @Override
     public int delByPrimaryKey(String guid) {
         return customerInfoMapper.deleteByPrimaryKey(guid);

+ 1 - 0
carbon-h5/carbon-h5-service/src/main/resources/com/hcloud/microserver/h5/dao/CustomerInfoMapper.xml

@@ -165,6 +165,7 @@
           t_customer_info a
       WHERE
           a.wx_id = #{myWxMpUser.openId}
+      OR a.phone = #{myWxMpUser.phone}
       OR a.union_id = #{myWxMpUser.unionId}
       LIMIT 1
   </select>