添加common下用户注册登录
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
|
||||
public interface MyUserService extends IService<MyUserEntity> {
|
||||
|
||||
void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.app.config.SMSConfig;
|
||||
import com.peanut.modules.app.config.Sample;
|
||||
import com.peanut.modules.common.dao.MyUserDao;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.service.MyUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("myUserService")
|
||||
public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> implements MyUserService {
|
||||
|
||||
@Autowired
|
||||
private SMSConfig smsConfig;
|
||||
|
||||
@Override
|
||||
public void sendCodeForRegister(String phone, String code, Integer areaCode) throws Exception {
|
||||
String scode = code.split("_")[0];
|
||||
sendCode(phone,scode,areaCode);
|
||||
}
|
||||
|
||||
private void sendCode(String phone, String code, Integer areaCode) throws Exception {
|
||||
com.aliyun.dysmsapi20170525.Client client = Sample.createClient(smsConfig.getAccessKeyId(),smsConfig.getAccessKeySecret());
|
||||
String tem;
|
||||
if(areaCode!=null&&areaCode>0&&areaCode!=86){
|
||||
tem = smsConfig.getSTemplateCode();
|
||||
phone = areaCode+phone;
|
||||
}else{
|
||||
tem = smsConfig.getTemplateCode();
|
||||
}
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setSignName(smsConfig.getSingName())
|
||||
.setTemplateCode(tem)
|
||||
.setPhoneNumbers(phone)
|
||||
.setTemplateParam("{\"code\":\""+ code +"\"}");
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
|
||||
SendSmsResponseBody body = sendSmsResponse.getBody();
|
||||
System.out.println(body.getMessage());
|
||||
} catch (TeaException error) {
|
||||
// 如有需要,请打印 error
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 如有需要,请打印 error
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user