app message sending api update

master
yixian 5 years ago
parent b22ecb893e
commit 5ea3a11d87

@ -4,7 +4,6 @@ import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder;
import au.com.royalpay.payment.manage.pushMessage.bean.AppMessageType;
import au.com.royalpay.payment.tools.device.message.AppMessage;
import au.com.royalpay.payment.tools.env.RequestEnvironment;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
@ -16,13 +15,13 @@ import java.util.Date;
public class RetailAppMessage {
private String title;
private String body;
private PartnerRole role = PartnerRole.ADMIN;
private JSONObject data;
public JSONObject forSave(String appid, int clientId) {
JSONObject msg = new JSONObject();
msg.put("appid", appid);
msg.put("client_id", clientId);
msg.put("role", role.getCode());
msg.put("role", "admin");
msg.put("title", title);
msg.put("body", body);
msg.put("send_time", new Date());
@ -38,7 +37,7 @@ public class RetailAppMessage {
managerMsg.put("title", title);
managerMsg.put("body", body);
managerMsg.put("type", sendType);
managerMsg.put("data", new JSONObject());
managerMsg.put("data", data == null ? new JSONObject() : data);
managerMsg.put("msgType", AppMessageType.MESSAGE.name());
return new AppManagerMessageBuilder(managerMsg).buildMessage();
}
@ -61,16 +60,12 @@ public class RetailAppMessage {
return this;
}
public PartnerRole getRole() {
return role;
public JSONObject getData() {
return data;
}
public RetailAppMessage setRole(PartnerRole role) {
this.role = role;
public RetailAppMessage setData(JSONObject data) {
this.data = data;
return this;
}
public boolean acceptRole(int roleNumber) {
return role.getCode() <= roleNumber;
}
}

@ -1423,7 +1423,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (token == null) {
continue;
}
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "notice", token,remark);
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), "notice", token, remark);
try {
JSONObject type = new JSONObject();
type.put("send_type", "notice");
@ -2206,7 +2206,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
String codeKeyValue = RandomStringUtils.random(6, false, true);
logger.debug("send sms code : {} ", codeKeyValue);
String nationCode = phone.getString("nation_code").contains("+")?phone.getString("nation_code").substring(1):phone.getString("nation_code");
String nationCode = phone.getString("nation_code").contains("+") ? phone.getString("nation_code").substring(1) : phone.getString("nation_code");
String phoneNumber = phone.getString("contact_phone");
ArrayList<String> param = new ArrayList<>();
param.add("绑定手机号");
@ -2221,6 +2221,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES);
}
@Override
public void sendUnbindAccountPhone(JSONObject device) {
String codeKey = device.getString("account_id");
@ -2230,7 +2231,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
JSONObject client = clientAccountMapper.findById(device.getString("account_id"));
String codeKeyValue = RandomStringUtils.random(6, false, true);
String nationCode = client.getString("nation_code").contains("+")?client.getString("nation_code").substring(1):client.getString("nation_code");
String nationCode = client.getString("nation_code").contains("+") ? client.getString("nation_code").substring(1) : client.getString("nation_code");
String phoneNumber = client.getString("contact_phone");
ArrayList<String> param = new ArrayList<>();
param.add("解綁绑定手机号");
@ -2260,7 +2261,7 @@ public class RetailAppServiceImp implements RetailAppService {
throw new BadRequestException("Verification code is wrong");
}
List<JSONObject> account = clientAccountMapper.findByPhone(contactPhone, "+" + nationCode);
if (account != null && account.size()>0) {
if (account != null && account.size() > 0) {
throw new BadRequestException("Mobile phone number has been bound to other users, please unbind it before binding");
}
@ -2332,19 +2333,19 @@ public class RetailAppServiceImp implements RetailAppService {
public JSONObject bindAccountWechat(JSONObject device, JSONObject params) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(params.getString("code"));
if (user == null) {
throw new BadRequestException("WeChat users do not exist");
throw new BadRequestException("WeChat users do not exist");
}
String openId = user.getString("openid");
JSONObject account = clientAccountMapper.findByOpenId(openId);
if (account != null) {
throw new BadRequestException("WeChat ID has been bound to other accounts, please unbind it before binding");
}
JSONObject wechatUserInfo = mpClientAppWechatApiProvider.getApi("merchant-app").appUserInfo(openId,user.getString("access_token"));
JSONObject wechatUserInfo = mpClientAppWechatApiProvider.getApi("merchant-app").appUserInfo(openId, user.getString("access_token"));
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", device.getString("account_id"));
updateAccount.put("wechat_openid", openId);
updateAccount.put("wechat_name",wechatUserInfo.getString("nickname"));
updateAccount.put("wx_unionid",wechatUserInfo.getString("unionid"));
updateAccount.put("wechat_name", wechatUserInfo.getString("nickname"));
updateAccount.put("wx_unionid", wechatUserInfo.getString("unionid"));
clientAccountMapper.update(updateAccount);
JSONObject result = new JSONObject();
result.put("status", "success");
@ -2355,16 +2356,16 @@ public class RetailAppServiceImp implements RetailAppService {
public JSONObject getAccountBindInfos(JSONObject device) {
JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
JSONObject result = new JSONObject();
result.put("phone_bind_status",account.containsKey("contact_phone"));
if(account.containsKey("contact_phone")){
result.put("contact_phone",account.getString("contact_phone"));
String contact_phone = account.getString("contact_phone").replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
result.put("remark_contact_phone",contact_phone);
result.put("nation_code",account.getString("nation_code"));
result.put("phone_bind_status", account.containsKey("contact_phone"));
if (account.containsKey("contact_phone")) {
result.put("contact_phone", account.getString("contact_phone"));
String contact_phone = account.getString("contact_phone").replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
result.put("remark_contact_phone", contact_phone);
result.put("nation_code", account.getString("nation_code"));
}
result.put("wechat_bind_status",account.containsKey("wx_unionid"));
if(account.containsKey("wx_unionid")){
result.put("wechat_name",account.getString("wechat_name"));
result.put("wechat_bind_status", account.containsKey("wx_unionid"));
if (account.containsKey("wx_unionid")) {
result.put("wechat_name", account.getString("wechat_name"));
}
return result;
}
@ -2514,8 +2515,8 @@ public class RetailAppServiceImp implements RetailAppService {
String clientType = device.getString("client_type");
deviceSupport.findRegister(clientType);
JSONObject client = clientMapper.findClient(device.getIntValue("client_id"));
if(!("PINE".equals(client.getString("client_moniker"))
|| "LEOH".equals(client.getString("client_moniker"))) ){
if (!("PINE".equals(client.getString("client_moniker"))
|| "LEOH".equals(client.getString("client_moniker")))) {
return null;
}
JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
@ -2525,20 +2526,20 @@ public class RetailAppServiceImp implements RetailAppService {
authFileStatus.put("content", messageSource.getMessage("client.auth.file.title", null, RequestEnvironment.getLocale()));
List<JSONObject> supplement_array = new ArrayList<>();
JSONObject complianceFilesNotice = complianceFilesNotice(client,account);
JSONObject kycFilesNotice = kycFilesNotice(client,account);
JSONObject complianceFilesNotice = complianceFilesNotice(client, account);
JSONObject kycFilesNotice = kycFilesNotice(client, account);
if (PartnerRole.getRole(account.getIntValue("role")) == PartnerRole.CASHIER) {
return null;
}
if(complianceFilesNotice != null){
if (complianceFilesNotice != null) {
JSONObject complianceStatus = retailAppService.getClientAuthFileStatus(device);
complianceFilesNotice.putAll(complianceStatus);
supplement_array.add(complianceFilesNotice);
}
if(kycFilesNotice != null){
supplement_array.add(kycFilesNotice);
if (kycFilesNotice != null) {
supplement_array.add(kycFilesNotice);
}
authFileStatus.put("supplement_array",supplement_array);
authFileStatus.put("supplement_array", supplement_array);
return authFileStatus;
}
@ -2555,7 +2556,7 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject file = checkKycFileStatusForApp(client);
JSONObject compliance = clientComplianceCompanyMapper.findKycFileByClientId(device.getIntValue("client_id"));
file.put("file_company", compliance);
if(compliance != null){
if (compliance != null) {
file.put("id_type", compliance.getString("id_type"));
}
return file;
@ -2565,9 +2566,9 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject result = new JSONObject();
boolean lessKycFiles = true;
JSONObject kycFilesAuth = clientComplianceCompanyMapper.findKycFileComplete(client.getIntValue("client_id"));
if(kycFilesAuth != null
if (kycFilesAuth != null
|| !("PINE".equals(client.getString("client_moniker"))
|| "LEOH".equals(client.getString("client_moniker")))){
|| "LEOH".equals(client.getString("client_moniker")))) {
lessKycFiles = false;
}
result.put("help_confirm", messageSource.getMessage("client.auth.file.help_confirm", null, RequestEnvironment.getLocale()));
@ -2577,7 +2578,7 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject compliance = clientComplianceCompanyMapper.findKycFileByClientId(client.getIntValue("client_id"));
if (lessKycFiles || compliance != null) {
List<JSONObject> kycFiles = new ArrayList<>();
kycFiles = clientFilesMapper.findKycClientFileByClient(client.getIntValue("client_id"));
kycFiles = clientFilesMapper.findKycClientFileByClient(client.getIntValue("client_id"));
for (JSONObject file : kycFiles) {
result.put(file.getString("file_name"), file.getString("file_value"));
}
@ -2600,51 +2601,49 @@ public class RetailAppServiceImp implements RetailAppService {
}
public JSONObject complianceFilesNotice(JSONObject client,JSONObject account){
public JSONObject complianceFilesNotice(JSONObject client, JSONObject account) {
JSONObject complianceFilesNotice = new JSONObject();
JSONObject complianceFileStatus = signInAccountService.checkAuthFileStatus(client);
JSONObject compliance = clientComplianceCompanyMapper.findFileByClientId(account.getIntValue("client_id"));
complianceFilesNotice.put("auth_type",FilesAuthTypeEnum.COMPLIANCE.getAuthType());
complianceFilesNotice.put("auth_type", FilesAuthTypeEnum.COMPLIANCE.getAuthType());
complianceFilesNotice.put("type", messageSource.getMessage("client.auth.file.compliance.type", null, RequestEnvironment.getLocale()));
complianceFilesNotice.put("client_less_file",complianceFileStatus.getBoolean("client_less_file"));
if(compliance != null){
complianceFilesNotice.put("client_refuse_reason",compliance.getString("description"));
complianceFilesNotice.put("status",compliance.getString("status"));
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")) );
}else if( !complianceFileStatus.getBoolean("client_less_file")){
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(1) );
}else{
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1) );
}
complianceFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status."+ complianceFilesNotice.getString( "status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
complianceFilesNotice.put("client_less_file", complianceFileStatus.getBoolean("client_less_file"));
if (compliance != null) {
complianceFilesNotice.put("client_refuse_reason", compliance.getString("description"));
complianceFilesNotice.put("status", compliance.getString("status"));
complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")));
} else if (!complianceFileStatus.getBoolean("client_less_file")) {
complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(1));
} else {
complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1));
}
complianceFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + complianceFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
return complianceFilesNotice;
}
public JSONObject kycFilesNotice(JSONObject client,JSONObject account){
public JSONObject kycFilesNotice(JSONObject client, JSONObject account) {
JSONObject kycFilesNotice = new JSONObject();
JSONObject kycFileStatus = signInAccountService.checkKycFileStatusForApp(client,account);
JSONObject kycFileStatus = signInAccountService.checkKycFileStatusForApp(client, account);
JSONObject compliance = clientComplianceCompanyMapper.findKycFileByClientId(account.getIntValue("client_id"));
/* if(!kycFileStatus.getBoolean("client_less_file")){
return null;
}*/
kycFilesNotice.put("auth_type",FilesAuthTypeEnum.KYC.getAuthType());
kycFilesNotice.put("auth_type", FilesAuthTypeEnum.KYC.getAuthType());
kycFilesNotice.put("type", messageSource.getMessage("client.auth.file.kyc.type", null, RequestEnvironment.getLocale()));
kycFilesNotice.put("client_less_file",kycFileStatus.getBoolean("client_less_file"));
if(compliance != null){
kycFilesNotice.put("client_refuse_reason",compliance.getString("description"));
kycFilesNotice.put("status",compliance.getString("status"));
kycFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")) );
}else{
kycFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1) );
}
kycFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status."+ kycFilesNotice.getString( "status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
kycFilesNotice.put("client_less_file", kycFileStatus.getBoolean("client_less_file"));
if (compliance != null) {
kycFilesNotice.put("client_refuse_reason", compliance.getString("description"));
kycFilesNotice.put("status", compliance.getString("status"));
kycFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")));
} else {
kycFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1));
}
kycFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + kycFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
return kycFilesNotice;
}
@ -2777,7 +2776,7 @@ public class RetailAppServiceImp implements RetailAppService {
deviceSupport.findRegister(clientType);
JSONObject client = clientManager.getClientInfo(device.getIntValue("client_id"));
JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
clientManager.uploadKycFilesForWaitComplianceForApp(account, client.getString("client_moniker"), filesInfo,fileType);
clientManager.uploadKycFilesForWaitComplianceForApp(account, client.getString("client_moniker"), filesInfo, fileType);
}
@ -2799,7 +2798,7 @@ public class RetailAppServiceImp implements RetailAppService {
}
@Override
public void commitAuthFilesToKyc(JSONObject device,String idType) {
public void commitAuthFilesToKyc(JSONObject device, String idType) {
String clientType = device.getString("client_type");
deviceSupport.findRegister(clientType);
JSONObject client = clientManager.getClientInfo(device.getIntValue("client_id"));
@ -2855,14 +2854,9 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject msg = message.forSave(appid, clientId);
authAppMessageMapper.save(msg);
String msgId = msg.getString("message_id");
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByClient_id(clientId);
List<JSONObject> tokens = clientDeviceTokenMapper.listTokensByAccountId(device.getString("account_id"));
final String[] supportedClientTypes = {"android", "iphone", "ipad"};
long successCount = tokens.parallelStream().filter(devToken -> ArrayUtils.contains(supportedClientTypes, devToken.getString("client_type")))
.filter(devToken -> StringUtils.isNoneEmpty(devToken.getString("account_id"), devToken.getString("token")))
.filter(devToken -> {
JSONObject account = clientAccountMapper.findById(devToken.getString("account_id"));
return account != null && message.acceptRole(account.getIntValue("role"));
})
.filter(devToken -> {
String token = devToken.getString("token");
JSONObject log = saveAppMessageLog(devToken.getString("dev_id"), devToken.getIntValue("client_id"), AppMessageType.MESSAGE.name(), token,
@ -2965,7 +2959,7 @@ public class RetailAppServiceImp implements RetailAppService {
res.put("base_info_lack", true);
}
clientLegalInfo = sysClientLegalPersonMapper.findRepresentativeInfo(res.getIntValue("client_id"));
if (clientLegalInfo == null||StringUtils.isEmpty(clientLegalInfo.getString("representative_person")) || StringUtils.isEmpty(clientLegalInfo.getString("job_title"))
if (clientLegalInfo == null || StringUtils.isEmpty(clientLegalInfo.getString("representative_person")) || StringUtils.isEmpty(clientLegalInfo.getString("job_title"))
|| StringUtils.isEmpty(clientLegalInfo.getString("phone"))
|| StringUtils.isEmpty(clientLegalInfo.getString("email"))
|| StringUtils.isEmpty(clientLegalInfo.getString("address"))

@ -24,6 +24,8 @@ public interface ClientDeviceTokenMapper {
List<JSONObject> listTokensByClient_id(@Param("client_id") int client_id);
List<JSONObject> listTokensByAccountId(@Param("client_id") String accountId);
List<JSONObject> listAllTokens(JSONObject devToken);
@AutoSql(type = SqlType.SELECT)

@ -13,6 +13,16 @@
GROUP BY token
</select>
<select id="listTokensByAccountId" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,
d.client_type,
d.account_id
FROM sys_clients_devices_token t
INNER JOIN sys_clients_devices d ON t.dev_id = d.dev_id and d.account_id=#{account_id} and d.is_offline=0
WHERE t.is_valid = 1
GROUP BY token
</select>
<select id="listAllTokensByClient_id" resultType="com.alibaba.fastjson.JSONObject">
SELECT t.*,
d.client_type

Loading…
Cancel
Save