|
@@ -1,14 +1,16 @@
|
1
|
1
|
package com.shigongli.controller;
|
2
|
2
|
|
|
3
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
4
|
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
3
|
5
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
6
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
7
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
|
-import com.shigongli.common.BaseController;
|
7
|
|
-import com.shigongli.common.JWTUtils;
|
8
|
|
-import com.shigongli.common.ResponseBean;
|
|
8
|
+import com.shigongli.common.*;
|
|
9
|
+import com.shigongli.vo.AuthPhoneParams;
|
9
|
10
|
import io.swagger.annotations.Api;
|
10
|
11
|
import io.swagger.annotations.ApiOperation;
|
11
|
12
|
import io.swagger.annotations.ApiParam;
|
|
13
|
+import me.chanjar.weixin.mp.api.WxMpService;
|
12
|
14
|
import org.slf4j.Logger;
|
13
|
15
|
import org.slf4j.LoggerFactory;
|
14
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -39,30 +41,30 @@ public class TaPersonController extends BaseController {
|
39
|
41
|
@Autowired
|
40
|
42
|
public ITaPersonService iTaPersonService;
|
41
|
43
|
|
42
|
|
-// @PostMapping("/ma/login")
|
43
|
|
-// public ResponseBean login(String code) {
|
44
|
|
-// // 用 code 去换 openid
|
45
|
|
-// String openid = "";
|
46
|
|
-//
|
47
|
|
-// // 先查询人员是否存在
|
48
|
|
-// TaPerson taPerson = iTaPersonService.getByOpenId(openid);
|
49
|
|
-//
|
50
|
|
-// // 如果人员不存在, 则新增
|
51
|
|
-// if (null == taPerson) {
|
52
|
|
-// taPerson = new TaPerson();
|
53
|
|
-// taPerson.setOpenid(openid);
|
54
|
|
-// iTaPersonService.save(taPerson);
|
55
|
|
-//// taPerson = iTaPersonService.getById(taPerson.getPersonId());
|
56
|
|
-// }
|
57
|
|
-//
|
58
|
|
-// // 生成 token
|
59
|
|
-// Map<String, Object> claims = new HashMap<>();
|
60
|
|
-// claims.put("personId", taPerson.getPersonId());
|
61
|
|
-// String token = JWTUtils.encode(claims);
|
62
|
|
-// taPerson.setToken(token);
|
63
|
|
-//
|
64
|
|
-// return ResponseBean.success(taPerson);
|
65
|
|
-// }
|
|
44
|
+ @Autowired
|
|
45
|
+ private WxUtils wxUtils;
|
|
46
|
+
|
|
47
|
+ @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "POST", response = ResponseBean.class)
|
|
48
|
+ @PostMapping("/ma/taPerson/phone")
|
|
49
|
+ public ResponseBean phone(@ApiParam("授权手机参数") @RequestBody AuthPhoneParams authPhoneParams,
|
|
50
|
+ HttpServletRequest request) {
|
|
51
|
+ if (null == authPhoneParams) {
|
|
52
|
+ return ResponseBean.error("请设置授权手机号的参数", ResponseBean.ERROR_UNAVAILABLE);
|
|
53
|
+ }
|
|
54
|
+ TaPerson taPerson = getPerson(request);
|
|
55
|
+ if (null == taPerson) {
|
|
56
|
+ return ResponseBean.error("校验用户失败, 请退出重新进入", ResponseBean.ERROR_UNAVAILABLE);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ WxMaService maService = wxUtils.getMaService();
|
|
60
|
+ WxMaPhoneNumberInfo phoneNoInfo = maService.getUserService().getPhoneNoInfo(authPhoneParams.getSessionKey(), authPhoneParams.getEncryptedData(), authPhoneParams.getIv());
|
|
61
|
+
|
|
62
|
+ String phone = phoneNoInfo.getPhoneNumber();
|
|
63
|
+ taPerson.setPhone(phone);
|
|
64
|
+ iTaPersonService.updateById(taPerson);
|
|
65
|
+
|
|
66
|
+ return ResponseBean.success(taPerson);
|
|
67
|
+ }
|
66
|
68
|
|
67
|
69
|
|
68
|
70
|
/**
|