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

master
duLingLing 6 years ago
parent b315f23776
commit d05bde6eb8

@ -188,7 +188,7 @@ public interface RetailAppService {
void updateAccountEmail(JSONObject device,JSONObject codekey); void updateAccountEmail(JSONObject device,JSONObject codekey);
JSONObject bindAccountPhone(JSONObject device,JSONObject phone); void bindAccountPhone(JSONObject device,JSONObject phone);
JSONObject updateAccountPhone(JSONObject device,JSONObject codekey); JSONObject updateAccountPhone(JSONObject device,JSONObject codekey);
@ -231,7 +231,9 @@ public interface RetailAppService {
JSONObject unbindAccountPhone(JSONObject device, JSONObject params); JSONObject unbindAccountPhone(JSONObject device, JSONObject params);
void unbindAccountWechat(JSONObject device); JSONObject unbindAccountWechat(JSONObject device);
JSONObject bindAccountWechat(JSONObject device, JSONObject params); 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.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds; import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList; 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.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -89,10 +87,8 @@ import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine; import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -2122,14 +2118,11 @@ public class RetailAppServiceImp implements RetailAppService {
} }
@Override @Override
public JSONObject bindAccountPhone(JSONObject device, JSONObject phone) { public void bindAccountPhone(JSONObject device, JSONObject phone) {
String codeKey = device.getString("account_id"); String codeKey = device.getString("account_id");
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).get(); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).get();
JSONObject result = new JSONObject();
if (StringUtils.isNotEmpty(codeKeyValueRedis)) { if (StringUtils.isNotEmpty(codeKeyValueRedis)) {
result.put("status","error"); throw new BadRequestException("Captcha has been sent.Please check your phone or try again in 1 minutes.");
result.put("message","Captcha has been sent.Please check your phone or try again in 5 minutes.");
return result;
} }
String codeKeyValue = RandomStringUtils.random(6, false, true); String codeKeyValue = RandomStringUtils.random(6, false, true);
String nationCode = phone.getString("nation_code"); String nationCode = phone.getString("nation_code");
@ -2137,44 +2130,33 @@ public class RetailAppServiceImp implements RetailAppService {
ArrayList<String> param = new ArrayList<>(); ArrayList<String> param = new ArrayList<>();
param.add("绑定手机号"); param.add("绑定手机号");
param.add(codeKeyValue); param.add(codeKeyValue);
String expireMin = "5"; String expireMin = "1";
param.add(expireMin); param.add(expireMin);
try { try {
// smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", ""); 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);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
result.put("status","error"); throw new BadRequestException("Phone number is wrong.Please try again.");
result.put("message","Phone number is wrong.Please try again.");
} }
return result; stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
} }
@Override @Override
public JSONObject updateAccountPhone(JSONObject device, JSONObject params) { public JSONObject updateAccountPhone(JSONObject device, JSONObject params) {
String key = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get(); String key = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get();
JSONObject result = new JSONObject();
if (key == null) { if (key == null) {
result.put("status","error"); throw new BadRequestException("Captcha has expired");
result.put("message","Captcha has expired");
return result;
} }
String captcha = key.split("&")[0]; String captcha = key.split("&")[0];
String nation_code = key.split("&")[1]; String nation_code = key.split("&")[1];
String contact_phone = key.split("&")[2]; String contact_phone = key.split("&")[2];
if (!StringUtils.equals(captcha, params.getString("captcha"))) { if (!StringUtils.equals(captcha, params.getString("captcha"))) {
result.put("status","error"); throw new BadRequestException("Verification code is wrong");
result.put("message","Verification code is wrong");
return result;
} }
JSONObject account = clientAccountMapper.findByPhone(contact_phone, "+" + nation_code); JSONObject account = clientAccountMapper.findByPhone(contact_phone, "+" + nation_code);
if (account != null) { if (account != null) {
result.put("status","error"); throw new BadRequestException("Mobile phone number has been bound to other users, please unbind it before binding");
result.put("message","Mobile phone number has been bound to other users, please unbind it before binding");
return result;
} }
JSONObject updateAccount = new JSONObject(); JSONObject updateAccount = new JSONObject();
@ -2183,6 +2165,7 @@ public class RetailAppServiceImp implements RetailAppService {
updateAccount.put("nation_code", "+" + nation_code); updateAccount.put("nation_code", "+" + nation_code);
clientAccountMapper.update(updateAccount); clientAccountMapper.update(updateAccount);
deleteAccountPhoneKey(device.getString("account_id")); deleteAccountPhoneKey(device.getString("account_id"));
JSONObject result = new JSONObject();
result.put("status", "success"); result.put("status", "success");
return result; return result;
} }
@ -2199,27 +2182,20 @@ public class RetailAppServiceImp implements RetailAppService {
@Override @Override
public void updateLoginClientAccountOpenId(JSONObject account, JSONObject params) { public void updateLoginClientAccountOpenId(JSONObject account, JSONObject params) {
JSONObject updateAccount = new JSONObject(); JSONObject updateAccount = new JSONObject();
JSONObject queryAccount = account.getJSONObject("account"); updateAccount.put("account_id", account.getString("account_id"));
updateAccount.put("account_id",queryAccount.getString("account_id"));
updateAccount.put("wechat_openid", params.getString("wechat_openid")); updateAccount.put("wechat_openid", params.getString("wechat_openid"));
clientAccountMapper.update(updateAccount); clientAccountMapper.update(updateAccount);
} }
@Override @Override
public JSONObject unbindAccountPhone(JSONObject device, JSONObject phone) { public JSONObject unbindAccountPhone(JSONObject device, JSONObject phone) {
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get(); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get();
JSONObject result = new JSONObject();
if (codeKeyValueRedis == null) { if (codeKeyValueRedis == null) {
result.put("status","error"); throw new BadRequestException("Captcha has expired");
result.put("message","Captcha has expired");
return result;
} }
String captcha = codeKeyValueRedis.split("&")[0]; String captcha = codeKeyValueRedis.split("&")[0];
if (!StringUtils.equals(captcha, phone.getString("captcha"))) { if (!StringUtils.equals(captcha, phone.getString("captcha"))) {
result.put("status","error"); throw new BadRequestException("");
result.put("message","Verification code is wrong");
return result;
} }
JSONObject account = new JSONObject(); JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id")); account.put("account_id", device.getString("account_id"));
@ -2227,42 +2203,56 @@ public class RetailAppServiceImp implements RetailAppService {
account.put("nation_code", null); account.put("nation_code", null);
clientAccountMapper.update(account); clientAccountMapper.update(account);
deleteAccountPhoneKey(device.getString("account_id")); deleteAccountPhoneKey(device.getString("account_id"));
JSONObject result = new JSONObject();
result.put("status", "success"); result.put("status", "success");
return result; return result;
} }
@Override @Override
public void unbindAccountWechat(JSONObject device) { public JSONObject unbindAccountWechat(JSONObject device) {
JSONObject account = new JSONObject(); JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id")); account.put("account_id", device.getString("account_id"));
account.put("wechat_openid", null); account.put("wechat_openid", null);
clientAccountMapper.update(account); clientAccountMapper.update(account);
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
} }
@Override @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 user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(params.getString("code"));
JSONObject result = new JSONObject();
if (user == null) { if (user == null) {
result.put("status","error"); throw new BadRequestException("WeChat users do not exist");
result.put("message","WeChat users do not exist");
return result;
} }
String openId = user.getString("openid"); String openId = user.getString("openid");
JSONObject account = clientAccountMapper.findByOpenId(openId); JSONObject account = clientAccountMapper.findByOpenId(openId);
if (account != null) { if (account != null) {
result.put("status","error"); throw new BadRequestException("WeChat ID has been bound to other accounts, please unbind it before binding");
result.put("message","WeChat ID has been bound to other accounts, please unbind it before binding");
return result;
} }
JSONObject updateAccount = new JSONObject(); JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", device.getString("account_id")); updateAccount.put("account_id", device.getString("account_id"));
updateAccount.put("wechat_openid", openId); updateAccount.put("wechat_openid", openId);
clientAccountMapper.update(updateAccount); clientAccountMapper.update(updateAccount);
JSONObject result = new JSONObject();
result.put("status", "success"); result.put("status", "success");
return result; 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;
}
@Override @Override
public void verifyRefundPassword(JSONObject device, JSONObject json) { public void verifyRefundPassword(JSONObject device, JSONObject json) {
String clientType = device.getString("client_type"); String clientType = device.getString("client_type");
@ -2570,7 +2560,6 @@ public class RetailAppServiceImp implements RetailAppService {
} }
private void exportCBBankAggregateFile(JSONObject client, HttpServletResponse httpResponse) { private void exportCBBankAggregateFile(JSONObject client, HttpServletResponse httpResponse) {
httpResponse.setContentType("application/pdf"); httpResponse.setContentType("application/pdf");
httpResponse.setHeader("content-disposition", "attachment;filename=" + client.getString("client_moniker") + "_AGREEMENT_" + new Date() + ".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); res.put("channels", channels);
return res; 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.AppPaymentConfigBean;
import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean; import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; 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.NewBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillBean; import au.com.royalpay.payment.manage.bill.bean.QueryBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean; 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. * Created by yishuqian on 28/03/2017.
*/ */
@RestController @AppClientController
@RequestMapping("/api/v1.0/retail/app") @RequestMapping("/api/v1.0/retail/app")
public class RetailAppController { public class RetailAppController {
Logger logger = LoggerFactory.getLogger(getClass()); Logger logger = LoggerFactory.getLogger(getClass());
@ -722,9 +723,9 @@ public class RetailAppController {
* @throws Exception * @throws Exception
*/ */
@PutMapping("/account/phone") @PutMapping("/account/phone")
public JSONObject bindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject phone) throws Exception { public JSONObject bindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject phone) throws Exception {
JSONObject deviceInfo = JSONObject.parseObject(device); retailAppService.bindAccountPhone(device, phone);
return retailAppService.bindAccountPhone(deviceInfo, phone); return new JSONObject();
} }
/** /**
@ -735,10 +736,8 @@ public class RetailAppController {
* @throws Exception * @throws Exception
*/ */
@PutMapping("/account/phone/bind") @PutMapping("/account/phone/bind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device, public JSONObject updateAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
public JSONObject updateAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception { return retailAppService.updateAccountPhone(device, params);
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.updateAccountPhone(deviceInfo, params);
} }
/** /**
@ -749,10 +748,8 @@ public class RetailAppController {
* @throws Exception * @throws Exception
*/ */
@PutMapping("/account/phone/unbind") @PutMapping("/account/phone/unbind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device, public JSONObject unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
public JSONObject unbindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception { return retailAppService.unbindAccountPhone(device, params);
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.unbindAccountPhone(deviceInfo, params);
} }
/** /**
@ -761,10 +758,8 @@ public class RetailAppController {
* @param params * @param params
*/ */
@PutMapping("/account/wechat/bind") @PutMapping("/account/wechat/bind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device, public JSONObject bindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params){
public JSONObject bindAccountWechat(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params){ return retailAppService.bindAccountWechat(device,params);
JSONObject deviceInfo = JSONObject.parseObject(device);
return retailAppService.bindAccountWechat(deviceInfo,params);
} }
@ -773,10 +768,8 @@ public class RetailAppController {
* @param device * @param device
*/ */
@PutMapping("/account/wechat/unbind") @PutMapping("/account/wechat/unbind")
// @ModelAttribute(RETAIL_DEVICE) JSONObject device, public JSONObject unbindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device){
public void unbindAccountWechat(@RequestHeader("X-Device-Info") String device){ return retailAppService.unbindAccountWechat(device);
JSONObject deviceInfo = JSONObject.parseObject(device);
retailAppService.unbindAccountWechat(deviceInfo);
} }
@ -896,4 +889,14 @@ public class RetailAppController {
return model; 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") @PostMapping("/send/{phone_number}/verify_code")
@ResponseBody @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, @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode,
HttpServletRequest request) { 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, @ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device,
Errors errors) { Errors errors) {
HttpUtils.handleValidErrors(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 result = new JSONObject();
JSONObject signKeyResult = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode); simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone);
if(signKeyResult.getBoolean("account_exist")){ String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode,RequestEnvironment.getClientIp());
JSONObject client = signInStatusManager.getCurrentClient(signKeyResult.getString("status_key")); if(signKey!=null){
client = JSON.parseObject(client.toJSONString()); JSONObject account = signInStatusManager.getCurrentClient(signKey);
account = JSON.parseObject(account.toJSONString());
if (params.getString("devId") != null) { if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId")); deviceSupport.validDeviceWithClient(account, params.getString("devId"));
} }
result=client; account.put("sign_key", signKey);
result.put("sign_key", signKeyResult.getString("status_key")); result.put("account",account);
result.put("status","success");
result.put("bind_status", true); 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{ }else{
result.put("status","success");
result.put("bind_status", false); result.put("bind_status", false);
result.put("contact_phone",contactPhone); result.put("contact_phone",contactPhone);
result.put("nation_code",nationCode); result.put("nation_code",nationCode);
@ -242,37 +242,42 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
@RequestBody JSONObject params, @RequestBody JSONObject params,
Errors errors){ Errors errors){
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId")); loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password")); loginInfo.setPassword(params.getString("password"));
JSONObject signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone"); String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone");
JSONObject client = signInStatusManager.getCurrentClient(signKey); signInStatusManager.verifyClientLoginPhoneBindCode(contactPhone,nationCode,RequestEnvironment.getClientIp());
retailAppService.updateLoginClientAccountPhone(client, contactPhone,nationCode); JSONObject account = signInStatusManager.getCurrentClient(signKey);
client = JSON.parseObject(client.toJSONString()); 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) { if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId")); deviceSupport.validDeviceWithClient(account, params.getString("devId"));
} }
client.put("sign_key", signKey); result.put("bind_status", true);
client.put("bind_status", true); this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE")); return result;
return client;
} }
/** /**
* App * App
* @param data * @param params
* @return * @return
*/ */
@PostMapping("/client_app_wechat_signin") @PostMapping("/client_app_wechat_signin")
public JSONObject clientAppWechatSignIn(@RequestBody JSONObject data, public JSONObject clientAppWechatSignIn(@RequestBody JSONObject params,
Errors errors) { Errors errors) {
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
JSONObject res = signInStatusManager.clientAppWechatSignIn(data.getString("code")); JSONObject account = signInStatusManager.clientAppWechatSignIn(params.getString("code"),RequestEnvironment.getClientIp());
if (!res.getBooleanValue("not_exists")) { if(!account.getBoolean("bind_status")){
deviceSupport.validDeviceWithClient(res, res.getString("app_openid")); deviceSupport.validDeviceWithClient(account, params.getString("app_openid"));
this.publisher.publishEvent(new ClientLoginEvent(this, res.getIntValue("client_id"), res.getString("account_id"), RequestEnvironment.getClientIp(), "wechat")); 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") @PostMapping("/login/wechat_bind")
public JSONObject wechatLoginBind(@RequestBody JSONObject params){ public JSONObject wechatLoginBind(@RequestBody JSONObject params){
signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid"),RequestEnvironment.getClientIp());
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId")); loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password")); loginInfo.setPassword(params.getString("password"));
JSONObject signKeyResult = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat"); String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat");
if("error".equals(signKeyResult.getString("status"))){ JSONObject account = signInStatusManager.getCurrentClient(signKey);
return signKeyResult; retailAppService.updateLoginClientAccountOpenId(account,params);
} account = JSON.parseObject(account.toJSONString());
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());
if (params.getString("devId") != null) { 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")); JSONObject result = new JSONObject();
client.put("bind_status", true); account.put("sign_key", signKey);
client.put("status","success"); result.put("account",account);
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "wechat")); result.put("bind_status", true);
return client; 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); void subscribeNewsletter(String mail, String lang);
//region 手机登录验证 void getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request);
String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request);
void verifyLoginSMSCode(String codeKey, String phoneNumber); void verifyLoginSMSCode(String codeKey, String phoneNumber);
//endregion
} }

