Pārlūkot izejas kodu

苹果登录,appOpenId,appleKey

ct 6 dienas atpakaļ
vecāks
revīzija
c95423a5ec

+ 4 - 0
fs-service/src/main/java/com/fs/his/domain/FsAppVersion.java

@@ -36,6 +36,10 @@ public class FsAppVersion extends BaseEntity
     @Excel(name = "下载地址")
     private String url;
 
+    /** 下载地址 */
+    @Excel(name = "wgt下载地址")
+    private String wgtUrl;
+
     /** APP类型 1android 2ios */
     @Excel(name = "APP类型 1android 2ios")
     private Integer type;

+ 4 - 0
fs-service/src/main/java/com/fs/his/domain/FsUser.java

@@ -190,6 +190,10 @@ public class FsUser extends BaseEntity
     /** app登录后不为null(表示是否下载app) */
     private String historyApp;
 
+    private String appOpenId;
+
+    private String appleKey; // 苹果key登陆验证
+
     public void setNickName(String nickname)
     {
         if(StringUtils.isNotEmpty(nickname)){

+ 3 - 4
fs-service/src/main/java/com/fs/his/mapper/FsUserMapper.java

@@ -470,14 +470,13 @@ public interface FsUserMapper
 
     List<FsUser> selectFsUserListByPhone(String phone);
 
-
-    @Select("select * from fs_user where apple_key = #{appleKey}")
-    FsUser findUserByAppleKey(String appleKey);
-
     void updatePasswordByPhone(@Param("password")String password, @Param("encryptPhone")String encryptPhone);
 
     /**
      * 查询用户列表(用于积分管理,支持手机号和昵称模糊查询)
      */
     List<FsUser> selectFsUserListForIntegral(FsUser fsUser);
+
+    @Select("select * from fs_user where apple_key = #{appleKey}")
+    FsUser findUserByAppleKey(String appleKey);
 }

+ 5 - 1
fs-service/src/main/resources/mapper/his/FsAppVersionMapper.xml

@@ -17,10 +17,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateConfig"    column="update_config"    />
         <result property="baiduUrl"    column="baidu_url"    />
         <result property="h5Url"    column="h5_url"    />
+        <result property="wgtUrl"    column="wgt_url"    />
     </resultMap>
 
     <sql id="selectFsAppVersionVo">
-        select version_id,baidu_url,update_config, version_name, version_code, note, url, type, is_force, create_time, app_type,h5_url from fs_app_version
+        select version_id,baidu_url,update_config, version_name, version_code, note, url, type, is_force, create_time, app_type,h5_url,wgt_url from fs_app_version
     </sql>
 
     <select id="selectFsAppVersionList" parameterType="FsAppVersion" resultMap="FsAppVersionResult">
@@ -57,6 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateConfig != null">update_config,</if>
             <if test="baiduUrl != null">baidu_url,</if>
             <if test="h5Url != null and h5Url !=''">h5_url,</if>
+            <if test="wgtUrl != null and wgtUrl !=''">wgt_url,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="versionName != null">#{versionName},</if>
@@ -70,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateConfig != null">#{updateConfig},</if>
             <if test="baiduUrl != null">#{baiduUrl},</if>
             <if test="h5Url != null and h5Url !=''">#{h5Url},</if>
+            <if test="wgtUrl != null and wgtUrl !=''">#{wgtUrl},</if>
          </trim>
     </insert>
 
@@ -87,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateConfig != null">update_config = #{updateConfig},</if>
             <if test="baiduUrl != null">baidu_url = #{baiduUrl},</if>
             <if test="h5Url != null and h5Url !=''">h5_url = #{h5Url},</if>
+            <if test="wgtUrl != null and wgtUrl !=''">wgt_url = #{wgtUrl},</if>
         </trim>
         where version_id = #{versionId}
     </update>

+ 23 - 1
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -50,10 +50,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="qwUserId"    column="qw_user_id"    />
         <result property="appId"    column="app_id"    />
         <result property="level" column="level"/>
+        <result property="appOpenId"    column="app_open_id"    />
+        <result property="appleKey"    column="apple_key"    />
     </resultMap>
 
     <sql id="selectFsUserVo">
-        select user_id,qw_ext_id,sex,is_buy,`level`,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type from fs_user
+        select user_id,qw_ext_id,sex,is_buy,`level`,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type,app_open_id,apple_key from fs_user
     </sql>
 
     <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
@@ -591,6 +593,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="payCount != null">pay_count,</if>
             <if test="spreadCount != null">spread_count,</if>
             <if test="appId != null">app_id,</if>
+            <if test="appOpenId != null">app_open_id,</if>
+            <if test="appleKey != null">apple_key,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="nickName != null">#{nickName},</if>
@@ -641,6 +645,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="payCount != null">#{payCount},</if>
             <if test="spreadCount != null">#{spreadCount},</if>
             <if test="appId != null">#{appId},</if>
+            <if test="appOpenId != null">#{appOpenId},</if>
+            <if test="appleKey != null">#{appleKey},</if>
          </trim>
     </insert>
 
@@ -693,6 +699,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="orderCount != null">order_count = #{orderCount},</if>
             <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
             <if test="appId != null">app_id = #{appId},</if>
+            <if test="appOpenId != null">app_open_id = #{appOpenId},</if>
+            <if test="appleKey != null">apple_key = #{appleKey},</if>
         </trim>
         where user_id = #{userId}
     </update>
@@ -2434,6 +2442,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
         select * from fs_user where phone=#{phone}
     </select>
+    <!-- 查询用户列表(用于积分管理) -->
+    <select id="selectFsUserListForIntegral" parameterType="FsUser" resultMap="FsUserResult">
+        select user_id, nick_name, phone, integral from fs_user
+        <where>
+            and is_del = 0
+            <if test="phone != null and phone != ''">
+                and phone like concat('%', #{phone}, '%')
+            </if>
+            <if test="nickName != null and nickName != ''">
+                and (nick_name like concat('%', #{nickName}, '%') or nickname like concat('%', #{nickName}, '%'))
+            </if>
+        </where>
+        order by user_id desc
+    </select>
 
     <!-- 批量更新用户积分(增加积分) -->
     <update id="batchUpdateUserIntegral">

+ 83 - 11
fs-user-app/src/main/java/com/fs/app/controller/AppLoginController.java

@@ -3,6 +3,7 @@ package com.fs.app.controller;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fs.app.annotation.Login;
 import com.fs.app.param.*;
 import com.fs.app.utils.WxUtil;
@@ -14,6 +15,8 @@ import com.fs.common.exception.ServiceException;
 import com.fs.common.service.ISmsService;
 import com.fs.common.utils.sign.Md5Utils;
 import com.fs.core.config.WxOpenProperties;
+import com.fs.course.domain.FsCoursePlaySourceConfig;
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
 import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserNewTask;
@@ -69,6 +72,9 @@ public class AppLoginController extends AppBaseController{
 
     @Autowired
     private ISmsService smsService;
+    @Autowired
+    private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
+
     @ApiOperation("注册app用户")
     @PostMapping("/register")
     @RepeatSubmit
@@ -236,8 +242,29 @@ public class AppLoginController extends AppBaseController{
             if (StringUtils.isBlank(param.getCode())) {
                 return R.error("code不存在");
             }
-            logger.info("zyp app微信登录,param:{},输出appid,{},secret:{}", param, openProperties.getAppId(), openProperties.getSecret());
-            Map result = WxUtil.getAccessToken(param.getCode(), openProperties.getAppId(), openProperties.getSecret());
+
+            String appId = param.getAppId();
+            String appSecret = "";
+            if (StringUtils.isBlank(appId)) {
+                List<FsCoursePlaySourceConfig> list = fsCoursePlaySourceConfigService.list(new QueryWrapper<FsCoursePlaySourceConfig>().eq("name", "app").eq("is_del", 0));
+                if(!list.isEmpty()){
+                    FsCoursePlaySourceConfig fsCoursePlaySourceConfig = list.get(0);
+                    appId = fsCoursePlaySourceConfig.getAppid();
+                    appSecret =  fsCoursePlaySourceConfig.getSecret();
+                }
+            } else {
+                FsCoursePlaySourceConfig fsCoursePlaySourceConfig = fsCoursePlaySourceConfigService.getOne(new QueryWrapper<FsCoursePlaySourceConfig>().eq("appid", appId).eq("is_del", 0));
+                if(fsCoursePlaySourceConfig != null){
+                    appId = fsCoursePlaySourceConfig.getAppid();
+                    appSecret =  fsCoursePlaySourceConfig.getSecret();
+                }
+            }
+            if (StringUtils.isBlank(appId) || StringUtils.isBlank(appSecret)) {
+                appId = openProperties.getAppId();
+                appSecret = openProperties.getSecret();
+            }
+            logger.info("zyp app微信登录,param:{},输出appid,{},secret:{}", param, appId, appSecret);
+            Map result = WxUtil.getAccessToken(param.getCode(),appId,appSecret);
             String accessToken = result.get("access_token").toString();
             String unionid = result.get("unionid").toString();
 
@@ -257,12 +284,13 @@ public class AppLoginController extends AppBaseController{
                 user.setSource(param.getSource()!=null ? param.getSource() : null);
                 user.setNickName(nickname);
                 user.setAvatar(avatar);
+                user.setAppOpenId(openid);
                 if (sex!=0){
                     user.setSex(sex);
                 }
                 user.setUnionId(unionid);
                 // 新用户 - 添加 appId
-                user.setAppId(openProperties.getAppId());
+                user.setAppId(appId);
                 user.setCreateTime(new Date());
                 user.setStatus(1);
                 if (StringUtils.isNotEmpty(param.getJpushId())) {
@@ -274,7 +302,7 @@ public class AppLoginController extends AppBaseController{
                 return R.ok(map);
             } else {
                 // 老用户 - 检查并添加appId(不重复添加)
-                String updatedAppId = addAppIdIfNotExists(user.getAppId(), openProperties.getAppId());
+                String updatedAppId = addAppIdIfNotExists(user.getAppId(), appId);
                 if (!updatedAppId.equals(user.getAppId())) {
                     FsUser userMap = new FsUser();
                     userMap.setUserId(user.getUserId());
@@ -283,6 +311,7 @@ public class AppLoginController extends AppBaseController{
                 }
 
                 if (StringUtils.isNotEmpty(param.getJpushId())) {
+                    user.setAppOpenId(openid);
                     updateExistingUserJpushId(user, param.getJpushId());
                 }
                 if (StringUtils.isEmpty(user.getPhone())) {
@@ -305,7 +334,6 @@ public class AppLoginController extends AppBaseController{
 
     }
 
-
     @ApiOperation("苹果登录")
     @PostMapping("/loginByApple")
     @Transactional
@@ -323,12 +351,6 @@ public class AppLoginController extends AppBaseController{
             } else {
                 if (StringUtils.isNotEmpty(param.getJpushId())) {
                     updateExistingUserJpushId(user, param.getJpushId());
-                    try {
-                        //发送注册优惠券
-                        fsUserCouponService.sendRegisterCoupon(user);
-                    } catch (Exception e) {
-                        logger.error("发送注册优惠券失败:{}",e.getMessage());
-                    }
                 }
                 if (StringUtils.isEmpty(user.getPhone())) {
                     map.put("isNew", true);
@@ -351,6 +373,52 @@ public class AppLoginController extends AppBaseController{
         }
     }
 
+    private FsUser createNewAppleUser(FsUserEditPhoneParam param, String phoneNumber) {
+        FsUser newUser = new FsUser();
+        newUser.setLoginDevice(param.getLoginDevice()!=null ? param.getLoginDevice() : null);
+        newUser.setSource(param.getSource()!=null ? param.getSource() : null);
+        newUser.setAppleKey(param.getAppleKey());
+        newUser.setPhone(param.getPhone());
+        newUser.setPassword(Md5Utils.hash(param.getPassword()));
+        newUser.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
+        newUser.setCreateTime(new Date());
+        newUser.setStatus(1);
+        newUser.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
+        if (StringUtils.isNotEmpty(param.getJpushId())) {
+            newUser.setJpushId(param.getJpushId());
+        }
+        userService.insertFsUser(newUser);
+        return newUser;
+
+    }
+
+    @ApiOperation("绑定手机号")
+    @PostMapping("/setIPhoneNumber")
+    public R setIPhoneNumber(@Validated @RequestBody FsUserEditPhoneParam param) {
+        FsUser userMap = findUserByPhone(param.getPhone());
+        if (userMap != null) {
+            if (StringUtils.isNotEmpty(userMap.getAppleKey()) && !param.getAppleKey().equals(userMap.getAppleKey())) {
+                return R.error("该手机号已绑定其他账号");
+            }
+            if (param.getSimExist() == 0 && !Md5Utils.hash(param.getPassword()).equals(userMap.getPassword())) {
+                return R.error("密码不正确");
+            }
+        } else {
+            userMap = createNewAppleUser(param, param.getPhone());
+        }
+
+        userMap.setLoginDevice(param.getLoginDevice());
+        userMap.setSource(param.getSource());
+        if (userMap.getNickName().equals("匿名用户**")) {
+            userMap.setNickName("苹果用户" + param.getPhone().substring(param.getPhone().length() - 4));
+        }
+        userMap.setAppleKey(param.getAppleKey());
+        if (userService.updateFsUser(userMap)>0){
+            return generateTokenAndReturn(userMap);
+        }
+        return R.error("绑定手机号失败");
+    }
+
     @PostMapping("/loginByPhone")
     public R loginByPhone(@RequestBody Map<String,String> map){
         String phone = map.get("phone");
@@ -525,6 +593,7 @@ public class AppLoginController extends AppBaseController{
                     user.setAvatar(avatar);
                     user.setSex(sex);
                     user.setUnionId(unionid);
+                    user.setAppOpenId(openid);
                     if (userService.updateFsUser(user)>0){
                         return generateTokenAndReturn(user);
                     }
@@ -544,6 +613,9 @@ public class AppLoginController extends AppBaseController{
         FsUser userMap = new FsUser();
         userMap.setUserId(user.getUserId());
         userMap.setJpushId(jpushId);
+        if (StringUtils.isNotEmpty(user.getAppOpenId())) {
+            userMap.setAppOpenId(user.getAppOpenId());
+        }
         userService.updateFsUser(userMap);
     }
 

+ 9 - 0
fs-user-app/src/main/java/com/fs/app/param/FsUserEditPhoneParam.java

@@ -21,4 +21,13 @@ public class FsUserEditPhoneParam implements Serializable {
     private String jpushId;
 
     private String source;
+
+    private String appleKey;
+
+    private String password;
+
+    /**
+     * 是否有SIM卡 0不存在 1存在
+     */
+    private Integer simExist;
 }

+ 2 - 0
fs-user-app/src/main/java/com/fs/app/param/FsUserLoginByWeChatParam.java

@@ -17,4 +17,6 @@ public class FsUserLoginByWeChatParam implements Serializable {
     private String source; //app来源
 
     private Long userId;
+
+    private String appId; //主要用于app微信登录
 }