Add:手机、微信登录

master
duLingLing 5 years ago
parent 6c684c0799
commit ed2acd46a8

@ -0,0 +1,34 @@
package au.com.royalpay.payment.manage.appclient.beans;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import javax.validation.constraints.NotEmpty;
/**
* @Author DuLingLing
* @create 2019/10/18 0018 18:14
*/
public class MobileLoginInfo {
public String getVerifyCode() {
return verifyCode;
}
public void setVerifyCode(String verifyCode) {
this.verifyCode = verifyCode;
}
@NotEmpty(message = "error.payment.valid.param_missing")
private String verifyCode;
private String devId;
public LoginInfo toLoginInfo(String username){
LoginInfo info = new LoginInfo();
info.setLoginId(username);
// info.setPassword(password);
info.setVerifyCode(verifyCode);
return info;
}
}

@ -225,4 +225,6 @@ public interface RetailAppService {
JSONObject getCustomerInfo(JSONObject device); JSONObject getCustomerInfo(JSONObject device);
boolean isSubPartner(JSONObject device, String clientMoniker); boolean isSubPartner(JSONObject device, String clientMoniker);
void unbindAccountPhone(JSONObject device, JSONObject params);
} }

@ -207,6 +207,7 @@ public class RetailAppServiceImp implements RetailAppService {
private SmsSender smsSender; private SmsSender smsSender;
private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL"; private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL";
private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE"; private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE";
private final String UNBIND_ACCOUNT_PHONE_PREFIX = "UHBIND_ACCOUNT_PHONE";
private final int BIND_PHONE_TEMPLID = 126978; private final int BIND_PHONE_TEMPLID = 126978;
private Map<String, AppMsgSender> senderMap = new HashMap<>(); private Map<String, AppMsgSender> senderMap = new HashMap<>();
@ -2156,6 +2157,24 @@ public class RetailAppServiceImp implements RetailAppService {
deleteAccountPhoneKey(device.getString("account_id")); deleteAccountPhoneKey(device.getString("account_id"));
} }
@Override
public void unbindAccountPhone(JSONObject device, JSONObject phone) {
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUnbindAccountPhoneKey(device.getString("account_id"))).get();
if (codeKeyValueRedis == null) {
throw new BadRequestException("Captcha has expired");
}
String captcha = codeKeyValueRedis.split("&")[0];
if (!StringUtils.equals(captcha, phone.getString("captcha"))) {
throw new BadRequestException("Verification code is wrong");
}
JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id"));
account.put("contact_phone", "");
account.put("nation_code", "");
clientAccountMapper.update(account);
deleteUnbindAccountPhoneKey(device.getString("account_id"));
}
@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");
@ -2462,6 +2481,8 @@ public class RetailAppServiceImp implements RetailAppService {
return (listSubClients.contains(client.getString("client_id")) && deviceClient.getBooleanValue("sub_manage")); return (listSubClients.contains(client.getString("client_id")) && deviceClient.getBooleanValue("sub_manage"));
} }
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");
@ -2514,6 +2535,14 @@ public class RetailAppServiceImp implements RetailAppService {
return BIND_ACCOUNT_PHONE_PREFIX + codeKey; return BIND_ACCOUNT_PHONE_PREFIX + codeKey;
} }
private String getUnbindAccountPhoneKey(String codeKey) {
return UNBIND_ACCOUNT_PHONE_PREFIX + codeKey;
}
private void deleteUnbindAccountPhoneKey(String codeKey) {
stringRedisTemplate.delete(getUnbindAccountPhoneKey(codeKey));
}
private JSONObject getBankAccountByClientId(int client_id) { private JSONObject getBankAccountByClientId(int client_id) {
List<JSONObject> list = clientBankAccountMapper.clientBankAccounts(client_id); List<JSONObject> list = clientBankAccountMapper.clientBankAccounts(client_id);
return list.isEmpty() ? new JSONObject() : list.get(0); return list.isEmpty() ? new JSONObject() : list.get(0);

@ -738,6 +738,20 @@ public class RetailAppController {
retailAppService.updateAccountPhone(device, params); retailAppService.updateAccountPhone(device, params);
} }
/**
*
*
* @param device
* @param params
* @throws Exception
*/
@PutMapping("/account/phone/unbind")
public void unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
retailAppService.unbindAccountPhone(device, params);
}
/** /**
* 退 * 退
*/ */

