shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.ishop.mobile.api;
 
import com.iplatform.base.Constants;
import com.iplatform.base.util.PlatformRSAUtils;
import com.ishop.mobile.BaseApi;
import com.ishop.model.po.EbUserConfig;
import com.ishop.model.request.PayPassRequest;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import com.walker.web.log.BusinessType;
import com.walker.web.log.Log;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * 用户自定义配置,添加模块。
 * @author 时克英
 * @date 2023-08-06
 */
@RestController
@RequestMapping("/front/user/config")
public class UserConfigApi extends BaseApi {
 
    /**
     * 设置支付密码
     * @param request
     * @return
     * @date 2023-08-06
     */
    @Log(title = "设置支付密码", businessType = BusinessType.Update, isSaveRequestData = true, isSaveResponseData = true)
    @RequestMapping(value = "/setPayPass", method = RequestMethod.POST)
    public ResponseValue setPayPass(
//            String encryptPassword, String code, String uuid
            @RequestBody PayPassRequest request
            ){
        if(request == null){
            return ResponseValue.error(Constants.ERROR_ARGUMENT);
        }
        if(StringUtils.isEmpty(request.getCode()) || StringUtils.isEmpty(request.getUuid())){
            return ResponseValue.error("验证码为空,无法修改支付密码");
        }
        if(StringUtils.isEmpty(request.getEncryptPassword())){
            return ResponseValue.error("请设置支付密码");
        }
 
        boolean smsCodeSuccess = this.validateSmsCode(request.getCode(), request.getUuid());
        if(!smsCodeSuccess){
            return ResponseValue.error("验证码错误");
        }
 
        long userId = this.getCurrentUserId();
        String originPassword = null;
        try{
            // 2023-08-06 uniapp端使用对称密码算法
            originPassword = PlatformRSAUtils.getAesDecryptValue(request.getEncryptPassword());
            String passwordMd5 = this.encryptPassword(originPassword);
            this.getUserRegConfigService().execSetupPayPass(userId, passwordMd5);
 
            // 更新缓存
            EbUserConfig config = this.getUserRegConfigCache().get(userId);
            config.setPayPwd(passwordMd5);
            this.getUserRegConfigCache().update(config);
 
            return ResponseValue.success();
 
        } catch (Exception ex){
            logger.error("无法解析设置的支付密码,msg=" + ex.getMessage(), ex);
            return ResponseValue.error("设置支付密码错误:无法解析密码");
        }
    }
}