| | |
| | | import com.ks.app.entity.AppInfo; |
| | | import com.ks.daylucky.exception.UserInfoException; |
| | | import com.ks.daylucky.exception.UserInfoExtraException; |
| | | import com.ks.daylucky.pojo.DO.AppConfig; |
| | | import com.ks.daylucky.pojo.DO.UserInfo; |
| | | import com.ks.daylucky.pojo.DO.UserInfoExtra; |
| | | import com.ks.daylucky.pojo.DO.UserMsg; |
| | | import com.ks.daylucky.pojo.DTO.AlipayUserInfo; |
| | | import com.ks.daylucky.pojo.DTO.ConfigKeyEnum; |
| | | import com.ks.daylucky.pojo.DTO.TokenDTO; |
| | | import com.ks.daylucky.pojo.DTO.UserMsgSettings; |
| | | import com.ks.daylucky.pojo.VO.AcceptData; |
| | | import com.ks.daylucky.pojo.VO.UserConfigVO; |
| | | import com.ks.daylucky.pojo.VO.UserMsgVO; |
| | | import com.ks.daylucky.service.AppConfigService; |
| | | import com.ks.daylucky.service.UserInfoExtraService; |
| | | import com.ks.daylucky.service.UserInfoService; |
| | | import com.ks.daylucky.service.UserMsgService; |
| | | import com.ks.daylucky.util.Constant; |
| | | import com.ks.daylucky.util.RSA2Encryptor; |
| | | import com.ks.daylucky.util.RSAUtil; |
| | | import com.ks.daylucky.util.UserInfoUtil; |
| | | import com.ks.daylucky.util.annotation.RequestSerializable; |
| | | import com.ks.daylucky.util.factory.vo.UserMsgVOFactory; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | |
| | | @Resource |
| | | private UserMsgService userMsgService; |
| | | |
| | | @Resource |
| | | private AppConfigService appConfigService; |
| | | |
| | | private AlipayAppInfo getAlipayAppInfo(AppInfo app) { |
| | | AppAlipayInfoWithBLOBs alipay = app.getAlipayInfo(); |
| | | AlipayAppInfo info = new AlipayAppInfo(alipay.getAlipayAppId(), alipay.getAlipayPrivateKey(), new AlipayCertInfo(new ByteArrayInputStream(alipay.getAlipayAppCertPublicKey()), new ByteArrayInputStream(alipay.getAlipayPublicCert()), new ByteArrayInputStream(alipay.getAlipayRootCert()))); |
| | | return info; |
| | | } |
| | | |
| | | @RequestSerializable(key = "'getToken-'+#alipayCode") |
| | | @ResponseBody |
| | | @RequestMapping("getToken") |
| | | public String getToken(AcceptData acceptData, String alipayCode, String wxCode) { |
| | |
| | | user.setNickName(alipayUserInfo.getNickName()); |
| | | user.setAlipayNickName(alipayUserInfo.getNickName()); |
| | | user.setAlipayPortrait(alipayUserInfo.getAvatar()); |
| | | if (user.getPortrait() != null && user.getPortrait().endsWith("undefined")) { |
| | | user.setPortrait(null); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(user.getNickName())) { |
| | | AppConfig config = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.defaultNickNamePrefix, acceptData.getVersion()); |
| | | user.setNickName(config.getValue() + acceptData.getUid()); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(user.getPortrait())) { |
| | | AppConfig config = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.defaultPortrait, acceptData.getVersion()); |
| | | user.setPortrait(config.getValue()); |
| | | } |
| | | |
| | | |
| | | userInfoService.updateUserInfo(user); |
| | | |
| | | user = userInfoService.getUserDetail(user.getId()); |
| | |
| | | @RequestMapping("getUserMsgList") |
| | | public String getUserMsgList(AcceptData acceptData, int page) { |
| | | List<UserMsg> msgList = userMsgService.getUserMsgList(acceptData.getUid(), page, Constant.PAGE_SIZE); |
| | | List<UserMsgVO> voList = new ArrayList<>(); |
| | | if (msgList != null) { |
| | | for (UserMsg userMsg : msgList) { |
| | | voList.add(UserMsgVOFactory.create(userMsg)); |
| | | } |
| | | } |
| | | |
| | | |
| | | long count = userMsgService.countUserMsg(acceptData.getUid()); |
| | | Gson gson = JsonUtil.getConvertDateToShortNameBuilder(new GsonBuilder().excludeFieldsWithoutExposeAnnotation()).create(); |
| | | Gson gson = JsonUtil.getConvertDateToShortNameBuilder(new GsonBuilder()).create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("data", gson.toJson(msgList)); |
| | | data.put("data", gson.toJson(voList)); |
| | | data.put("count", count); |
| | | |
| | | //设置消息已读 |
| | | try { |
| | | userInfoExtraService.setMsgRead(acceptData.getUid()); |
| | | } catch (UserInfoExtraException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("getUserConfig") |
| | | public String getUserConfig(AcceptData acceptData) { |
| | | //消息未读数 |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(acceptData.getUid()); |
| | | if (extra == null) { |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | UserConfigVO vo = new UserConfigVO(); |
| | | vo.setMsgCount(extra.getMsgUnreadCount()); |
| | | return JsonUtil.loadTrueResult(vo); |
| | | } |
| | | |
| | | |
| | | } |