提交 f26e5057 编写于 作者: rushui.chen's avatar rushui.chen

20190902 微信信息表修改表结构

上级 3ede406b
流水线 #13895 已失败 于阶段
in 1 second
...@@ -40,6 +40,10 @@ public class LoginController extends AccountBaseController { ...@@ -40,6 +40,10 @@ public class LoginController extends AccountBaseController {
@Autowired @Autowired
private PicaLogUtils picaLogUtils; private PicaLogUtils picaLogUtils;
@Autowired
private AccountUtils accountUtils;
/** /**
* 密码登录接口 * 密码登录接口
* *
...@@ -72,8 +76,8 @@ public class LoginController extends AccountBaseController { ...@@ -72,8 +76,8 @@ public class LoginController extends AccountBaseController {
@PostMapping(value = "/login-register") @PostMapping(value = "/login-register")
public PicaResponse loginAndRegister(@RequestBody EncryptEntity entity) throws Exception { public PicaResponse loginAndRegister(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class); BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
AccountUtils.checkMobilePhone(request.getMobile()); accountUtils.checkMobilePhone(request.getMobile());
AccountUtils.getAuthCodeKey(request.getSysCode(), EnumsType.SYSCODE_TYPE_REGISTER.getCode() + ""); accountUtils.getAuthCodeKey(request.getMobile(), EnumsType.SYSCODE_TYPE_LOGIN.getCode() + "");
request.setProductType(super.getProductType()); request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType()); request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr()); request.setLoginIp(super.getIpAddr());
...@@ -92,6 +96,36 @@ public class LoginController extends AccountBaseController { ...@@ -92,6 +96,36 @@ public class LoginController extends AccountBaseController {
return PicaResponse.toResponse(result); return PicaResponse.toResponse(result);
} }
@ApiOperation("微信登录第二步接口")
@PostMapping(value = "/login/wechat/step2")
public PicaResponse loginByWeChatStep(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
accountUtils.checkMobilePhone(request.getMobile());
accountUtils.checkAuthCode(request.getMobile(), EnumsType.SYSCODE_TYPE_WE_CHAT.getCode() + "", request.getSysCode());
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
String result = loginService.loginByWeChatStep(request);
return PicaResponse.toResponse(result);
}
/**
* 绑定微信接口
*
* @param entity
* @return
* @throws Exception
*/
@ApiOperation("绑定微信接口")
@PostMapping("/login/wechat/bind")
public PicaResponse<String> bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String weChatCode = request.getWeChatCode();
request.setProductType(super.getProductType());
// TODO: 2019/8/29 绑定微信接口
return null;
}
/** /**
* 退出登录接口 * 退出登录接口
* *
...@@ -128,23 +162,6 @@ public class LoginController extends AccountBaseController { ...@@ -128,23 +162,6 @@ public class LoginController extends AccountBaseController {
} }
/**
* 绑定微信接口
*
* @param entity
* @return
* @throws Exception
*/
@ApiOperation("绑定微信接口")
@PostMapping("/login/wechat/bind")
public PicaResponse<String> bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String weChatCode = request.getWeChatCode();
request.setProductType(super.getProductType());
// TODO: 2019/8/29 绑定微信接口
return null;
}
@ApiOperation("微信解除绑定接口") @ApiOperation("微信解除绑定接口")
@PostMapping("/login/wechat/unbind") @PostMapping("/login/wechat/unbind")
public PicaResponse unbindWeChat(@RequestBody EncryptEntity entity) throws Exception { public PicaResponse unbindWeChat(@RequestBody EncryptEntity entity) throws Exception {
......
...@@ -11,20 +11,6 @@ public class AccountUnionEntity { ...@@ -11,20 +11,6 @@ public class AccountUnionEntity {
private String unionId; private String unionId;
private String nickname;
private String headImgUrl;
private int sex;
private String country;
private String province;
private String city;
private String language;
private Integer deleteFlag; private Integer deleteFlag;
private Integer createdId; private Integer createdId;
...@@ -67,62 +53,6 @@ public class AccountUnionEntity { ...@@ -67,62 +53,6 @@ public class AccountUnionEntity {
this.unionId = unionId == null ? null : unionId.trim(); this.unionId = unionId == null ? null : unionId.trim();
} }
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname == null ? null : nickname.trim();
}
public String getHeadImgUrl() {
return headImgUrl;
}
public void setHeadImgUrl(String headImgUrl) {
this.headImgUrl = headImgUrl == null ? null : headImgUrl.trim();
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country == null ? null : country.trim();
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province == null ? null : province.trim();
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city == null ? null : city.trim();
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language == null ? null : language.trim();
}
public Integer getDeleteFlag() { public Integer getDeleteFlag() {
return deleteFlag; return deleteFlag;
} }
......
...@@ -9,6 +9,20 @@ public class AccountWeChatInfoEntity { ...@@ -9,6 +9,20 @@ public class AccountWeChatInfoEntity {
private String openid; private String openid;
private String nickname;
private String headImgUrl;
private int sex;
private String country;
private String province;
private String city;
private String language;
private Integer type; private Integer type;
private String privilege; private String privilege;
...@@ -46,7 +60,7 @@ public class AccountWeChatInfoEntity { ...@@ -46,7 +60,7 @@ public class AccountWeChatInfoEntity {
} }
public void setUnionid(String unionid) { public void setUnionid(String unionid) {
this.unionid = unionid == null ? null : unionid.trim(); this.unionid = unionid;
} }
public String getOpenid() { public String getOpenid() {
...@@ -54,7 +68,63 @@ public class AccountWeChatInfoEntity { ...@@ -54,7 +68,63 @@ public class AccountWeChatInfoEntity {
} }
public void setOpenid(String openid) { public void setOpenid(String openid) {
this.openid = openid == null ? null : openid.trim(); this.openid = openid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getHeadImgUrl() {
return headImgUrl;
}
public void setHeadImgUrl(String headImgUrl) {
this.headImgUrl = headImgUrl;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
} }
public Integer getType() { public Integer getType() {
...@@ -70,7 +140,7 @@ public class AccountWeChatInfoEntity { ...@@ -70,7 +140,7 @@ public class AccountWeChatInfoEntity {
} }
public void setPrivilege(String privilege) { public void setPrivilege(String privilege) {
this.privilege = privilege == null ? null : privilege.trim(); this.privilege = privilege;
} }
public Integer getSubscribe() { public Integer getSubscribe() {
...@@ -94,7 +164,7 @@ public class AccountWeChatInfoEntity { ...@@ -94,7 +164,7 @@ public class AccountWeChatInfoEntity {
} }
public void setRemark(String remark) { public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim(); this.remark = remark;
} }
public String getGroupid() { public String getGroupid() {
...@@ -102,7 +172,7 @@ public class AccountWeChatInfoEntity { ...@@ -102,7 +172,7 @@ public class AccountWeChatInfoEntity {
} }
public void setGroupid(String groupid) { public void setGroupid(String groupid) {
this.groupid = groupid == null ? null : groupid.trim(); this.groupid = groupid;
} }
public String getTagidList() { public String getTagidList() {
...@@ -110,7 +180,7 @@ public class AccountWeChatInfoEntity { ...@@ -110,7 +180,7 @@ public class AccountWeChatInfoEntity {
} }
public void setTagidList(String tagidList) { public void setTagidList(String tagidList) {
this.tagidList = tagidList == null ? null : tagidList.trim(); this.tagidList = tagidList;
} }
public Integer getDeleteFlag() { public Integer getDeleteFlag() {
......
package com.pica.cloud.account.account.server.entity; package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class WeChatEntity { public class WeChatEntity {
//用户唯一标识 /** 获取到的凭证 */
private String access_token;
/** 凭证有效时间,单位:秒 */
private int expires_in;
/** 用户刷新access_token */
private String refresh_token;
/** 用户唯一标识,请注意,在未关注公众号时,用户访问公众号的网页,也会产生一个用户和公众号唯一的OpenID */
private String openid; private String openid;
//会话密钥 /** 用户授权的作用域,使用逗号(,)分隔 */
private String session_key; private String scope;
//用户在开放平台的唯一标识符,在满足 UnionID 下发条件的情况下会返回,详见 UnionID 机制说明。
private String unionid;
//错误码
private String errcode;
// 错误信息
private String errmsg;
public String getOpenid() { private Date createdAt;
return openid;
public String getAccess_token() {
return access_token;
} }
public void setOpenid(String openid) { public void setAccess_token(String access_token) {
this.openid = openid; this.access_token = access_token;
}
public int getExpires_in() {
return expires_in;
} }
public String getSession_key() { public void setExpires_in(int expires_in) {
return session_key; this.expires_in = expires_in;
} }
public void setSession_key(String session_key) { public String getRefresh_token() {
this.session_key = session_key; return refresh_token;
} }
public String getUnionid() { public void setRefresh_token(String refresh_token) {
return unionid; this.refresh_token = refresh_token;
} }
public void setUnionid(String unionid) { public String getOpenid() {
this.unionid = unionid; return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
} }
public String getErrcode() { public String getScope() {
return errcode; return scope;
} }
public void setErrcode(String errcode) { public void setScope(String scope) {
this.errcode = errcode; this.scope = scope;
} }
public String getErrmsg() { public Date getCreatedAt() {
return errmsg; return createdAt;
} }
public void setErrmsg(String errmsg) { public void setCreatedAt(Date createdAt) {
this.errmsg = errmsg; this.createdAt = createdAt;
} }
} }
package com.pica.cloud.account.account.server.entity;
import java.util.Date;
public class WeChatUserInfoEntity {
/** 是否订阅该公众号标识 */
private Integer subscribe;
/** 用户标识 */
private String openid;
/** 昵称 */
private String nickname;
/** 性别 */
private Integer sex;
/** 用户所在城市 */
private String city;
/** 用户所在省份 */
private String province;
/** 国家*/
private String country;
/** 用户的语言 */
private String language;
/** 用户头像 */
private String headimgurl;
/** 用户关注时间 */
private Date subscribe_time;
/** 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段 */
private String unionid;
private String remark;
private Integer groupid;
private String tagid_list;
private String privilege;
public Integer getSubscribe() {
return subscribe;
}
public void setSubscribe(Integer subscribe) {
this.subscribe = subscribe;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getHeadimgurl() {
return headimgurl;
}
public void setHeadimgurl(String headimgurl) {
this.headimgurl = headimgurl;
}
public Date getSubscribe_time() {
return subscribe_time;
}
public void setSubscribe_time(Date subscribe_time) {
this.subscribe_time = subscribe_time;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Integer getGroupid() {
return groupid;
}
public void setGroupid(Integer groupid) {
this.groupid = groupid;
}
public String getTagid_list() {
return tagid_list;
}
public void setTagid_list(String tagid_list) {
this.tagid_list = tagid_list;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
}
...@@ -12,17 +12,23 @@ public interface AccountUnionMapper { ...@@ -12,17 +12,23 @@ public interface AccountUnionMapper {
AccountUnionEntity selectByPrimaryKey(Integer id); AccountUnionEntity selectByPrimaryKey(Integer id);
AccountUnionEntity selectByUnionId(String unionId);
int updateByPrimaryKeySelective(AccountUnionEntity record); int updateByPrimaryKeySelective(AccountUnionEntity record);
int updateByPrimaryKey(AccountUnionEntity record); int updateByPrimaryKey(AccountUnionEntity record);
/** /**
* 解除绑定关系 * 解除绑定关系
*
* @param acctId * @param acctId
* @return * @return
*/ */
int updateUnbindByAcctId(Integer acctId); int updateUnbindByAcctId(Integer acctId);
/**
* 是否绑定过手机号
*
* @param unionId
* @return
*/
AccountUnionEntity selectByUnionId(String unionId);
} }
\ No newline at end of file
package com.pica.cloud.account.account.server.mapper; package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity; import com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity;
public interface AccountWeChatInfoMapper { public interface AccountWeChatInfoMapper {
...@@ -15,4 +14,11 @@ public interface AccountWeChatInfoMapper { ...@@ -15,4 +14,11 @@ public interface AccountWeChatInfoMapper {
int updateByPrimaryKeySelective(AccountWeChatInfoEntity record); int updateByPrimaryKeySelective(AccountWeChatInfoEntity record);
int updateByPrimaryKey(AccountWeChatInfoEntity record); int updateByPrimaryKey(AccountWeChatInfoEntity record);
/**
* UnionId 是否存在
* @param id
* @return
*/
AccountWeChatInfoEntity selectByUnionId(String id);
} }
\ No newline at end of file
...@@ -23,6 +23,9 @@ public class BaseRequest { ...@@ -23,6 +23,9 @@ public class BaseRequest {
private String unionId; private String unionId;
@ApiModelProperty("微信code") @ApiModelProperty("微信code")
private String weChatCode; private String weChatCode;
@ApiModelProperty("微信登录类型")
private Integer weChatLoginType;
public Integer getAccId() { public Integer getAccId() {
return accId; return accId;
...@@ -111,4 +114,12 @@ public class BaseRequest { ...@@ -111,4 +114,12 @@ public class BaseRequest {
public void setWeChatCode(String weChatCode) { public void setWeChatCode(String weChatCode) {
this.weChatCode = weChatCode; this.weChatCode = weChatCode;
} }
public Integer getWeChatLoginType() {
return weChatLoginType;
}
public void setWeChatLoginType(Integer weChatLoginType) {
this.weChatLoginType = weChatLoginType;
}
} }
...@@ -26,6 +26,14 @@ public interface LoginService { ...@@ -26,6 +26,14 @@ public interface LoginService {
*/ */
String loginByWeChat(BaseRequest baseRequest); String loginByWeChat(BaseRequest baseRequest);
/**
* 微信登陆第二步
*
* @param request
* @return
*/
String loginByWeChatStep(BaseRequest request);
/** /**
* 解除绑定 * 解除绑定
* *
......
package com.pica.cloud.account.account.server.service.impl; package com.pica.cloud.account.account.server.service.impl;
import com.pica.cloud.account.account.server.entity.AccountUnionEntity; import com.pica.cloud.account.account.server.entity.AccountUnionEntity;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.service.AccountUnionService; import com.pica.cloud.account.account.server.service.AccountUnionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
......
package com.pica.cloud.account.account.server.service.impl; package com.pica.cloud.account.account.server.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.pica.cloud.account.account.server.entity.*; import com.pica.cloud.account.account.server.entity.*;
import com.pica.cloud.account.account.server.enums.EnumsType; import com.pica.cloud.account.account.server.enums.EnumsType;
import com.pica.cloud.account.account.server.enums.ExceptionType; import com.pica.cloud.account.account.server.enums.ExceptionType;
import com.pica.cloud.account.account.server.log.PicaLogUtils; import com.pica.cloud.account.account.server.log.PicaLogUtils;
import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper; import com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper;
import com.pica.cloud.account.account.server.mapper.AccountUnionMapper;
import com.pica.cloud.account.account.server.mapper.AccountUserInfoMapper; import com.pica.cloud.account.account.server.mapper.AccountUserInfoMapper;
import com.pica.cloud.account.account.server.req.AccountReq; import com.pica.cloud.account.account.server.req.AccountReq;
import com.pica.cloud.account.account.server.req.BaseRequest; import com.pica.cloud.account.account.server.req.BaseRequest;
...@@ -14,6 +14,7 @@ import com.pica.cloud.account.account.server.service.LoginService; ...@@ -14,6 +14,7 @@ import com.pica.cloud.account.account.server.service.LoginService;
import com.pica.cloud.account.account.server.service.RegisterService; import com.pica.cloud.account.account.server.service.RegisterService;
import com.pica.cloud.account.account.server.util.AccountUtils; import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.TokenUtils; import com.pica.cloud.account.account.server.util.TokenUtils;
import com.pica.cloud.account.account.server.util.WeChatUtils;
import com.pica.cloud.foundation.entity.PicaException; import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode; import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.ICacheClient; import com.pica.cloud.foundation.redis.ICacheClient;
...@@ -23,12 +24,16 @@ import org.slf4j.Logger; ...@@ -23,12 +24,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service @Service
public class LoginServiceImpl implements LoginService { public class LoginServiceImpl implements LoginService {
private Logger logger = LoggerFactory.getLogger(this.getClass()); private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired @Autowired
...@@ -40,6 +45,9 @@ public class LoginServiceImpl implements LoginService { ...@@ -40,6 +45,9 @@ public class LoginServiceImpl implements LoginService {
@Autowired @Autowired
private AccountUnionMapper accountUnionMapper; private AccountUnionMapper accountUnionMapper;
@Autowired
private AccountWeChatInfoMapper accountWeChatInfoMapper;
@Autowired @Autowired
private PicaLogUtils picaLogUtils; private PicaLogUtils picaLogUtils;
...@@ -53,6 +61,13 @@ public class LoginServiceImpl implements LoginService { ...@@ -53,6 +61,13 @@ public class LoginServiceImpl implements LoginService {
@Qualifier("cacheMigrateClient") @Qualifier("cacheMigrateClient")
private ICacheClient redisClient; private ICacheClient redisClient;
@Value("${weChatAppID}")
private String appId;
@Value("${weChatAppSecret}")
private String appSecret;
@Value("${weChatURL}")
private String weChatURL;
@Override @Override
public String login(BaseRequest request) { public String login(BaseRequest request) {
String mobile = request.getMobile(); String mobile = request.getMobile();
...@@ -107,27 +122,34 @@ public class LoginServiceImpl implements LoginService { ...@@ -107,27 +122,34 @@ public class LoginServiceImpl implements LoginService {
@Override @Override
public String loginAndRegister(BaseRequest baseRequest) { public String loginAndRegister(BaseRequest baseRequest) {
String mobile = baseRequest.getMobile(); String mobile = baseRequest.getMobile();
int productType = baseRequest.getProductType();
int sourceType = baseRequest.getSourceType();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(EncryptCreateUtil.encrypt(mobile)); AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(EncryptCreateUtil.encrypt(mobile));
if (accountInfoEntity == null) { if (accountInfoEntity == null) {
return registerService.register(baseRequest); return registerService.register(baseRequest);
} else { } else {
return processLogin(baseRequest, accountInfoEntity.getId());
}
}
/**
* 登录逻辑处理
*
* @param baseRequest
*/
private String processLogin(BaseRequest baseRequest, Integer acctId) {
Date currentTime = new Date(); Date currentTime = new Date();
Integer acctId = accountInfoEntity.getId();
AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByAcctId(acctId); AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByAcctId(acctId);
//验证码登陆:只要相同即可成功 //验证码登陆:只要相同即可成功
AccountReq accountReq = new AccountReq(); AccountReq accountReq = new AccountReq();
accountReq.setAuthCode(baseRequest.getSysCode()); accountReq.setAuthCode(baseRequest.getSysCode());
accountReq.setMobilePhone(mobile); accountReq.setMobilePhone(baseRequest.getMobile());
accountReq.setFlag("0"); accountReq.setFlag("0");
checkAuthCode(accountReq); checkAuthCode(accountReq);
Account account = new Account(); Account account = new Account();
account.setId(accountUserInfoEntity.getId().longValue()); account.setId(accountUserInfoEntity.getId().longValue());
account.setAcctId(acctId); account.setAcctId(acctId);
account.setCreatTime(currentTime); account.setCreatTime(currentTime);
account.setMobilePhone(mobile); account.setMobilePhone(baseRequest.getMobile());
account.setRegisterSource(sourceType); account.setRegisterSource(baseRequest.getSourceType());
String newToken = tokenUtils.generateToken(account); String newToken = tokenUtils.generateToken(account);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken); jsonObject.put("token", newToken);
...@@ -140,7 +162,7 @@ public class LoginServiceImpl implements LoginService { ...@@ -140,7 +162,7 @@ public class LoginServiceImpl implements LoginService {
entity.setModifyTime(currentTime); entity.setModifyTime(currentTime);
entity.setDeleteFlag(1); entity.setDeleteFlag(1);
entity.setLoginTime(currentTime); entity.setLoginTime(currentTime);
entity.setProductType(productType); entity.setProductType(baseRequest.getProductType());
entity.setSourceType(baseRequest.getSourceType()); entity.setSourceType(baseRequest.getSourceType());
entity.setLoginType(EnumsType.LOGIN_REGISTER.getCode()); entity.setLoginType(EnumsType.LOGIN_REGISTER.getCode());
entity.setLoginIp(baseRequest.getLoginIp()); entity.setLoginIp(baseRequest.getLoginIp());
...@@ -149,47 +171,86 @@ public class LoginServiceImpl implements LoginService { ...@@ -149,47 +171,86 @@ public class LoginServiceImpl implements LoginService {
picaLogUtils.info(entity); picaLogUtils.info(entity);
return jsonObject.toJSONString(); return jsonObject.toJSONString();
} }
}
@Override @Override
public String loginByWeChat(BaseRequest request) { public String loginByWeChat(BaseRequest request) {
//todo:微信登录获取信息 WeChatEntity weChatEntity = WeChatUtils.getAuthorizationInfo(appId, appSecret, request.getWeChatCode());
WeChatEntity weChatEntity = null; //todo:微信登录获取个人信息
String unionId = weChatEntity.getUnionid();
//账号逻辑处理 Map map = new HashMap();
map.put("access_token", weChatEntity.getAccess_token());
map.put("openid", weChatEntity.getOpenid());
Map weChatUserInfo = WeChatUtils.getWeChatUserInfo(map, weChatURL);
WeChatUserInfoEntity weChatUserInfoEntity = WeChatUtils.mergeWechatUserInfo(weChatUserInfo, weChatEntity.getOpenid());
String unionId = weChatUserInfoEntity.getUnionid();
AccountUnionEntity accountUnionEntity = accountUnionMapper.selectByUnionId(unionId);
if (accountUnionEntity != null) {
//是否绑定逻辑的判断
Long acctId = accountUnionEntity.getAcctId();
AccountUserInfoEntity accountUserInfoEntity = accountUserInfoMapper.selectByAcctId(acctId.intValue());
Account account = new Account();
account.setId(accountUserInfoEntity.getId().longValue());
account.setAcctId(acctId.intValue());
account.setCreatTime(new Date());
account.setMobilePhone(request.getMobile());
account.setRegisterSource(request.getSourceType());
String newToken = tokenUtils.generateToken(account);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", newToken);
jsonObject.put("userId", accountUserInfoEntity.getId().longValue());
jsonObject.put("bindFlag", EnumsType.BIND_STATUS_SUCCESS.getCode());
return jsonObject.toJSONString();
} else {
AccountWeChatInfoEntity entity = accountWeChatInfoMapper.selectByUnionId(unionId);
if (entity == null) {
Date currentTime = new Date(); Date currentTime = new Date();
AccountInfoEntity entity = new AccountInfoEntity(); AccountWeChatInfoEntity accountWeChatInfoEntity = new AccountWeChatInfoEntity();
entity.setCreatedTime(currentTime); accountWeChatInfoEntity.setCreatedId(0);
entity.setCreatedId(0); accountWeChatInfoEntity.setCreatedTime(currentTime);
entity.setModifiedId(0); accountWeChatInfoEntity.setDeleteFlag(1);
entity.setModifiedTime(currentTime); accountWeChatInfoEntity.setGroupid(weChatUserInfoEntity.getGroupid() + "");
entity.setRegTime(currentTime); accountWeChatInfoEntity.setType(request.getWeChatLoginType());
entity.setDeleteFlag(1); accountWeChatInfoEntity.setModifiedId(0);
entity.setSex(0); accountWeChatInfoEntity.setModifiedTime(currentTime);
entity.setRegisterProduct(request.getProductType()); accountWeChatInfoEntity.setOpenid(weChatUserInfoEntity.getOpenid());
entity.setRegisterSource(request.getSourceType()); accountWeChatInfoEntity.setUnionid(weChatUserInfoEntity.getUnionid());
accountInfoDetailMapper.insertSelective(entity); accountWeChatInfoEntity.setPrivilege(weChatUserInfoEntity.getPrivilege());
Integer acctId = entity.getId(); accountWeChatInfoEntity.setRemark(weChatUserInfoEntity.getRemark());
//联合登录逻辑的处理 accountWeChatInfoEntity.setSubscribe(weChatUserInfoEntity.getSubscribe());
AccountUnionEntity accountUnionEntity = new AccountUnionEntity(); accountWeChatInfoEntity.setSubscribeTime(weChatUserInfoEntity.getSubscribe_time());
accountUnionEntity.setAcctId(acctId.longValue()); accountWeChatInfoEntity.setTagidList(weChatUserInfoEntity.getTagid_list());
accountUnionEntity.setCreatedId(acctId); accountWeChatInfoMapper.insertSelective(accountWeChatInfoEntity);
accountUnionEntity.setModifiedId(acctId); }
accountUnionEntity.setUnionId(unionId);
accountUnionEntity.setUnionType(EnumsType.UNION_LOGIN_WE_CHAT.getCode());
accountUnionEntity.setModifiedTime(currentTime);
accountUnionEntity.setCreatedTime(currentTime);
accountUnionMapper.insertSelective(accountUnionEntity);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("bindFlag", EnumsType.BIND_STATUS_FAILURE.getCode()); jsonObject.put("bindFlag", EnumsType.BIND_STATUS_FAILURE.getCode());
jsonObject.put("unionId", unionId); jsonObject.put("unionId", unionId);
return jsonObject.toJSONString(); return jsonObject.toJSONString();
} }
}
@Override
public String loginByWeChatStep(BaseRequest request) {
//判断当前手机号是否注册过,注册过,直接登录;没有注册过,进行注册操操作
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(EncryptCreateUtil.encrypt(request.getMobile()));
String json;
if (accountInfoEntity == null) {
json = registerService.register(request);
} else {
json = processLogin(request, accountInfoEntity.getId());
}
//向表中插入数据
//todo:向联合登录表插入信息,信息哪里来?
return json;
}
@Override @Override
public void unbindWeChat(Integer acctId) { public void unbindWeChat(Integer acctId) {
accountUnionMapper.updateUnbindByAcctId(acctId); accountUnionMapper.updateUnbindByAcctId(acctId);
} }
//校验验证码 //校验验证码
...@@ -211,5 +272,4 @@ public class LoginServiceImpl implements LoginService { ...@@ -211,5 +272,4 @@ public class LoginServiceImpl implements LoginService {
redisClient.del(authCodeKey); //清除验证码 redisClient.del(authCodeKey); //清除验证码
} }
} }
package com.pica.cloud.account.account.server.util;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* 证书信任管理器(用于https请求)
*
* @author bo.dang
* @date 2014-12-04
*/
public class MyX509TrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
\ No newline at end of file
package com.pica.cloud.account.account.server.util;
import com.pica.cloud.account.account.server.entity.WeChatEntity;
import com.pica.cloud.foundation.utils.constants.WeChatConstants;
import com.pica.cloud.foundation.utils.utils.JsonUtil;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import com.pica.cloud.foundation.utils.utils.date.DateTimeUtils;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URL;
import java.util.Date;
//import com.picahealth.common.utils.DateTimeUtils;
//import com.picahealth.common.utils.JsonUtil;
//import com.picahealth.common.utils.StringUtil;
//import com.picahealth.wit.wechat.constants.WeChatConstants;
//import com.picahealth.wit.wechat.entity.AccessToken;
//import com.picahealth.wit.wechat.entity.JsapiTicket;
//import com.picahealth.wit.wechat.entity.Menu;
//import static com.picahealth.wechat.wechat.thread.AccessTokenThread.appid;
//import static com.picahealth.wechat.wechat.thread.AccessTokenThread.appsecret;
//import static com.picahealth.wechat.wechat.thread.AccessTokenThread.appid;
//import static com.picahealth.wechat.wechat.thread.AccessTokenThread.appsecret;
//import static com.picahealth.wechat.wechat.thread.AccessTokenThread.jsapiTicket;
/**
* 公众平台通用接口工具类
*
* @author bo.dang
* @date 2013-08-09
*/
public class WeChatToolUtil {
private static Logger logger = LoggerFactory.getLogger(WeChatToolUtil.class);
/** access_token */
public static String access_token;
public static WeChatEntity accessToken;
/** 获取access_token的时间 */
private static Date get_access_token_time;
/**
* 发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public static JSONObject httpRequest(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = { new MyX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setSSLSocketFactory(ssf);
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
// 设置请求方式(GET/POST)
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
// 当有数据需要提交时
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
// 注意编码格式,防止中文乱码
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
logger.info(buffer.toString());
jsonObject = JSONObject.fromObject(buffer.toString());
} catch (ConnectException ce) {
logger.error("Weixin server connection timed out.");
} catch (Exception e) {
logger.error("https request error:{}", e);
}
return jsonObject;
}
/**
* 获取access_token
*
* @param appid 凭证
* @param appsecret 密钥
* @return
*/
public static WeChatEntity getAccessToken(String appid, String appsecret) {
WeChatEntity accessToken = null;
String requestUrl = WeChatConstants.ACCESS_TOKEN_URL.replace("APPID", appid).replace("APPSECRET", appsecret);
JSONObject jsonObject = httpRequest(requestUrl, "GET", null);
// 如果请求成功
if (null != jsonObject) {
try {
access_token = jsonObject.getString("access_token");
if(!StringUtil.isEmpty(access_token)){
get_access_token_time = new Date();
accessToken = JsonUtil.toGsonBean(jsonObject.toString(), WeChatEntity.class);
/*
accessToken.setAccess_token(jsonObject.getString("access_token"));
accessToken.setExpires_in(jsonObject.getInt("expires_in"));*/
}
else {
get_access_token_time = new Date();
}
} catch (JSONException e) {
accessToken = null;
// 获取token失败
logger.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
}
}
else {
// 获取token失败
logger.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
}
WeChatToolUtil.accessToken = accessToken;
return accessToken;
}
/**
* 校验accessToken是否过期
* @param access_token
* @return
*/
// public static WeChatEntity checkAccessTokencheckAccessToken(String access_token){
//
//
// WeChatEntity accessToken = WeChatToolUtil.accessToken;
//
// if(WeChatToolUtil.isExpired() || StringUtil.isEmpty(access_token)){
//
// accessToken = WeChatToolUtil.getAccessToken(appId, WeChatConstants.APP_SECRET);
// }
//
//
// return accessToken;
//
// }
// /**
// * 获得jsapi_ticket
// * @return
// */
// public static JsapiTicket getJsapi_ticket(){
//
// //AccessToken accessToken = getAccessToken(WeChatConstants.APP_ID, WeChatConstants.APP_SECRET);
//
// String requestUrl = WeChatConstants.GET_JSAPI_TICKET.replace("ACCESS_TOKEN", access_token);
// JSONObject jsonObject = httpRequest(requestUrl, "GET", null);
// JsapiTicket jsapiTicket = null;
// if(StringUtil.isNotNull(jsonObject)){
// jsapiTicket = JsonUtil.toGsonBean(jsonObject.toString(), JsapiTicket.class);
// }
//
// return jsapiTicket;
//
// }
//
// /**
// * 签名算法
// * @param url
// * @return
// */
// public static Map<String, String> sign(String url){
// //String jsapi_ticket = getJsapi_ticket();
// return Sign.sign(jsapiTicket.getTicket(), url);
// }
//
// /**
// * 创建菜单
// *
// * @param menu 菜单实例
// * @param accessToken 有效的access_token
// * @return 0表示成功,其他值表示失败
// */
// public static int createMenu(Menu menu, String accessToken) {
// int result = 0;
//
// // 拼装创建菜单的url
// String url = WeChatConstants.MENU_CREATE_URL.replace("ACCESS_TOKEN", accessToken);
// // 将菜单对象转换成json字符串
// String jsonMenu = JSONObject.fromObject(menu).toString();
// // 调用接口创建菜单
// JSONObject jsonObject = httpRequest(url, "POST", jsonMenu);
//
// if (null != jsonObject) {
// if (0 != jsonObject.getInt("errcode")) {
// result = jsonObject.getInt("errcode");
// logger.error("创建菜单失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
// }
// }
//
// return result;
// }
// /**
// * 设置所属行业
// *
// * @param menu 菜单实例
// * @param accessToken 有效的access_token
// * @return 0表示成功,其他值表示失败
// */
// public static int setIndustry(, String accessToken) {
// int result = 0;
//
// // 拼装创建菜单的url
// String url = WeChatConstants.MENU_CREATE_URL.replace("ACCESS_TOKEN", accessToken);
// // 将菜单对象转换成json字符串
// String jsonMenu = JSONObject.fromObject(menu).toString();
// // 调用接口创建菜单
// JSONObject jsonObject = httpRequest(url, "POST", jsonMenu);
//
// if (null != jsonObject) {
// if (0 != jsonObject.getInt("errcode")) {
// result = jsonObject.getInt("errcode");
// logger.error("创建菜单失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
// }
// }
//
// return result;
// }
/**
* 判断是否是QQ表情
*
* @param content
* @return
*/
// public static boolean isQqFace(String content) {
// boolean result = false;
//
// // 判断QQ表情的正则表达式
// String qqfaceRegex = "/::\\)|/::~|/::B|/::\\||/:8-\\)|/::<|/::$|/::X|/::Z|/::'\\(|/::-\\||/::@|/::P|/::D|/::O|/::\\(|/::\\+|/:--b|/::Q|/::T|/:,@P|/:,@-D|/::d|/:,@o|/::g|/:\\|-\\)|/::!|/::L|/::>|/::,@|/:,@f|/::-S|/:\\?|/:,@x|/:,@@|/::8|/:,@!|/:!!!|/:xx|/:bye|/:wipe|/:dig|/:handclap|/:&-\\(|/:B-\\)|/:<@|/:@>|/::-O|/:>-\\||/:P-\\(|/::'\\||/:X-\\)|/::\\*|/:@x|/:8\\*|/:pd|/:<W>|/:beer|/:basketb|/:oo|/:coffee|/:eat|/:pig|/:rose|/:fade|/:showlove|/:heart|/:break|/:cake|/:li|/:bome|/:kn|/:footb|/:ladybug|/:shit|/:moon|/:sun|/:gift|/:hug|/:strong|/:weak|/:share|/:v|/:@\\)|/:jj|/:@@|/:bad|/:lvu|/:no|/:ok|/:love|/:<L>|/:jump|/:shake|/:<O>|/:circle|/:kotow|/:turn|/:skip|/:oY|/:#-0|/:hiphot|/:kiss|/:<&|/:&>";
// Pattern p = Pattern.compile(qqfaceRegex);
// Matcher m = p.matcher(content);
// if (m.matches()) {
// result = true;
// }
// return result;
// }
/**
* 判断access_token是否过期
*/
public static Boolean isExpired(){
if(null != get_access_token_time){
logger.info("判断access_token是否过期 get_access_token_time:{} currentTime:{}", DateTimeUtils.DateTimeFormater.format(get_access_token_time), DateTimeUtils.currentDateTime());
return DateTimeUtils.compare2Date(new Date(), DateTimeUtils.addDateSeconds(get_access_token_time, (7200-60) * 1000));
}
else {
return true;
}
}
// /**
// * 判断access_token是否过期
// */
// public static Boolean isExpired(Date createdAt, Integer expireIn){
// if(null != createdAt){
// logger.info("判断access_token是否过期 createdAt time:{} currentTime:{}", DateTimeUtils.DateTimeFormater.format(createdAt), DateTimeUtils.currentDateTime());
// return DateTimeUtils.compare2Date(new Date(), DateTimeUtils.addDateSeconds(createdAt, (expireIn - 60) * 1000));
// }
// else {
// return true;
// }
// }
/**
* 系统启动时取得AccessToken
* @return
*/
// public static WeChatEntity initWechatAccessToken(String appid, String appsecret){
//
// accessToken = WeChatToolUtil.getAccessToken(appid, appsecret);
// if (null != accessToken) {
// logger.info("获取access_token成功,有效时长{}秒 access_token:{}", accessToken.getExpires_in(), accessToken.getAccess_token());
// // 获取权限签名
// jsapiTicket = WeChatToolUtil.getJsapi_ticket();
// if (StringUtil.isNotNull(jsapiTicket)) {
// logger.info("获取jsapi_ticket成功,有效时长{}秒 jsapi_ticket:{}", jsapiTicket.getExpires_in(), jsapiTicket.getTicket());
// }
// }
//
// return accessToken;
// }
/* // 文本消息
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
// 文本消息内容
String content = requestMap.get("Content");
// 判断用户发送的是否是单个QQ表情
if(XiaoqUtil.isQqFace(content)) {
// 回复文本消息
TextMessage textMessage = new TextMessage();
textMessage.setToUserName(fromUserName);
textMessage.setFromUserName(toUserName);
textMessage.setCreateTime(new Date().getTime());
textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
textMessage.setFuncFlag(0);
// 用户发什么QQ表情,就返回什么QQ表情
textMessage.setContent(content);
// 将文本消息对象转换成xml字符串
respMessage = MessageUtil.textMessageToXml(textMessage);
}
}*/
}
\ No newline at end of file
package com.pica.cloud.account.account.server.util;
import com.alibaba.fastjson.JSON;
import com.pica.cloud.account.account.server.entity.WeChatEntity;
import com.pica.cloud.account.account.server.entity.WeChatUserInfoEntity;
import com.pica.cloud.foundation.utils.constants.WeChatConstants;
import com.pica.cloud.foundation.utils.utils.JsonUtil;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WeChatUtils {
private static Logger logger = LoggerFactory.getLogger(WeChatUtils.class);
public static WeChatEntity getAuthorizationInfo(String appId, String appSecret, String code) {
logger.info("网页授权获取access_token: code:{}", code);
String requestUrl = WeChatConstants.AUTH_ACCESS_TOKEN_URL.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);
JSONObject jsonObject = WeChatToolUtil.httpRequest(requestUrl, "GET", null);
WeChatEntity accessToken = null;
// 如果请求成功
if (null != jsonObject) {
try {
accessToken = JsonUtil.toGsonBean(jsonObject.toString(), WeChatEntity.class);
logger.info("网页授权获取access_token: access_token:{} openid:{}", accessToken.getAccess_token(), accessToken.getOpenid());
} catch (JSONException e) {
// 获取token失败
logger.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
}
} else {
// 获取token失败
logger.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
}
return accessToken;
}
public static Map getWeChatUserInfo(Map map, String url) {
String param = "access_token=" + map.get("access_token") + "&openid=" + map.get("openid") + "&lang=zh_CN";
List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(param, Charset.forName("utf-8"));
HttpGet method = null;
try {
url = url + param;
URL url1 = new URL(url);
URI uri = new URI(url1.getProtocol(), url1.getHost(), url1.getPath(), url1.getQuery(), null);
method = new HttpGet(uri);
// 建立一个NameValuePair数组,用于存储欲传送的参数
method.addHeader("Content-type", "application/json; charset=utf-8");
method.setHeader("Accept", "application/json");
HttpResponse response = HttpClients.createDefault().execute(method);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
String body = EntityUtils.toString(response.getEntity(), "utf-8");
return JSON.parseObject(body, Map.class);
} else {
logger.warn("微信获取用户信息(包括UnionID)失败,param:{}, result:{}", JSON.toJSONString(map), JSON.toJSONString(response));
return new HashMap();
}
} catch (IOException e) {
logger.error("微信获取access_token异常,param:{}", JSON.toJSONString(map), e);
return new HashMap();
} catch (URISyntaxException e) {
logger.error("异常抛出exception ", e);
} finally {
if (method != null) {
method.releaseConnection();
}
}
return new HashMap();
}
public static WeChatUserInfoEntity mergeWechatUserInfo(Map map, String openid){
WeChatUserInfoEntity user = new WeChatUserInfoEntity();
user.setOpenid(openid);
user.setLanguage("zh_CN");
if (StringUtil.isNotNull(map) && map.size() > 0) {
user.setSubscribe((Integer) map.get("subscribe"));
user.setNickname((String) (map.get("nickname")));
user.setSex((Integer) map.get("sex"));
user.setLanguage((String) map.get("language"));
user.setCity((String) map.get("city"));
user.setProvince((String) map.get("province"));
user.setCountry((String) map.get("country"));
user.setHeadimgurl((String) map.get("headimgurl"));
user.setSubscribe_time(new Date(map.get("subscribe_time") == null ? 1501052712L : Long.valueOf(map.get("subscribe_time").toString())));
user.setRemark((String) map.get("remark"));
user.setUnionid((String) map.get("unionid"));
user.setGroupid((Integer) map.get("groupid"));
user.setTagid_list(JSON.toJSONString(map.get("tagid_list")));
}
return user;
}
}
...@@ -35,3 +35,10 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss ...@@ -35,3 +35,10 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
memcached.url=192.168.130.230:11211 memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatURL=https://api.weixin.qq.com/sns/userinfo?
...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss ...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
memcached.url=172.19.121.31:11211 memcached.url=172.19.121.31:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatURL=https://api.weixin.qq.com/sns/userinfo?
\ No newline at end of file
...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss ...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
memcached.url=192.168.130.230:11211 memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatURL=https://api.weixin.qq.com/sns/userinfo?
\ No newline at end of file
...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss ...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
memcached.url=192.168.130.230:11211 memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatURL=https://api.weixin.qq.com/sns/userinfo?
\ No newline at end of file
...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss ...@@ -35,3 +35,8 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
memcached.url=192.168.130.230:11211 memcached.url=192.168.130.230:11211
#微信登陆
weChatAppID=wx5103ed453ef2dbe8
weChatAppSecret=6faa9bef3302786c08b2baf278613f38
weChatURL=https://api.weixin.qq.com/sns/userinfo?
\ No newline at end of file
...@@ -6,13 +6,6 @@ ...@@ -6,13 +6,6 @@
<result column="acct_id" property="acctId" jdbcType="BIGINT"/> <result column="acct_id" property="acctId" jdbcType="BIGINT"/>
<result column="union_type" property="unionType" jdbcType="INTEGER"/> <result column="union_type" property="unionType" jdbcType="INTEGER"/>
<result column="union_id" property="unionId" jdbcType="VARCHAR"/> <result column="union_id" property="unionId" jdbcType="VARCHAR"/>
<result column="nickname" property="nickname" jdbcType="VARCHAR"/>
<result column="head_img_url" property="headImgUrl" jdbcType="VARCHAR"/>
<result column="sex" property="sex" jdbcType="TINYINT"/>
<result column="country" property="country" jdbcType="VARCHAR"/>
<result column="province" property="province" jdbcType="VARCHAR"/>
<result column="city" property="city" jdbcType="VARCHAR"/>
<result column="language" property="language" jdbcType="VARCHAR"/>
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/> <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
<result column="created_id" property="createdId" jdbcType="INTEGER"/> <result column="created_id" property="createdId" jdbcType="INTEGER"/>
<result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/> <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
...@@ -20,9 +13,10 @@ ...@@ -20,9 +13,10 @@
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP"/> <result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, acct_id, union_type, union_id, nickname, head_img_url, sex, country, province, id, acct_id, union_type, union_id, delete_flag, created_id, created_time, modified_id,
city, language, delete_flag, created_id, created_time, modified_id, modified_time modified_time
</sql> </sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer"> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
...@@ -30,7 +24,6 @@ ...@@ -30,7 +24,6 @@
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<!--通过unionId查询用户信息--> <!--通过unionId查询用户信息-->
<select id="selectByUnionId" resultMap="BaseResultMap" parameterType="java.lang.String"> <select id="selectByUnionId" resultMap="BaseResultMap" parameterType="java.lang.String">
select select
...@@ -44,26 +37,22 @@ ...@@ -44,26 +37,22 @@
update account_union update account_union
set delete_flag = 2 set delete_flag = 2
where acct_id = #{acctId,jdbcType=INTEGER} where acct_id = #{acctId,jdbcType=INTEGER}
</update> </update>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from account_union delete from account_union
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountUnionEntity"> <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountUnionEntity">
insert into account_union (id, acct_id, union_type, insert into account_union (id, acct_id, union_type,
union_id, nickname, head_img_url, union_id, delete_flag, created_id,
sex, country, province, created_time, modified_id, modified_time
city, language, delete_flag, )
created_id, created_time, modified_id,
modified_time)
values (#{id,jdbcType=INTEGER}, #{acctId,jdbcType=BIGINT}, #{unionType,jdbcType=INTEGER}, values (#{id,jdbcType=INTEGER}, #{acctId,jdbcType=BIGINT}, #{unionType,jdbcType=INTEGER},
#{unionId,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, #{headImgUrl,jdbcType=VARCHAR}, #{unionId,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER},
#{sex,jdbcType=TINYINT}, #{country,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER}, #{modifiedTime,jdbcType=TIMESTAMP}
#{city,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER}, )
#{createdId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountUnionEntity"> <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountUnionEntity">
insert into account_union insert into account_union
...@@ -80,27 +69,6 @@ ...@@ -80,27 +69,6 @@
<if test="unionId != null"> <if test="unionId != null">
union_id, union_id,
</if> </if>
<if test="nickname != null">
nickname,
</if>
<if test="headImgUrl != null">
head_img_url,
</if>
<if test="sex != null">
sex,
</if>
<if test="country != null">
country,
</if>
<if test="province != null">
province,
</if>
<if test="city != null">
city,
</if>
<if test="language != null">
language,
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
delete_flag, delete_flag,
</if> </if>
...@@ -130,27 +98,6 @@ ...@@ -130,27 +98,6 @@
<if test="unionId != null"> <if test="unionId != null">
#{unionId,jdbcType=VARCHAR}, #{unionId,jdbcType=VARCHAR},
</if> </if>
<if test="nickname != null">
#{nickname,jdbcType=VARCHAR},
</if>
<if test="headImgUrl != null">
#{headImgUrl,jdbcType=VARCHAR},
</if>
<if test="sex != null">
#{sex,jdbcType=TINYINT},
</if>
<if test="country != null">
#{country,jdbcType=VARCHAR},
</if>
<if test="province != null">
#{province,jdbcType=VARCHAR},
</if>
<if test="city != null">
#{city,jdbcType=VARCHAR},
</if>
<if test="language != null">
#{language,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
#{deleteFlag,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER},
</if> </if>
...@@ -181,27 +128,6 @@ ...@@ -181,27 +128,6 @@
<if test="unionId != null"> <if test="unionId != null">
union_id = #{unionId,jdbcType=VARCHAR}, union_id = #{unionId,jdbcType=VARCHAR},
</if> </if>
<if test="nickname != null">
nickname = #{nickname,jdbcType=VARCHAR},
</if>
<if test="headImgUrl != null">
head_img_url = #{headImgUrl,jdbcType=VARCHAR},
</if>
<if test="sex != null">
sex = #{sex,jdbcType=TINYINT},
</if>
<if test="country != null">
country = #{country,jdbcType=VARCHAR},
</if>
<if test="province != null">
province = #{province,jdbcType=VARCHAR},
</if>
<if test="city != null">
city = #{city,jdbcType=VARCHAR},
</if>
<if test="language != null">
language = #{language,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null"> <if test="deleteFlag != null">
delete_flag = #{deleteFlag,jdbcType=INTEGER}, delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if> </if>
...@@ -225,13 +151,6 @@ ...@@ -225,13 +151,6 @@
set acct_id = #{acctId,jdbcType=BIGINT}, set acct_id = #{acctId,jdbcType=BIGINT},
union_type = #{unionType,jdbcType=INTEGER}, union_type = #{unionType,jdbcType=INTEGER},
union_id = #{unionId,jdbcType=VARCHAR}, union_id = #{unionId,jdbcType=VARCHAR},
nickname = #{nickname,jdbcType=VARCHAR},
head_img_url = #{headImgUrl,jdbcType=VARCHAR},
sex = #{sex,jdbcType=TINYINT},
country = #{country,jdbcType=VARCHAR},
province = #{province,jdbcType=VARCHAR},
city = #{city,jdbcType=VARCHAR},
language = #{language,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER}, delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER}, created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP}, created_time = #{createdTime,jdbcType=TIMESTAMP},
......
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
<id column="id" property="id" jdbcType="INTEGER" /> <id column="id" property="id" jdbcType="INTEGER" />
<result column="unionid" property="unionid" jdbcType="VARCHAR" /> <result column="unionid" property="unionid" jdbcType="VARCHAR" />
<result column="openid" property="openid" jdbcType="VARCHAR" /> <result column="openid" property="openid" jdbcType="VARCHAR" />
<result column="nickname" property="nickname" jdbcType="VARCHAR" />
<result column="head_img_url" property="headImgUrl" jdbcType="VARCHAR" />
<result column="sex" property="sex" jdbcType="TINYINT" />
<result column="country" property="country" jdbcType="VARCHAR" />
<result column="province" property="province" jdbcType="VARCHAR" />
<result column="city" property="city" jdbcType="VARCHAR" />
<result column="language" property="language" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="INTEGER" /> <result column="type" property="type" jdbcType="INTEGER" />
<result column="privilege" property="privilege" jdbcType="VARCHAR" /> <result column="privilege" property="privilege" jdbcType="VARCHAR" />
<result column="subscribe" property="subscribe" jdbcType="INTEGER" /> <result column="subscribe" property="subscribe" jdbcType="INTEGER" />
...@@ -18,33 +25,49 @@ ...@@ -18,33 +25,49 @@
<result column="modified_id" property="modifiedId" jdbcType="INTEGER" /> <result column="modified_id" property="modifiedId" jdbcType="INTEGER" />
<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" /> <result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
id, unionid, openid, type, privilege, subscribe, subscribe_time, remark, groupid, id, unionid, openid, nickname, head_img_url, sex, country, province, city, language,
tagid_list, delete_flag, created_id, created_time, modified_id, modified_time type, privilege, subscribe, subscribe_time, remark, groupid, tagid_list, delete_flag,
created_id, created_time, modified_id, modified_time
</sql> </sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from account_wechat_info from account_wechat_info
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</select> </select>
<!--通过UnionId获取微信信息-->
<select id="selectByUnionId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from account_wechat_info
where unionid = #{id}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from account_wechat_info delete from account_wechat_info
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity" > <insert id="insert" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity" >
insert into account_wechat_info (id, unionid, openid, insert into account_wechat_info (id, unionid, openid,
type, privilege, subscribe, nickname, head_img_url, sex,
subscribe_time, remark, groupid, country, province, city,
tagid_list, delete_flag, created_id, language, type, privilege,
created_time, modified_id, modified_time subscribe, subscribe_time, remark,
) groupid, tagid_list, delete_flag,
created_id, created_time, modified_id,
modified_time)
values (#{id,jdbcType=INTEGER}, #{unionid,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR}, values (#{id,jdbcType=INTEGER}, #{unionid,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR},
#{type,jdbcType=INTEGER}, #{privilege,jdbcType=VARCHAR}, #{subscribe,jdbcType=INTEGER}, #{nickname,jdbcType=VARCHAR}, #{headImgUrl,jdbcType=VARCHAR}, #{sex,jdbcType=TINYINT},
#{subscribeTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR}, #{groupid,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR},
#{tagidList,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER}, #{language,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{privilege,jdbcType=VARCHAR},
#{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER}, #{modifiedTime,jdbcType=TIMESTAMP} #{subscribe,jdbcType=INTEGER}, #{subscribeTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR},
) #{groupid,jdbcType=VARCHAR}, #{tagidList,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},
#{createdId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity" > <insert id="insertSelective" parameterType="com.pica.cloud.account.account.server.entity.AccountWeChatInfoEntity" >
insert into account_wechat_info insert into account_wechat_info
...@@ -58,6 +81,27 @@ ...@@ -58,6 +81,27 @@
<if test="openid != null" > <if test="openid != null" >
openid, openid,
</if> </if>
<if test="nickname != null" >
nickname,
</if>
<if test="headImgUrl != null" >
head_img_url,
</if>
<if test="sex != null" >
sex,
</if>
<if test="country != null" >
country,
</if>
<if test="province != null" >
province,
</if>
<if test="city != null" >
city,
</if>
<if test="language != null" >
language,
</if>
<if test="type != null" > <if test="type != null" >
type, type,
</if> </if>
...@@ -105,6 +149,27 @@ ...@@ -105,6 +149,27 @@
<if test="openid != null" > <if test="openid != null" >
#{openid,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR},
</if> </if>
<if test="nickname != null" >
#{nickname,jdbcType=VARCHAR},
</if>
<if test="headImgUrl != null" >
#{headImgUrl,jdbcType=VARCHAR},
</if>
<if test="sex != null" >
#{sex,jdbcType=TINYINT},
</if>
<if test="country != null" >
#{country,jdbcType=VARCHAR},
</if>
<if test="province != null" >
#{province,jdbcType=VARCHAR},
</if>
<if test="city != null" >
#{city,jdbcType=VARCHAR},
</if>
<if test="language != null" >
#{language,jdbcType=VARCHAR},
</if>
<if test="type != null" > <if test="type != null" >
#{type,jdbcType=INTEGER}, #{type,jdbcType=INTEGER},
</if> </if>
...@@ -152,6 +217,27 @@ ...@@ -152,6 +217,27 @@
<if test="openid != null" > <if test="openid != null" >
openid = #{openid,jdbcType=VARCHAR}, openid = #{openid,jdbcType=VARCHAR},
</if> </if>
<if test="nickname != null" >
nickname = #{nickname,jdbcType=VARCHAR},
</if>
<if test="headImgUrl != null" >
head_img_url = #{headImgUrl,jdbcType=VARCHAR},
</if>
<if test="sex != null" >
sex = #{sex,jdbcType=TINYINT},
</if>
<if test="country != null" >
country = #{country,jdbcType=VARCHAR},
</if>
<if test="province != null" >
province = #{province,jdbcType=VARCHAR},
</if>
<if test="city != null" >
city = #{city,jdbcType=VARCHAR},
</if>
<if test="language != null" >
language = #{language,jdbcType=VARCHAR},
</if>
<if test="type != null" > <if test="type != null" >
type = #{type,jdbcType=INTEGER}, type = #{type,jdbcType=INTEGER},
</if> </if>
...@@ -195,6 +281,13 @@ ...@@ -195,6 +281,13 @@
update account_wechat_info update account_wechat_info
set unionid = #{unionid,jdbcType=VARCHAR}, set unionid = #{unionid,jdbcType=VARCHAR},
openid = #{openid,jdbcType=VARCHAR}, openid = #{openid,jdbcType=VARCHAR},
nickname = #{nickname,jdbcType=VARCHAR},
head_img_url = #{headImgUrl,jdbcType=VARCHAR},
sex = #{sex,jdbcType=TINYINT},
country = #{country,jdbcType=VARCHAR},
province = #{province,jdbcType=VARCHAR},
city = #{city,jdbcType=VARCHAR},
language = #{language,jdbcType=VARCHAR},
type = #{type,jdbcType=INTEGER}, type = #{type,jdbcType=INTEGER},
privilege = #{privilege,jdbcType=VARCHAR}, privilege = #{privilege,jdbcType=VARCHAR},
subscribe = #{subscribe,jdbcType=INTEGER}, subscribe = #{subscribe,jdbcType=INTEGER},
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册