@ -682,30 +682,30 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
//region 手机登录 //region 手机登录
@Override @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 reidsCheckCodeKey = getLoginClientRedisKey(phoneNumber);
String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get(); String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get();
if (StringUtils.isNotEmpty(value)) { 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<>(); ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true); String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay"); param.add("RoyalPay");
param.add(registerClientCode); param.add(registerClientCode);
String expireMin = "3"; String expireMin = "1";
param.add(expireMin); param.add(expireMin);
try { 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", "", ""); smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID, param, "RoyalPay", "", "");
}else{ }else{
smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", ""); smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", "");
}*/ }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new ServerErrorException("Phone number is wrong Please try again"); throw new ServerErrorException("Phone number is wrong Please try again");
} }
stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
return registerClientCode;
} }
@Override @Override

@ -82,4 +82,13 @@ public interface ClientAccountMapper {
@AutoSql(type = SqlType.SELECT) @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"}) @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); 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); JSONObject clientWechatSignIn(String openid);
/**
*
* @param openid
* @return
*/
JSONObject clientWechatOneSignIn(String openid);
JSONObject clientWechatAppSignIn(String openId); JSONObject clientWechatAppSignIn(String openId);
JSONObject clientWechatAppSignInByUnionId(String unionId); JSONObject clientWechatAppSignInByUnionId(String unionId);

@ -73,7 +73,7 @@ public interface SignInStatusManager {
* @param code * @param code
* @return * @return
*/ */
JSONObject clientAppWechatSignIn(String code); JSONObject clientAppWechatSignIn(String code,String ip);
/** /**
* *
@ -81,12 +81,29 @@ public interface SignInStatusManager {
* @param nationCode * @param nationCode
* @return * @return
*/ */
JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode); String getClientInfoByPhoneStatusKey(String phone,String nationCode,String ip);
/** /**
* *
* @param loginInfo * @param loginInfo
* @return * @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; 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 @Override
public JSONObject clientWechatAppSignIn(String openId) { public JSONObject clientWechatAppSignIn(String openId) {
JSONObject account = clientAccountMapper.findByAppOpenId(openId); JSONObject account = clientAccountMapper.findByAppOpenId(openId);

@ -38,6 +38,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Resource @Resource
private ClientAccountMapper clientAccountMapper; 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 @Override
public JSONObject getCurrentManager(String statusKey) { public JSONObject getCurrentManager(String statusKey) {
BoundValueOperations<String, String> op = stringRedisTemplate.boundValueOps(managerLoginRedisKey(statusKey)); BoundValueOperations<String, String> op = stringRedisTemplate.boundValueOps(managerLoginRedisKey(statusKey));
@ -61,22 +64,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return null; return null;
} }
op.expire(30, TimeUnit.MINUTES); op.expire(30, TimeUnit.MINUTES);
JSONObject result = new JSONObject();
try{
JSONObject account = signInAccountService.getClient(accountId); JSONObject account = signInAccountService.getClient(accountId);
if(account.containsKey("wechat_openid")){ return account;
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;
} }
private String partnerLoginRedisKey(String statusKey) { private String partnerLoginRedisKey(String statusKey) {
@ -92,18 +82,16 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
} }
@Override @Override
public JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode) { public String getClientInfoByPhoneStatusKey(String phone, String nationCode,String ip) {
JSONObject result = new JSONObject();
String statusKey = newStatusKey(); String statusKey = newStatusKey();
JSONObject account = clientAccountMapper.findByPhone(phone, "+"+nationCode); JSONObject account = clientAccountMapper.findOneByPhoneAndCreateTimeDesc(phone, "+" + nationCode);
if (account == null) { if (account == null) {
result.put("account_exist",false); String expireMin = "5";
return result; 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); stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
return result; return statusKey;
} }
private String newStatusKey() { private String newStatusKey() {
@ -111,27 +99,20 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
} }
@Override @Override
public JSONObject verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType){ public String verifyClientAccountLogin(LoginInfo loginInfo, String verfiyType) {
JSONObject account = signInAccountService.clientAccountCheck(loginInfo); JSONObject account = signInAccountService.clientAccountCheck(loginInfo);;
JSONObject result = new JSONObject();
if ("phone".equals(verfiyType)) { if ("phone".equals(verfiyType)) {
if (account.containsKey("contact_phone")) { if (account.containsKey("contact_phone")) {
result.put("status","error"); throw new BadRequestException("The account has been linked to the phone number!");
result.put("message","The account has been linked to the phone number!");
return result;
} }
} else { } else {
if (account.containsKey("wechat_openid")) { if (account.containsKey("wechat_openid")) {
result.put("status","error"); throw new BadRequestException("The account has been linked to the wechat!");
result.put("message","The account has been linked to the wechat!");
return result;
} }
} }
String statusKey = newStatusKey(); String statusKey = newStatusKey();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set("" + account.getString("account_id"), 30, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set("" + account.getString("account_id"), 30, TimeUnit.MINUTES);
result.put("status","success"); return statusKey;
result.put("status_key",statusKey);
return result;
} }
@Override @Override
@ -399,32 +380,63 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
} }
@Override @Override
public JSONObject clientAppWechatSignIn(String code) { public JSONObject clientAppWechatSignIn(String code,String ip) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code); 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 openId = user.getString("openid");
String unionId = user.getString("unionid"); JSONObject account = signInAccountService.clientWechatOneSignIn(openId);
JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
String statusKey = newStatusKey();
if (account == null) {
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
if (account == null) { if (account == null) {
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
res.put("bind_status", false); res.put("bind_status", false);
res.put("app_openid", openId); res.put("app_openid", openId);
res.put("status", "success"); res.put("status", "success");
String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId,ip)).set(openId, Long.parseLong(expireMin), TimeUnit.MINUTES);
return res; return res;
} }
} String statusKey = newStatusKey();
JSONObject result = new JSONObject();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
account = getCurrentClient(statusKey); account = getCurrentClient(statusKey);
account.put("sign_key", statusKey); account.put("sign_key", statusKey);
account.put("app_openid", openId); result.put("account",account);
account.put("bind_status",true); result.put("app_openid", openId);
account.put("status","success"); result.put("bind_status", true);
return account; 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) { private void lockRandomCodeId(String codeId) {
stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS); stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS);

@ -28,4 +28,17 @@
OR OR
sc.parent_client_id IN (select client_id from sys_clients where client_id =#{client_id} or parent_client_id=#{client_id})); sc.parent_client_id IN (select client_id from sys_clients where client_id =#{client_id} or parent_client_id=#{client_id}));
</select> </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> </mapper>

Loading…
Cancel
Save