@ -2,10 +2,15 @@ package au.com.royalpay.payment.manage.appclient.web;
import au.com.royalpay.payment.manage.appclient.beans.RetailLoginInfo; import au.com.royalpay.payment.manage.appclient.beans.RetailLoginInfo;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent;
import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.DeviceSupport;
import au.com.royalpay.payment.tools.device.ManageDeviceSupport; import au.com.royalpay.payment.tools.device.ManageDeviceSupport;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.env.RequestEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.http.HttpUtils;
import au.com.royalpay.payment.tools.locale.LocaleSupport; import au.com.royalpay.payment.tools.locale.LocaleSupport;
@ -17,12 +22,17 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -32,7 +42,7 @@ import java.io.IOException;
*/ */
@RestController @RestController
@RequestMapping("/api/v1.0/retail_valid") @RequestMapping("/api/v1.0/retail_valid")
public class RetailValidationController { public class RetailValidationController implements ApplicationEventPublisherAware {
Logger logger = LoggerFactory.getLogger(getClass()); Logger logger = LoggerFactory.getLogger(getClass());
@Resource @Resource
private Producer captchaProducer; private Producer captchaProducer;
@ -44,6 +54,16 @@ public class RetailValidationController {
private ManageDeviceSupport manageDeviceSupport; private ManageDeviceSupport manageDeviceSupport;
@Resource @Resource
private RetailAppService retailAppService; private RetailAppService retailAppService;
@Resource
private ClientManager clientManager;
@Resource
private SimpleClientApplyService simpleClientApplyService;
private ApplicationEventPublisher publisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
@PostMapping("/devices/{devType}/register") @PostMapping("/devices/{devType}/register")
public JSONObject register(@RequestBody String registeration, @PathVariable String devType) { public JSONObject register(@RequestBody String registeration, @PathVariable String devType) {
@ -151,4 +171,73 @@ public class RetailValidationController {
public JSONObject getAdDetail(@PathVariable String article_id) { public JSONObject getAdDetail(@PathVariable String article_id) {
return retailAppService.getAdDetail(article_id); return retailAppService.getAdDetail(article_id);
} }
/**
*
*
* @param phoneNumber
* @param nationCode
* @param request
* @return
*/
@PostMapping("/send/{phoneNumber}/verify_code")
@ResponseBody
public String sendLoginMobileVerifyCode(@PathVariable("phoneNumber") @NotEmpty(message = "phone number can't be null") String phoneNumber,
@RequestParam("nationCode") @NotEmpty(message = "nation code can't be null") String nationCode,
HttpServletRequest request) {
return simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request);
}
/**
*
*
* @param phoneNumber
* @param nationCode
* @param params
*/
@PostMapping("/login/verify/{phoneNumber}/verify_code")
public JSONObject verifyLoginMobileCode(@PathVariable("phoneNumber") @NotEmpty(message = "phone number can't be null") String phoneNumber,
@RequestParam("nationCode") @NotEmpty(message = "nation code can't be null") String nationCode,
@RequestBody JSONObject params) {
if (params.getString("codeKey").isEmpty() && params.getString("codeKey") == null) {
throw new BadRequestException("verify code can't be null");
}
simpleClientApplyService.verifyLoginSMSCode(params.getString("codeKey"), phoneNumber);
nationCode = "+"+nationCode;
JSONObject result = new JSONObject();
String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(phoneNumber, nationCode);
JSONObject client = signInStatusManager.getCurrentClient(signKey);
client = JSON.parseObject(client.toJSONString());
if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(client, params.getString("devId"));
}
if(client!=null){
result =client;
client.put("sign_key", signKey);
result.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
}else{
result.put("bind_status", false);
}
return result;
}
/**
* App
* @param data
* @return
*/
@PostMapping("/client_app_wechat_signin")
public JSONObject clientAppWechatSignIn(@RequestBody JSONObject data) {
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"));
}
return res;
}
} }

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

@ -104,6 +104,8 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT"; private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS"; private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL"; private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
private final String LOGIN_CLIENT_PREFIX = "LGOIN_CLIENT";
private final String LOGIN_CLIENT_PROCESS_PREFIX = "LOGIN_CLIENT_PROCESS";
private final List<String> tags = new ArrayList<>(); private final List<String> tags = new ArrayList<>();
@PostConstruct @PostConstruct
@ -533,7 +535,55 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
return REGISTER_CLIENT_PROCESS_PREFIX + codeKey; return REGISTER_CLIENT_PROCESS_PREFIX + codeKey;
} }
//region 手机登录
@Override
public String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request) {
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.");
}
ArrayList<String> param = new ArrayList<>();
String registerClientCode = RandomStringUtils.random(6, false, true);
param.add("RoyalPay");
param.add(registerClientCode);
String expireMin = "3";
param.add(expireMin);
try {
/* 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
public void verifyLoginSMSCode(String codeKey, String phoneNumber) {
String rediskey = getLoginClientRedisKey(phoneNumber);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(codeKey)) {
throw new BadRequestException("Verification code has expired or is not correct");
}
stringRedisTemplate.delete(rediskey);
}
private String getVerifyMailRedisKey(String codekey) { private String getVerifyMailRedisKey(String codekey) {
return VERIFY_MAIL_PREFIX + codekey; return VERIFY_MAIL_PREFIX + codekey;
} }
private String getLoginClientRedisKey(String phoneNumber){
return LOGIN_CLIENT_PREFIX + phoneNumber;
}
private String getLoginClientProcessRedisKey(String codeKey) {
return LOGIN_CLIENT_PROCESS_PREFIX + codeKey;
}
//endregion
} }

@ -67,4 +67,21 @@ public interface SignInStatusManager {
void scanCustomerQrcode(String codeId, String openid); void scanCustomerQrcode(String codeId, String openid);
String getWechatCustomerId(String codeId); String getWechatCustomerId(String codeId);
/**
* App
* @param code
* @return
*/
JSONObject clientAppWechatSignIn(String code);
/**
*
* @param phone
* @param nationCode
* @return
*/
String getClientInfoByPhoneStatusKey(String phone,String nationCode);
} }

@ -1,16 +1,15 @@
package au.com.royalpay.payment.manage.signin.core.impls; package au.com.royalpay.payment.manage.signin.core.impls;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo; import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
import au.com.royalpay.payment.tools.connections.mpsupport.WechatAppApi; import au.com.royalpay.payment.tools.connections.mpsupport.MpClientAppWechatApiProvider;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.utils.QRCodeUtils; import au.com.royalpay.payment.tools.utils.QRCodeUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -19,10 +18,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/** /**
* Created by yixian on 2016-06-29. * Created by yixian on 2016-06-29.
@ -36,7 +33,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Resource @Resource
private SignInAccountService signInAccountService; private SignInAccountService signInAccountService;
@Resource @Resource
private WechatAppApi wechatAppApi; private MpClientAppWechatApiProvider mpClientAppWechatApiProvider;
@Resource
private ClientAccountMapper clientAccountMapper;
@Override @Override
public JSONObject getCurrentManager(String statusKey) { public JSONObject getCurrentManager(String statusKey) {
@ -76,6 +75,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return statusKey; return statusKey;
} }
@Override
public String getClientInfoByPhoneStatusKey(String phone,String nationCode) {
JSONObject account = clientAccountMapper.findByPhone(phone, nationCode);
String statusKey = newStatusKey();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
return statusKey;
}
private String newStatusKey() { private String newStatusKey() {
return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true); return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true);
} }
@ -231,7 +238,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Override @Override
public JSONObject partnerWechatAppSignIn(String code) { public JSONObject partnerWechatAppSignIn(String code) {
JSONObject user = wechatAppApi.appLoginUser(code); JSONObject user = mpClientAppWechatApiProvider.getApi("clientapp").appLoginUser(code);
String openId = user.getString("openid"); String openId = user.getString("openid");
String unionId = user.getString("unionid"); String unionId = user.getString("unionid");
JSONObject account = signInAccountService.clientWechatAppSignIn(openId); JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
@ -344,6 +351,30 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return statusKey; return statusKey;
} }
@Override
public JSONObject clientAppWechatSignIn(String code) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code);
String openId = user.getString("openid");
String unionId = user.getString("unionid");
JSONObject account = signInAccountService.clientWechatAppSignIn(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);
return res;
}
}
String statusKey = newStatusKey();
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);
return account;
}
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);

@ -0,0 +1,28 @@
package au.com.royalpay.payment.manage.support.wechatclients;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
import au.com.royalpay.payment.tools.connections.mpsupport.WechatAppApi;
import au.com.royalpay.payment.tools.connections.mpsupport.impls.AbstractClientWechatAppImpl;
import org.springframework.stereotype.Service;
/**
* @Author DuLingLing
* @create 2019/10/21 0021 17:57
*/
@Service
public class MerchantAppWechatImpl extends AbstractClientWechatAppImpl implements WechatAppApi {
@Override
public String targetMpAccount() {
return "merchant-app";
}
@Override
public String getOpenIdKey() {
return "";
}
@Override
public boolean matchOpenId(String openId) {
return false;
}
}
Loading…
Cancel
Save