Commit c4813872 authored by hezhen's avatar hezhen

123

parent 950599c5
...@@ -174,6 +174,7 @@ public class AuthController { ...@@ -174,6 +174,7 @@ public class AuthController {
*/ */
@PostMapping(value = "/applet/uid/login") @PostMapping(value = "/applet/uid/login")
public JSONObject appletLoginByUserId(@RequestParam("userId") Integer userId) throws Exception{ public JSONObject appletLoginByUserId(@RequestParam("userId") Integer userId) throws Exception{
log.info(userId+"----require appletLoginByUserId...");
JSONObject data = appAuthService.appletLoginByUserId(userId); JSONObject data = appAuthService.appletLoginByUserId(userId);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){ if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data"); JSONObject result=data.getJSONObject("data");
...@@ -188,8 +189,11 @@ public class AuthController { ...@@ -188,8 +189,11 @@ public class AuthController {
} }
@PostMapping(value = "/applet/registry") @PostMapping(value = "/applet/registry")
public JSONObject registryWithApplet(@RequestParam("username") String phone,@RequestParam("password") String pwd,@RequestParam("mobilecode") String code)throws Exception { public JSONObject registryWithApplet(
JSONObject data=appAuthService.appletRegistry(phone,pwd,code); @RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="nickname",defaultValue="")String nickname,
@RequestParam(value="headimgurl",defaultValue="")String headimgurl)throws Exception {
JSONObject data=appAuthService.appletRegistry(username,nickname,headimgurl);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){ if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data"); JSONObject result=data.getJSONObject("data");
if(result==null){ if(result==null){
......
...@@ -54,16 +54,16 @@ public interface IUserService { ...@@ -54,16 +54,16 @@ public interface IUserService {
* @param userid * @param userid
* @return * @return
*/ */
@PostMapping("/api/app/applet/uid/login") @RequestMapping(value = "/api/app/applet/uid/login", method = RequestMethod.POST)
JSONObject appletLogin(@RequestParam(value = "userid") Integer userid); public JSONObject appletLogin(@RequestParam(value = "userid") Integer userid);
/** /**
* 小程序注册 * 小程序注册
* @param phone * @param username
* @param pwd * @param nickname
* @param code * @param headimgurl
* @return * @return
*/ */
@PostMapping("/api/app/applet/registry") @PostMapping("/api/app/applet/registry")
JSONObject appletRegistry(@RequestParam(value = "phone") String phone,@RequestParam("pwd") String pwd,@RequestParam("code") String code); public JSONObject appletRegistry(@RequestParam(value="username")String username, @RequestParam(value="nickname")String nickname,@RequestParam(value="headimgurl")String headimgurl);
} }
...@@ -27,10 +27,10 @@ public interface AuthService { ...@@ -27,10 +27,10 @@ public interface AuthService {
/** /**
* 通过小程序注册 * 通过小程序注册
* @param phone * @param username
* @param pwd * @param headimgurl
* @param code * @param nickname
* @return * @return
*/ */
JSONObject appletRegistry(String phone,String pwd,String code); JSONObject appletRegistry(String username,String headimgurl,String nickname);
} }
...@@ -92,8 +92,8 @@ public class AppAuthServiceImpl implements AuthService { ...@@ -92,8 +92,8 @@ public class AppAuthServiceImpl implements AuthService {
} }
@Override @Override
public JSONObject appletRegistry(String phone, String pwd, String code) { public JSONObject appletRegistry(String username,String headimgurl,String nickname) {
return userService.appletRegistry(phone,pwd,code); return userService.appletRegistry(username,headimgurl,nickname);
} }
} }
...@@ -90,7 +90,7 @@ public class AuthServiceImpl implements AuthService { ...@@ -90,7 +90,7 @@ public class AuthServiceImpl implements AuthService {
} }
@Override @Override
public JSONObject appletRegistry(String phone, String pwd, String code) { public JSONObject appletRegistry(String username,String headimgurl,String nickname) {
return userService.appletRegistry(phone,pwd,code); return userService.appletRegistry(username,headimgurl,nickname);
} }
} }
...@@ -183,8 +183,17 @@ public class AppUserRest { ...@@ -183,8 +183,17 @@ public class AppUserRest {
@PostMapping("/applet/registry") @PostMapping("/applet/registry")
public JSONObject appletRegistry(@RequestParam(value = "phone") String phone,@RequestParam("pwd") String pwd,@RequestParam("code") String code){ public JSONObject appletRegistry(
return appPermissionService.appletRegistry(phone,pwd,code); @RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="nickname",defaultValue="")String nickname,
@RequestParam(value="headimgurl",defaultValue="")String headimgurl){
if(StringUtils.isBlank(headimgurl)){
headimgurl=SystemConfig.USER_HEADER_URL_DEFAULT;
}
if(StringUtils.isBlank(nickname)){
nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
}
return appPermissionService.appletRegistry(username,headimgurl,nickname);
} }
} }
...@@ -245,7 +245,6 @@ public class AppPermissionService { ...@@ -245,7 +245,6 @@ public class AppPermissionService {
data.put("imToken",access_token); data.put("imToken",access_token);
data.put("imUserId",imUserId); data.put("imUserId",imUserId);
} }
if (data != null) { if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data); return JsonResultUtil.createSuccessResultWithObj(data);
} else { } else {
...@@ -672,22 +671,101 @@ public class AppPermissionService { ...@@ -672,22 +671,101 @@ public class AppPermissionService {
/** /**
*通过小程序注册 * 小程序注册用户
*
* @param username * @param username
* @param password * @param password
* @param mobilecode * @param headimgurl
* @param nickname
*/
@Transactional
public JSONObject applyRegister(String username, String password, String headimgurl,String nickname) {
// 判断参数
if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
// 是否已存在
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if (null != user) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
}
// 新增用户登录信息
try {
Long now = System.currentTimeMillis() / 1000;
AppUserLogin appUserLogin = new AppUserLogin();
appUserLogin.setUsername(username);
appUserLogin.setPassword(password);
appUserLogin.setIsdel(0);
appUserLogin.setStatus(0);
appUserLogin.setCreatetime(now);
appUserLogin.setUpdatetime(now);
appUserLoginBiz.insertSelective(appUserLogin);
Integer userid = appUserLogin.getId();
log.error("注册:新增登陆用户信息: " + userid);
// 新增用户详情
AppUserDetail rsUserDetail = new AppUserDetail();
rsUserDetail.setUserid(userid);
rsUserDetail.setNickname(nickname);
rsUserDetail.setHeadimgurl(headimgurl); // 默认路径,待写
rsUserDetail.setCreatetime(now);
rsUserDetail.setUpdatetime(now);
rsUserDetail.setIsdel(0);
appUserDetailBiz.insertSelective(rsUserDetail);
log.error("注册:新增用户详情: " + userid);
//自动登录获取优惠卷
authCoupn(userid);
//发送短信通知用户
thirdFeign.sendCode(username,password,SystemConfig.TEMPLATECODE);
// 登录结果要做做统一处理
JSONObject data = autoLogin(userid, username, headimgurl, nickname);
// 到im注册,获取返回结果
Map<String,Object> map=registerIm(username,appUserLogin.getPassword(),nickname);
if(map!=null){
Integer imUserId=Integer.parseInt(map.get("userId").toString());
String access_token=map.get("access_token").toString();
String imPassword=map.get("password").toString();
if(imUserId!=null&&imUserId>0&&StringUtils.isNotBlank(imPassword)){
AppUserLogin userLogin = new AppUserLogin();
userLogin.setId(userid);
userLogin.setImPassword(imPassword);
userLogin.setImUserid(imUserId);
userLogin.setUsername(username);
appUserLoginBiz.updateSelectiveById(userLogin);
log.info(username+"----userLogin updateSelectiveById---username====="+username+"----imPassword===="+imPassword);
}
data.put("imToken",access_token);
data.put("imUserId",imUserId);
}
if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data);
} else {
return JsonResultUtil.createDefaultFail();
}
} catch (Exception e) {
e.printStackTrace();
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
}
/**
*通过小程序注册
* @param username
* @return * @return
*/ */
public JSONObject appletRegistry(String username,String password,String mobilecode){ public JSONObject appletRegistry(String username,String headimgurl,String nickname ){
try { try {
// 是否已存在 // 是否已存在
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
JSONObject data=new JSONObject(); JSONObject data=new JSONObject();
if (null == user) { if (null == user) {
data=register(username, password, SystemConfig.USER_HEADER_URL_DEFAULT,SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000), mobilecode, null, null,0); String password="12345678";
data=applyRegister(username,password,headimgurl,nickname);
}else{ }else{
data=login(username,null,mobilecode,2); data=appletLoginByUserId(user.getId());
} }
return data; return data;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -27,6 +27,9 @@ import java.util.Map; ...@@ -27,6 +27,9 @@ import java.util.Map;
public interface ThirdFeign { public interface ThirdFeign {
@RequestMapping(value = "/sms/app/unauth/send", method = RequestMethod.GET) @RequestMapping(value = "/sms/app/unauth/send", method = RequestMethod.GET)
public JSONObject send(@RequestParam(value = "phone") String phone); public JSONObject send(@RequestParam(value = "phone") String phone);
@RequestMapping(value = "/sms/app/unauth/sendCode", method = RequestMethod.GET)
//发送短信模板消息
public JSONObject sendCode(@RequestParam("phone") String phone, @RequestParam("code")String code, @RequestParam("templateCode")String templateCode );
@RequestMapping(value = "/file/app/unauth/uploadFiles", method = RequestMethod.POST) @RequestMapping(value = "/file/app/unauth/uploadFiles", method = RequestMethod.POST)
public JSONObject uploadFiles(@RequestParam(value = "files") MultipartFile[] files); public JSONObject uploadFiles(@RequestParam(value = "files") MultipartFile[] files);
@RequestMapping(value = "/pay/app/wx", method = RequestMethod.POST) @RequestMapping(value = "/pay/app/wx", method = RequestMethod.POST)
......
...@@ -33,5 +33,12 @@ public class SmsController { ...@@ -33,5 +33,12 @@ public class SmsController {
public JSONObject sendSms(@RequestParam("phone") String phone) throws Exception { public JSONObject sendSms(@RequestParam("phone") String phone) throws Exception {
return smsService.smsCode(phone); return smsService.smsCode(phone);
} }
@RequestMapping(value = "/app/unauth/sendCode", method = RequestMethod.GET)
public JSONObject sendCode(
@RequestParam("phone") String phone,
@RequestParam("code")String code,
@RequestParam("templateCode")String templateCode ) throws Exception {
return smsService.smsByCode(phone,code,templateCode);
}
} }
...@@ -57,6 +57,18 @@ public class SmsService { ...@@ -57,6 +57,18 @@ public class SmsService {
} }
} }
public JSONObject smsByCode(String mobile,String pwd,String templateCode){
try {
if(StringUtils.isNotBlank(mobile)){
mobile=mobile.replace(" ", "");
}
sendSmsByStr(mobile,pwd,templateCode);
return JsonResultUtil.createSuccessResult();
} catch (ClientException e) {
e.printStackTrace();
return JsonResultUtil.createDefaultFail();
}
}
public String sendSms(String mobile, String code) throws ClientException { public String sendSms(String mobile, String code) throws ClientException {
//可自助调整超时时间 //可自助调整超时时间
...@@ -93,13 +105,56 @@ public class SmsService { ...@@ -93,13 +105,56 @@ public class SmsService {
log.info("RequestId=" + sendSmsResponse.getRequestId()); log.info("RequestId=" + sendSmsResponse.getRequestId());
log.info("BizId=" + sendSmsResponse.getBizId()); log.info("BizId=" + sendSmsResponse.getBizId());
if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) { if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
//请求成功 //请求成功
return code; return code;
} }
return null; return null;
} }
public boolean sendSmsByStr(String mobile, String str,String templateCode) throws ClientException {
//可自助调整超时时间
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化acsClient,暂不支持region化
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象-具体描述见控制台-文档部分内容
SendSmsRequest request = new SendSmsRequest();
//必填:待发送手机号
request.setPhoneNumbers(mobile);
//必填:短信签名-可在短信控制台中找到
request.setSignName(SignName);
//必填:短信模板-可在短信控制台中找到
request.setTemplateCode(templateCode);
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.setTemplateParam(TemplateParam.replace("str",str));//\"name\":\"Tom\",
//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
//request.setSmsUpExtendCode("90997");
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.setOutId("yourOutId");
//hint 此处可能会抛出异常,注意catch
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
log.info("短信接口返回的数据----------------mobile======"+mobile+"----str===="+str);
log.info("Code=" + sendSmsResponse.getCode());
log.info("Message=" + sendSmsResponse.getMessage());
log.info("RequestId=" + sendSmsResponse.getRequestId());
log.info("BizId=" + sendSmsResponse.getBizId());
if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
//请求成功
return true;
}
return false;
}
/* public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException { /* public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment