Upd:APP用户设置绑定解绑手机、微信

master
duLingLing 5 years ago
parent b315f23776
commit d05bde6eb8

@ -188,7 +188,7 @@ public interface RetailAppService {
void updateAccountEmail(JSONObject device,JSONObject codekey);
JSONObject bindAccountPhone(JSONObject device,JSONObject phone);
void bindAccountPhone(JSONObject device,JSONObject phone);
JSONObject updateAccountPhone(JSONObject device,JSONObject codekey);
@ -231,7 +231,9 @@ public interface RetailAppService {
JSONObject unbindAccountPhone(JSONObject device, JSONObject params);
void unbindAccountWechat(JSONObject device);
JSONObject unbindAccountWechat(JSONObject device);
JSONObject bindAccountWechat(JSONObject device, JSONObject params);
JSONObject getAccountBindInfos(JSONObject device);
}

@ -68,14 +68,12 @@ import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.slf4j.LoggerFactory;
@ -89,10 +87,8 @@ import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -676,7 +672,7 @@ public class RetailAppServiceImp implements RetailAppService {
res.put("skip_clearing", !res.getBoolean("skip_clearing"));
}
sysClientLegalPersonMapper.findRepresentativeInfo(device.getIntValue("client_id"));
res.put("representative_info",sysClientLegalPersonMapper.findRepresentativeInfo(device.getIntValue("client_id")));
res.put("representative_info", sysClientLegalPersonMapper.findRepresentativeInfo(device.getIntValue("client_id")));
return res;
}
@ -938,7 +934,7 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("dev_id", device.getString("dev_id"));
}
params.put("client_id", client_id);
params.put("after_limit", (query.getPage()-1)*query.getLimit());
params.put("after_limit", (query.getPage() - 1) * query.getLimit());
params.put("limit", query.getLimit());
List<JSONObject> orders = orderMapper.listTransactionsForApp(params);
TimeZoneUtils.switchTimeZone(orders, query.getTimezone(), "create_time", "transaction_time", "confirm_time");
@ -2122,14 +2118,11 @@ public class RetailAppServiceImp implements RetailAppService {
}
@Override
public JSONObject bindAccountPhone(JSONObject device, JSONObject phone) {
public void bindAccountPhone(JSONObject device, JSONObject phone) {
String codeKey = device.getString("account_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).get();
JSONObject result = new JSONObject();
if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
result.put("status","error");
result.put("message","Captcha has been sent.Please check your phone or try again in 5 minutes.");
return result;
throw new BadRequestException("Captcha has been sent.Please check your phone or try again in 1 minutes.");
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
String nationCode = phone.getString("nation_code");
@ -2137,44 +2130,33 @@ public class RetailAppServiceImp implements RetailAppService {
ArrayList<String> param = new ArrayList<>();
param.add("绑定手机号");
param.add(codeKeyValue);
String expireMin = "5";
String expireMin = "1";
param.add(expireMin);
try {
// smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", "");
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
result.put("status","success");
result.put("code_Key_Value",codeKeyValue);
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", "");
} catch (Exception e) {
e.printStackTrace();
result.put("status","error");
result.put("message","Phone number is wrong.Please try again.");
throw new BadRequestException("Phone number is wrong.Please try again.");
}
return result;
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
}
@Override
public JSONObject updateAccountPhone(JSONObject device, JSONObject params) {
String key = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get();
JSONObject result = new JSONObject();
if (key == null) {
result.put("status","error");
result.put("message","Captcha has expired");
return result;
throw new BadRequestException("Captcha has expired");
}
String captcha = key.split("&")[0];
String nation_code = key.split("&")[1];
String contact_phone = key.split("&")[2];
if (!StringUtils.equals(captcha, params.getString("captcha"))) {
result.put("status","error");
result.put("message","Verification code is wrong");
return result;
throw new BadRequestException("Verification code is wrong");
}
JSONObject account = clientAccountMapper.findByPhone(contact_phone, "+"+nation_code);
if(account!=null){
result.put("status","error");
result.put("message","Mobile phone number has been bound to other users, please unbind it before binding");
return result;
JSONObject account = clientAccountMapper.findByPhone(contact_phone, "+" + nation_code);
if (account != null) {
throw new BadRequestException("Mobile phone number has been bound to other users, please unbind it before binding");
}
JSONObject updateAccount = new JSONObject();
@ -2183,43 +2165,37 @@ public class RetailAppServiceImp implements RetailAppService {
updateAccount.put("nation_code", "+" + nation_code);
clientAccountMapper.update(updateAccount);
deleteAccountPhoneKey(device.getString("account_id"));
result.put("status","success");
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override
public void updateLoginClientAccountPhone(JSONObject account, String contactPhone, String nationCode){
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id",account.getString("account_id"));
updateAccount.put("contact_phone",contactPhone);
updateAccount.put("nation_code","+" + nationCode);
public void updateLoginClientAccountPhone(JSONObject account, String contactPhone, String nationCode) {
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", account.getString("account_id"));
updateAccount.put("contact_phone", contactPhone);
updateAccount.put("nation_code", "+" + nationCode);
clientAccountMapper.update(updateAccount);
}
@Override
public void updateLoginClientAccountOpenId(JSONObject account,JSONObject params){
JSONObject updateAccount = new JSONObject();
JSONObject queryAccount = account.getJSONObject("account");
updateAccount.put("account_id",queryAccount.getString("account_id"));
updateAccount.put("wechat_openid",params.getString("wechat_openid"));
public void updateLoginClientAccountOpenId(JSONObject account, JSONObject params) {
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", account.getString("account_id"));
updateAccount.put("wechat_openid", params.getString("wechat_openid"));
clientAccountMapper.update(updateAccount);
}
@Override
public JSONObject unbindAccountPhone(JSONObject device, JSONObject phone) {
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get();
JSONObject result = new JSONObject();
if (codeKeyValueRedis == null) {
result.put("status","error");
result.put("message","Captcha has expired");
return result;
throw new BadRequestException("Captcha has expired");
}
String captcha = codeKeyValueRedis.split("&")[0];
if (!StringUtils.equals(captcha, phone.getString("captcha"))) {
result.put("status","error");
result.put("message","Verification code is wrong");
return result;
throw new BadRequestException("");
}
JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id"));
@ -2227,39 +2203,53 @@ public class RetailAppServiceImp implements RetailAppService {
account.put("nation_code", null);
clientAccountMapper.update(account);
deleteAccountPhoneKey(device.getString("account_id"));
result.put("status","success");
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override
public void unbindAccountWechat(JSONObject device) {
public JSONObject unbindAccountWechat(JSONObject device) {
JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id"));
account.put("wechat_openid", null);
clientAccountMapper.update(account);
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override
public JSONObject bindAccountWechat(JSONObject device, JSONObject params){
public JSONObject bindAccountWechat(JSONObject device, JSONObject params) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(params.getString("code"));
JSONObject result = new JSONObject();
if(user==null){
result.put("status","error");
result.put("message","WeChat users do not exist");
return result;
if (user == null) {
throw new BadRequestException("WeChat users do not exist");
}
String openId = user.getString("openid");
JSONObject account = clientAccountMapper.findByOpenId(openId);
if(account!=null){
result.put("status","error");
result.put("message","WeChat ID has been bound to other accounts, please unbind it before binding");
return result;
if (account != null) {
throw new BadRequestException("WeChat ID has been bound to other accounts, please unbind it before binding");
}
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", device.getString("account_id"));
updateAccount.put("wechat_openid", openId);
clientAccountMapper.update(updateAccount);
result.put("status","success");
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override
public JSONObject getAccountBindInfos(JSONObject device) {
JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
JSONObject result = new JSONObject();
result.put("phone_bind_status",!account.containsValue("contact_phone"));
if(!account.containsValue("contact_phone")){
result.put("contact_phone",account.getString("contact_phone"));
result.put("naticon_code",account.getString("naticon_code"));
}
result.put("wechat_bind_status",!account.containsValue("wechat_openid"));
return result;
}
@ -2556,7 +2546,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
@Override
public boolean isSubPartner(JSONObject device,String clientMoniker) {
public boolean isSubPartner(JSONObject device, String clientMoniker) {
JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker);
if (client == null) {
throw new NotFoundException("Client not found, please check");
@ -2570,7 +2560,6 @@ public class RetailAppServiceImp implements RetailAppService {
}
private void exportCBBankAggregateFile(JSONObject client, HttpServletResponse httpResponse) {
httpResponse.setContentType("application/pdf");
httpResponse.setHeader("content-disposition", "attachment;filename=" + client.getString("client_moniker") + "_AGREEMENT_" + new Date() + ".pdf");
@ -2707,4 +2696,5 @@ public class RetailAppServiceImp implements RetailAppService {
res.put("channels", channels);
return res;
}
}

@ -7,6 +7,7 @@ import au.com.royalpay.payment.manage.appclient.beans.AppClientBean;
import au.com.royalpay.payment.manage.appclient.beans.AppPaymentConfigBean;
import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.apps.AppController;
import au.com.royalpay.payment.manage.bill.bean.NewBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean;
@ -57,7 +58,7 @@ import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE;
/**
* Created by yishuqian on 28/03/2017.
*/
@RestController
@AppClientController
@RequestMapping("/api/v1.0/retail/app")
public class RetailAppController {
Logger logger = LoggerFactory.getLogger(getClass());
@ -722,9 +723,9 @@ public class RetailAppController {
* @throws Exception
*/
@PutMapping("/account/phone")
public JSONObject bindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject phone) throws Exception {
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.bindAccountPhone(deviceInfo, phone);
public JSONObject bindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject phone) throws Exception {
retailAppService.bindAccountPhone(device, phone);
return new JSONObject();
}
/**
@ -735,10 +736,8 @@ public class RetailAppController {
* @throws Exception
*/
@PutMapping("/account/phone/bind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device,
public JSONObject updateAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception {
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.updateAccountPhone(deviceInfo, params);
public JSONObject updateAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
return retailAppService.updateAccountPhone(device, params);
}
/**
@ -749,10 +748,8 @@ public class RetailAppController {
* @throws Exception
*/
@PutMapping("/account/phone/unbind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device,
public JSONObject unbindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception {
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.unbindAccountPhone(deviceInfo, params);
public JSONObject unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
return retailAppService.unbindAccountPhone(device, params);
}
/**
@ -761,10 +758,8 @@ public class RetailAppController {
* @param params
*/
@PutMapping("/account/wechat/bind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device,
public JSONObject bindAccountWechat(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params){
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.bindAccountWechat(deviceInfo,params);
public JSONObject bindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params){
return retailAppService.bindAccountWechat(device,params);
}
@ -773,10 +768,8 @@ public class RetailAppController {
* @param device
*/
@PutMapping("/account/wechat/unbind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device,
public void unbindAccountWechat(@RequestHeader("X-Device-Info") String device){
JSONObject deviceInfo = JSONObject.parseObject(device);
retailAppService.unbindAccountWechat(deviceInfo);
public JSONObject unbindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device){
return retailAppService.unbindAccountWechat(device);
}
@ -896,4 +889,14 @@ public class RetailAppController {
return model;
}
/**
* ()
* @param device
* @return
*/
@GetMapping("/client/account/bind/infos")
public JSONObject findClientAccountBindStatusInfos(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){
return retailAppService.getAccountBindInfos(device);
}
}

@ -185,10 +185,11 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
*/
@PostMapping("/send/{phone_number}/verify_code")
@ResponseBody
public String sendLoginMobileVerifyCode(@PathVariable("phone_number") String phoneNumber,
public JSONObject sendLoginMobileVerifyCode(@PathVariable("phone_number") String phoneNumber,
@RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode,
HttpServletRequest request) {
return simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request);
simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request);
return new JSONObject();
}
/**
@ -205,24 +206,23 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device,
Errors errors) {
HttpUtils.handleValidErrors(errors);
if (params.getString("verify_code").isEmpty() && params.getString("verify_code") == null) {
throw new BadRequestException("verify code can't be null");
}
simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone);
nationCode = nationCode;
JSONObject result = new JSONObject();
JSONObject signKeyResult = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode);
if(signKeyResult.getBoolean("account_exist")){
JSONObject client = signInStatusManager.getCurrentClient(signKeyResult.getString("status_key"));
client = JSON.parseObject(client.toJSONString());
simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone);
String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode,RequestEnvironment.getClientIp());
if(signKey!=null){
JSONObject account = signInStatusManager.getCurrentClient(signKey);
account = JSON.parseObject(account.toJSONString());
if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId"));
deviceSupport.validDeviceWithClient(account, params.getString("devId"));
}
result=client;
result.put("sign_key", signKeyResult.getString("status_key"));
account.put("sign_key", signKey);
result.put("account",account);
result.put("status","success");
result.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
}else{
result.put("status","success");
result.put("bind_status", false);
result.put("contact_phone",contactPhone);
result.put("nation_code",nationCode);
@ -242,37 +242,42 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
@RequestBody JSONObject params,
Errors errors){
HttpUtils.handleValidErrors(errors);
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password"));
JSONObject signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone");
JSONObject client = signInStatusManager.getCurrentClient(signKey);
retailAppService.updateLoginClientAccountPhone(client, contactPhone,nationCode);
client = JSON.parseObject(client.toJSONString());
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone");
signInStatusManager.verifyClientLoginPhoneBindCode(contactPhone,nationCode,RequestEnvironment.getClientIp());
JSONObject account = signInStatusManager.getCurrentClient(signKey);
retailAppService.updateLoginClientAccountPhone(account, contactPhone,nationCode);
account.put("sign_key", signKey);
account = JSON.parseObject(account.toJSONString());
JSONObject result = new JSONObject();
result.put("account",account);
if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId"));
deviceSupport.validDeviceWithClient(account, params.getString("devId"));
}
client.put("sign_key", signKey);
client.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
return client;
result.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
return result;
}
/**
* App
* @param data
* @param params
* @return
*/
@PostMapping("/client_app_wechat_signin")
public JSONObject clientAppWechatSignIn(@RequestBody JSONObject data,
public JSONObject clientAppWechatSignIn(@RequestBody JSONObject params,
Errors errors) {
HttpUtils.handleValidErrors(errors);
JSONObject res = signInStatusManager.clientAppWechatSignIn(data.getString("code"));
if (!res.getBooleanValue("not_exists")) {
deviceSupport.validDeviceWithClient(res, res.getString("app_openid"));
this.publisher.publishEvent(new ClientLoginEvent(this, res.getIntValue("client_id"), res.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
JSONObject account = signInStatusManager.clientAppWechatSignIn(params.getString("code"),RequestEnvironment.getClientIp());
if(!account.getBoolean("bind_status")){
deviceSupport.validDeviceWithClient(account, params.getString("app_openid"));
return account;
}
return res;
this.publisher.publishEvent(new ClientLoginEvent(this, account.getJSONObject("account").getIntValue("client_id"), account.getJSONObject("account").getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return account;
}
/**
@ -282,27 +287,24 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
*/
@PostMapping("/login/wechat_bind")
public JSONObject wechatLoginBind(@RequestBody JSONObject params){
signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid"),RequestEnvironment.getClientIp());
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password"));
JSONObject signKeyResult = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat");
if("error".equals(signKeyResult.getString("status"))){
return signKeyResult;
}
JSONObject client = signInStatusManager.getCurrentClient(signKeyResult.getString("status_key"));
if("error".equals(client.getString("status"))){
return client;
}
retailAppService.updateLoginClientAccountOpenId(client,params);
client = JSON.parseObject(client.toJSONString());
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat");
JSONObject account = signInStatusManager.getCurrentClient(signKey);
retailAppService.updateLoginClientAccountOpenId(account,params);
account = JSON.parseObject(account.toJSONString());
if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId"));
deviceSupport.validDeviceWithClient(account, params.getString("devId"));
}
client.put("sign_key", signKeyResult.getString("status_key"));
client.put("bind_status", true);
client.put("status","success");
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return client;
JSONObject result = new JSONObject();
account.put("sign_key", signKey);
result.put("account",account);
result.put("bind_status", true);
result.put("status","success");
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return result;
}
}

@ -41,10 +41,8 @@ public interface SimpleClientApplyService {
void subscribeNewsletter(String mail, String lang);
//region 手机登录验证
String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request);
void getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request);
void verifyLoginSMSCode(String codeKey, String phoneNumber);
//endregion
}

@ -682,30 +682,30 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
//region 手机登录
@Override
public String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request) {
public void getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request) {
JSONObject result = new JSONObject();
String reidsCheckCodeKey = getLoginClientRedisKey(phoneNumber);
String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get();
if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes.");
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 1 minutes.");
}
ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay");
param.add(registerClientCode);
String expireMin = "3";
String expireMin = "1";
param.add(expireMin);
try {
/* if(request.getLocales().nextElement().equals(Locale.CHINESE)|| request.getLocales().nextElement().equals(Locale.SIMPLIFIED_CHINESE)){
if(request.getLocales().nextElement().equals(Locale.CHINESE)|| request.getLocales().nextElement().equals(Locale.SIMPLIFIED_CHINESE)){
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID, param, "RoyalPay", "", "");
}else{
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", "");
}*/
}
} catch (Exception e) {
e.printStackTrace();
throw new ServerErrorException("Phone number is wrong Please try again");
}
stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
return registerClientCode;
}
@Override

@ -82,4 +82,13 @@ public interface ClientAccountMapper {
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1 and (role=1 or role=2) and wechat_openid is not null", excludeColumns = {"salt", "password_hash"})
List<JSONObject> listRiskNoticeAccounts(@Param("client_id") int clientId);
/**
*
* @param openid
* @return
*/
JSONObject findOneByOpenIdAndCreateTimeDesc(@Param("wechat_openid")String openid);
JSONObject findOneByPhoneAndCreateTimeDesc(@Param("contact_phone")String contactPhone,@Param("nation_code")String nationCode);
}

@ -40,6 +40,13 @@ public interface SignInAccountService {
JSONObject clientWechatSignIn(String openid);
/**
*
* @param openid
* @return
*/
JSONObject clientWechatOneSignIn(String openid);
JSONObject clientWechatAppSignIn(String openId);
JSONObject clientWechatAppSignInByUnionId(String unionId);

@ -73,7 +73,7 @@ public interface SignInStatusManager {
* @param code
* @return
*/
JSONObject clientAppWechatSignIn(String code);
JSONObject clientAppWechatSignIn(String code,String ip);
/**
*
@ -81,12 +81,29 @@ public interface SignInStatusManager {
* @param nationCode
* @return
*/
JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode);
String getClientInfoByPhoneStatusKey(String phone,String nationCode,String ip);
/**
*
* @param loginInfo
* @return
*/
JSONObject verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType);
String verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType);
/**
* openId
* @param codeId
* @param ip
* @return
*/
void verifyClientLoginWechatBindCode (String codeId,String ip);
/**
*
* @param phone
* @param nationCode
* @param ip
* @return
*/
void verifyClientLoginPhoneBindCode (String phone,String nationCode,String ip);
}

@ -362,6 +362,17 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
return account;
}
@Override
public JSONObject clientWechatOneSignIn(String openid){
JSONObject account = clientAccountMapper.findOneByOpenIdAndCreateTimeDesc(openid);
if (account == null) {
return null;
}
publisher.publishEvent(
new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return account;
}
@Override
public JSONObject clientWechatAppSignIn(String openId) {
JSONObject account = clientAccountMapper.findByAppOpenId(openId);

@ -38,6 +38,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Resource
private ClientAccountMapper clientAccountMapper;
private final String CLIENT_LOGIN_WECHAT_BIND_PREFIX = "CLIENT_LOGIN_WECHAT_BIND_PREFIX";
private final String CLIENT_LOGIN_PHONE_BIND_PREFIX = "CLIENT_LOGIN_PHONE_BIND_PREFIX";
@Override
public JSONObject getCurrentManager(String statusKey) {
BoundValueOperations<String, String> op = stringRedisTemplate.boundValueOps(managerLoginRedisKey(statusKey));
@ -61,22 +64,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return null;
}
op.expire(30, TimeUnit.MINUTES);
JSONObject result = new JSONObject();
try{
JSONObject account = signInAccountService.getClient(accountId);
if(account.containsKey("wechat_openid")){
result.put("status","error");
result.put("account","The account has been bound to WeChat, please unbind it before binding");
}else{
result.put("status","success");
result.put("account",account);
}
}catch (ForbiddenException e){
result.put("status","error");
result.put("message",e.getMessage());
}
return result;
JSONObject account = signInAccountService.getClient(accountId);
return account;
}
private String partnerLoginRedisKey(String statusKey) {
@ -92,18 +82,16 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
}
@Override
public JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode) {
JSONObject result = new JSONObject();
public String getClientInfoByPhoneStatusKey(String phone, String nationCode,String ip) {
String statusKey = newStatusKey();
JSONObject account = clientAccountMapper.findByPhone(phone, "+"+nationCode);
if(account==null){
result.put("account_exist",false);
return result;
JSONObject account = clientAccountMapper.findOneByPhoneAndCreateTimeDesc(phone, "+" + nationCode);
if (account == null) {
String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginPhoneBindRedisKey(phone,nationCode,ip)).set(phone, Long.parseLong(expireMin), TimeUnit.MINUTES);
return null;
}
result.put("account_exist",true);
result.put("status_key",statusKey);
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
return result;
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
return statusKey;
}
private String newStatusKey() {
@ -111,27 +99,20 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
}
@Override
public JSONObject verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType){
JSONObject account = signInAccountService.clientAccountCheck(loginInfo);
JSONObject result = new JSONObject();
if("phone".equals(verfiyType)){
if(account.containsKey("contact_phone")){
result.put("status","error");
result.put("message","The account has been linked to the phone number!");
return result;
public String verifyClientAccountLogin(LoginInfo loginInfo, String verfiyType) {
JSONObject account = signInAccountService.clientAccountCheck(loginInfo);;
if ("phone".equals(verfiyType)) {
if (account.containsKey("contact_phone")) {
throw new BadRequestException("The account has been linked to the phone number!");
}
}else{
if(account.containsKey("wechat_openid")){
result.put("status","error");
result.put("message","The account has been linked to the wechat!");
return result;
} else {
if (account.containsKey("wechat_openid")) {
throw new BadRequestException("The account has been linked to the wechat!");
}
}
String statusKey = newStatusKey();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set("" + account.getString("account_id"), 30, TimeUnit.MINUTES);
result.put("status","success");
result.put("status_key",statusKey);
return result;
return statusKey;
}
@Override
@ -399,33 +380,64 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
}
@Override
public JSONObject clientAppWechatSignIn(String code) {
public JSONObject clientAppWechatSignIn(String code,String ip) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code);
if(user==null){
throw new BadRequestException("WeChat users do not exist");
}
String openId = user.getString("openid");
String unionId = user.getString("unionid");
JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
String statusKey = newStatusKey();
JSONObject account = signInAccountService.clientWechatOneSignIn(openId);
if (account == null) {
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
if (account == null) {
JSONObject res = new JSONObject();
res.put("bind_status", false);
res.put("app_openid", openId);
res.put("status","success");
return res;
}
JSONObject res = new JSONObject();
res.put("bind_status", false);
res.put("app_openid", openId);
res.put("status", "success");
String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId,ip)).set(openId, Long.parseLong(expireMin), TimeUnit.MINUTES);
return res;
}
String statusKey = newStatusKey();
JSONObject result = new JSONObject();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
account = getCurrentClient(statusKey);
account.put("sign_key", statusKey);
account.put("app_openid", openId);
account.put("bind_status",true);
account.put("status","success");
return account;
result.put("account",account);
result.put("app_openid", openId);
result.put("bind_status", true);
result.put("status", "success");
return result;
}
private String getClientLoginWechatBindRedisKey(String openId,String ip){
return "login:"+":"+CLIENT_LOGIN_WECHAT_BIND_PREFIX + "&"+openId+"&"+ip;
}
public void verifyClientLoginWechatBindCode(String openId,String ip){
String rediskey = getClientLoginWechatBindRedisKey(openId,ip);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(openId)) {
throw new BadRequestException("The WeChat ID does not apply for binding");
}
stringRedisTemplate.delete(rediskey);
}
private String getClientLoginPhoneBindRedisKey(String phone,String nationCode,String ip){
return "login:"+CLIENT_LOGIN_PHONE_BIND_PREFIX + "&"+nationCode+"&"+phone+"&"+ip;
}
public void verifyClientLoginPhoneBindCode(String phone,String nationCode,String ip){
String rediskey = getClientLoginPhoneBindRedisKey(phone,nationCode,ip);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(phone)) {
throw new BadRequestException("The phone number is for application binding");
}
stringRedisTemplate.delete(rediskey);
}
private void lockRandomCodeId(String codeId) {
stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS);
}

@ -28,4 +28,17 @@
OR
sc.parent_client_id IN (select client_id from sys_clients where client_id =#{client_id} or parent_client_id=#{client_id}));
</select>
<select id="findOneByOpenIdAndCreateTimeDesc" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM sys_accounts a
WHERE a.is_valid =1 and a.wechat_openid=#{wechat_openid}
ORDER BY a.create_time DESC
limit 1
</select>
<select id="findOneByPhoneAndCreateTimeDesc" resultType="com.alibaba.fastjson.JSONObject">
SELECT * FROM sys_accounts a
WHERE a.is_valid =1 and a.contact_phone=#{contact_phone} AND a.nation_code = #{nation_code}
ORDER BY a.create_time DESC
limit 1
</select>
</mapper>

Loading…
Cancel
Save