UserInfoServiceImpl.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. package com.izouma.awesomeadmin.service.impl;
  2. import cn.binarywang.wx.miniapp.api.WxMaService;
  3. import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
  4. import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
  5. import com.izouma.awesomeadmin.constant.AppConstant;
  6. import com.izouma.awesomeadmin.dao.*;
  7. import com.izouma.awesomeadmin.dto.Page;
  8. import com.izouma.awesomeadmin.dto.Result;
  9. import com.izouma.awesomeadmin.model.AlipayTemp;
  10. import com.izouma.awesomeadmin.model.RecommenderLog;
  11. import com.izouma.awesomeadmin.model.UserInfo;
  12. import com.izouma.awesomeadmin.service.OSSFileService;
  13. import com.izouma.awesomeadmin.service.UserInfoService;
  14. import com.izouma.awesomeadmin.util.MD5Util;
  15. import com.izouma.awesomeadmin.util.PropertiesFileLoader;
  16. import com.izouma.weixin.util.WeixinUtil;
  17. import io.jsonwebtoken.Claims;
  18. import io.jsonwebtoken.Jwt;
  19. import io.jsonwebtoken.Jwts;
  20. import io.jsonwebtoken.security.Keys;
  21. import io.rong.RongCloud;
  22. import io.rong.models.SMSVerifyCodeResult;
  23. import org.apache.commons.lang.RandomStringUtils;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.apache.log4j.Logger;
  26. import org.json.JSONException;
  27. import org.json.JSONObject;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.context.annotation.Lazy;
  30. import org.springframework.stereotype.Service;
  31. import javax.crypto.SecretKey;
  32. import java.io.IOException;
  33. import java.net.HttpURLConnection;
  34. import java.net.URL;
  35. import java.text.SimpleDateFormat;
  36. import java.util.*;
  37. /**
  38. * user_info service接口实现类
  39. * Tue Apr 17 10:32:49 CST 2018 Suo Chen Cheng
  40. */
  41. @Service
  42. public class UserInfoServiceImpl implements UserInfoService {
  43. private static Logger logger = Logger.getLogger(UserInfoServiceImpl.class);
  44. private RongCloud rongCloud = RongCloud.getInstance(PropertiesFileLoader.getProperties("rongyunappkey"), PropertiesFileLoader.getProperties("rongyunappsecret"));
  45. @Autowired
  46. private UserInfoMapper userInfoMapper;
  47. @Autowired
  48. private SysRoleMapper sysRoleMapper;
  49. @Autowired
  50. private DepartInfoMapper departInfoMapper;
  51. @Autowired
  52. private OSSFileService ossFileService;
  53. @Autowired
  54. private AlipayTempMapper alipayTempMapper;
  55. @Autowired
  56. private RecommenderLogMapper recommenderLogMapper;
  57. @Autowired
  58. @Lazy
  59. private WxMaService wxMaService;
  60. @Override
  61. public List<UserInfo> getUserInfoList(UserInfo record) {
  62. logger.info("getUserInfoList");
  63. try {
  64. return userInfoMapper.queryAllUserInfo(record);
  65. } catch (Exception e) {
  66. logger.error("getUserInfoList", e);
  67. }
  68. return null;
  69. }
  70. @Override
  71. public List<UserInfo> getUserInfoByPage(Page page, UserInfo record) {
  72. logger.info("getUserInfoByPage");
  73. try {
  74. Map<String, Object> parameter = new HashMap<String, Object>();
  75. parameter.put("record", record);
  76. parameter.put(AppConstant.PAGE, page);
  77. return userInfoMapper.queryUserInfosByPage(parameter);
  78. } catch (Exception e) {
  79. logger.error("getUserInfoByPage", e);
  80. }
  81. return null;
  82. }
  83. @Override
  84. public UserInfo getUserInfoById(String id) {
  85. logger.info("getUserInfoById");
  86. try {
  87. return userInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
  88. } catch (Exception e) {
  89. logger.error("getUserInfoById", e);
  90. }
  91. return null;
  92. }
  93. @Override
  94. public UserInfo getUserInfo(UserInfo record) {
  95. logger.info("getUserInfo");
  96. try {
  97. return userInfoMapper.queryUserInfo(record);
  98. } catch (Exception e) {
  99. logger.error("getUserInfo", e);
  100. }
  101. return null;
  102. }
  103. @Override
  104. public UserInfo getSingleUserInfo(UserInfo record) {
  105. logger.info("getSingleUserInfo");
  106. try {
  107. return userInfoMapper.querySingleUserInfo(record);
  108. } catch (Exception e) {
  109. logger.error("getSingleUserInfo", e);
  110. }
  111. return null;
  112. }
  113. @Override
  114. public boolean createUserInfo(UserInfo record) {
  115. logger.info("createUserInfo");
  116. try {
  117. if (StringUtils.isNotEmpty(record.getPhone())) {//检测是否有推荐用户,并更新推荐人
  118. RecommenderLog recommenderLog = new RecommenderLog();
  119. recommenderLog.setTelephone(record.getPhone());
  120. recommenderLog = recommenderLogMapper.queryRecommenderLog(recommenderLog);
  121. if (recommenderLog != null) {
  122. record.setRecommender(recommenderLog.getUserId());
  123. }
  124. }
  125. if (StringUtils.isNotEmpty(record.getPassword())) {
  126. record.setPassword(MD5Util.getMD5(record.getPassword()));
  127. }
  128. int updates = userInfoMapper.insertSelective(record);
  129. if (updateUserRolesAndDeparts(record, updates)) return true;
  130. } catch (Exception e) {
  131. logger.error("createUserInfo", e);
  132. }
  133. return false;
  134. }
  135. // /**
  136. // * 用户注册赠送余额
  137. // *
  138. // * @param record
  139. // */
  140. // private void songMoney(UserInfo record) {
  141. //
  142. // try {
  143. //
  144. // String registerSong = systemVariableService.get("registerSong");
  145. // if (StringUtils.isNotEmpty(registerSong)) {
  146. //
  147. // int song = Integer.valueOf(registerSong);
  148. // if (song > 0) {
  149. // MemberCoin memberCoin = new MemberCoin();
  150. // memberCoin.setMoney(BigDecimal.valueOf(song));
  151. // memberCoin.setUserId(record.getId());
  152. // double money = memberCoin.getMoney().doubleValue();
  153. //
  154. //
  155. // int userId = Integer.valueOf(memberCoin.getUserId());
  156. // UserInfo userInfo = userInfoMapper.selectByPrimaryKey(record.getId());
  157. //
  158. // UserInfo updateUser = new UserInfo();
  159. // updateUser.setId(userId);
  160. //
  161. //
  162. // double balance = userInfo.getMoneyCoin();
  163. // double moneyCoin = balance + money;
  164. //
  165. // memberCoin.setCreateUser("管理员");
  166. // memberCoin.setBalance(BigDecimal.valueOf(moneyCoin));
  167. // memberCoin.setTypeFlag(AppConstant.CoinType.SONG);
  168. // memberCoin.setRemark("新用户注册,后台赠送:" + money + "余额");
  169. // memberCoinMapper.insertSelective(memberCoin);
  170. //
  171. // updateUser.setMoneyCoin(moneyCoin);
  172. // this.updateUserInfo(updateUser);
  173. // }
  174. // }
  175. //
  176. // } catch (Exception e) {
  177. // logger.error("新用户注册赠送余额异常", e);
  178. // }
  179. //
  180. //
  181. // }
  182. private boolean updateUserRolesAndDeparts(UserInfo record, int updates) {
  183. if (updates > 0) {
  184. if (StringUtils.isNotEmpty(record.getDepartId())) {
  185. departInfoMapper.clearUserDeparts(record.getId());
  186. departInfoMapper.setUserDeparts(record.getId(), Arrays.asList(record.getDepartId().split(",")));
  187. }
  188. if (StringUtils.isNotEmpty(record.getRoleId())) {
  189. sysRoleMapper.clearUserRoles(record.getId());
  190. sysRoleMapper.setUserRoles(record.getId(), Arrays.asList(record.getRoleId().split(",")));
  191. }
  192. return true;
  193. }
  194. return false;
  195. }
  196. @Override
  197. public boolean deleteUserInfo(String id) {
  198. logger.info("deleteUserInfo");
  199. try {
  200. int updates = userInfoMapper.delete(id);
  201. departInfoMapper.clearUserDeparts(Integer.valueOf(id));
  202. sysRoleMapper.clearUserRoles(Integer.valueOf(id));
  203. if (updates > 0) {
  204. return true;
  205. }
  206. } catch (Exception e) {
  207. logger.error("deleteUserInfo", e);
  208. }
  209. return false;
  210. }
  211. @Override
  212. public boolean updateUserInfo(UserInfo record) {
  213. logger.info("updateUserInfo");
  214. try {
  215. int updates = userInfoMapper.updateByPrimaryKeySelective(record);
  216. if (updateUserRolesAndDeparts(record, updates)) return true;
  217. } catch (Exception e) {
  218. logger.error("updateUserInfo", e);
  219. }
  220. return false;
  221. }
  222. @Override
  223. public boolean updatePassword(UserInfo record) {
  224. logger.info("updatePassword");
  225. try {
  226. if (record.getId() != null ||
  227. StringUtils.isNotEmpty(record.getUsername()) ||
  228. StringUtils.isNotEmpty(record.getPhone()) ||
  229. StringUtils.isNotEmpty(record.getMail())) {
  230. if (StringUtils.isNotEmpty(record.getPassword())) {
  231. record.setPassword(MD5Util.getMD5(record.getPassword()));
  232. }
  233. int updates = userInfoMapper.updatePassword(record);
  234. if (updates > 0) {
  235. return true;
  236. }
  237. }
  238. } catch (Exception e) {
  239. logger.error("updatePassword", e);
  240. }
  241. return false;
  242. }
  243. @Override
  244. public Result weiren(UserInfo record) {
  245. logger.info("weiren");
  246. try {
  247. if (record.getId() != null) {
  248. if (record.getLevelId() > 1) {//如果委任非普通会员,可以创建房间
  249. record.setCreateFlag("Y");
  250. }
  251. int updates = userInfoMapper.updateByPrimaryKeySelective(record);
  252. if (updates > 0) {
  253. return new Result(true, "委任成功");
  254. }
  255. }
  256. } catch (Exception e) {
  257. logger.error("weiren", e);
  258. }
  259. return new Result(false, "委任失败");
  260. }
  261. @Override
  262. public UserInfo login(String username, String password) {
  263. logger.info("login");
  264. try {
  265. Map<String, Object> map = new HashMap<>();
  266. map.put("username", username);
  267. map.put("password", MD5Util.getMD5(password));
  268. UserInfo result = userInfoMapper.login(map);
  269. return result;
  270. } catch (Exception e) {
  271. logger.error("login", e);
  272. }
  273. return null;
  274. }
  275. // @Override
  276. // public UserInfo loginSms(String phone, String code, String sessionId) throws LoginException {
  277. // logger.info("loginSms");
  278. //// SMSVerifyCodeResult sMSVerifyCodeResult;
  279. //// try {
  280. //// sMSVerifyCodeResult = rongCloud.sms.verifyCode(sessionId, code);
  281. //// } catch (Exception e) {
  282. //// e.printStackTrace();
  283. //// throw new LoginException("验证码错误");
  284. //// }
  285. // try {
  286. // if (code.toLowerCase().equals(sessionId)) {
  287. // UserInfo userInfo = new UserInfo();
  288. // userInfo.setPhone(phone);
  289. // userInfo = getUserInfo(userInfo);
  290. // if (userInfo == null) {
  291. // userInfo = new UserInfo();
  292. // userInfo.setPhone(phone);
  293. // userInfo.setUsername(phone);
  294. // userInfo.setNickname(phone);
  295. // userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png");
  296. // if (!createUserInfo(userInfo)) {
  297. // throw new LoginException("登录失败");
  298. // }
  299. // }
  300. // return userInfo;
  301. // }
  302. // } catch (Exception e) {
  303. // e.printStackTrace();
  304. // throw new LoginException("验证码错误");
  305. // }
  306. // throw new LoginException("验证码错误");
  307. // }
  308. @Override
  309. public UserInfo loginSms(String phone, String code, String sessionId) throws LoginException {
  310. logger.info("loginSms");
  311. SMSVerifyCodeResult sMSVerifyCodeResult;
  312. try {
  313. sMSVerifyCodeResult = rongCloud.sms.verifyCode(sessionId, code);
  314. } catch (Exception e) {
  315. e.printStackTrace();
  316. throw new LoginException("验证码错误");
  317. }
  318. if (200 == sMSVerifyCodeResult.getCode()) {
  319. Boolean success = sMSVerifyCodeResult.getSuccess();
  320. if (success) {
  321. UserInfo userInfo = new UserInfo();
  322. userInfo.setPhone(phone);
  323. userInfo = getUserInfo(userInfo);
  324. if (userInfo == null) {
  325. userInfo = new UserInfo();
  326. userInfo.setPhone(phone);
  327. userInfo.setUsername(phone);
  328. userInfo.setNickname(phone);
  329. userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png");
  330. if (!createUserInfo(userInfo)) {
  331. throw new LoginException("登录失败");
  332. }
  333. }
  334. return userInfo;
  335. }
  336. }
  337. throw new LoginException("验证码错误");
  338. }
  339. @Override
  340. public UserInfo loginAppToken(String token) {
  341. logger.info("loginAppToken");
  342. UserInfo userInfo = null;
  343. try {
  344. // AppToken appToken = sysAppTokenMapper.getToken(token);
  345. // if (appToken != null) {
  346. SecretKey key = Keys.hmacShaKeyFor(Base64.getDecoder().decode(PropertiesFileLoader.getProperties("jwtsecret").getBytes()));
  347. Jwt jwt = Jwts.parser()
  348. .setSigningKey(key)
  349. .parse(token);
  350. Claims claims = (Claims) jwt.getBody();
  351. if (claims.getExpiration() != null) {
  352. if (claims.getExpiration().before(new Date())) {
  353. return null;
  354. }
  355. }
  356. if (claims.getSubject().equals("guest")) {
  357. userInfo = new UserInfo();
  358. } else {
  359. userInfo = getUserInfoById(claims.getSubject());
  360. }
  361. // }
  362. } catch (Exception e) {
  363. logger.error("loginAppToken", e);
  364. }
  365. return userInfo;
  366. }
  367. @Override
  368. public List<String> findDepartLeader(String userId) {
  369. logger.info("findDepartLeader");
  370. try {
  371. return userInfoMapper.findDepartLeader(userId);
  372. } catch (Exception e) {
  373. logger.error("findDepartLeader", e);
  374. }
  375. return null;
  376. }
  377. @Override
  378. public List<String> findUserByRoleName(String roleName) {
  379. logger.info("findUserByRoleName");
  380. try {
  381. return userInfoMapper.findUserByRoleName(roleName);
  382. } catch (Exception e) {
  383. logger.error("findUserByRoleName", e);
  384. }
  385. return null;
  386. }
  387. public class LoginException extends Exception {
  388. public LoginException(String message) {
  389. super(message);
  390. }
  391. }
  392. @Override
  393. public UserInfo loginWechat(String code) {
  394. try {
  395. final String APP_ID = PropertiesFileLoader.getProperties("weixinappid");
  396. final String APP_SECRET = PropertiesFileLoader.getProperties("weixinsecret");
  397. String accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + APP_ID + "&secret=" + APP_SECRET + "&code=" + code
  398. + "&grant_type=authorization_code";
  399. JSONObject data = WeixinUtil.loadJSON(accessTokenUrl);
  400. logger.debug("微信授权获取access_token:\n" + data.toString(4));
  401. String openId = data.getString("openid");
  402. String access_token = data.getString("access_token");
  403. String userDataUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openId;
  404. JSONObject userData = WeixinUtil.loadJSON(userDataUrl);
  405. logger.debug("微信授权获取用户信息:\n" + userData.toString(4));
  406. UserInfo userInfo = new UserInfo();
  407. userInfo.setOpenId(openId);
  408. userInfo = getUserInfo(userInfo);
  409. if (userInfo != null) {
  410. return userInfo;
  411. }
  412. userInfo = new UserInfo();
  413. userInfo.setOpenId(openId);
  414. String nickname = userData.getString("nickname");
  415. userInfo.setNickname(nickname);
  416. userInfo.setUsername(nickname);
  417. try {
  418. String country = userData.getString("country");
  419. userInfo.setCountry(country);
  420. } catch (JSONException ignored) {
  421. }
  422. try {
  423. String province = userData.getString("province");
  424. userInfo.setProvince(province);
  425. } catch (JSONException ignored) {
  426. }
  427. try {
  428. String city = userData.getString("city");
  429. userInfo.setCity(city);
  430. } catch (JSONException ignored) {
  431. }
  432. int sex = 1;
  433. try {
  434. sex = userData.getInt("sex");
  435. } catch (JSONException ignored) {
  436. }
  437. userInfo.setSex(sex == 1 ? "男" : "女");
  438. String headimgurl = null;
  439. try {
  440. headimgurl = userData.getString("headimgurl");
  441. } catch (JSONException ignored) {
  442. }
  443. userInfo.setIcon(saveAvatar(headimgurl));
  444. if (createUserInfo(userInfo)) {
  445. return userInfo;
  446. }
  447. } catch (Exception e) {
  448. logger.error("loginWechat", e);
  449. }
  450. return null;
  451. }
  452. private String saveAvatar(String url) {
  453. String path;
  454. HttpURLConnection httpUrl = null;
  455. URL iconUrl = null;
  456. try {
  457. iconUrl = new URL(url);
  458. httpUrl = (HttpURLConnection) iconUrl.openConnection();
  459. httpUrl.connect();
  460. Random random = new Random();
  461. StringBuilder randomCode = new StringBuilder();
  462. for (int i = 0; i < 8; i++) {
  463. randomCode.append(Integer.toString(random.nextInt(36), 36));
  464. }
  465. String uploadPath = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode);
  466. path = ossFileService.upload(httpUrl.getInputStream(), uploadPath);
  467. } catch (IOException e) {
  468. path = "https://microball.oss-cn-hangzhou.aliyuncs.com/huanbaojia/icon_morentouxiang.png";
  469. e.printStackTrace();
  470. } finally {
  471. if (httpUrl != null) {
  472. httpUrl.disconnect();
  473. }
  474. }
  475. return path;
  476. }
  477. /**
  478. * <p>支付宝支付成功回调接口。充值</p>
  479. *
  480. * @param tradeNo
  481. * @param tradeStatus
  482. */
  483. @Override
  484. public void alipaySuccess(String tradeNo, String tradeStatus) {
  485. logger.info("alipaySuccess:支付宝支付成功回调接口 tradeNo:" + tradeNo + ", tradeStatus:" + tradeStatus);
  486. try {
  487. AlipayTemp alipayTemp = new AlipayTemp();
  488. alipayTemp.setOutTradeNo(tradeNo);
  489. alipayTemp = alipayTempMapper.queryAlipayTemp(alipayTemp);
  490. if (alipayTemp != null) {
  491. if (!AppConstant.Aliapi.TRADE_SUCCESS.equals(alipayTemp.getTradeStatus())) {
  492. UserInfo userInfo = this.getUserInfoById(alipayTemp.getOrderId());
  493. int cashPledge = userInfo.getCashPledge();
  494. UserInfo updateUser = new UserInfo();
  495. updateUser.setId(userInfo.getId());
  496. updateUser.setCashPledge(cashPledge + alipayTemp.getTotalAmount().intValue());
  497. if (userInfo.getApproveStep() == 3) {
  498. //如果是交押金状态,更新为完成。
  499. updateUser.setApproveStep(4);
  500. }
  501. this.updateUserInfo(updateUser);
  502. alipayTemp.setTradeStatus(tradeStatus);
  503. alipayTempMapper.updateByPrimaryKeySelective(alipayTemp);
  504. }
  505. }
  506. } catch (Exception e) {
  507. logger.error("alipaySuccess:支付宝支付成功回调接口异常 tradeNo:" + tradeNo + ", tradeStatus:" + tradeStatus, e);
  508. }
  509. }
  510. @Override
  511. public UserInfo loginMiniApp(String code) {
  512. try {
  513. WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(code);
  514. String openId = result.getOpenid();
  515. String sessionKey = result.getSessionKey();
  516. UserInfo userInfo = new UserInfo();
  517. userInfo.setOpenId(openId);
  518. userInfo = getUserInfo(userInfo);
  519. if (userInfo != null) {
  520. userInfo.setSessionKey(sessionKey);
  521. updateUserInfo(userInfo);
  522. return userInfo;
  523. }
  524. userInfo = new UserInfo();
  525. userInfo.setUsername(UUID.randomUUID().toString());
  526. userInfo.setNickname("用户" + RandomStringUtils.randomAlphabetic(6));
  527. userInfo.setOpenId(openId);
  528. userInfo.setIcon("https://microball.oss-cn-hangzhou.aliyuncs.com/awesomeAdmin/user.png");
  529. userInfo.setSessionKey(sessionKey);
  530. createUserInfo(userInfo);
  531. return userInfo;
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. return null;
  536. }
  537. @Override
  538. public Result getMiniAppUserInfo(String sessionKey, String rawData, String signature,
  539. String encryptedData, String iv) {
  540. // 用户信息校验
  541. if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  542. return new Result(false, "获取用户信息失败");
  543. }
  544. // 解密用户信息
  545. WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
  546. UserInfo userInfo = new UserInfo();
  547. userInfo.setOpenId(wxUserInfo.getOpenId());
  548. userInfo = getUserInfo(userInfo);
  549. String avatarUrl = "https://microball.oss-cn-hangzhou.aliyuncs.com/awesomeAdmin/user.png";
  550. try {
  551. avatarUrl = saveAvatar(wxUserInfo.getAvatarUrl());
  552. } catch (Exception e) {
  553. logger.error("获取头像失败", e);
  554. }
  555. if (userInfo == null) {
  556. userInfo = new UserInfo();
  557. userInfo.setUsername(UUID.randomUUID().toString());
  558. userInfo.setNickname(wxUserInfo.getNickName());
  559. userInfo.setOpenId(wxUserInfo.getOpenId());
  560. userInfo.setUnionId(wxUserInfo.getUnionId());
  561. userInfo.setIcon(avatarUrl);
  562. userInfo.setSex(Integer.valueOf(wxUserInfo.getGender()) == 1 ? "男" : "女");
  563. userInfo.setCountry(wxUserInfo.getCountry());
  564. userInfo.setProvince(wxUserInfo.getProvince());
  565. userInfo.setCity(wxUserInfo.getCity());
  566. createUserInfo(userInfo);
  567. } else {
  568. userInfo.setIcon(avatarUrl);
  569. userInfo.setNickname(wxUserInfo.getNickName());
  570. userInfo.setUnionId(wxUserInfo.getUnionId());
  571. userInfo.setSex(Integer.valueOf(wxUserInfo.getGender()) == 1 ? "男" : "女");
  572. userInfo.setCountry(wxUserInfo.getCountry());
  573. userInfo.setProvince(wxUserInfo.getProvince());
  574. userInfo.setCity(wxUserInfo.getCity());
  575. updateUserInfo(userInfo);
  576. }
  577. if (userInfo != null) {
  578. return new Result(true, userInfo);
  579. }
  580. return new Result(false, "获取用户信息失败");
  581. }
  582. }