短信/阿里云oss/wx相关接口/短剧小程序登录
This commit is contained in:
parent
fc2fb12b30
commit
c2fdab2b93
|
|
@ -0,0 +1,35 @@
|
|||
package com.playlet.web.controller.app;
|
||||
|
||||
import com.playlet.common.core.domain.Result;
|
||||
import com.playlet.system.domain.PlayletUser;
|
||||
import com.playlet.web.service.app.PlayletUserAppService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "小程序*短剧用户接口")
|
||||
@RestController
|
||||
@RequestMapping(value = "/app/user")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class PlayletUserAppController {
|
||||
|
||||
private final PlayletUserAppService playletUserAppService;
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/loginByOpenid")
|
||||
@ApiOperation(value = "小程序通过openid登录系统", httpMethod = "post")
|
||||
public Result<PlayletUser> loginByOpenid(@RequestParam(value = "openid") String openid){
|
||||
try {
|
||||
return Result.success(playletUserAppService.getByOpenId(openid));
|
||||
}catch (Exception e){
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.playlet.common.core.domain.Result;
|
|||
import com.playlet.web.service.OssService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -13,12 +14,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
* @author clunt
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "App*文件上传")
|
||||
@Api(tags = "通用*文件上传")
|
||||
@RequestMapping(value = "/tool/oss")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class OssFileController {
|
||||
|
||||
@Autowired
|
||||
private OssService ossService;
|
||||
private final OssService ossService;
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/upload")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.playlet.web.controller.tool;
|
||||
|
||||
import com.playlet.common.core.domain.Result;
|
||||
import com.playlet.web.service.SmsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>短信接口</p>
|
||||
* @author clunt
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "通用*短信接口")
|
||||
@RequestMapping(value = "/tool/sms")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class SmsController {
|
||||
|
||||
private final SmsService smsService;
|
||||
|
||||
@ApiOperation(value = "发送短信验证码", httpMethod = "post")
|
||||
@GetMapping("/sendSmsCode")
|
||||
@ResponseBody
|
||||
public Result<String> sendSmsCode(@RequestParam(value = "phone") String phone){
|
||||
try {
|
||||
smsService.sendSmsCode(phone);
|
||||
return Result.success();
|
||||
}catch (Exception e){
|
||||
log.error("调用短信服务异常:{}", e.getMessage(), e);
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ import io.swagger.annotations.ApiOperation;
|
|||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Api("用户信息管理")
|
||||
//@Api("用户信息管理")
|
||||
@RestController
|
||||
@RequestMapping("/test/user")
|
||||
public class TestController extends BaseController
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package com.playlet.web.controller.tool;
|
||||
|
||||
import com.playlet.common.core.domain.Result;
|
||||
import com.playlet.web.service.WxService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>微信服务端接口</p>
|
||||
* @author clunt
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "小程序*微信接口")
|
||||
@RequestMapping("/tool/wx")
|
||||
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class WxController {
|
||||
|
||||
private final WxService wxService;
|
||||
|
||||
@ApiOperation(value = "获取openId", httpMethod = "post")
|
||||
@GetMapping("/getOpenidByCode")
|
||||
@ResponseBody
|
||||
public Result<String> getOpenidByCode(@RequestParam(value = "code") String code){
|
||||
return Result.success(wxService.getOpenidByCode(code));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.playlet.web.core.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms")
|
||||
public class SmsConfig {
|
||||
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String signName;
|
||||
private String templateCode;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.playlet.web.core.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "wx")
|
||||
public class WxConfig {
|
||||
|
||||
/*微信小程序AppId*/
|
||||
public String appId;
|
||||
|
||||
/*微信小程序Secret*/
|
||||
public String secret;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.playlet.web.req;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>短剧请求对象</p>
|
||||
* @author clunt
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "短剧请求对象")
|
||||
public class PlayUserReq {
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String code;
|
||||
|
||||
private String password;
|
||||
|
||||
private String inviteCode;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.playlet.web.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>短剧响应对象</p>
|
||||
* @author clunt
|
||||
*/
|
||||
@Data
|
||||
public class PlayUserResp {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.playlet.web.service;
|
||||
|
||||
/**
|
||||
* <p>短信验证码service</p>
|
||||
* @author clunt
|
||||
*/
|
||||
public interface SmsService {
|
||||
|
||||
/**
|
||||
* @param phone 接收短信手机号
|
||||
*/
|
||||
void sendSmsCode(String phone) throws Exception;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.playlet.web.service;
|
||||
|
||||
/**
|
||||
* <p>微信service类</p>
|
||||
* @author clunt
|
||||
*/
|
||||
public interface WxService {
|
||||
|
||||
String getAccessToken();
|
||||
|
||||
String getOpenidByCode(String code);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.playlet.web.service.app;
|
||||
|
||||
import com.playlet.system.domain.PlayletUser;
|
||||
|
||||
/**
|
||||
* <p>短剧小程序用户service</p>
|
||||
* @author clunt
|
||||
*/
|
||||
public interface PlayletUserAppService {
|
||||
|
||||
/**
|
||||
* @param openid 微信唯一凭证
|
||||
* @return 短剧用户
|
||||
*/
|
||||
PlayletUser getByOpenId(String openid);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.playlet.web.service.app.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.playlet.common.constant.PlayletConstants;
|
||||
import com.playlet.system.domain.PlayletUser;
|
||||
import com.playlet.system.service.IPlayletUserService;
|
||||
import com.playlet.web.service.app.PlayletUserAppService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class PlayletUserAppServiceImpl implements PlayletUserAppService {
|
||||
|
||||
private final IPlayletUserService iPlayletUserService;
|
||||
|
||||
@Override
|
||||
public PlayletUser getByOpenId(String openid) {
|
||||
PlayletUser playletUser = iPlayletUserService.lambdaQuery().eq(PlayletUser::getOpenId, openid).one();
|
||||
if(ObjectUtil.isNull(playletUser)){
|
||||
playletUser = new PlayletUser();
|
||||
playletUser.setOpenId(openid);
|
||||
playletUser.setCreateBy(PlayletConstants.DEFAULT_CREATE);
|
||||
playletUser.setCreateTime(new Date());
|
||||
iPlayletUserService.save(playletUser);
|
||||
}
|
||||
return playletUser;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.playlet.web.service.impl;
|
||||
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.playlet.web.core.config.SmsConfig;
|
||||
import com.playlet.web.service.SmsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class SmsServiceImpl implements SmsService {
|
||||
|
||||
private final SmsConfig smsConfig;
|
||||
|
||||
private final StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public void sendSmsCode(String phone) throws Exception{
|
||||
// 短信验证码
|
||||
String code = String.valueOf((int)((Math.random() * 9 + 1) * Math.pow(10,5)));
|
||||
// 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
|
||||
Client client = createClient(smsConfig.getAccessKeyId(), smsConfig.getAccessKeySecret());
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setSignName(smsConfig.getSignName())
|
||||
.setTemplateCode(smsConfig.getTemplateCode())
|
||||
.setPhoneNumbers(phone)
|
||||
.setTemplateParam("{\"code\":"+ code +"}");
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
||||
log.info("发送给{}短信响应为{}", phone, sendSmsResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId key
|
||||
* @param accessKeySecret 密钥
|
||||
* @throws Exception 异常信息
|
||||
*/
|
||||
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new Config()
|
||||
// 必填,您的 AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 必填,您的 AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = "dysmsapi.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.playlet.web.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.playlet.common.constant.PlayletConstants;
|
||||
import com.playlet.common.utils.http.HttpUtils;
|
||||
import com.playlet.web.core.config.WxConfig;
|
||||
import com.playlet.web.service.WxService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class WxServiceImpl implements WxService {
|
||||
|
||||
private final WxConfig wxConfig;
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxConfig.getAppId() + "&secret=" + wxConfig.getSecret();
|
||||
log.info("调用微信获取access_token,入参url:{}", url);
|
||||
String result = HttpUtils.sendGet(url);
|
||||
log.info("调用微信获取access_token,响应内容:{}", result);
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
if(json.containsKey(PlayletConstants.ACCESS_TOKEN)){
|
||||
return json.getString(PlayletConstants.ACCESS_TOKEN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOpenidByCode(String code) {
|
||||
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+ wxConfig.getAppId() + "&secret=" + wxConfig.getSecret() + "&code=" + code + "&grant_type=authorization_code";
|
||||
log.info("调用微信获取openId,入参url:{}", url);
|
||||
String result = HttpUtils.sendGet(url);
|
||||
log.info("调用微信获取openId,响应内容:{}", result);
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
if(json.containsKey(PlayletConstants.OPEN_ID)){
|
||||
return json.getString(PlayletConstants.OPEN_ID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ ruoyi:
|
|||
# 开发环境配置
|
||||
server:
|
||||
# 服务器的HTTP端口,默认为80
|
||||
port: 80
|
||||
port: 18080
|
||||
servlet:
|
||||
# 应用的访问路径
|
||||
context-path: /
|
||||
|
|
@ -145,9 +145,22 @@ swagger:
|
|||
# 是否开启swagger
|
||||
enabled: true
|
||||
|
||||
#小程序配置
|
||||
wx:
|
||||
appId: 'wx60fa92c432e05ed1'
|
||||
secret: '8ff8ab065446e2ad552e88a37780d8fe'
|
||||
|
||||
#阿里云OSS配置
|
||||
aliyun:
|
||||
access-key-id: LTAI5tADpNeJG3YL1qQJiDk7
|
||||
access-key-secret: BbxcqZjvx6yupekOLUbKDMINhbOioa
|
||||
bucket-name: qiepian2024
|
||||
endpoint: http://oss-cn-shenzhen.aliyuncs.com
|
||||
url-prefix: http://qiepian2024.oss-cn-shenzhen.aliyuncs.com/
|
||||
|
||||
#阿里云短信验证码配置
|
||||
sms:
|
||||
access-key-id: LTAI5tADpNeJG3YL1qQJiDk7
|
||||
access-key-secret: BbxcqZjvx6yupekOLUbKDMINhbOioa
|
||||
sign-name: 微信小程序短剧切片
|
||||
template-code: SMS_465346724
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||
<title>登录麻雀短剧系统</title>
|
||||
<title>追风者</title>
|
||||
<meta name="description" content="登录麻雀短剧系统">
|
||||
<link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
|
||||
<link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
|
||||
|
|
@ -65,7 +65,9 @@
|
|||
</div>
|
||||
<div class="signup-footer">
|
||||
<div class="pull-left">
|
||||
Copyright © 2018-2023 QuHe All Rights Reserved. <br>
|
||||
Copyright © 2022-2024 广州曲和网络科技有限公司 All Rights Reserved. <br>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">备案号:</a>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备2021044349号-1</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@
|
|||
<script th:inline="javascript">
|
||||
var editFlag = [[${@permission.hasPermi('system:project:edit')}]];
|
||||
var removeFlag = [[${@permission.hasPermi('system:project:remove')}]];
|
||||
var prefix = ctx + "system/project";
|
||||
var prefix = ctx + "system/playlet/project";
|
||||
|
||||
$(function() {
|
||||
var options = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.playlet.common.constant;
|
||||
|
||||
/**
|
||||
* <p>短剧小程序静态参数</p>
|
||||
* @author clunt
|
||||
*/
|
||||
public class PlayletConstants {
|
||||
|
||||
/** 微信AccessToken返回格式 */
|
||||
public static final String ACCESS_TOKEN = "access_token";
|
||||
|
||||
/** 微信OpenId返回格式 */
|
||||
public static final String OPEN_ID = "openid";
|
||||
|
||||
/** 小程序用户初始默认创建人 */
|
||||
public static final String DEFAULT_CREATE = "system";
|
||||
|
||||
/** 阿里云短信默认URL */
|
||||
private final static String ALI_SMS_URL = "dysmsapi.aliyuncs.com";
|
||||
}
|
||||
|
|
@ -293,6 +293,12 @@ public class ShiroConfig
|
|||
filterChainDefinitionMap.put("/tool/swagger/**", "anon");
|
||||
// oss文件接口
|
||||
filterChainDefinitionMap.put("/tool/oss/**", "anon");
|
||||
// wx接口
|
||||
filterChainDefinitionMap.put("/tool/wx/**", "anon");
|
||||
// 短信接口
|
||||
filterChainDefinitionMap.put("/tool/sms/**", "anon");
|
||||
// 小程序请求接口
|
||||
filterChainDefinitionMap.put("/app/**/**", "anon");
|
||||
// 退出 logout地址,shiro去清除session
|
||||
filterChainDefinitionMap.put("/logout", "logout");
|
||||
// 不需要拦截的访问
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.playlet.system.domain;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.playlet.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.playlet.common.annotation.Excel;
|
||||
|
|
@ -16,6 +18,7 @@ import com.playlet.common.annotation.Excel;
|
|||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName(value = "playlet_user")
|
||||
@ApiModel(value = "短剧用户")
|
||||
public class PlayletUser extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -25,10 +28,15 @@ public class PlayletUser extends BaseEntity
|
|||
|
||||
/** 手机号 */
|
||||
@Excel(name = "手机号")
|
||||
@ApiModelProperty(value = "手机号")
|
||||
private String phone;
|
||||
|
||||
@Excel(name = "微信唯一凭证")
|
||||
private String openId;
|
||||
|
||||
/** 昵称 */
|
||||
@Excel(name = "昵称")
|
||||
@ApiModelProperty(value = "昵称")
|
||||
private String nickName;
|
||||
|
||||
/** 密码 */
|
||||
|
|
@ -37,14 +45,17 @@ public class PlayletUser extends BaseEntity
|
|||
|
||||
/** 头像 */
|
||||
@Excel(name = "头像")
|
||||
@ApiModelProperty(value = "头像")
|
||||
private String icon;
|
||||
|
||||
/** 代理ID */
|
||||
@Excel(name = "代理ID")
|
||||
@ApiModelProperty(value = "代理ID")
|
||||
private String agencyId;
|
||||
|
||||
/** 父级分销ID */
|
||||
@Excel(name = "父级分销ID")
|
||||
@ApiModelProperty(value = "父级分销ID")
|
||||
private String parentId;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue