Merge branch 'develop' into develop_T1068_client_apply

master
duLingLing 5 years ago
commit 19229e1da4

@ -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);
boolean isSubPartner(JSONObject device, String clientMoniker);
void unbindAccountPhone(JSONObject device, JSONObject params);
}

@ -210,6 +210,7 @@ public class RetailAppServiceImp implements RetailAppService {
private SmsSender smsSender;
private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL";
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 Map<String, AppMsgSender> senderMap = new HashMap<>();
@ -2161,6 +2162,24 @@ public class RetailAppServiceImp implements RetailAppService {
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
public void verifyRefundPassword(JSONObject device, JSONObject json) {
String clientType = device.getString("client_type");
@ -2467,6 +2486,8 @@ public class RetailAppServiceImp implements RetailAppService {
return (listSubClients.contains(client.getString("client_id")) && deviceClient.getBooleanValue("sub_manage"));
}
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");
@ -2519,6 +2540,14 @@ public class RetailAppServiceImp implements RetailAppService {
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) {
List<JSONObject> list = clientBankAccountMapper.clientBankAccounts(client_id);
return list.isEmpty() ? new JSONObject() : list.get(0);

@ -738,6 +738,20 @@ public class RetailAppController {
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.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.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.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.http.HttpUtils;
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.slf4j.Logger;
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.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -32,8 +42,8 @@ import java.io.IOException;
*/
@RestController
@RequestMapping("/api/v1.0/retail_valid")
public class RetailValidationController {
Logger logger = LoggerFactory.getLogger(getClass());
public class RetailValidationController implements ApplicationEventPublisherAware {
Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private Producer captchaProducer;
@Resource
@ -44,6 +54,16 @@ public class RetailValidationController {
private ManageDeviceSupport manageDeviceSupport;
@Resource
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")
public JSONObject register(@RequestBody String registeration, @PathVariable String devType) {
@ -149,6 +169,75 @@ public class RetailValidationController {
@GetMapping("/ads/{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;
}
}

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

@ -123,6 +123,8 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
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<>();
@PostConstruct
@ -677,7 +679,55 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
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) {
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);
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;
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.core.SignInAccountService;
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.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.utils.QRCodeUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
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.web.servlet.ModelAndView;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
/**
* Created by yixian on 2016-06-29.
@ -36,7 +33,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Resource
private SignInAccountService signInAccountService;
@Resource
private WechatAppApi wechatAppApi;
private MpClientAppWechatApiProvider mpClientAppWechatApiProvider;
@Resource
private ClientAccountMapper clientAccountMapper;
@Override
public JSONObject getCurrentManager(String statusKey) {
@ -76,6 +75,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
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() {
return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true);
}
@ -177,7 +184,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String codeId = "manager_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
JSONObject res = new JSONObject();
res.put("code_id", codeId);
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat_qrcode/" + codeId), 300,false));
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat_qrcode/" + codeId), 300, false));
return res;
}
@ -231,13 +238,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Override
public JSONObject partnerWechatAppSignIn(String code) {
JSONObject user = wechatAppApi.appLoginUser(code);
JSONObject user = mpClientAppWechatApiProvider.getApi("clientapp").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){
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
if (account == null) {
JSONObject res = new JSONObject();
res.put("not_exists", true);
res.put("app_openid", openId);
@ -265,7 +272,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String codeId = "client_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
JSONObject res = new JSONObject();
res.put("code_id", codeId);
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_wechat_qrcode/" + codeId), 300,false));
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_wechat_qrcode/" + codeId), 300, false));
lockRandomCodeId(codeId);
return res;
}
@ -275,13 +282,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String codeId = "app_" + RandomStringUtils.random(20, true, true) + "_" + System.currentTimeMillis();
JSONObject res = new JSONObject();
res.put("code_id", codeId);
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_qrcode/verify/" + codeId), 300,false));
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_qrcode/verify/" + codeId), 300, false));
lockRandomCodeId(codeId);
return res;
}
@Override
public void clientQRCodeAppSignIn(JSONObject device,String codeId) {
public void clientQRCodeAppSignIn(JSONObject device, String codeId) {
getlockRandomCodeId(codeId);
String statusKey = newStatusKey();
JSONObject account = new JSONObject();
@ -296,7 +303,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
}
@Override
public void clientQRCodeWechatSignIn(JSONObject wxUser,String codeId) {
public void clientQRCodeWechatSignIn(JSONObject wxUser, String codeId) {
getlockRandomCodeId(codeId);
String statusKey = newStatusKey();
JSONObject account = new JSONObject();
@ -325,7 +332,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String codeId = "customer_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
JSONObject res = new JSONObject();
res.put("code_id", codeId);
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/customer_qrcode_scan/" + codeId), 300,false));
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/customer_qrcode_scan/" + codeId), 300, false));
return res;
}
@ -344,6 +351,30 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
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) {
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