Upd:新增查询微信绑定获取微信详情名称

master
duLingLing 5 years ago
parent a6845d6c3c
commit c4ac20095e

@ -2184,6 +2184,7 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", account.getString("account_id"));
updateAccount.put("wechat_openid", params.getString("wechat_openid"));
updateAccount.put("wechat_name", params.getString("nick_name"));
clientAccountMapper.update(updateAccount);
}
@ -2213,6 +2214,7 @@ public class RetailAppServiceImp implements RetailAppService {
JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id"));
account.put("wechat_openid", null);
account.put("wechat_name", null);
clientAccountMapper.update(account);
JSONObject result = new JSONObject();
result.put("status", "success");
@ -2230,10 +2232,11 @@ public class RetailAppServiceImp implements RetailAppService {
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 updateAccount = new JSONObject();
updateAccount.put("account_id", device.getString("account_id"));
updateAccount.put("wechat_openid", openId);
updateAccount.put("wechat_name",wechatUserInfo.getString("nickname"));
clientAccountMapper.update(updateAccount);
JSONObject result = new JSONObject();
result.put("status", "success");
@ -2252,6 +2255,9 @@ public class RetailAppServiceImp implements RetailAppService {
result.put("naticon_code",account.getString("nation_code"));
}
result.put("wechat_bind_status",account.containsKey("wechat_openid"));
if(account.containsKey("wechat_openid")){
result.put("wechat_name",account.getString("wechat_name"));
}
return result;
}

@ -287,12 +287,13 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
*/
@PostMapping("/login/wechat_bind")
public JSONObject wechatLoginBind(@RequestBody JSONObject params){
signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid"),RequestEnvironment.getClientIp());
String nickName = signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid"),RequestEnvironment.getClientIp());
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password"));
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat");
JSONObject account = signInStatusManager.getCurrentClient(signKey);
params.put("nick_name",nickName);
retailAppService.updateLoginClientAccountOpenId(account,params);
account = JSON.parseObject(account.toJSONString());
if (params.getString("devId") != null) {

@ -96,7 +96,7 @@ public interface SignInStatusManager {
* @param ip
* @return
*/
void verifyClientLoginWechatBindCode (String codeId,String ip);
String verifyClientLoginWechatBindCode (String codeId,String ip);
/**
*

@ -4,6 +4,7 @@ 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.MpClient;
import au.com.royalpay.payment.tools.connections.mpsupport.MpClientAppWechatApiProvider;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
@ -37,7 +38,6 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
private MpClientAppWechatApiProvider mpClientAppWechatApiProvider;
@Resource
private ClientAccountMapper clientAccountMapper;
private final String CLIENT_LOGIN_WECHAT_BIND_PREFIX = "CLIENT_LOGIN_WECHAT_BIND_PREFIX";
private final String CLIENT_LOGIN_PHONE_BIND_PREFIX = "CLIENT_LOGIN_PHONE_BIND_PREFIX";
@ -388,12 +388,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String openId = user.getString("openid");
JSONObject account = signInAccountService.clientWechatOneSignIn(openId);
if (account == null) {
JSONObject wechatUserInfo = mpClientAppWechatApiProvider.getApi("merchant-app").appUserInfo(openId,user.getString("access_token"));
JSONObject res = new JSONObject();
String nickName = wechatUserInfo.getString("nickname");
res.put("bind_status", false);
res.put("app_openid", openId);
res.put("status", "success");
String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId,ip)).set(openId, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId,ip)).set(openId+"&"+nickName, Long.parseLong(expireMin), TimeUnit.MINUTES);
return res;
}
String statusKey = newStatusKey();
@ -413,14 +415,16 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
}
public void verifyClientLoginWechatBindCode(String openId,String ip){
@Override
public String verifyClientLoginWechatBindCode(String openId,String ip){
String rediskey = getClientLoginWechatBindRedisKey(openId,ip);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(openId)) {
if (codeValue == null || !codeValue.split("&")[0].equals(openId)) {
throw new BadRequestException("The WeChat ID does not apply for binding");
}
String nickName = codeValue.split("&")[1];
stringRedisTemplate.delete(rediskey);
return nickName;
}
private String getClientLoginPhoneBindRedisKey(String phone,String nationCode,String ip){

Loading…
Cancel
Save